From 7de8b6be396310b248a8c6d51f5f1dabe92eef70 Mon Sep 17 00:00:00 2001 From: ahodgkinson Date: Mon, 5 Jun 2006 22:59:36 +0000 Subject: [PATCH] Ported FLAIM to FTK. git-svn-id: https://svn.code.sf.net/p/flaim/code/trunk@509 0109f412-320b-0410-ab79-c3e0c5ffbbe6 --- flaim/Makefile | 886 ++-- flaim/src/Makefile.am | 183 - flaim/src/checksum.cpp | 628 +-- flaim/src/ecache.cpp | 722 ---- flaim/src/ecache.h | 164 - flaim/src/f64bitfh.cpp | 856 ---- flaim/src/f64bitfh.h | 154 - flaim/src/f_nici.cpp | 344 +- flaim/src/f_nici.h | 99 +- flaim/src/fblob.cpp | 32 +- flaim/src/fbuff.cpp | 518 --- flaim/src/fbuff.h | 276 -- flaim/src/fcs.cpp | 1756 +------- flaim/src/fcs.h | 328 +- flaim/src/fdb.cpp | 18 +- flaim/src/fdbcnfig.cpp | 136 +- flaim/src/fdbcopy.cpp | 203 +- flaim/src/fdbremov.cpp | 45 +- flaim/src/fdbrenam.cpp | 47 +- flaim/src/fdict.cpp | 659 +-- flaim/src/fdict.h | 2 +- flaim/src/fdir.h | 186 - flaim/src/fdynbtre.cpp | 1069 ----- flaim/src/fdynsset.cpp | 339 -- flaim/src/fdynsset.h | 601 --- flaim/src/ffilehdl.cpp | 705 ---- flaim/src/ffilehdl.h | 344 -- flaim/src/ffilehdr.cpp | 28 +- flaim/src/ffilesys.cpp | 1218 ------ flaim/src/ffilesys.h | 160 - flaim/src/fgedcom.cpp | 231 +- flaim/src/filesys.h | 34 +- flaim/src/flaim.h | 1905 ++------- flaim/src/flaim.vcproj | 1162 ------ flaim/src/flaim_static.vcproj | 1134 ----- flaim/src/flaimsys.h | 248 +- flaim/src/{ftksem.h => flaimtk.h} | 17 +- flaim/src/flalloc.cpp | 1464 ------- flaim/src/flbackup.cpp | 298 +- flaim/src/flchkdb.cpp | 430 +- flaim/src/flclose.cpp | 21 +- flaim/src/flconvrt.cpp | 2 +- flaim/src/flcreate.cpp | 90 +- flaim/src/flerror.cpp | 18 +- flaim/src/flfixed.cpp | 2128 ---------- flaim/src/flfixed.h | 445 -- flaim/src/flindex.cpp | 33 +- flaim/src/flist.cpp | 385 -- flaim/src/flist.h | 94 - flaim/src/flkeyret.cpp | 25 +- flaim/src/flmimon.h | 129 +- flaim/src/flmstat.cpp | 44 +- flaim/src/flmstat.h | 4 +- flaim/src/flog.cpp | 44 +- flaim/src/flopen.cpp | 491 +-- flaim/src/flprintf.cpp | 826 ---- flaim/src/flrddrct.cpp | 10 +- flaim/src/flreduce.cpp | 36 +- flaim/src/flsweep.cpp | 4 +- flaim/src/flutil.cpp | 706 ---- flaim/src/flverify.cpp | 12 +- flaim/src/fmisc.cpp | 91 - flaim/src/fmutxref.h | 95 - flaim/src/fnlm.cpp | 3946 ------------------ flaim/src/fnlm.h | 236 -- flaim/src/fntable.cpp | 42 +- flaim/src/fobjtrck.cpp | 789 ---- flaim/src/fobjtrck.h | 168 - flaim/src/fposix.cpp | 1598 ------- flaim/src/fposix.h | 225 - flaim/src/fqcur.cpp | 46 +- flaim/src/fqdecl.cpp | 12 +- flaim/src/fqeval.cpp | 51 +- flaim/src/fqget.cpp | 12 +- flaim/src/fqkeys.cpp | 18 +- flaim/src/fqlog.cpp | 3 +- flaim/src/fqopt.cpp | 78 +- flaim/src/fqparse.cpp | 103 + flaim/src/fqprep.cpp | 37 +- flaim/src/fqread.cpp | 6 +- flaim/src/fqsrch.cpp | 93 +- flaim/src/fqstack.cpp | 81 +- flaim/src/fquery.h | 19 +- flaim/src/frebuild.cpp | 366 +- flaim/src/frec.cpp | 175 +- flaim/src/frset.cpp | 1517 ------- flaim/src/frset.h | 666 --- flaim/src/frsetblk.cpp | 1339 ------ flaim/src/fsconvrt.cpp | 8 +- flaim/src/fscursor.cpp | 7 +- flaim/src/fscursor.h | 6 +- flaim/src/fsdatacu.cpp | 12 +- flaim/src/fslfileu.cpp | 104 +- flaim/src/fsrecget.cpp | 38 +- flaim/src/fsrecupd.cpp | 4 +- flaim/src/fsrvlock.cpp | 1282 ------ flaim/src/fsrvlock.h | 427 -- flaim/src/fssearch.cpp | 11 +- flaim/src/fstructs.h | 356 +- flaim/src/fsuperfl.cpp | 713 +--- flaim/src/fsuperfl.h | 201 +- flaim/src/fsv.cpp | 575 +-- flaim/src/fsv.h | 16 +- flaim/src/fsysdata.cpp | 2279 ++++------ flaim/src/ftext.cpp | 80 +- flaim/src/ftk.h | 1583 ------- flaim/src/ftkdir.cpp | 974 ----- flaim/src/ftkmem.h | 99 - flaim/src/ftkmisc.cpp | 784 ---- flaim/src/ftkmod.cpp | 384 -- flaim/src/ftknlm.h | 1714 -------- flaim/src/ftknsem.cpp | 354 -- flaim/src/ftknsem.h | 97 - flaim/src/ftkpath.cpp | 777 ---- flaim/src/ftkrand.cpp | 267 -- flaim/src/ftksem.cpp | 429 -- flaim/src/ftkthrd.cpp | 1062 ----- flaim/src/ftkthrd.h | 344 -- flaim/src/ftktime.cpp | 442 -- flaim/src/ftrace.cpp | 767 ---- flaim/src/ftrace.h | 238 -- flaim/src/ftrans.cpp | 2 +- flaim/src/furl.h | 2 +- flaim/src/fwin.cpp | 1757 -------- flaim/src/fwin.h | 235 -- flaim/src/fxml.cpp | 6334 ---------------------------- flaim/src/fxml.h | 529 --- flaim/src/gdpool.cpp | 381 -- flaim/src/imonbase.cpp | 6 +- flaim/src/imonchk.cpp | 105 +- flaim/src/imonerr.cpp | 40 - flaim/src/imonfact.cpp | 112 +- flaim/src/imonffil.cpp | 45 - flaim/src/imonfhdl.cpp | 805 ---- flaim/src/imonfmgr.cpp | 438 -- flaim/src/imonfram.cpp | 20 +- flaim/src/imonfsys.cpp | 266 +- flaim/src/imonix.cpp | 17 +- flaim/src/imonqury.cpp | 67 +- flaim/src/imonscfg.cpp | 3 - flaim/src/imonsel.cpp | 23 +- flaim/src/imonslmg.cpp | 190 - flaim/src/imonstat.cpp | 101 +- flaim/src/imonutil.cpp | 258 +- flaim/src/kybuild.cpp | 63 +- flaim/src/kycollat.cpp | 160 +- flaim/src/kyget.cpp | 37 +- flaim/src/lock.cpp | 89 +- flaim/src/nlmload.cpp | 442 -- flaim/src/nwyield.cpp | 258 -- flaim/src/rcache.cpp | 218 +- flaim/src/recover.cpp | 62 +- flaim/src/rfl.cpp | 148 +- flaim/src/rfl.h | 13 +- flaim/src/scache.cpp | 237 +- flaim/src/translog.cpp | 12 +- flaim/util/Makefile.am | 42 - flaim/util/basic_test.cpp | 27 +- flaim/util/checkdb.cpp | 376 +- flaim/util/dbshell.cpp | 1211 +----- flaim/util/dbshell.h | 45 +- flaim/util/flm_dlst.cpp | 160 +- flaim/util/flm_dlst.h | 8 +- flaim/util/flm_edit.cpp | 1349 +++--- flaim/util/flm_edit.h | 41 +- flaim/util/flm_lutl.cpp | 164 +- flaim/util/flm_lutl.h | 6 +- flaim/util/flmunittest.cpp | 129 +- flaim/util/flmunittest.h | 14 +- flaim/util/ftx.cpp | 6403 ----------------------------- flaim/util/ftx.h | 799 ---- flaim/util/ftxunix.cpp | 554 --- flaim/util/ftxunix.h | 56 - flaim/util/rebuild.cpp | 314 +- flaim/util/sharutil.cpp | 188 +- flaim/util/sharutil.h | 18 +- flaim/util/view.cpp | 370 +- flaim/util/view.h | 30 +- flaim/util/viewblk.cpp | 177 +- flaim/util/viewdisp.cpp | 22 +- flaim/util/viewedit.cpp | 44 +- flaim/util/viewfhdr.cpp | 30 +- flaim/util/viewlfil.cpp | 24 +- flaim/util/viewlhdr.cpp | 12 +- flaim/util/viewmenu.cpp | 177 +- flaim/util/viewsrch.cpp | 4 +- flaim/util/wpscreen.h | 153 - flaim/util/wpscrnkb.cpp | 831 ---- 188 files changed, 7093 insertions(+), 73582 deletions(-) delete mode 100644 flaim/src/Makefile.am delete mode 100644 flaim/src/ecache.cpp delete mode 100644 flaim/src/ecache.h delete mode 100644 flaim/src/f64bitfh.cpp delete mode 100644 flaim/src/f64bitfh.h delete mode 100644 flaim/src/fbuff.cpp delete mode 100644 flaim/src/fbuff.h delete mode 100644 flaim/src/fdir.h delete mode 100644 flaim/src/fdynbtre.cpp delete mode 100644 flaim/src/fdynsset.cpp delete mode 100644 flaim/src/fdynsset.h delete mode 100644 flaim/src/ffilehdl.cpp delete mode 100644 flaim/src/ffilehdl.h delete mode 100644 flaim/src/ffilesys.cpp delete mode 100644 flaim/src/ffilesys.h delete mode 100644 flaim/src/flaim.vcproj delete mode 100644 flaim/src/flaim_static.vcproj rename flaim/src/{ftksem.h => flaimtk.h} (75%) delete mode 100644 flaim/src/flalloc.cpp delete mode 100644 flaim/src/flfixed.cpp delete mode 100644 flaim/src/flfixed.h delete mode 100644 flaim/src/flist.cpp delete mode 100644 flaim/src/flist.h delete mode 100644 flaim/src/flprintf.cpp delete mode 100644 flaim/src/flutil.cpp delete mode 100644 flaim/src/fmutxref.h delete mode 100644 flaim/src/fnlm.cpp delete mode 100644 flaim/src/fnlm.h delete mode 100644 flaim/src/fobjtrck.cpp delete mode 100644 flaim/src/fobjtrck.h delete mode 100644 flaim/src/fposix.cpp delete mode 100644 flaim/src/fposix.h delete mode 100644 flaim/src/frset.cpp delete mode 100644 flaim/src/frset.h delete mode 100644 flaim/src/frsetblk.cpp delete mode 100644 flaim/src/fsrvlock.cpp delete mode 100644 flaim/src/fsrvlock.h delete mode 100644 flaim/src/ftk.h delete mode 100644 flaim/src/ftkdir.cpp delete mode 100644 flaim/src/ftkmem.h delete mode 100644 flaim/src/ftkmisc.cpp delete mode 100644 flaim/src/ftkmod.cpp delete mode 100644 flaim/src/ftknlm.h delete mode 100644 flaim/src/ftknsem.cpp delete mode 100644 flaim/src/ftknsem.h delete mode 100644 flaim/src/ftkpath.cpp delete mode 100644 flaim/src/ftkrand.cpp delete mode 100644 flaim/src/ftksem.cpp delete mode 100644 flaim/src/ftkthrd.cpp delete mode 100644 flaim/src/ftkthrd.h delete mode 100644 flaim/src/ftktime.cpp delete mode 100644 flaim/src/ftrace.cpp delete mode 100644 flaim/src/ftrace.h delete mode 100644 flaim/src/fwin.cpp delete mode 100644 flaim/src/fwin.h delete mode 100644 flaim/src/fxml.cpp delete mode 100644 flaim/src/fxml.h delete mode 100644 flaim/src/gdpool.cpp delete mode 100644 flaim/src/imonfhdl.cpp delete mode 100644 flaim/src/imonfmgr.cpp delete mode 100644 flaim/src/imonslmg.cpp delete mode 100644 flaim/src/nlmload.cpp delete mode 100644 flaim/src/nwyield.cpp delete mode 100644 flaim/util/Makefile.am delete mode 100644 flaim/util/ftx.cpp delete mode 100644 flaim/util/ftx.h delete mode 100644 flaim/util/ftxunix.cpp delete mode 100644 flaim/util/ftxunix.h delete mode 100644 flaim/util/wpscreen.h delete mode 100644 flaim/util/wpscrnkb.cpp diff --git a/flaim/Makefile b/flaim/Makefile index f487236..df3be1f 100644 --- a/flaim/Makefile +++ b/flaim/Makefile @@ -37,125 +37,9 @@ # -- Project -- project_name = flaim +project_display_name = FLAIM project_desc = An extensible, flexible, adaptable, embeddable database engine -# -- Subversion Revision -- - -calc_svn_revision = - -ifneq (,$(findstring ignore-local-mods,$(MAKECMDGOALS))) - submake_targets += ignore-local-mods - ignore_local_mods = 1 -endif - -ifneq (,$(findstring ilm,$(MAKECMDGOALS))) - submake_targets += ilm - ignore_local_mods = 1 -endif - -ifdef ignore_local_mods - local_mods_ok = 1 -else - local_mods_ok = -endif - -ifneq (,$(findstring dist,$(MAKECMDGOALS))) - calc_svn_revision = 1 - ifndef ignore_local_mods - local_mods_ok = - endif -endif - -ifneq (,$(findstring rpm,$(MAKECMDGOALS))) - calc_svn_revision = 1 - ifndef ignore_local_mods - local_mods_ok = - endif -endif - -ifneq (,$(findstring pathinfo,$(MAKECMDGOALS))) - calc_svn_revision = 1 - ifndef ignore_local_mods - local_mods_ok = - endif -endif - -ifneq (,$(findstring changelog,$(MAKECMDGOALS))) - - calc_svn_revision = 1 - - # Get the info for this directory - - ifndef svn_user - $(error Must define svn_user= in environment or as a parameter) - endif - - ifndef svn_rev - $(error Must define svn_rev= in environment or as a parameter) - endif - - svnrevs = $(subst :, ,$(svn_rev)) - svn_low_rev = $(word 1,$(svnrevs)) - svn_high_rev = $(word 2,$(svnrevs)) - - svnurl0 := $(shell svn info) - svnurl1 = $(subst URL: ,URL:,$(svnurl0)) - svnurl2 = $(filter URL:%,$(svnurl1)) - svnurl3 = $(subst URL:,,$(svnurl2)) - svnurl = $(subst ://,://$(svn_user)@,$(svnurl3)) -endif - -ifdef calc_svn_revision - - # Get the info for all files. - - ifndef local_mods_ok - srevision := $(shell svnversion . -n) - - ifneq (,$(findstring M,$(srevision))) - $(error Local modifications found - please check in before making distro) - endif - - ifneq (,$(findstring :,$(srevision))) - $(error Mixed revisions in repository - please update before making distro) - endif - endif - - numdigits = $(words $(subst 9,9 ,$(subst 8,8 ,$(subst 7,7 ,\ - $(subst 6,6 ,$(subst 5,5 ,$(subst 4,4 ,$(subst 3,3 ,\ - $(subst 2,2 ,$(subst 1,1 ,$(subst 0,0 ,$(1)))))))))))) - revision0 := $(shell svn info -R) - revision1 = $(subst Last Changed Rev: ,LastChangedRev:,$(revision0)) - revision2 = $(filter LastChangedRev:%,$(revision1)) - revision3 = $(subst LastChangedRev:,,$(revision2)) - revision4 = $(sort $(revision3)) - revision5 = $(foreach num,$(revision4),$(call numdigits,$(num)):$(num)) - revision6 = $(sort $(revision5)) - revision7 = $(word $(words $(revision6)),$(revision6)) - svn_revision = $(word 2,$(subst :, ,$(revision7))) - -else - ifeq "$(wildcard SVNRevision.*)" "" - svn_revision = 0 - else - svn_revision = $(word 2,$(subst ., ,$(wildcard SVNRevision.*))) - endif -endif - -ifeq "$(svn_high_rev)" "" - svn_high_rev = $(svn_revision) -endif - -# -- Paths initializations -- - -ifndef rpm_build_root - ifneq (,$(DESTDIR)) - rpm_build_root = $(DESTDIR)/ - else - rpm_build_root = - endif -endif - # -- Versions -- major_version = 4 @@ -650,6 +534,7 @@ dollar := \044 question := \077 asterisk := \052 dash := \055 +backslash := \134 # -- Tools -- @@ -657,6 +542,135 @@ ifdef unix_target gprintf = printf else gprintf = $(call hostpath,$(tooldir)/printf.exe) + +# Determine the toolkit directory + +ifeq "$(wildcard $(topdir)/ftk)" "" + ftk_dir := $(dir $(topdir))ftk +else + ftk_dir := $(topdir)/ftk +endif + +ftk_src_dir = $(ftk_dir)/src + +# -- Subversion Revision -- + +calc_svn_revision = +ignore_local_mods = + +ifneq (,$(findstring ignore-local-mods,$(MAKECMDGOALS))) + submake_targets += ignore-local-mods + ignore_local_mods = 1 +endif + +ifneq (,$(findstring ilm,$(MAKECMDGOALS))) + submake_targets += ilm + ignore_local_mods = 1 +endif + +ifdef ignore_local_mods + local_mods_ok = 1 +else + local_mods_ok = +endif + +ifneq (,$(findstring dist,$(MAKECMDGOALS))) + calc_svn_revision = 1 + ifndef ignore_local_mods + local_mods_ok = + endif +endif + +ifneq (,$(findstring rpm,$(MAKECMDGOALS))) + calc_svn_revision = 1 + ifndef ignore_local_mods + local_mods_ok = + endif +endif + +ifneq (,$(findstring docs,$(MAKECMDGOALS))) + calc_svn_revision = 1 + ifndef ignore_local_mods + local_mods_ok = + endif +endif + +ifneq (,$(findstring changelog,$(MAKECMDGOALS))) + + calc_svn_revision = 1 + + # Get the info for this directory + + ifndef svn_user + $(error Must define svn_user= in environment or as a parameter) + endif + + ifndef svn_rev + $(error Must define svn_rev= in environment or as a parameter) + endif + + svnrevs = $(subst :, ,$(svn_rev)) + svn_low_rev = $(word 1,$(svnrevs)) + svn_high_rev = $(word 2,$(svnrevs)) + + svnurl0 := $(shell svn info) + svnurl1 = $(subst URL: ,URL:,$(svnurl0)) + svnurl2 = $(filter URL:%,$(svnurl1)) + svnurl3 = $(subst URL:,,$(svnurl2)) + svnurl = $(subst ://,://$(svn_user)@,$(svnurl3)) +endif + +ifdef calc_svn_revision + + # Get the info for all files. + + ifndef local_mods_ok + srevision := $(shell svnversion . -n) + + ifneq (,$(findstring M,$(srevision))) + $(error Local modifications found - please check in before making distro) + endif + + ifneq (,$(findstring :,$(srevision))) + $(error Mixed revisions in repository - please update before making distro) + endif + + srevision := $(shell svnversion $(ftk_dir) -n) + + ifneq (,$(findstring M,$(srevision))) + $(error Local modifications found - please check in before making distro) + endif + + ifneq (,$(findstring :,$(srevision))) + $(error Mixed revisions in repository - please update before making distro) + endif + endif + + numdigits = $(words $(subst 9,9 ,$(subst 8,8 ,$(subst 7,7 ,\ + $(subst 6,6 ,$(subst 5,5 ,$(subst 4,4 ,$(subst 3,3 ,\ + $(subst 2,2 ,$(subst 1,1 ,$(subst 0,0 ,$(1)))))))))))) + revision0 := $(shell svn info -R . $(ftk_dir)) + revision1 = $(subst Last Changed Rev: ,LastChangedRev:,$(revision0)) + revision2 = $(filter LastChangedRev:%,$(revision1)) + revision3 = $(subst LastChangedRev:,,$(revision2)) + revision4 = $(sort $(revision3)) + revision5 = $(foreach num,$(revision4),$(call numdigits,$(num)):$(num)) + revision6 = $(sort $(revision5)) + revision7 = $(word $(words $(revision6)),$(revision6)) + svn_revision = $(word 2,$(subst :, ,$(revision7))) + +else + ifeq "$(wildcard SVNRevision.*)" "" + svn_revision = 0 + else + svn_revision = $(word 2,$(subst ., ,$(wildcard SVNRevision.*))) + endif +endif + +ifeq "$(svn_high_rev)" "" + svn_high_rev = $(svn_revision) +endif + endif # Files and Directories @@ -671,11 +685,19 @@ ifndef lib_dir_name lib_dir_name = lib endif +ifndef rpm_build_root + ifneq (,$(DESTDIR)) + rpm_build_root = $(DESTDIR)/ + else + rpm_build_root = + endif +endif + lib_install_dir = $(rpm_build_root)$(install_prefix)/$(lib_dir_name) include_install_dir = $(rpm_build_root)$(install_prefix)/include pkgconfig_install_dir = $(lib_install_dir)/pkgconfig build_output_dir = $(topdir)/build -docs_output_dir = $(build_output_dir)/docs +doxygen_output_dir = $(build_output_dir)/docs target_path = $(build_output_dir)/$(target_os_family)-$(target_processor_family)-$(target_word_size)/$(target_build_type) @@ -712,7 +734,7 @@ rpm_name = $(package_proj_name_and_ver)-$(package_release_num).$(HOSTTYPE).rpm srpm_name = $(package_proj_name_and_ver)-$(package_release_num).src.rpm develrpm_name = $(package_proj_name)-devel-$(version)-$(package_release_num).$(HOSTTYPE).rpm -inc_dirs = src util +inc_dirs = src util $(ftk_src_dir) util_dir = $(target_path)/util test_dir = $(target_path)/test sample_dir = $(target_path)/sample @@ -731,6 +753,8 @@ else lib_sobj_dir = $(lib_obj_dir) endif +doxyfile = $(doxygen_output_dir)/Doxyfile + # -- Tools -- libr = @@ -913,7 +937,7 @@ ifdef unix_target ifeq ($(target_os_family),solaris) ifeq ($(usenativecc),yes) - ccflags += -KPIC -errwarn=%all -errtags -erroff=hidef,inllargeuse + ccflags += -KPIC -errwarn=%all -errtags -erroff=hidef,inllargeuse,doubunder ifeq ($(target_word_size),64) ccflags += -xarch=generic64 else @@ -947,6 +971,10 @@ ifdef unix_target endif endif + ifeq ($(target_os_family),osx) + ccdefs += OSX + endif + ccdefs += _REENTRANT ifeq ($(target_build_type),debug) @@ -984,7 +1012,7 @@ ifdef unix_target exe_link_libs = -lpthread ifeq ($(target_os_family),linux) - lib_link_libs += -lrt -lstdc++ -ldl + lib_link_libs += -lrt -lstdc++ -ldl -lncurses exe_link_libs += -lrt -lstdc++ -ldl -lncurses shared_link_flags += -shared -Wl,-Bsymbolic -fpic \ -Wl,-soname,$(@F).1 -o $@ @@ -1002,23 +1030,23 @@ ifdef unix_target endif endif - lib_link_libs += -lm -lc -ldl -lsocket -lnsl -lrt + lib_link_libs += -lm -lc -ldl -lsocket -lnsl -lrt -lcurses exe_link_libs += -lm -lc -ldl -lsocket -lnsl -lrt -lcurses endif ifeq ($(target_os_family),aix) - lib_link_libs += -lm -lc + lib_link_libs += -lm -lc -lcurses exe_link_libs += -lm -lc -lcurses endif ifeq ($(target_os_family),hpux) - lib_link_libs += -lm -lc -lrt + lib_link_libs += -lm -lc -lrt -lcurses exe_link_libs += -lm -lc -lrt -lcurses endif ifeq ($(target_os_family),osx) shared_lib_suffix = -$(major_version).$(so_current).dylib - lib_link_libs += -lstdc++ -ldl + lib_link_libs += -lstdc++ -ldl -lncurses exe_link_libs += -lstdc++ -ldl -lncurses shared_link_flags += -dynamiclib shared_link_flags += -current_version $(major_version).$(so_current).$(so_revision) @@ -1051,9 +1079,13 @@ ifdef netware_target wc_dir = $(WC_DIR) endif - ifndef wc_dir - $(error Target operating system could not be determined) + wc_dir := $(call normpath,$(wc_dir)) + + ifndef ndk_dir + $(error Netware SDK could not be found. Please define ndk_dir.) endif + + ndk_dir := $(call normpath,$(ndk_dir)) libr = "$(call normpath,$(strip $(wc_dir)))/binnt/wlib.exe" exe_linker = "$(call normpath,$(strip $(wc_dir)))/binnt/wlink.exe" @@ -1075,192 +1107,221 @@ ifdef netware_target libflags += /b /q /p=256 link_flags = /m /l /v /s + inc_dirs += $(ndk_dir)/libc/include \ + $(ndk_dir)/libc/include/winsock + export include = $(foreach inc_dir,$(strip $(inc_dirs)),$(call hostpath,$(inc_dir));) export INCLUDE = $(include) export wpp386 = /d$(subst $(sp), /d,$(strip $(ccdefs))) $(ccflags) export wcc386 = /d$(subst $(sp), /d,$(strip $(ccdefs))) $(ccflags) +# define make_lis_file_cmd +# $(ec)$(gprintf) "option verbose\n" > $(4) +# $(ec)$(gprintf) "option stack=32k\n" >> $(4) +# $(ec)$(gprintf) "option synchronize\n" >> $(4) +# $(ec)$(gprintf) "option nod\n" >> $(4) +# $(ec)$(gprintf) "option map\n" >> $(4) +# $(ec)$(gprintf) "option start=FlmLoad, exit=FlmUnload, caseexact\n" >> $(4) +# $(ec)$(gprintf) "option nodefaultlibs\n" >> $(4) +# $(ec)$(gprintf) "option screenname 'NONE'\n" >> $(4) +# $(ec)$(gprintf) "option threadname '$(2)'\n" >> $(4) +# $(ec)$(gprintf) "debug all debug novell\n" >> $(4) +# $(ec)$(gprintf) "form novell nlm '$(2)'\n" >> $(4) +# $(ec)$(gprintf) "name $(call ppath,$(1)/$(2)$(exe_suffix))\n" >> $(4) +# +# $(ec)$(gprintf) "import __WSAFDIsSet\n" >> $(4) +# $(ec)$(gprintf) "import ActivateScreen\n" >> $(4) +# $(ec)$(gprintf) "import Alloc\n" >> $(4) +# $(ec)$(gprintf) "import AllocateResourceTag\n" >> $(4) +# $(ec)$(gprintf) "import atomic_dec\n" >> $(4) +# $(ec)$(gprintf) "import atomic_inc\n" >> $(4) +# $(ec)$(gprintf) "import atomic_xchg\n" >> $(4) +# $(ec)$(gprintf) "import BitTest\n" >> $(4) +# $(ec)$(gprintf) "import CEvaluateExpression\n" >> $(4) +# $(ec)$(gprintf) "import CFindLoadModuleHandle\n" >> $(4) +# $(ec)$(gprintf) "import CheckKeyStatus\n" >> $(4) +# $(ec)$(gprintf) "import ClearScreen\n" >> $(4) +# $(ec)$(gprintf) "import CloseFile\n" >> $(4) +# $(ec)$(gprintf) "import CloseScreen\n" >> $(4) +# $(ec)$(gprintf) "import CMovB\n" >> $(4) +# $(ec)$(gprintf) "import CMoveFast\n" >> $(4) +# $(ec)$(gprintf) "import ConvertPathString\n" >> $(4) +# $(ec)$(gprintf) "import ConvertSecondsToTicks\n" >> $(4) +# $(ec)$(gprintf) "import ConvertTicksToSeconds\n" >> $(4) +# $(ec)$(gprintf) "import CpuCurrentProcessor\n" >> $(4) +# $(ec)$(gprintf) "import CreateDirectory\n" >> $(4) +# $(ec)$(gprintf) "import CreateFile\n" >> $(4) +# $(ec)$(gprintf) "import CSetD\n" >> $(4) +# $(ec)$(gprintf) "import DebuggerSymbolList\n" >> $(4) +# $(ec)$(gprintf) "import DeleteDirectory\n" >> $(4) +# $(ec)$(gprintf) "import DirectorySearch\n" >> $(4) +# $(ec)$(gprintf) "import DirectReadFile\n" >> $(4) +# $(ec)$(gprintf) "import DirectWriteFile\n" >> $(4) +# $(ec)$(gprintf) "import DirectWriteFile\n" >> $(4) +# $(ec)$(gprintf) "import DirectWriteFileNoWait\n" >> $(4) +# $(ec)$(gprintf) "import DirectWriteFileNoWait\n" >> $(4) +# $(ec)$(gprintf) "import DisableInputCursor\n" >> $(4) +# $(ec)$(gprintf) "import DisplayScreenTextWithAttribute\n" >> $(4) +# $(ec)$(gprintf) "import DOSFirstByteBitMap\n" >> $(4) +# $(ec)$(gprintf) "import EnableInputCursor\n" >> $(4) +# $(ec)$(gprintf) "import EnterDebugger\n" >> $(4) +# $(ec)$(gprintf) "import EraseFile\n" >> $(4) +# $(ec)$(gprintf) "import ExpandFileInContiguousBlocks\n" >> $(4) +# $(ec)$(gprintf) "import ExpandFileInContiguousBlocks\n" >> $(4) +# $(ec)$(gprintf) "import ExportPublicSymbol\n" >> $(4) +# $(ec)$(gprintf) "import FindAndLoadNLM\n" >> $(4) +# $(ec)$(gprintf) "import Free\n" >> $(4) +# $(ec)$(gprintf) "import FreeLimboVolumeSpace\n" >> $(4) +# $(ec)$(gprintf) "import FreeLimboVolumeSpace\n" >> $(4) +# $(ec)$(gprintf) "import GetCacheBufferSize\n" >> $(4) +# $(ec)$(gprintf) "import GetClosestSymbol\n" >> $(4) +# $(ec)$(gprintf) "import GetCurrentClock\n" >> $(4) +# $(ec)$(gprintf) "import GetCurrentNumberOfCacheBuffers\n" >> $(4) +# $(ec)$(gprintf) "import GetCurrentTime\n" >> $(4) +# $(ec)$(gprintf) "import GetEntryFromPathStringBase\n" >> $(4) +# $(ec)$(gprintf) "import GetEntryFromPathStringBase\n" >> $(4) +# $(ec)$(gprintf) "import GetFileSize\n" >> $(4) +# $(ec)$(gprintf) "import GetKey\n" >> $(4) +# $(ec)$(gprintf) "import GetNLMAllocMemoryCounts\n" >> $(4) +# $(ec)$(gprintf) "import GetOriginalNumberOfCacheBuffers\n" >> $(4) +# $(ec)$(gprintf) "import GetProductMajorVersionNumber\n" >> $(4) +# $(ec)$(gprintf) "import GetRunningProcess\n" >> $(4) +# $(ec)$(gprintf) "import GetScreenSize\n" >> $(4) +# $(ec)$(gprintf) "import GetSyncClockFields\n" >> $(4) +# $(ec)$(gprintf) "import GetSystemConsoleScreen\n" >> $(4) +# $(ec)$(gprintf) "import ImportPublicSymbol\n" >> $(4) +# $(ec)$(gprintf) "import kCreateThread\n" >> $(4) +# $(ec)$(gprintf) "import kCurrentThread\n" >> $(4) +# $(ec)$(gprintf) "import kDelayThread\n" >> $(4) +# $(ec)$(gprintf) "import kDestroyThread\n" >> $(4) +# $(ec)$(gprintf) "import kExitThread\n" >> $(4) +# $(ec)$(gprintf) "import kGetThreadName\n" >> $(4) +# $(ec)$(gprintf) "import kGetThreadName\n" >> $(4) +# $(ec)$(gprintf) "import KillMe\n" >> $(4) +# $(ec)$(gprintf) "import kMutexAlloc\n" >> $(4) +# $(ec)$(gprintf) "import kMutexFree\n" >> $(4) +# $(ec)$(gprintf) "import kMutexLock\n" >> $(4) +# $(ec)$(gprintf) "import kMutexUnlock\n" >> $(4) +# $(ec)$(gprintf) "import kQueCount\n" >> $(4) +# $(ec)$(gprintf) "import kReturnCurrentProcessorID\n" >> $(4) +# $(ec)$(gprintf) "import kScheduleThread\n" >> $(4) +# $(ec)$(gprintf) "import kSemaphoreAlloc\n" >> $(4) +# $(ec)$(gprintf) "import kSemaphoreExamineCount\n" >> $(4) +# $(ec)$(gprintf) "import kSemaphoreFree\n" >> $(4) +# $(ec)$(gprintf) "import kSemaphoreSignal\n" >> $(4) +# $(ec)$(gprintf) "import kSemaphoreTimedWait\n" >> $(4) +# $(ec)$(gprintf) "import kSemaphoreWait\n" >> $(4) +# $(ec)$(gprintf) "import kSetThreadLoadHandle\n" >> $(4) +# $(ec)$(gprintf) "import kSetThreadName\n" >> $(4) +# $(ec)$(gprintf) "import kYieldIfTimeSliceUp\n" >> $(4) +# $(ec)$(gprintf) "import kYieldThread\n" >> $(4) +# $(ec)$(gprintf) "import LoadModule\n" >> $(4) +# $(ec)$(gprintf) "import LoadRules\n" >> $(4) +# $(ec)$(gprintf) "import MapFileHandleToFCB\n" >> $(4) +# $(ec)$(gprintf) "import MapPathToDirectoryNumber\n" >> $(4) +# $(ec)$(gprintf) "import MapPathToDirectoryNumber\n" >> $(4) +# $(ec)$(gprintf) "import MapVolumeNameToNumber\n" >> $(4) +# $(ec)$(gprintf) "import ModifyDirectoryEntry\n" >> $(4) +# $(ec)$(gprintf) "import ModifyDirectoryEntry\n" >> $(4) +# $(ec)$(gprintf) "import MountVolume\n" >> $(4) +# $(ec)$(gprintf) "import NDSCreateStreamFile\n" >> $(4) +# $(ec)$(gprintf) "import NDSDeleteStreamFile\n" >> $(4) +# $(ec)$(gprintf) "import NDSOpenStreamFile\n" >> $(4) +# $(ec)$(gprintf) "import NWLocalToUnicode\n" >> $(4) +# $(ec)$(gprintf) "import NWUnicodeToLocal\n" >> $(4) +# $(ec)$(gprintf) "import OpenFile\n" >> $(4) +# $(ec)$(gprintf) "import OpenScreen\n" >> $(4) +# $(ec)$(gprintf) "import OutputToScreen\n" >> $(4) +# $(ec)$(gprintf) "import PositionInputCursor\n" >> $(4) +# $(ec)$(gprintf) "import PositionOutputCursor\n" >> $(4) +# $(ec)$(gprintf) "import ReadFile\n" >> $(4) +# $(ec)$(gprintf) "import RenameEntry\n" >> $(4) +# $(ec)$(gprintf) "import RestartServer\n" >> $(4) +# $(ec)$(gprintf) "import ReturnResourceTag\n" >> $(4) +# $(ec)$(gprintf) "import ReturnVolumeMappingInformation\n" >> $(4) +# $(ec)$(gprintf) "import ReturnVolumeMappingInformation\n" >> $(4) +# $(ec)$(gprintf) "import RevokeFileHandleRights\n" >> $(4) +# $(ec)$(gprintf) "import SetCursorStyle\n" >> $(4) +# $(ec)$(gprintf) "import SetFileSize\n" >> $(4) +# $(ec)$(gprintf) "import SetFileSize\n" >> $(4) +# $(ec)$(gprintf) "import SGUIDCreate\n" >> $(4) +# $(ec)$(gprintf) "import SizeOfAllocBlock\n" >> $(4) +# $(ec)$(gprintf) "import StopBell\n" >> $(4) +# $(ec)$(gprintf) "import SwitchToDirectFileMode\n" >> $(4) +# $(ec)$(gprintf) "import SwitchToDirectFileMode\n" >> $(4) +# $(ec)$(gprintf) "import UngetKey\n" >> $(4) +# $(ec)$(gprintf) "import UnImportPublicSymbol\n" >> $(4) +# $(ec)$(gprintf) "import UnloadRules\n" >> $(4) +# $(ec)$(gprintf) "import VMGetDirectoryEntry\n" >> $(4) +# $(ec)$(gprintf) "import WorkToDoListHead\n" >> $(4) +# $(ec)$(gprintf) "import WriteFile\n" >> $(4) +# $(ec)$(gprintf) "import WS2_32_bind\n" >> $(4) +# $(ec)$(gprintf) "import WS2_32_closesocket\n" >> $(4) +# $(ec)$(gprintf) "import WS2_32_gethostbyaddr\n" >> $(4) +# $(ec)$(gprintf) "import WS2_32_gethostbyname\n" >> $(4) +# $(ec)$(gprintf) "import WS2_32_gethostname\n" >> $(4) +# $(ec)$(gprintf) "import WS2_32_htonl\n" >> $(4) +# $(ec)$(gprintf) "import WS2_32_htons\n" >> $(4) +# $(ec)$(gprintf) "import WS2_32_inet_addr\n" >> $(4) +# $(ec)$(gprintf) "import WS2_32_inet_ntoa\n" >> $(4) +# $(ec)$(gprintf) "import WS2_32_listen\n" >> $(4) +# $(ec)$(gprintf) "import WS2_32_recv\n" >> $(4) +# $(ec)$(gprintf) "import WS2_32_select\n" >> $(4) +# $(ec)$(gprintf) "import WS2_32_send\n" >> $(4) +# $(ec)$(gprintf) "import WS2_32_setsockopt\n" >> $(4) +# $(ec)$(gprintf) "import WS2_32_shutdown\n" >> $(4) +# $(ec)$(gprintf) "import WS2_32_socket\n" >> $(4) +# $(ec)$(gprintf) "import WSAAccept\n" >> $(4) +# $(ec)$(gprintf) "import WSACleanup\n" >> $(4) +# $(ec)$(gprintf) "import WSAConnect\n" >> $(4) +# $(ec)$(gprintf) "import WSAGetLastError\n" >> $(4) +# $(ec)$(gprintf) "import WSAStartup\n" >> $(4) +# $(ec)$(gprintf) "file $(subst $(sp),\nfile ,$(call ppath,$(3)))\n" >> $(4) +# $(ec)$(gprintf) "file $(call ppath,$(wc_dir)/lib386/plib3s.lib(ctorarst))\n" >> $(4) +# $(ec)$(gprintf) "file $(call ppath,$(wc_dir)/lib386/plib3s.lib(dtorarst))\n" >> $(4) +# $(ec)$(gprintf) "file $(call ppath,$(wc_dir)/lib386/plib3s.lib(undefed))\n" >> $(4) +# $(ec)$(gprintf) "file $(call ppath,$(wc_dir)/lib386/plib3s.lib(undefmbd))\n" >> $(4) +# $(ec)$(gprintf) "file $(call ppath,$(wc_dir)/lib386/plib3s.lib(pure_err))\n" >> $(4) +# $(ec)$(gprintf) "file $(call ppath,$(wc_dir)/lib386/plib3s.lib(stablcl))\n" >> $(4) +# $(ec)$(gprintf) "file $(call ppath,$(wc_dir)/lib386/plib3s.lib(stabact))\n" >> $(4) +# $(ec)$(gprintf) "file $(call ppath,$(wc_dir)/lib386/plib3s.lib(stabactv))\n" >> $(4) +# $(ec)$(gprintf) "file $(call ppath,$(wc_dir)/lib386/plib3s.lib(stabmod))\n" >> $(4) +# $(ec)$(gprintf) "file $(call ppath,$(wc_dir)/lib386/plib3s.lib(prwdata))\n" >> $(4) +# $(ec)$(gprintf) "file $(call ppath,$(wc_dir)/lib386/plib3s.lib(moddtorr))\n" >> $(4) +# $(ec)$(gprintf) "file $(call ppath,$(wc_dir)/lib386/plib3s.lib(stabadt))\n" >> $(4) +# $(ec)$(gprintf) "file $(call ppath,$(wc_dir)/lib386/netware/clib3s.lib(i8d))\n" >> $(4) +# $(ec)$(gprintf) "file $(call ppath,$(wc_dir)/lib386/netware/clib3s.lib(i8m))\n" >> $(4) +# $(ec)$(gprintf) "file $(call ppath,$(wc_dir)/lib386/netware/clib3s.lib(i8s))\n" >> $(4) +# $(ec)$(gprintf) "library $(call ppath,$(flaim_static_lib))\n" >> $(4) +# endef + define make_lis_file_cmd $(ec)$(gprintf) "option verbose\n" > $(4) $(ec)$(gprintf) "option stack=32k\n" >> $(4) $(ec)$(gprintf) "option synchronize\n" >> $(4) $(ec)$(gprintf) "option nod\n" >> $(4) $(ec)$(gprintf) "option map\n" >> $(4) - $(ec)$(gprintf) "option start=FlmLoad, exit=FlmUnload, caseexact\n" >> $(4) $(ec)$(gprintf) "option nodefaultlibs\n" >> $(4) $(ec)$(gprintf) "option screenname 'NONE'\n" >> $(4) $(ec)$(gprintf) "option threadname '$(2)'\n" >> $(4) + $(ec)$(gprintf) "option start = _LibCPrelude\n" >> $(4) + $(ec)$(gprintf) "option exit = _LibCPostlude\n" >> $(4) + $(ec)$(gprintf) "option pseudopreemption\n" >> $(4) $(ec)$(gprintf) "debug all debug novell\n" >> $(4) $(ec)$(gprintf) "form novell nlm '$(2)'\n" >> $(4) $(ec)$(gprintf) "name $(call ppath,$(1)/$(2)$(exe_suffix))\n" >> $(4) - - $(ec)$(gprintf) "import __WSAFDIsSet\n" >> $(4) - $(ec)$(gprintf) "import ActivateScreen\n" >> $(4) - $(ec)$(gprintf) "import Alloc\n" >> $(4) - $(ec)$(gprintf) "import AllocateResourceTag\n" >> $(4) - $(ec)$(gprintf) "import atomic_dec\n" >> $(4) - $(ec)$(gprintf) "import atomic_inc\n" >> $(4) - $(ec)$(gprintf) "import atomic_xchg\n" >> $(4) - $(ec)$(gprintf) "import BitTest\n" >> $(4) - $(ec)$(gprintf) "import CEvaluateExpression\n" >> $(4) - $(ec)$(gprintf) "import CFindLoadModuleHandle\n" >> $(4) - $(ec)$(gprintf) "import CheckKeyStatus\n" >> $(4) - $(ec)$(gprintf) "import ClearScreen\n" >> $(4) - $(ec)$(gprintf) "import CloseFile\n" >> $(4) - $(ec)$(gprintf) "import CloseScreen\n" >> $(4) - $(ec)$(gprintf) "import CMovB\n" >> $(4) - $(ec)$(gprintf) "import CMoveFast\n" >> $(4) - $(ec)$(gprintf) "import ConvertPathString\n" >> $(4) - $(ec)$(gprintf) "import ConvertSecondsToTicks\n" >> $(4) - $(ec)$(gprintf) "import ConvertTicksToSeconds\n" >> $(4) - $(ec)$(gprintf) "import CpuCurrentProcessor\n" >> $(4) - $(ec)$(gprintf) "import CreateDirectory\n" >> $(4) - $(ec)$(gprintf) "import CreateFile\n" >> $(4) - $(ec)$(gprintf) "import CSetD\n" >> $(4) - $(ec)$(gprintf) "import DebuggerSymbolList\n" >> $(4) - $(ec)$(gprintf) "import DeleteDirectory\n" >> $(4) - $(ec)$(gprintf) "import DirectorySearch\n" >> $(4) - $(ec)$(gprintf) "import DirectReadFile\n" >> $(4) - $(ec)$(gprintf) "import DirectReadFile\n" >> $(4) - $(ec)$(gprintf) "import DirectWriteFile\n" >> $(4) - $(ec)$(gprintf) "import DirectWriteFile\n" >> $(4) - $(ec)$(gprintf) "import DirectWriteFileNoWait\n" >> $(4) - $(ec)$(gprintf) "import DirectWriteFileNoWait\n" >> $(4) - $(ec)$(gprintf) "import DisableInputCursor\n" >> $(4) - $(ec)$(gprintf) "import DisplayScreenTextWithAttribute\n" >> $(4) - $(ec)$(gprintf) "import DOSFirstByteBitMap\n" >> $(4) - $(ec)$(gprintf) "import EnableInputCursor\n" >> $(4) - $(ec)$(gprintf) "import EnterDebugger\n" >> $(4) - $(ec)$(gprintf) "import EraseFile\n" >> $(4) - $(ec)$(gprintf) "import ExpandFileInContiguousBlocks\n" >> $(4) - $(ec)$(gprintf) "import ExpandFileInContiguousBlocks\n" >> $(4) - $(ec)$(gprintf) "import ExportPublicSymbol\n" >> $(4) - $(ec)$(gprintf) "import FindAndLoadNLM\n" >> $(4) - $(ec)$(gprintf) "import Free\n" >> $(4) - $(ec)$(gprintf) "import FreeLimboVolumeSpace\n" >> $(4) - $(ec)$(gprintf) "import FreeLimboVolumeSpace\n" >> $(4) - $(ec)$(gprintf) "import GetCacheBufferSize\n" >> $(4) - $(ec)$(gprintf) "import GetClosestSymbol\n" >> $(4) - $(ec)$(gprintf) "import GetCurrentClock\n" >> $(4) - $(ec)$(gprintf) "import GetCurrentNumberOfCacheBuffers\n" >> $(4) - $(ec)$(gprintf) "import GetCurrentTime\n" >> $(4) - $(ec)$(gprintf) "import GetEntryFromPathStringBase\n" >> $(4) - $(ec)$(gprintf) "import GetEntryFromPathStringBase\n" >> $(4) - $(ec)$(gprintf) "import GetFileSize\n" >> $(4) - $(ec)$(gprintf) "import GetKey\n" >> $(4) - $(ec)$(gprintf) "import GetNLMAllocMemoryCounts\n" >> $(4) - $(ec)$(gprintf) "import GetOriginalNumberOfCacheBuffers\n" >> $(4) - $(ec)$(gprintf) "import GetProductMajorVersionNumber\n" >> $(4) - $(ec)$(gprintf) "import GetRunningProcess\n" >> $(4) - $(ec)$(gprintf) "import GetScreenSize\n" >> $(4) - $(ec)$(gprintf) "import GetSyncClockFields\n" >> $(4) - $(ec)$(gprintf) "import GetSystemConsoleScreen\n" >> $(4) - $(ec)$(gprintf) "import ImportPublicSymbol\n" >> $(4) - $(ec)$(gprintf) "import kCreateThread\n" >> $(4) - $(ec)$(gprintf) "import kCurrentThread\n" >> $(4) - $(ec)$(gprintf) "import kDelayThread\n" >> $(4) - $(ec)$(gprintf) "import kDestroyThread\n" >> $(4) - $(ec)$(gprintf) "import kExitThread\n" >> $(4) - $(ec)$(gprintf) "import kGetThreadName\n" >> $(4) - $(ec)$(gprintf) "import kGetThreadName\n" >> $(4) - $(ec)$(gprintf) "import KillMe\n" >> $(4) - $(ec)$(gprintf) "import kMutexAlloc\n" >> $(4) - $(ec)$(gprintf) "import kMutexFree\n" >> $(4) - $(ec)$(gprintf) "import kMutexLock\n" >> $(4) - $(ec)$(gprintf) "import kMutexUnlock\n" >> $(4) - $(ec)$(gprintf) "import kQueCount\n" >> $(4) - $(ec)$(gprintf) "import kReturnCurrentProcessorID\n" >> $(4) - $(ec)$(gprintf) "import kScheduleThread\n" >> $(4) - $(ec)$(gprintf) "import kSemaphoreAlloc\n" >> $(4) - $(ec)$(gprintf) "import kSemaphoreExamineCount\n" >> $(4) - $(ec)$(gprintf) "import kSemaphoreFree\n" >> $(4) - $(ec)$(gprintf) "import kSemaphoreSignal\n" >> $(4) - $(ec)$(gprintf) "import kSemaphoreTimedWait\n" >> $(4) - $(ec)$(gprintf) "import kSemaphoreWait\n" >> $(4) - $(ec)$(gprintf) "import kSetThreadLoadHandle\n" >> $(4) - $(ec)$(gprintf) "import kSetThreadName\n" >> $(4) - $(ec)$(gprintf) "import kYieldIfTimeSliceUp\n" >> $(4) - $(ec)$(gprintf) "import kYieldThread\n" >> $(4) - $(ec)$(gprintf) "import LoadModule\n" >> $(4) - $(ec)$(gprintf) "import LoadRules\n" >> $(4) - $(ec)$(gprintf) "import MapFileHandleToFCB\n" >> $(4) - $(ec)$(gprintf) "import MapPathToDirectoryNumber\n" >> $(4) - $(ec)$(gprintf) "import MapPathToDirectoryNumber\n" >> $(4) - $(ec)$(gprintf) "import MapVolumeNameToNumber\n" >> $(4) - $(ec)$(gprintf) "import ModifyDirectoryEntry\n" >> $(4) - $(ec)$(gprintf) "import ModifyDirectoryEntry\n" >> $(4) - $(ec)$(gprintf) "import MountVolume\n" >> $(4) - $(ec)$(gprintf) "import NDSCreateStreamFile\n" >> $(4) - $(ec)$(gprintf) "import NDSDeleteStreamFile\n" >> $(4) - $(ec)$(gprintf) "import NDSOpenStreamFile\n" >> $(4) - $(ec)$(gprintf) "import NWLocalToUnicode\n" >> $(4) - $(ec)$(gprintf) "import NWUnicodeToLocal\n" >> $(4) - $(ec)$(gprintf) "import OpenFile\n" >> $(4) - $(ec)$(gprintf) "import OpenScreen\n" >> $(4) - $(ec)$(gprintf) "import OutputToScreen\n" >> $(4) - $(ec)$(gprintf) "import PositionInputCursor\n" >> $(4) - $(ec)$(gprintf) "import PositionOutputCursor\n" >> $(4) - $(ec)$(gprintf) "import ReadFile\n" >> $(4) - $(ec)$(gprintf) "import RenameEntry\n" >> $(4) - $(ec)$(gprintf) "import RestartServer\n" >> $(4) - $(ec)$(gprintf) "import ReturnResourceTag\n" >> $(4) - $(ec)$(gprintf) "import ReturnVolumeMappingInformation\n" >> $(4) - $(ec)$(gprintf) "import ReturnVolumeMappingInformation\n" >> $(4) - $(ec)$(gprintf) "import RevokeFileHandleRights\n" >> $(4) - $(ec)$(gprintf) "import SetCursorStyle\n" >> $(4) - $(ec)$(gprintf) "import SetFileSize\n" >> $(4) - $(ec)$(gprintf) "import SetFileSize\n" >> $(4) - $(ec)$(gprintf) "import SGUIDCreate\n" >> $(4) - $(ec)$(gprintf) "import SizeOfAllocBlock\n" >> $(4) - $(ec)$(gprintf) "import StopBell\n" >> $(4) - $(ec)$(gprintf) "import SwitchToDirectFileMode\n" >> $(4) - $(ec)$(gprintf) "import SwitchToDirectFileMode\n" >> $(4) - $(ec)$(gprintf) "import UngetKey\n" >> $(4) - $(ec)$(gprintf) "import UnImportPublicSymbol\n" >> $(4) - $(ec)$(gprintf) "import UnloadRules\n" >> $(4) - $(ec)$(gprintf) "import VMGetDirectoryEntry\n" >> $(4) - $(ec)$(gprintf) "import WorkToDoListHead\n" >> $(4) - $(ec)$(gprintf) "import WriteFile\n" >> $(4) - $(ec)$(gprintf) "import WS2_32_bind\n" >> $(4) - $(ec)$(gprintf) "import WS2_32_closesocket\n" >> $(4) - $(ec)$(gprintf) "import WS2_32_gethostbyaddr\n" >> $(4) - $(ec)$(gprintf) "import WS2_32_gethostbyname\n" >> $(4) - $(ec)$(gprintf) "import WS2_32_gethostname\n" >> $(4) - $(ec)$(gprintf) "import WS2_32_htonl\n" >> $(4) - $(ec)$(gprintf) "import WS2_32_htons\n" >> $(4) - $(ec)$(gprintf) "import WS2_32_inet_addr\n" >> $(4) - $(ec)$(gprintf) "import WS2_32_inet_ntoa\n" >> $(4) - $(ec)$(gprintf) "import WS2_32_listen\n" >> $(4) - $(ec)$(gprintf) "import WS2_32_recv\n" >> $(4) - $(ec)$(gprintf) "import WS2_32_select\n" >> $(4) - $(ec)$(gprintf) "import WS2_32_send\n" >> $(4) - $(ec)$(gprintf) "import WS2_32_setsockopt\n" >> $(4) - $(ec)$(gprintf) "import WS2_32_shutdown\n" >> $(4) - $(ec)$(gprintf) "import WS2_32_socket\n" >> $(4) - $(ec)$(gprintf) "import WSAAccept\n" >> $(4) - $(ec)$(gprintf) "import WSACleanup\n" >> $(4) - $(ec)$(gprintf) "import WSAConnect\n" >> $(4) - $(ec)$(gprintf) "import WSAGetLastError\n" >> $(4) - $(ec)$(gprintf) "import WSAStartup\n" >> $(4) + $(ec)$(gprintf) "file $(subst $(sp),\nfile ,$(call ppath,$(3)))\n" >> $(4) - $(ec)$(gprintf) "file $(call ppath,$(wc_dir)/lib386/plib3s.lib(ctorarst))\n" >> $(4) - $(ec)$(gprintf) "file $(call ppath,$(wc_dir)/lib386/plib3s.lib(dtorarst))\n" >> $(4) - $(ec)$(gprintf) "file $(call ppath,$(wc_dir)/lib386/plib3s.lib(undefed))\n" >> $(4) - $(ec)$(gprintf) "file $(call ppath,$(wc_dir)/lib386/plib3s.lib(undefmbd))\n" >> $(4) - $(ec)$(gprintf) "file $(call ppath,$(wc_dir)/lib386/plib3s.lib(pure_err))\n" >> $(4) - $(ec)$(gprintf) "file $(call ppath,$(wc_dir)/lib386/plib3s.lib(stablcl))\n" >> $(4) - $(ec)$(gprintf) "file $(call ppath,$(wc_dir)/lib386/plib3s.lib(stabact))\n" >> $(4) - $(ec)$(gprintf) "file $(call ppath,$(wc_dir)/lib386/plib3s.lib(stabactv))\n" >> $(4) - $(ec)$(gprintf) "file $(call ppath,$(wc_dir)/lib386/plib3s.lib(stabmod))\n" >> $(4) - $(ec)$(gprintf) "file $(call ppath,$(wc_dir)/lib386/plib3s.lib(prwdata))\n" >> $(4) - $(ec)$(gprintf) "file $(call ppath,$(wc_dir)/lib386/plib3s.lib(moddtorr))\n" >> $(4) - $(ec)$(gprintf) "file $(call ppath,$(wc_dir)/lib386/plib3s.lib(stabadt))\n" >> $(4) - $(ec)$(gprintf) "file $(call ppath,$(wc_dir)/lib386/netware/clib3s.lib(i8d))\n" >> $(4) - $(ec)$(gprintf) "file $(call ppath,$(wc_dir)/lib386/netware/clib3s.lib(i8m))\n" >> $(4) - $(ec)$(gprintf) "file $(call ppath,$(wc_dir)/lib386/netware/clib3s.lib(i8s))\n" >> $(4) + $(ec)$(gprintf) "file $(call ppath,$(ndk_dir)/libc/imports/libcpre.obj)\n" >> $(4) $(ec)$(gprintf) "library $(call ppath,$(flaim_static_lib))\n" >> $(4) + $(ec)$(gprintf) "library $(call ppath,$(wc_dir)/lib386/plib3s.lib)\n" >> $(4) + $(ec)$(gprintf) "library $(call ppath,$(wc_dir)/lib386/netware/libc3s.lib)\n" >> $(4) + $(ec)$(gprintf) "import CurrentProcess\n" >> $(4) + $(ec)$(gprintf) "import @$(call ppath,$(ndk_dir)/libc/imports/libc.imp)\n" >> $(4) + $(ec)$(gprintf) "import @$(call ppath,$(ndk_dir)/libc/imports/netware.imp)\n" >> $(4) + $(ec)$(gprintf) "import @$(call ppath,$(ndk_dir)/libc/imports/ws2nlm.imp)\n" >> $(4) endef - + define flm_exe_link_cmd $(call make_lis_file_cmd,$(1),$(2),$(3),$(call hostpath,$(1)/$(2).lis)) $(ec)$(call hostpath,$(exe_linker)) @$(call hostpath,$(1)/$(2).lis) @@ -1274,13 +1335,13 @@ endif flaim_src = \ $(patsubst src/%.cpp,%.cpp,$(wildcard src/*.cpp)) +ftk_src = \ + $(patsubst $(ftk_src_dir)/%.cpp,%.cpp,$(wildcard $(ftk_src_dir)/*.cpp)) + utilsup_src = \ flm_dlst.cpp \ flm_lutl.cpp \ - ftx.cpp \ - ftxunix.cpp \ - sharutil.cpp \ - wpscrnkb.cpp + sharutil.cpp checkdb_src = \ checkdb.cpp \ @@ -1317,6 +1378,7 @@ ut_basictest_src = \ # -- FLAIM library -- +ftk_obj = $(patsubst %.cpp,$(lib_obj_dir)/%$(obj_suffix),$(ftk_src)) flaim_static_obj = $(patsubst %.cpp,$(lib_obj_dir)/%$(obj_suffix),$(flaim_src)) flaim_shared_obj = $(patsubst %.cpp,$(lib_sobj_dir)/%$(obj_suffix),$(flaim_src)) flaim_static_lib = $(static_lib_dir)/$(lib_prefix)$(project_name)$(static_lib_suffix) @@ -1348,7 +1410,7 @@ sample_exe = $(sample_dir)/sample$(exe_suffix) # -- Make system pattern search paths -- -vpath %.cpp src util sample +vpath %.cpp src util sample java/jni $(ftk_src_dir) # -- Default target -- @@ -1391,7 +1453,7 @@ endif # -- flaim.lib and libflaim.a -- -$(flaim_static_lib) : $(flaim_static_obj) +$(flaim_static_lib) : $(flaim_static_obj) $(ftk_obj) $(ec)$(gprintf) "Building $@ ...\n" ifdef win_target $(ec)$(libr) /NOLOGO $(call hostpath,$+) /OUT:$(call hostpath,$@) @@ -1411,7 +1473,7 @@ endif # -- flaim.dll and libflaim.so -- -$(flaim_shared_lib) : $(flaim_shared_obj) +$(flaim_shared_lib) : $(flaim_shared_obj) $(ftk_obj) $(ec)$(gprintf) "Building $@ ...\n" ifdef win_target $(ec)$(exe_linker) $(call hostpath,$+) $(shared_link_flags) $(lib_link_libs) @@ -1432,7 +1494,7 @@ endif # -- checkdb -- .PHONY : checkdb -checkdb: status clean dircheck $(flaim_static_lib) $(checkdb_exe) +checkdb: status clean dircheck libs $(checkdb_exe) $(checkdb_exe): $(checkdb_obj) $(flaim_static_lib) $(ec)$(gprintf) "Linking $@ ...\n" $(call flm_exe_link_cmd,$(util_dir),checkdb,$(checkdb_obj)) @@ -1440,7 +1502,7 @@ $(checkdb_exe): $(checkdb_obj) $(flaim_static_lib) # -- rebuild -- .PHONY : rebuild -rebuild: status clean dircheck $(flaim_static_lib) $(rebuild_exe) +rebuild: status clean dircheck libs $(rebuild_exe) $(rebuild_exe): $(rebuild_obj) $(flaim_static_lib) $(ec)$(gprintf) "Linking $@ ...\n" $(call flm_exe_link_cmd,$(util_dir),rebuild,$(rebuild_obj)) @@ -1448,7 +1510,7 @@ $(rebuild_exe): $(rebuild_obj) $(flaim_static_lib) # -- view -- .PHONY : view -view: status clean dircheck $(flaim_static_lib) $(view_exe) +view: status clean dircheck libs $(view_exe) $(view_exe): $(view_obj) $(flaim_static_lib) $(ec)$(gprintf) "Linking $@ ...\n" $(call flm_exe_link_cmd,$(util_dir),view,$(view_obj)) @@ -1456,7 +1518,7 @@ $(view_exe): $(view_obj) $(flaim_static_lib) # -- dbshell -- .PHONY : dbshell -dbshell: status clean dircheck $(flaim_static_lib) $(dbshell_exe) +dbshell: status clean dircheck libs $(dbshell_exe) $(dbshell_exe): $(dbshell_obj) $(flaim_static_lib) $(ec)$(gprintf) "Linking $@ ...\n" $(call flm_exe_link_cmd,$(util_dir),dbshell,$(dbshell_obj)) @@ -1465,7 +1527,7 @@ $(dbshell_exe): $(dbshell_obj) $(flaim_static_lib) .PHONY : sample ifndef netware_target -sample: status clean dircheck $(flaim_static_lib) $(sample_exe) +sample: status clean dircheck libs $(sample_exe) $(sample_exe): $(sample_obj) $(flaim_static_lib) $(ec)$(gprintf) "Linking $@ ...\n" $(call flm_exe_link_cmd,$(sample_dir),sample,$(sample_obj)) @@ -1477,7 +1539,7 @@ endif basictest: status clean dircheck $(flaim_static_lib) $(test_dir)/basictest$(exe_suffix) $(test_dir)/basictest$(exe_suffix): $(ut_basictest_obj) $(flaim_static_lib) $(ec)$(gprintf) "Linking $@ ...\n" - $(call flm_exe_link_cmd,$(test_dir)basictest,$(ut_basictest_obj)) + $(call flm_exe_link_cmd,$(test_dir),basictest,$(ut_basictest_obj)) # -- version -- @@ -1498,17 +1560,20 @@ srcdist: status clean dircheck docs spec endif -$(ec)$(call rmdircmd,$(package_stage_dir)) $(ec)$(call mkdircmd,$(package_stage_dir)) - $(ec)$(call make_version_files,$(package_stage_dir)) + $(ec)$(call make_version_files,$(package_stage_dir)) $(ec)$(call copycmd,Makefile,$(package_stage_dir)) $(ec)$(call copycmd,COPYING,$(package_stage_dir)) - $(ec)$(call copycmd,Doxyfile,$(package_stage_dir)) + $(ec)$(call dircopycmd,docs,$(package_stage_dir)/docs) $(ec)$(call dircopycmd,src,$(package_stage_dir)/src) $(ec)$(call dircopycmd,util,$(package_stage_dir)/util) + $(ec)$(call dircopycmd,sample,$(package_stage_dir)/sample) + $(ec)$(call dircopycmd,$(doxygen_output_dir),$(package_stage_dir)/docs) $(ec)$(call dircopycmd,$(dir $(topdir))tools,$(package_stage_dir)/tools) + $(ec)$(call mkdircmd,$(package_stage_dir)/ftk) + $(ec)$(call dircopycmd,$(dir $(topdir))ftk/src,$(package_stage_dir)/ftk/src) ifneq ($(host_os_family),win) -$(ec)rm -rf `find $(package_stage_dir) -name .svn` endif - $(ec)$(call dircopycmd,$(docs_output_dir),$(package_stage_dir)/docs) ifeq ($(host_os_family),win) $(ec)$(call copycmd,make.exe,$(package_stage_dir)) endif @@ -1540,9 +1605,10 @@ binpackage: status $(ec)$(call mkdircmd,$(package_shared_lib_stage_dir)) $(ec)$(call mkdircmd,$(package_static_lib_stage_dir)) $(ec)$(call mkdircmd,$(package_util_stage_dir)) - $(ec)$(call make_version_files,$(package_stage_dir)) + $(ec)$(call make_version_files,$(package_stage_dir)) $(ec)$(call copycmd,COPYING,$(package_stage_dir)) $(ec)$(call copycmd,src/flaim.h,$(package_inc_stage_dir)) + $(ec)$(call copycmd,$(ftk_src_dir)/ftk.h,$(package_inc_stage_dir)/flaimtk.h) $(ec)$(call copycmd,$(flaim_static_lib),$(package_static_lib_stage_dir)) ifdef flaim_shared_lib $(ec)$(call copycmd,$(flaim_shared_lib),$(package_shared_lib_stage_dir)) @@ -1600,6 +1666,7 @@ ifneq ($(host_os_family),win) install --mode=644 $(flaim_static_lib) $(lib_install_dir) install --mode=644 $(pkgconfig_file) $(pkgconfig_install_dir) install --mode=644 src/flaim.h $(include_install_dir) + install --mode=644 src/flaimtk.h $(include_install_dir) -ldconfig $(lib_install_dir) -l -v $(lib_install_dir)/$(lib_prefix)$(project_name)$(shared_lib_suffix) $(ec)$(gprintf) "Installation complete.\n" endif @@ -1614,6 +1681,7 @@ ifneq ($(host_os_family),win) -rm -rf $(lib_install_dir)/$(lib_prefix)$(project_name)$(static_lib_suffix) -rm -rf $(pkgconfig_install_dir)/$(pkgconfig_file_name) -rm -rf $(include_install_dir)/flaim.h + -rm -rf $(include_install_dir)/flaimtk.h $(ec)$(gprintf) "Uninstalled.\n" endif @@ -1686,6 +1754,7 @@ spec: dircheck $(ec)$(gprintf) "$(percent){prefix}/$(percent){_lib}/$(lib_prefix)$(project_name)$(static_lib_suffix)\n" >> $(spec_file) $(ec)$(gprintf) "$(percent){prefix}/$(percent){_lib}/pkgconfig/$(pkgconfig_file_name)\n" >> $(spec_file) $(ec)$(gprintf) "$(percent){prefix}/include/flaim.h\n" >> $(spec_file) + $(ec)$(gprintf) "$(percent){prefix}/include/flaimtk.h\n" >> $(spec_file) $(ec)$(gprintf) "Created spec file.\n" # -- PKG-CONFIG -- @@ -1722,11 +1791,13 @@ rpms: dist spec # -- Documentation -- .PHONY : docs -docs: status clean dircheck +docs: status clean dircheck doxyfile $(ec)$(gprintf) "Creating documentation ...\n" - $(ec)doxygen Doxyfile + $(ec)doxygen $(doxyfile) $(ec)$(gprintf) "Documentation created.\n" +# -- misc. targets -- + .PHONY : dircheck dircheck: $(ec)$(call mkdircmd,$(util_obj_dir)) @@ -1736,6 +1807,7 @@ dircheck: ifneq ($(lib_sobj_dir),$(lib_obj_dir)) $(ec)$(call mkdircmd,$(lib_sobj_dir)) endif + $(ec)$(call mkdircmd,$(doxygen_output_dir)) $(ec)$(call mkdircmd,$(util_dir)) $(ec)$(call mkdircmd,$(test_dir)) $(ec)$(call mkdircmd,$(sample_dir)) @@ -1756,12 +1828,14 @@ all: libs allutils $(ec)$(gprintf) "" .PHONY : allutils -allutils: status clean dircheck $(util_targets) +allutils: status dircheck libs $(util_targets) $(ec)$(gprintf) "" .PHONY : test -test: status clean dircheck $(flaim_static_lib) $(test_targets) +test: status dircheck $(flaim_static_lib) $(test_targets) +ifndef netware_target $(ec)$(call runtest,basictest) +endif .PHONY : debug debug: @@ -1872,3 +1946,187 @@ status: $(ec)$(gprintf) "Librarian....................... $(call ppath,$(libr))\n" $(ec)$(gprintf) "Defines......................... $(strip $(ccdefs))\n" $(ec)$(gprintf) "===============================================================================\n" + +.PHONY : doxyfile +doxyfile: dircheck + $(ec)$(gprintf) "PROJECT_NAME = \"$(project_display_name)\"\n" > $(doxyfile) + $(ec)$(gprintf) "PROJECT_NUMBER = \"$(version)\"\n" >> $(doxyfile) + $(ec)$(gprintf) "OUTPUT_DIRECTORY = $(doxygen_output_dir)\n" >> $(doxyfile) + $(ec)$(gprintf) "CREATE_SUBDIRS = NO\n" >> $(doxyfile) + $(ec)$(gprintf) "OUTPUT_LANGUAGE = English\n" >> $(doxyfile) + $(ec)$(gprintf) "USE_WINDOWS_ENCODING = YES\n" >> $(doxyfile) + $(ec)$(gprintf) "BRIEF_MEMBER_DESC = YES\n" >> $(doxyfile) + $(ec)$(gprintf) "REPEAT_BRIEF = YES\n" >> $(doxyfile) + $(ec)$(gprintf) "ABBREVIATE_BRIEF = \"The $(dollar)name class\" $(backslash)\n" >> $(doxyfile) + $(ec)$(gprintf) " \"The $(dollar)name widget\" $(backslash)\n" >> $(doxyfile) + $(ec)$(gprintf) " \"The $(dollar)name file\" $(backslash)\n" >> $(doxyfile) + $(ec)$(gprintf) " is $(backslash)\n" >> $(doxyfile) + $(ec)$(gprintf) " provides $(backslash)\n" >> $(doxyfile) + $(ec)$(gprintf) " specifies $(backslash)\n" >> $(doxyfile) + $(ec)$(gprintf) " contains $(backslash)\n" >> $(doxyfile) + $(ec)$(gprintf) " represents $(backslash)\n" >> $(doxyfile) + $(ec)$(gprintf) " a $(backslash)\n" >> $(doxyfile) + $(ec)$(gprintf) " an $(backslash)\n" >> $(doxyfile) + $(ec)$(gprintf) " the\n" >> $(doxyfile) + $(ec)$(gprintf) "ALWAYS_DETAILED_SEC = NO\n" >> $(doxyfile) + $(ec)$(gprintf) "INLINE_INHERITED_MEMB = NO\n" >> $(doxyfile) + $(ec)$(gprintf) "FULL_PATH_NAMES = NO\n" >> $(doxyfile) + $(ec)$(gprintf) "STRIP_FROM_PATH = \"\"\n" >> $(doxyfile) + $(ec)$(gprintf) "STRIP_FROM_INC_PATH = \n" >> $(doxyfile) + $(ec)$(gprintf) "SHORT_NAMES = NO\n" >> $(doxyfile) + $(ec)$(gprintf) "JAVADOC_AUTOBRIEF = YES\n" >> $(doxyfile) + $(ec)$(gprintf) "MULTILINE_CPP_IS_BRIEF = NO\n" >> $(doxyfile) + $(ec)$(gprintf) "DETAILS_AT_TOP = NO\n" >> $(doxyfile) + $(ec)$(gprintf) "INHERIT_DOCS = YES\n" >> $(doxyfile) + $(ec)$(gprintf) "SEPARATE_MEMBER_PAGES = NO\n" >> $(doxyfile) + $(ec)$(gprintf) "TAB_SIZE = 3\n" >> $(doxyfile) + $(ec)$(gprintf) "ALIASES = \n" >> $(doxyfile) + $(ec)$(gprintf) "OPTIMIZE_OUTPUT_FOR_C = NO\n" >> $(doxyfile) + $(ec)$(gprintf) "OPTIMIZE_OUTPUT_JAVA = NO\n" >> $(doxyfile) + $(ec)$(gprintf) "BUILTIN_STL_SUPPORT = NO\n" >> $(doxyfile) + $(ec)$(gprintf) "DISTRIBUTE_GROUP_DOC = NO\n" >> $(doxyfile) + $(ec)$(gprintf) "SUBGROUPING = YES\n" >> $(doxyfile) + $(ec)$(gprintf) "EXTRACT_ALL = NO\n" >> $(doxyfile) + $(ec)$(gprintf) "EXTRACT_PRIVATE = NO\n" >> $(doxyfile) + $(ec)$(gprintf) "EXTRACT_STATIC = NO\n" >> $(doxyfile) + $(ec)$(gprintf) "EXTRACT_LOCAL_CLASSES = YES\n" >> $(doxyfile) + $(ec)$(gprintf) "EXTRACT_LOCAL_METHODS = NO\n" >> $(doxyfile) + $(ec)$(gprintf) "HIDE_UNDOC_MEMBERS = YES\n" >> $(doxyfile) + $(ec)$(gprintf) "HIDE_UNDOC_CLASSES = YES\n" >> $(doxyfile) + $(ec)$(gprintf) "HIDE_FRIEND_COMPOUNDS = NO\n" >> $(doxyfile) + $(ec)$(gprintf) "HIDE_IN_BODY_DOCS = NO\n" >> $(doxyfile) + $(ec)$(gprintf) "INTERNAL_DOCS = NO\n" >> $(doxyfile) + $(ec)$(gprintf) "CASE_SENSE_NAMES = NO\n" >> $(doxyfile) + $(ec)$(gprintf) "HIDE_SCOPE_NAMES = NO\n" >> $(doxyfile) + $(ec)$(gprintf) "SHOW_INCLUDE_FILES = YES\n" >> $(doxyfile) + $(ec)$(gprintf) "INLINE_INFO = YES\n" >> $(doxyfile) + $(ec)$(gprintf) "SORT_MEMBER_DOCS = YES\n" >> $(doxyfile) + $(ec)$(gprintf) "SORT_BRIEF_DOCS = NO\n" >> $(doxyfile) + $(ec)$(gprintf) "SORT_BY_SCOPE_NAME = NO\n" >> $(doxyfile) + $(ec)$(gprintf) "GENERATE_TODOLIST = YES\n" >> $(doxyfile) + $(ec)$(gprintf) "GENERATE_TESTLIST = YES\n" >> $(doxyfile) + $(ec)$(gprintf) "GENERATE_BUGLIST = YES\n" >> $(doxyfile) + $(ec)$(gprintf) "GENERATE_DEPRECATEDLIST= YES\n" >> $(doxyfile) + $(ec)$(gprintf) "ENABLED_SECTIONS = \n" >> $(doxyfile) + $(ec)$(gprintf) "MAX_INITIALIZER_LINES = 30\n" >> $(doxyfile) + $(ec)$(gprintf) "SHOW_USED_FILES = NO\n" >> $(doxyfile) + $(ec)$(gprintf) "SHOW_DIRECTORIES = NO\n" >> $(doxyfile) + $(ec)$(gprintf) "FILE_VERSION_FILTER = \n" >> $(doxyfile) + $(ec)$(gprintf) "QUIET = NO\n" >> $(doxyfile) + $(ec)$(gprintf) "WARNINGS = YES\n" >> $(doxyfile) + $(ec)$(gprintf) "WARN_IF_UNDOCUMENTED = YES\n" >> $(doxyfile) + $(ec)$(gprintf) "WARN_IF_DOC_ERROR = YES\n" >> $(doxyfile) + $(ec)$(gprintf) "WARN_NO_PARAMDOC = NO\n" >> $(doxyfile) + $(ec)$(gprintf) "WARN_FORMAT = \"$(dollar)file:$(dollar)line: $(dollar)text\"\n" >> $(doxyfile) + $(ec)$(gprintf) "WARN_LOGFILE = \n" >> $(doxyfile) + $(ec)$(gprintf) "INPUT = src/flaim.h $(backslash)\n" >> $(doxyfile) + $(ec)$(gprintf) " $(ftk_src_dir)/ftk.h\n" >> $(doxyfile) + $(ec)$(gprintf) "FILE_PATTERNS = *.h\n" >> $(doxyfile) + $(ec)$(gprintf) "RECURSIVE = NO\n" >> $(doxyfile) + $(ec)$(gprintf) "EXCLUDE = \n" >> $(doxyfile) + $(ec)$(gprintf) "EXCLUDE_SYMLINKS = NO\n" >> $(doxyfile) + $(ec)$(gprintf) "EXCLUDE_PATTERNS = \n" >> $(doxyfile) + $(ec)$(gprintf) "EXAMPLE_PATH = \n" >> $(doxyfile) + $(ec)$(gprintf) "EXAMPLE_PATTERNS = *\n" >> $(doxyfile) + $(ec)$(gprintf) "EXAMPLE_RECURSIVE = NO\n" >> $(doxyfile) + $(ec)$(gprintf) "IMAGE_PATH = \n" >> $(doxyfile) + $(ec)$(gprintf) "INPUT_FILTER = \n" >> $(doxyfile) + $(ec)$(gprintf) "FILTER_PATTERNS = \n" >> $(doxyfile) + $(ec)$(gprintf) "FILTER_SOURCE_FILES = NO\n" >> $(doxyfile) + $(ec)$(gprintf) "SOURCE_BROWSER = NO\n" >> $(doxyfile) + $(ec)$(gprintf) "INLINE_SOURCES = NO\n" >> $(doxyfile) + $(ec)$(gprintf) "STRIP_CODE_COMMENTS = YES\n" >> $(doxyfile) + $(ec)$(gprintf) "REFERENCED_BY_RELATION = NO\n" >> $(doxyfile) + $(ec)$(gprintf) "REFERENCES_RELATION = NO\n" >> $(doxyfile) + $(ec)$(gprintf) "USE_HTAGS = NO\n" >> $(doxyfile) + $(ec)$(gprintf) "VERBATIM_HEADERS = NO\n" >> $(doxyfile) + $(ec)$(gprintf) "ALPHABETICAL_INDEX = YES\n" >> $(doxyfile) + $(ec)$(gprintf) "COLS_IN_ALPHA_INDEX = 5\n" >> $(doxyfile) + $(ec)$(gprintf) "IGNORE_PREFIX = \n" >> $(doxyfile) + $(ec)$(gprintf) "GENERATE_HTML = YES\n" >> $(doxyfile) + $(ec)$(gprintf) "HTML_OUTPUT = html\n" >> $(doxyfile) + $(ec)$(gprintf) "HTML_FILE_EXTENSION = .html\n" >> $(doxyfile) + $(ec)$(gprintf) "HTML_HEADER = \n" >> $(doxyfile) + $(ec)$(gprintf) "HTML_FOOTER = \n" >> $(doxyfile) + $(ec)$(gprintf) "HTML_STYLESHEET = \n" >> $(doxyfile) + $(ec)$(gprintf) "HTML_ALIGN_MEMBERS = YES\n" >> $(doxyfile) + $(ec)$(gprintf) "GENERATE_HTMLHELP = NO\n" >> $(doxyfile) + $(ec)$(gprintf) "CHM_FILE = \n" >> $(doxyfile) + $(ec)$(gprintf) "HHC_LOCATION = \n" >> $(doxyfile) + $(ec)$(gprintf) "GENERATE_CHI = NO\n" >> $(doxyfile) + $(ec)$(gprintf) "BINARY_TOC = NO\n" >> $(doxyfile) + $(ec)$(gprintf) "TOC_EXPAND = NO\n" >> $(doxyfile) + $(ec)$(gprintf) "DISABLE_INDEX = NO\n" >> $(doxyfile) + $(ec)$(gprintf) "ENUM_VALUES_PER_LINE = 4\n" >> $(doxyfile) + $(ec)$(gprintf) "GENERATE_TREEVIEW = YES\n" >> $(doxyfile) + $(ec)$(gprintf) "TREEVIEW_WIDTH = 250\n" >> $(doxyfile) + $(ec)$(gprintf) "GENERATE_LATEX = NO\n" >> $(doxyfile) + $(ec)$(gprintf) "LATEX_OUTPUT = latex\n" >> $(doxyfile) + $(ec)$(gprintf) "LATEX_CMD_NAME = latex\n" >> $(doxyfile) + $(ec)$(gprintf) "MAKEINDEX_CMD_NAME = makeindex\n" >> $(doxyfile) + $(ec)$(gprintf) "COMPACT_LATEX = NO\n" >> $(doxyfile) + $(ec)$(gprintf) "PAPER_TYPE = a4wide\n" >> $(doxyfile) + $(ec)$(gprintf) "EXTRA_PACKAGES = \n" >> $(doxyfile) + $(ec)$(gprintf) "LATEX_HEADER = \n" >> $(doxyfile) + $(ec)$(gprintf) "PDF_HYPERLINKS = NO\n" >> $(doxyfile) + $(ec)$(gprintf) "USE_PDFLATEX = NO\n" >> $(doxyfile) + $(ec)$(gprintf) "LATEX_BATCHMODE = NO\n" >> $(doxyfile) + $(ec)$(gprintf) "LATEX_HIDE_INDICES = NO\n" >> $(doxyfile) + $(ec)$(gprintf) "GENERATE_RTF = NO\n" >> $(doxyfile) + $(ec)$(gprintf) "RTF_OUTPUT = rtf\n" >> $(doxyfile) + $(ec)$(gprintf) "COMPACT_RTF = NO\n" >> $(doxyfile) + $(ec)$(gprintf) "RTF_HYPERLINKS = NO\n" >> $(doxyfile) + $(ec)$(gprintf) "RTF_STYLESHEET_FILE = \n" >> $(doxyfile) + $(ec)$(gprintf) "RTF_EXTENSIONS_FILE = \n" >> $(doxyfile) + $(ec)$(gprintf) "GENERATE_MAN = NO\n" >> $(doxyfile) + $(ec)$(gprintf) "MAN_OUTPUT = man\n" >> $(doxyfile) + $(ec)$(gprintf) "MAN_EXTENSION = .3\n" >> $(doxyfile) + $(ec)$(gprintf) "MAN_LINKS = NO\n" >> $(doxyfile) + $(ec)$(gprintf) "GENERATE_XML = NO\n" >> $(doxyfile) + $(ec)$(gprintf) "XML_OUTPUT = xml\n" >> $(doxyfile) + $(ec)$(gprintf) "XML_SCHEMA = \n" >> $(doxyfile) + $(ec)$(gprintf) "XML_DTD = \n" >> $(doxyfile) + $(ec)$(gprintf) "XML_PROGRAMLISTING = YES\n" >> $(doxyfile) + $(ec)$(gprintf) "GENERATE_AUTOGEN_DEF = NO\n" >> $(doxyfile) + $(ec)$(gprintf) "GENERATE_PERLMOD = NO\n" >> $(doxyfile) + $(ec)$(gprintf) "PERLMOD_LATEX = NO\n" >> $(doxyfile) + $(ec)$(gprintf) "PERLMOD_PRETTY = YES\n" >> $(doxyfile) + $(ec)$(gprintf) "PERLMOD_MAKEVAR_PREFIX = \n" >> $(doxyfile) + $(ec)$(gprintf) "ENABLE_PREPROCESSING = YES\n" >> $(doxyfile) + $(ec)$(gprintf) "MACRO_EXPANSION = NO\n" >> $(doxyfile) + $(ec)$(gprintf) "EXPAND_ONLY_PREDEF = NO\n" >> $(doxyfile) + $(ec)$(gprintf) "SEARCH_INCLUDES = YES\n" >> $(doxyfile) + $(ec)$(gprintf) "INCLUDE_PATH = \n" >> $(doxyfile) + $(ec)$(gprintf) "INCLUDE_FILE_PATTERNS = \n" >> $(doxyfile) + $(ec)$(gprintf) "PREDEFINED = \n" >> $(doxyfile) + $(ec)$(gprintf) "EXPAND_AS_DEFINED = \n" >> $(doxyfile) + $(ec)$(gprintf) "SKIP_FUNCTION_MACROS = YES\n" >> $(doxyfile) + $(ec)$(gprintf) "TAGFILES = \n" >> $(doxyfile) + $(ec)$(gprintf) "GENERATE_TAGFILE = \n" >> $(doxyfile) + $(ec)$(gprintf) "ALLEXTERNALS = NO\n" >> $(doxyfile) + $(ec)$(gprintf) "EXTERNAL_GROUPS = YES\n" >> $(doxyfile) + $(ec)$(gprintf) "PERL_PATH = \n" >> $(doxyfile) + $(ec)$(gprintf) "CLASS_DIAGRAMS = YES\n" >> $(doxyfile) + $(ec)$(gprintf) "HIDE_UNDOC_RELATIONS = YES\n" >> $(doxyfile) + $(ec)$(gprintf) "HAVE_DOT = NO\n" >> $(doxyfile) + $(ec)$(gprintf) "CLASS_GRAPH = YES\n" >> $(doxyfile) + $(ec)$(gprintf) "COLLABORATION_GRAPH = YES\n" >> $(doxyfile) + $(ec)$(gprintf) "GROUP_GRAPHS = YES\n" >> $(doxyfile) + $(ec)$(gprintf) "UML_LOOK = NO\n" >> $(doxyfile) + $(ec)$(gprintf) "TEMPLATE_RELATIONS = NO\n" >> $(doxyfile) + $(ec)$(gprintf) "INCLUDE_GRAPH = YES\n" >> $(doxyfile) + $(ec)$(gprintf) "INCLUDED_BY_GRAPH = YES\n" >> $(doxyfile) + $(ec)$(gprintf) "CALL_GRAPH = NO\n" >> $(doxyfile) + $(ec)$(gprintf) "GRAPHICAL_HIERARCHY = YES\n" >> $(doxyfile) + $(ec)$(gprintf) "DIRECTORY_GRAPH = YES\n" >> $(doxyfile) + $(ec)$(gprintf) "DOT_IMAGE_FORMAT = png\n" >> $(doxyfile) + $(ec)$(gprintf) "DOT_PATH = \n" >> $(doxyfile) + $(ec)$(gprintf) "DOTFILE_DIRS = \n" >> $(doxyfile) + $(ec)$(gprintf) "MAX_DOT_GRAPH_WIDTH = 1024\n" >> $(doxyfile) + $(ec)$(gprintf) "MAX_DOT_GRAPH_HEIGHT = 1024\n" >> $(doxyfile) + $(ec)$(gprintf) "MAX_DOT_GRAPH_DEPTH = 1000\n" >> $(doxyfile) + $(ec)$(gprintf) "DOT_TRANSPARENT = NO\n" >> $(doxyfile) + $(ec)$(gprintf) "DOT_MULTI_TARGETS = NO\n" >> $(doxyfile) + $(ec)$(gprintf) "GENERATE_LEGEND = YES\n" >> $(doxyfile) + $(ec)$(gprintf) "DOT_CLEANUP = YES\n" >> $(doxyfile) + $(ec)$(gprintf) "SEARCHENGINE = NO\n" >> $(doxyfile) diff --git a/flaim/src/Makefile.am b/flaim/src/Makefile.am deleted file mode 100644 index e282273..0000000 --- a/flaim/src/Makefile.am +++ /dev/null @@ -1,183 +0,0 @@ -lib_LTLIBRARIES = libflaim.la -libflaim_la_SOURCES = \ - checksum.cpp \ - ecache.cpp \ - ecache.h \ - f_nici.cpp \ - f_nici.h \ - f64bitfh.cpp \ - f64bitfh.h \ - fblob.cpp \ - fbuff.cpp \ - fbuff.h \ - fcs.cpp \ - fcs.h \ - fdb.cpp \ - fdbcnfig.cpp \ - fdbcopy.cpp \ - fdbremov.cpp \ - fdbrenam.cpp \ - fdict.cpp \ - fdict.h \ - fdir.h \ - fdynbtre.cpp \ - fdynsset.cpp \ - fdynsset.h \ - ffilehdl.cpp \ - ffilehdl.h \ - ffilehdr.cpp \ - ffilesys.cpp \ - ffilesys.h \ - fgedcom.cpp \ - filesys.h \ - flaim.h \ - flaimsys.h \ - flalloc.cpp \ - flbackup.cpp \ - flchkdb.cpp \ - flclose.cpp \ - flconvrt.cpp \ - flcreate.cpp \ - fldbglog.cpp \ - flerror.cpp \ - flfixed.cpp \ - flfixed.h \ - flindex.cpp \ - flist.cpp \ - flist.h \ - flkeyret.cpp \ - flmimon.cpp \ - flmimon.h \ - flmstat.cpp \ - flmstat.h \ - flog.cpp \ - flog.h \ - flopen.cpp \ - flprintf.cpp \ - flrddrct.cpp \ - flreduce.cpp \ - flsweep.cpp \ - flupdate.cpp \ - flutil.cpp \ - flverify.cpp \ - fmisc.cpp \ - fmutxref.h \ - fnlm.cpp \ - fnlm.h \ - fntable.cpp \ - fnumber.cpp \ - fobjtrck.cpp \ - fobjtrck.h \ - fpackoff.h \ - fpackon.h \ - fposix.cpp \ - fposix.h \ - fqcur.cpp \ - fqdecl.cpp \ - fqeval.cpp \ - fqget.cpp \ - fqkeys.cpp \ - fqlog.cpp \ - fqopt.cpp \ - fqparse.cpp \ - fqprep.cpp \ - fqread.cpp \ - fqsrch.cpp \ - fqstack.cpp \ - fquery.h \ - frebuild.cpp \ - frec.cpp \ - frecset.cpp \ - frset.cpp \ - frset.h \ - frsetblk.cpp \ - fsblk_u.cpp \ - fscomblk.cpp \ - fsconvrt.cpp \ - fscounts.cpp \ - fscursor.cpp \ - fscursor.h \ - fsdatacu.cpp \ - fsdelelm.cpp \ - fsinselm.cpp \ - fslfile.cpp \ - fslfileu.cpp \ - fsnext.cpp \ - fsprev.cpp \ - fsrecget.cpp \ - fsrecupd.cpp \ - fsrefspl.cpp \ - fsrefupd.cpp \ - fsrvlock.cpp \ - fsrvlock.h \ - fssearch.cpp \ - fssplblk.cpp \ - fstructs.h \ - fsuperfl.cpp \ - fsuperfl.h \ - fsv.cpp \ - fsv.h \ - fsysdata.cpp \ - ftext.cpp \ - ftk.h \ - ftkdir.cpp \ - ftkmem.h \ - ftkmisc.cpp \ - ftkmod.cpp \ - ftknlm.h \ - ftknsem.cpp \ - ftknsem.h \ - ftkpath.cpp \ - ftkrand.cpp \ - ftksem.cpp \ - ftksem.h \ - ftkthrd.cpp \ - ftkthrd.h \ - ftktime.cpp \ - ftrace.cpp \ - ftrace.h \ - ftrans.cpp \ - furl.cpp \ - furl.h \ - fwin.cpp \ - fwin.h \ - fxml.cpp \ - fxml.h \ - gdpool.cpp \ - imonbase.cpp \ - imonchk.cpp \ - imonerr.cpp \ - imonfact.cpp \ - imonfdb.cpp \ - imonffil.cpp \ - imonfhdl.cpp \ - imonfhsh.cpp \ - imonfmgr.cpp \ - imonfram.cpp \ - imonfsys.cpp \ - imonix.cpp \ - imonlhdr.cpp \ - imonqury.cpp \ - imonrche.cpp \ - imonrec.cpp \ - imonscfg.cpp \ - imonsche.cpp \ - imonsel.cpp \ - imonslmg.cpp \ - imonstat.cpp \ - imonutil.cpp \ - kybuild.cpp \ - kycollat.cpp \ - kyget.cpp \ - lock.cpp \ - nlmload.cpp \ - nwyield.cpp \ - rcache.cpp \ - recover.cpp \ - rfl.cpp \ - rfl.h \ - scache.cpp \ - translog.cpp - -libflaim_la_LDFLAGS = -version-info 0:0:0 - diff --git a/flaim/src/checksum.cpp b/flaim/src/checksum.cpp index 8a714ef..09289e6 100644 --- a/flaim/src/checksum.cpp +++ b/flaim/src/checksum.cpp @@ -24,513 +24,6 @@ #include "flaimsys.h" -#if defined( FLM_WATCOM_NLM) - - extern void FastBlockCheckSumMMX( - void * pBlk, - unsigned long *puiChecksum, - unsigned long *puiXORdata, - unsigned long uiNumberOfBytes); - - extern void FastBlockCheckSum386( - void * pBlk, - unsigned long *puiChecksum, - unsigned long *puiXORdata, - unsigned long uiNumberOfBytes); - - extern unsigned long GetMMXSupported(void); - - static unsigned long gv_mmxCheckSumFlag = 1; - -#elif (defined( FLM_WIN) && !defined( FLM_64BIT)) || defined( FLM_NLM) - - static void FastBlockCheckSumMMX( - void * pBlk, - unsigned long *puiChecksum, - unsigned long *puiXORdata, - unsigned long uiNumberOfBytes); - - static void FastBlockCheckSum386( - void * pBlk, - unsigned long *puiChecksum, - unsigned long *puiXORdata, - unsigned long uiNumberOfBytes); - - static unsigned long GetMMXSupported(void); - - static unsigned long gv_mmxCheckSumFlag = 1; - -#endif - -/******************************************************************** -Desc: Returns 1 if the CPU supports MMX -Ret: 0 or 1 if CPU supports MMX -*********************************************************************/ -#if defined( FLM_WATCOM_NLM) - - #pragma aux GetMMXSupported parm; - #pragma aux GetMMXSupported = \ - 0xB8 0x01 0x00 0x00 0x00 /* mov eax, 1 */\ - 0x0F 0xA2 /* CPUID */\ - 0x33 0xC0 /* xor eax, eax */\ - 0xF7 0xC2 0x00 0x00 0x80 0x00 /* test edx, (1 SHL 23) ;check for MMX Instruction support */\ - 0x0F 0x95 0xC0 /* setnz al */\ - modify exact [EAX EBX ECX EDX]; - -#elif (defined( FLM_WIN) && !defined( FLM_64BIT)) || defined( FLM_NLM) - - unsigned long GetMMXSupported( void) - { - unsigned long bMMXSupported; - __asm - { - mov eax, 1 - cpuid - xor eax, eax - test edx, (1 SHL 23) - setnz al - mov bMMXSupported, eax - } - return bMMXSupported; - } - -#endif - -/******************************************************************** -Desc: Performs part of the FLAIM block checksum algorithm - using MMX instructions. -*********************************************************************/ -#if defined( FLM_WATCOM_NLM) - - #pragma aux FastBlockCheckSumMMX parm [ESI] [eax] [ebx] [ecx]; - #pragma aux FastBlockCheckSumMMX = \ - 0x50 /* push eax ;save the sum pointer */\ - 0x53 /* push ebx ;save the xor pointer */\ - 0x8B 0x10 /* mov edx, [eax] ;for local add */\ - 0x81 0xE2 0xFF 0x00 0x00 0x00 /* and edx, 0ffh ;clear unneeded bits */\ - 0x8B 0x1B /* mov ebx, [ebx] ;for local xor */\ - 0x81 0xE3 0xFF 0x00 0x00 0x00 /* and ebx, 0ffh ;clear unneeded bits */\ - 0x8B 0xF9 /* mov edi, ecx ;save the amount to copy */\ - 0x83 0xF9 0x20 /* cmp ecx, 32 ;see if we have enough for the big loop */\ - 0x0F 0x82 0x63 0x00 0x00 0x00 /* jb #MediumStuff */\ - 0xC1 0xE9 0x05 /* shr ecx, 5 ;convert length to 32 byte blocks */\ - 0x83 0xE7 0x1F /* and edi, 01fh ;change saved length to remainder */\ - 0x0F 0xEF 0xED /* pxor mm5, mm5 ;wasted space to 16 byte align the upcoming loop */\ - 0x0F 0x6E 0xE2 /* movd mm4,edx */\ - 0x0F 0x6E 0xEB /* movd mm5,ebx */\ - /* #BigStuffLoop: */\ - /* ;load up mm0 - mm3 with 8 bytes each of data. */\ - 0x0F 0x6F 0x06 /* movq mm0, [esi] */\ - 0x0F 0x6F 0x4E 0x08 /* movq mm1, [esi + 8] */\ - 0x0F 0x6F 0x56 0x10 /* movq mm2, [esi + 16] */\ - 0x0F 0x6F 0x5E 0x18 /* movq mm3, [esi + 24] */\ - 0x83 0xC6 0x20 /* add esi, 32 ;move the data pointer ahead 32 */\ - /* ;add mm0 - mm3 to mm4 */\ - /* ;xor mm0 - mm3 with mm5 */\ - 0x0F 0xFC 0xE0 /* paddb mm4, mm0 */\ - 0x0F 0xEF 0xE8 /* pxor mm5, mm0 */\ - 0x0F 0xFC 0xE1 /* paddb mm4, mm1 */\ - 0x0F 0xEF 0xE9 /* pxor mm5, mm1 */\ - 0x0F 0xFC 0xE2 /* paddb mm4, mm2 */\ - 0x0F 0xEF 0xEA /* pxor mm5, mm2 */\ - 0x0F 0xFC 0xE3 /* paddb mm4, mm3 */\ - 0x0F 0xEF 0xEB /* pxor mm5, mm3 */\ - 0x49 /* dec ecx ;see if there is more to do */\ - 0x75 0xD3 /* jnz #BigStuffLoop */\ - /* ;mm4 contains the sum to this point */\ - /* ;mm5 contains the xor to this point */\ - /* ;edi contains the bytes left */\ - /* ;esi points to data left to do */\ - /* ;extract the xor value from mm5 and put it in ebx */\ - 0x0F 0x7E 0xEB /* movd ebx, mm5 */\ - 0x0F 0x73 0xD5 0x20 /* psrlq mm5, 32 */\ - 0x0F 0x7E 0xE8 /* movd eax, mm5 */\ - 0x33 0xD8 /* xor ebx, eax */\ - /* ;extract the sum value from mm4 and put it in dl & dh */\ - 0x0F 0x6F 0xC4 /* movq mm0, mm4 */\ - 0x0F 0x73 0xD0 0x20 /* psrlq mm0, 32 */\ - 0x0F 0xFC 0xE0 /* paddb mm4, mm0 */\ - 0x0F 0x6F 0xC4 /* movq mm0, mm4 */\ - 0x0F 0x73 0xD0 0x10 /* psrlq mm0, 16 */\ - 0x0F 0xFC 0xE0 /* paddb mm4, mm0 */\ - 0x0F 0x7E 0xE2 /* movd edx, mm4 */\ - 0x0F 0x77 /* emms ;end of MMX stuff */\ - 0x8B 0xCF /* mov ecx, edi ;load up the rest of the length */\ - /* ;dl contains half the sum to this point */\ - /* ;dh contains half the sum to this point */\ - /* ;ebx contains the xor to this point - 32 bits wide. */\ - /* ;ecx contains the bytes still left to do */\ - /* ;esi contains pointer to data to checksum */\ - /* #MediumStuff: */\ - 0x83 0xF9 0x04 /* cmp ecx, 4 */\ - 0x0F 0x82 0x1D 0x00 0x00 0x00 /* jb #SmallStuff */\ - 0xC1 0xE9 0x02 /* shr ecx, 2 */\ - 0x83 0xE7 0x03 /* and edi, 3 */\ - /* #DSSumLoop: */\ - 0x8B 0x06 /* mov eax, [esi] */\ - 0x83 0xC6 0x04 /* add esi, 4 */\ - 0x33 0xD8 /* xor ebx, eax */\ - 0x02 0xD0 /* add dl, al */\ - 0x02 0xF4 /* add dh, ah */\ - 0xC1 0xE8 0x10 /* shr eax, 16 */\ - 0x02 0xD0 /* add dl, al */\ - 0x02 0xF4 /* add dh, ah */\ - 0x49 /* dec ecx */\ - 0x75 0xEB /* jnz #DSSumLoop */\ - 0x8B 0xCF /* mov ecx, edi ;load up the rest of the length */\ - /* ;dl contains half the sum to this point */\ - /* ;dh contains half the sum to this point */\ - /* ;ebx contains the xor to this point - 32 bits wide. */\ - /* ;ecx contains the bytes still left to do */\ - /* ;esi contains pointer to data to checksum */\ - /* #SmallStuff: */\ - 0x02 0xD6 /* add dl, dh ;get complete sum in dl */\ - 0x8B 0xC3 /* mov eax, ebx ;get complete xor in bl*/\ - 0xC1 0xE8 0x10 /* shr eax, 16 */\ - 0x66 0x33 0xD8 /* xor bx, ax */\ - 0x32 0xDF /* xor bl, bh */\ - 0x83 0xF9 0x00 /* cmp ecx, 0 ;see if anything left to do - 3 or less bytes */\ - 0x0F 0x84 0x0A 0x00 0x00 0x00 /* jz #Done */\ - /* #SmallStuffLoop: */\ - 0x8A 0x06 /* mov al, [esi] */\ - 0x46 /* inc esi */\ - 0x02 0xD0 /* add dl, al */\ - 0x32 0xD8 /* xor bl, al */\ - 0x49 /* dec ecx */\ - 0x75 0xF6 /* jnz #SmallStuffLoop */\ - /* #Done: */\ - 0x81 0xE2 0xFF 0x00 0x00 0x00 /* and edx, 0ffh ;clear unneeded bits */\ - 0x58 /* pop eax */\ - 0x81 0xE3 0xFF 0x00 0x00 0x00 /* and ebx, 0ffh ;clear unneeded bits */\ - 0x5F /* pop edi */\ - 0x89 0x18 /* mov [eax], ebx */\ - 0x89 0x17 /* mov [edi], edx */\ - parm [ESI] [eax] [ebx] [ecx] \ - modify exact [eax ebx ecx edx ESI EDI]; - -#elif (defined( FLM_WIN) && !defined( FLM_64BIT)) || defined( FLM_NLM) - - static void FastBlockCheckSumMMX( - void * pBlk, - unsigned long *puiChecksum, - unsigned long *puiXORdata, - unsigned long uiNumberOfBytes) - { - __asm - { - mov esi, pBlk - - // Load up the starting checksum values into edx (add) and ebx (XOR) - - mov eax, puiChecksum - mov edx, [eax] // Set local add - and edx, 0ffh ;clear unneeded bits - mov eax, puiXORdata - mov ebx, [eax] - and ebx, 0ffh ;clear unneeded bits - mov ecx, uiNumberOfBytes - mov edi, ecx ;save the amount to copy - - cmp ecx, 32 ;see if we have enough for the big loop - jb MediumStuff - - shr ecx, 5 ;convert length to 32 byte blocks - and edi, 01fh ;change saved length to remainder - pxor mm5, mm5 ;wasted space to 16 byte align the upcoming loop - check tHIS.. - - movd mm4, edx ;set ADD - movd mm5, ebx ;set XOR - - BigStuffLoop: - ;load up mm0 - mm3 with 8 bytes each of data. - movq mm0, [esi] - movq mm1, [esi + 8] - movq mm2, [esi + 16] - movq mm3, [esi + 24] - add esi, 32 ;move the data pointer ahead 32 - ;add mm0 - mm3 to mm4 - ;xor mm0 - mm3 with mm5 - paddb mm4, mm0 - pxor mm5, mm0 - paddb mm4, mm1 - pxor mm5, mm1 - paddb mm4, mm2 - pxor mm5, mm2 - paddb mm4, mm3 - pxor mm5, mm3 - dec ecx ;see if there is more to do - jnz BigStuffLoop - ;mm4 contains the sum to this point - ;mm5 contains the xor to this point - ;edi contains the bytes left - ;esi points to data left to do - ;extract the xor value from mm5 and put it in ebx - movd ebx, mm5 - psrlq mm5, 32 - movd eax, mm5 - xor ebx, eax - ;extract the sum value from mm4 and put it in dl & dh - movq mm0, mm4 - psrlq mm0, 32 - paddb mm4, mm0 - movq mm0, mm4 - psrlq mm0, 16 - paddb mm4, mm0 - movd edx, mm4 - emms ;end of MMX stuff - - mov ecx, edi ;load up the rest of the length - ;dl contains half the sum to this point - ;dh contains half the sum to this point - ;ebx contains the xor to this point - 32 bits wide. - ;ecx contains the bytes still left to do - ;esi contains pointer to data to checksum - MediumStuff: - cmp ecx, 4 - jb SmallStuff - shr ecx, 2 - and edi, 3 - - DSSumLoop: - mov eax, [esi] - add esi, 4 - xor ebx, eax - add dl, al - add dh, ah - shr eax, 16 - add dl, al - add dh, ah - dec ecx - jnz DSSumLoop - mov ecx, edi ;load up the rest of the length - ;dl contains half the sum to this point - ;dh contains half the sum to this point - ;ebx contains the xor to this point - 32 bits wide. - ;ecx contains the bytes still left to do - ;esi contains pointer to data to checksum - SmallStuff: - add dl, dh ;get complete sum in dl - mov eax, ebx ;get complete xor in bl - shr eax, 16 - xor bx, ax - xor bl, bh - cmp ecx, 0 ;see if anything left to do - 3 or less bytes - jz Done - - SmallStuffLoop: - mov al, [esi] - inc esi - add dl, al - xor bl, al - dec ecx - jnz SmallStuffLoop - Done: - and edx, 0ffh ;clear unneeded bits - and ebx, 0ffh ;clear unneeded bits - - // Set the return values. - - mov eax, puiChecksum // Address of add result/start - mov [eax], edx - - mov eax, puiXORdata // Address of xor result/start - mov [eax], ebx - } - return; - } -#endif - -/****************************************************************************** -Desc: Performs part of the FLAIM block checksum algorithm - using 386 and NOT MMX instructions. -******************************************************************************/ -#if defined( FLM_WATCOM_NLM) - - #pragma aux FastBlockCheckSum386 parm [ESI] [eax] [ebx] [ecx]; - - #pragma aux FastBlockCheckSum386 = \ - 0x50 /* push eax ;save the sum pointer */\ - 0x53 /* push ebx ;save the xor pointer */\ - 0x8B 0x10 /* mov edx, [eax] ;for local add */\ - 0x81 0xE2 0xFF 0x00 0x00 0x00 /* and edx, 0ffh ;clear unneeded bits */\ - 0x8B 0x1B /* mov ebx, [ebx] ;for local xor */\ - 0x81 0xE3 0xFF 0x00 0x00 0x00 /* and ebx, 0ffh ;clear unneeded bits */\ - /* ;dl contains the sum to this point */\ - /* ;ebx contains the xor to this point - 32 bits wide. */\ - /* ;ecx contains the bytes still left to do */\ - /* ;esi contains pointer to data to checksum */\ - 0x83 0xF9 0x04 /* cmp ecx, 4 */\ - 0x0F 0x82 0x1F 0x00 0x00 0x00 /* jb #SmallStuff */\ - 0x8B 0xF9 /* mov edi, ecx */\ - 0xC1 0xE9 0x02 /* shr ecx, 2 */\ - 0x83 0xE7 0x03 /* and edi, 3 */\ - /* #DSSumLoop: */\ - 0x8B 0x06 /* mov eax, [esi] */\ - 0x83 0xC6 0x04 /* add esi, 4 */\ - 0x33 0xD8 /* xor ebx, eax */\ - 0x02 0xD0 /* add dl, al */\ - 0x02 0xF4 /* add dh, ah */\ - 0xC1 0xE8 0x10 /* shr eax, 16 */\ - 0x02 0xD0 /* add dl, al */\ - 0x02 0xF4 /* add dh, ah */\ - 0x49 /* dec ecx */\ - 0x75 0xEB /* jnz #DSSumLoop */\ - 0x8B 0xCF /* mov ecx, edi ;load up the rest of the length */\ - /* ;dl contains half the sum to this point */\ - /* ;dh contains half the sum to this point */\ - /* ;ebx contains the xor to this point - 32 bits wide. */\ - /* ;ecx contains the bytes still left to do */\ - /* ;esi contains pointer to data to checksum */\ - /* #SmallStuff: */\ - 0x02 0xD6 /* add dl, dh ;get complete sum in dl */\ - 0x8B 0xC3 /* mov eax, ebx ;get complete xor in bl*/\ - 0xC1 0xE8 0x10 /* shr eax, 16 */\ - 0x66 0x33 0xD8 /* xor bx, ax */\ - 0x32 0xDF /* xor bl, bh */\ - 0x83 0xF9 0x00 /* cmp ecx, 0 ;see if anything left to do - 3 or less bytes */\ - 0x0F 0x84 0x0A 0x00 0x00 0x00 /* jz #Done */\ - /* #SmallStuffLoop: */\ - 0x8A 0x06 /* mov al, [esi] */\ - 0x46 /* inc esi */\ - 0x02 0xD0 /* add dl, al */\ - 0x32 0xD8 /* xor bl, al */\ - 0x49 /* dec ecx */\ - 0x75 0xF6 /* jnz #SmallStuffLoop */\ - /* #Done: */\ - 0x81 0xE2 0xFF 0x00 0x00 0x00 /* and edx, 0ffh ;clear unneeded bits */\ - 0x58 /* pop eax */\ - 0x81 0xE3 0xFF 0x00 0x00 0x00 /* and ebx, 0ffh ;clear unneeded bits */\ - 0x5F /* pop edi */\ - 0x89 0x18 /* mov [eax], ebx */\ - 0x89 0x17 /* mov [edi], edx */\ - parm [ESI] [eax] [ebx] [ecx] \ - modify exact [eax ebx ecx edx ESI EDI]; - -#elif (defined( FLM_WIN) && !defined( FLM_64BIT)) || defined( FLM_NLM) - - static void FastBlockCheckSum386( - void * pBlk, - unsigned long *puiChecksum, - unsigned long *puiXORdata, - unsigned long uiNumberOfBytes) - { - __asm - { - mov esi, pBlk - - // Load up the starting checksum values into edx (add) and ebx (XOR) - - mov eax, puiChecksum - mov edx, [eax] // Set local add - and edx, 0ffh ;clear unneeded bits - mov eax, puiXORdata - mov ebx, [eax] - and ebx, 0ffh ;clear unneeded bits - mov ecx, uiNumberOfBytes - - ;dl contains the sum to this point - ;ebx contains the xor to this point - 32 bits wide. - ;ecx contains the bytes still left to do - ;esi contains pointer to data to checksum - cmp ecx, 4 - jb SmallStuff - mov edi, ecx - shr ecx, 2 - and edi, 3 - DSSumLoop: - mov eax, [esi] - add esi, 4 - xor ebx, eax - add dl, al - add dh, ah - shr eax, 16 - add dl, al - add dh, ah - dec ecx - jnz DSSumLoop - mov ecx, edi ;load up the rest of the length - ;dl contains half the sum to this point - ;dh contains half the sum to this point - ;ebx contains the xor to this point - 32 bits wide. - ;ecx contains the bytes still left to do - ;esi contains pointer to data to checksum - SmallStuff: - add dl, dh ;get complete sum in dl - mov eax, ebx ;get complete xor in bl - shr eax, 16 - xor bx, ax - xor bl, bh - cmp ecx, 0 ;see if anything left to do - 3 or less bytes - jz Done - - SmallStuffLoop: - mov al, [esi] - inc esi - add dl, al - xor bl, al - dec ecx - jnz SmallStuffLoop - Done: - and edx, 0ffh ;clear unneeded bits - and ebx, 0ffh ;clear unneeded bits - - // Set the return values. - - mov eax, puiChecksum // Address of add result/start - mov [eax], edx - - mov eax, puiXORdata // Address of xor result/start - mov [eax], ebx - } - return; - } -#endif - -/****************************************************************************** -Desc: Performs part of the FLAIM block checksum algorithm - using MMX or 386 instructions. -Note: FastBlockCheckSum will start with the checksum and xordata you - pass in. It assumes that the data is already dword aligned. -******************************************************************************/ -#if (defined( FLM_WIN) && !defined( FLM_64BIT)) || defined( FLM_NLM) -void FastBlockCheckSum( - void * pBlk, - FLMUINT * puiChecksum, - FLMUINT * puiXORdata, - FLMUINT uiNumberOfBytes) -{ - if( gv_mmxCheckSumFlag == 1) - { - FastBlockCheckSumMMX( (void *) pBlk, (unsigned long *) puiChecksum, - (unsigned long *) puiXORdata, (unsigned long) uiNumberOfBytes); - } - else - { - FastBlockCheckSum386( (void *) pBlk, (unsigned long *) puiChecksum, - (unsigned long *) puiXORdata, (unsigned long) uiNumberOfBytes); - } -} -#endif - -/****************************************************************************** -Desc: Sets the global variable to check if MMX instructions are allowed. -******************************************************************************/ -#if (defined( FLM_WIN) && !defined( FLM_64BIT)) || defined( FLM_NLM) -void InitFastBlockCheckSum( void) -{ - // NOTE that GetMMXSupported assumes that we are running on at least a - // pentium. The check to see if we are on a pentium requires that we - // modify the flags register, and we can't do that if we are running - // in ring3. Because NetWare 5 - according to our product marketing - - // requires at least a P5 90Mhz, we will be safe. When you port this - // code to NT, you may need to come up with a safe way to see if we - // can do MMX instructions - unless you can assume that even on NT you - // will be on at least a P5. - - gv_mmxCheckSumFlag = GetMMXSupported(); -} -#endif - /******************************************************************** Desc: Compares or sets the checksum value in a block. Operates to compare the block checksum with the actual checksum. @@ -538,24 +31,17 @@ Ret: if (Compare) returns FERR_BLOCK_CHECKSUM block checksum does not agree with checksum header values. *********************************************************************/ RCODE BlkCheckSum( - FLMBYTE * pucBlkPtr, // Points to block - FLMINT iCompare, // TRUE compare checksums, FALSE set chksum - // Use CHECKSUM_CHECK or CHECKSUM_SET - FLMUINT uiBlkAddress, // Expected block address (3.x version) - FLMUINT uiBlkSize) // Used to verify that we don't read outside - // of an allocation. + FLMBYTE * pucBlkPtr, + FLMINT iCompare, + FLMUINT uiBlkAddress, + FLMUINT uiBlkSize) { RCODE rc = FERR_OK; -#if !((defined( FLM_WIN) && !defined( FLM_64BIT)) || defined( FLM_NLM)) - FLMBYTE ucTmp; - FLMBYTE * pucCur; - FLMBYTE * pucEnd; -#endif - FLMUINT uiAdds; - FLMUINT uiXORs; - FLMUINT uiCurrCheckSum = 0; - FLMUINT uiNewCheckSum; + FLMUINT uiCurrChecksum; + FLMUINT uiNewChecksum; FLMUINT uiEncryptSize; + FLMUINT uiAdds = 0; + FLMUINT uiXORs = 0; FLMBYTE * pucSaveBlkPtr = pucBlkPtr; // Check the block length against the maximum block size @@ -574,7 +60,7 @@ RCODE BlkCheckSum( if( iCompare == CHECKSUM_CHECK) { - uiCurrCheckSum = (FLMUINT)(((FLMUINT)pucBlkPtr[ BH_CHECKSUM_HIGH] << 8) + + uiCurrChecksum = (FLMUINT)(((FLMUINT)pucBlkPtr[ BH_CHECKSUM_HIGH] << 8) + (FLMUINT)pucBlkPtr[ BH_CHECKSUM_LOW]); } @@ -597,84 +83,16 @@ RCODE BlkCheckSum( uiAdds += (FLMBYTE)uiBlkAddress; uiXORs ^= (FLMBYTE)uiBlkAddress; } - -#if defined( FLM_NLM) || (defined( FLM_WIN) && !defined( FLM_64BIT)) - - FastBlockCheckSum( pucBlkPtr, &uiAdds, &uiXORs, - (unsigned long)uiEncryptSize); - -#else - -#ifdef FLM_64BIT - pucCur = pucBlkPtr; - pucEnd = pucBlkPtr + (uiEncryptSize & 0xFFFFFFFFFFFFFFF8); -#else - pucCur = pucBlkPtr; - pucEnd = pucBlkPtr + (uiEncryptSize & 0xFFFFFFFC); -#endif - - while( pucCur < pucEnd) - { - FLMUINT uiValue = *(FLMUINT *)pucCur; - - uiXORs ^= uiValue; - - uiAdds += (FLMBYTE)uiValue; - - uiValue >>= 8; - uiAdds += (FLMBYTE)uiValue; - - uiValue >>= 8; - uiAdds += (FLMBYTE)uiValue; - -#ifdef FLM_64BIT - uiValue >>= 8; - uiAdds += (FLMBYTE)uiValue; - - uiValue >>= 8; - uiAdds += (FLMBYTE)uiValue; - - uiValue >>= 8; - uiAdds += (FLMBYTE)uiValue; - - uiValue >>= 8; - uiAdds += (FLMBYTE)uiValue; -#endif - - uiAdds += (FLMBYTE)(uiValue >> 8); - pucCur += sizeof( FLMUINT); - } - - ucTmp = (FLMBYTE)uiXORs; - ucTmp ^= (FLMBYTE)(uiXORs >> 8); - ucTmp ^= (FLMBYTE)(uiXORs >> 16); - ucTmp ^= (FLMBYTE)(uiXORs >> 24); -#ifdef FLM_64BIT - ucTmp ^= (FLMBYTE)(uiXORs >> 32); - ucTmp ^= (FLMBYTE)(uiXORs >> 40); - ucTmp ^= (FLMBYTE)(uiXORs >> 48); - ucTmp ^= (FLMBYTE)(uiXORs >> 56); -#endif - uiXORs = ucTmp; - - pucCur = pucEnd; - pucEnd = pucBlkPtr + uiEncryptSize; - - while( pucCur < pucEnd) - { - uiAdds += *pucCur; - uiXORs ^= *pucCur++; - } -#endif - - uiNewCheckSum = (((uiAdds << 8) + uiXORs) & 0xFFFF); + + f_calcFastChecksum( pucBlkPtr, uiEncryptSize, &uiAdds, &uiXORs); + uiNewChecksum = (((uiAdds << 8) + uiXORs) & 0xFFFF); // Set the checksum if (iCompare == CHECKSUM_SET) { - pucSaveBlkPtr[ BH_CHECKSUM_HIGH] = (FLMBYTE)(uiNewCheckSum >> 8); - pucSaveBlkPtr[ BH_CHECKSUM_LOW] = (FLMBYTE)uiNewCheckSum; + pucSaveBlkPtr[ BH_CHECKSUM_HIGH] = (FLMBYTE)(uiNewChecksum >> 8); + pucSaveBlkPtr[ BH_CHECKSUM_LOW] = (FLMBYTE)uiNewChecksum; goto Exit; } @@ -692,8 +110,8 @@ RCODE BlkCheckSum( // sides of the checksum, the checksum is OK and that value // is the first byte value. - byXor = (FLMBYTE) uiNewCheckSum; - byAdd = (FLMBYTE) (uiNewCheckSum >> 8); + byXor = (FLMBYTE) uiNewChecksum; + byAdd = (FLMBYTE) (uiNewChecksum >> 8); byDelta = byXor ^ pucSaveBlkPtr [BH_CHECKSUM_LOW]; // Here is the big check, if byDelta is also what is @@ -722,8 +140,8 @@ RCODE BlkCheckSum( // we just allow it - checksumming isn't a perfect check anyway. // VISIT: We do eventually want to get rid of this forgiving code. - if (uiNewCheckSum == uiCurrCheckSum || - ((!uiNewCheckSum) && (uiCurrCheckSum == 1))) + if (uiNewChecksum == uiCurrChecksum || + ((!uiNewChecksum) && (uiCurrChecksum == 1))) { pucSaveBlkPtr [BH_CHECKSUM_LOW] = (FLMBYTE) uiBlkAddress; goto Exit; @@ -748,7 +166,7 @@ FLMUINT lgHdrCheckSum( { FLMUINT uiCnt; FLMUINT uiTempSum; - FLMUINT uiCurrCheckSum; + FLMUINT uiCurrChecksum; FLMUINT uiTempSum2; FLMUINT uiBytesToChecksum; @@ -764,13 +182,13 @@ FLMUINT lgHdrCheckSum( // Unconverted databases may have a 0xFFFF or a zero in the checksum // If 0xFFFF, change to a zero so we only have to deal with one value. - if( (uiCurrCheckSum = (FLMUINT)FB2UW( + if( (uiCurrChecksum = (FLMUINT)FB2UW( &pucLogHdr[ LOG_HDR_CHECKSUM])) == 0xFFFF) { - uiCurrCheckSum = 0; + uiCurrChecksum = 0; } - if( bCompare && !uiCurrCheckSum) + if( bCompare && !uiCurrChecksum) { return( 0); } @@ -798,7 +216,7 @@ FLMUINT lgHdrCheckSum( uiTempSum2 = 1; } - return( (FLMUINT)(((bCompare) && (uiTempSum2 == uiCurrCheckSum)) + return( (FLMUINT)(((bCompare) && (uiTempSum2 == uiCurrChecksum)) ? (FLMUINT)0 : uiTempSum2) ); } diff --git a/flaim/src/ecache.cpp b/flaim/src/ecache.cpp deleted file mode 100644 index 2b9fc0a..0000000 --- a/flaim/src/ecache.cpp +++ /dev/null @@ -1,722 +0,0 @@ -//------------------------------------------------------------------------- -// Desc: Extended cache manager. -// Tabs: 3 -// -// Copyright (c) 2001-2006 Novell, Inc. All Rights Reserved. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of version 2 of the GNU General Public -// License as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, contact Novell, Inc. -// -// To contact Novell about this file by physical or electronic mail, -// you may find current contact information at www.novell.com -// -// $Id: ecache.cpp 12245 2006-01-19 14:29:51 -0700 (Thu, 19 Jan 2006) dsanders $ -//------------------------------------------------------------------------- - -#include "flaimsys.h" - -#ifdef ECACHE_TEST -/**************************************************************************** -Desc: Routine to simulate the ESMAlloc function on platforms that do not - support ESM -****************************************************************************/ -FLMUINT testESMAllocFunc( - FLMUINT64 size, - FLMUINT options, - ESMADDR64 * esmAddress) -{ - FLMUINT uiErr = 0; - void * pvAlloc; - - F_UNREFERENCED_PARM( options); - - if( RC_BAD( f_alloc( (FLMUINT)size, &pvAlloc))) - { - uiErr = 1; - goto Exit; - } - - *esmAddress = (FLMUINT64)pvAlloc; - -Exit: - - return( uiErr); -} - -/**************************************************************************** -Desc: Routine to simulate the ESMFree function on platforms that do not - support ESM -****************************************************************************/ -FLMUINT testESMFreeFunc( - ESMADDR64 esmAddress) -{ - void * pvAlloc = (void *)((FLMUINT)esmAddress); - - f_free( &pvAlloc); - return( 0); -} - -/**************************************************************************** -Desc: Routine to simulate the ESMQuery function on platforms that do not - support ESM -****************************************************************************/ -FLMUINT testESMQueryFunc( - FLMUINT32 ui32BufferSize, - ESMQueryInfo * pBuffer) -{ - F_UNREFERENCED_PARM( ui32BufferSize); - - f_memset( pBuffer, 0, sizeof( ESMQueryInfo)); - pBuffer->ui64TotalExtendedMemory = FLM_MAX_UINT64; - pBuffer->ui64RemainingExtendedMemory = FLM_MAX_UINT64; - pBuffer->ui32TotalMemoryBelow4Gig = FLM_MAX_UINT32; - return( 0); -} - -/**************************************************************************** -Desc: Routine to simulate the ESMAllocWindow function on platforms that - do not support ESM -****************************************************************************/ -FLMUINT testESMAllocWinFunc( - FLMUINT32 ui32Size, - FLMUINT32 * pui32LogicalAddress, - FLMUINT32 ui32Caller) -{ - F_UNREFERENCED_PARM( ui32Caller); - *pui32LogicalAddress = FLM_MAX_UINT32; - return( 0); - -} - -/**************************************************************************** -Desc: Routine to simulate the ESMFreeWindow function on platforms that do not - support ESM -****************************************************************************/ -FLMUINT testESMFreeWinFunc( - FLMUINT32 ui32LogicalAddress, - FLMUINT32 ui32Caller) -{ - F_UNREFERENCED_PARM( ui32LogicalAddress); - F_UNREFERENCED_PARM( ui32Caller); - return( 0); -} - -/**************************************************************************** -Desc: Routine to simulate the ESMMapMemory function on platforms that do not - support ESM -****************************************************************************/ -FLMUINT testESMMapMemoryFunc( - FLMUINT32 ui32WindowAddress, - ESMADDR64 esmAddress, - FLMUINT32 ui32Size) -{ - F_UNREFERENCED_PARM( ui32WindowAddress); - F_UNREFERENCED_PARM( esmAddress); - F_UNREFERENCED_PARM( ui32Size); - - flmAssert( 0); - return( 0); -} - -#endif // ECACHE_TEST - -/**************************************************************************** -Desc: Constructor -****************************************************************************/ -FlmECache::FlmECache() -{ - m_uiDbBlockSize = 0; - m_uiPageSize = 0; - m_ui64MaxFileSize = 0; - m_hMutex = F_MUTEX_NULL; - m_pAllocTable = NULL; - m_uiAllocTableSize = 0; - m_pvWindow = NULL; - m_ui64MappedESMAddr = 0; - m_ui64BytesAllocated = 0; - m_ui64CacheHits = 0; - m_ui64CacheFaults = 0; - m_fnESMAlloc = NULL; - m_fnESMFree = NULL; - m_fnESMQuery = NULL; - m_fnESMAllocWindow = NULL; - m_fnESMFreeWindow = NULL; - m_fnESMMapMemory = NULL; -} - -/**************************************************************************** -Desc: Destructor -****************************************************************************/ -FlmECache::~FlmECache() -{ - cleanup(); -} - -/**************************************************************************** -Desc: Frees all allocated resources -****************************************************************************/ -void FlmECache::cleanup( void) -{ - FLMUINT uiLoop; - ECACHE_HDR * pECache; - - if( m_pAllocTable) - { - for( uiLoop = 0, pECache = m_pAllocTable; - uiLoop < m_uiAllocTableSize; uiLoop++, pECache++) - { - if( pECache->esmAddr != 0) - { - if( m_fnESMFree( pECache->esmAddr) != 0) - { - flmAssert( 0); - } - pECache->esmAddr = 0; - } - } - - f_free( &m_pAllocTable); - } - - if( m_pvWindow) - { - m_fnESMFreeWindow( (FLMUINT32)((FLMUINT)m_pvWindow), 0); - m_pvWindow = NULL; - m_ui64MappedESMAddr = 0; - } - - if( m_hMutex != F_MUTEX_NULL) - { - f_mutexDestroy( &m_hMutex); - } -} - -/**************************************************************************** -Desc: Allocates resources needed by the ECache object -****************************************************************************/ -FLMBOOL FlmECache::setupECache( - FLMUINT uiBlockSize, - FLMUINT uiMaxFileSize) -{ - FLMBOOL bSetupOk = FALSE; - ESMQueryInfo esmQueryInfo; - - flmAssert( VALID_BLOCK_SIZE( uiBlockSize)); - flmAssert( uiMaxFileSize && (uiMaxFileSize % 4096) == 0); - flmAssert( m_pAllocTable == NULL); - -#if defined( FLM_NLM) && !defined( ECACHE_TEST) - - if( (m_fnESMAlloc = (ESM_ALLOC_FUNC)ImportPublicSymbol( - (unsigned long)f_getNLMHandle(), - (unsigned char *)"\x08" "ESMAlloc")) == NULL) - { - goto Exit; - } - - if( (m_fnESMFree = (ESM_FREE_FUNC)ImportPublicSymbol( - (unsigned long)f_getNLMHandle(), - (unsigned char *)"\x07" "ESMFree")) == NULL) - { - goto Exit; - } - - if( (m_fnESMQuery = (ESM_QUERY_FUNC)ImportPublicSymbol( - (unsigned long)f_getNLMHandle(), - (unsigned char *)"\x08" "ESMQuery")) == NULL) - { - goto Exit; - } - - if( (m_fnESMAllocWindow = (ESM_ALLOC_WIN_FUNC)ImportPublicSymbol( - (unsigned long)f_getNLMHandle(), - (unsigned char *)"\x0E" "ESMAllocWindow")) == NULL) - { - goto Exit; - } - - if( (m_fnESMFreeWindow = (ESM_FREE_WIN_FUNC)ImportPublicSymbol( - (unsigned long)f_getNLMHandle(), - (unsigned char *)"\x0D" "ESMFreeWindow")) == NULL) - { - goto Exit; - } - - if( (m_fnESMMapMemory = (ESM_MAP_MEM_FUNC)ImportPublicSymbol( - (unsigned long)f_getNLMHandle(), - (unsigned char *)"\x0C" "ESMMapMemory")) == NULL) - { - goto Exit; - } - -#elif defined( ECACHE_TEST) - - m_fnESMAlloc = testESMAllocFunc; - m_fnESMFree = testESMFreeFunc; - m_fnESMQuery = testESMQueryFunc; - m_fnESMAllocWindow = testESMAllocWinFunc; - m_fnESMFreeWindow = testESMFreeWinFunc; - m_fnESMMapMemory = testESMMapMemoryFunc; - -#endif - - if (!m_fnESMQuery) - { - goto Exit; - } - - // Query to see if the machine has any ESM memory. - - if( m_fnESMQuery( (unsigned)sizeof( ESMQueryInfo), &esmQueryInfo) != 0) - { - goto Exit; - } - - // If no ESM, fail with a "not implemented" error - - if( !esmQueryInfo.ui64TotalExtendedMemory) - { - goto Exit; - } - - // Determine the system's memory page size - -#ifdef FLM_NLM - m_uiPageSize = (4 * 1024 * 1024); // NetWare uses a fixed page size -#endif - - // Allocate the lookup table. Set m_uiAllocTableSize to - // 64 GB / 4MB (max supported memory on NetWare / min alloc - // size in extended memory). - - flmAssert( m_uiPageSize != 0); - m_uiAllocTableSize = (FLMUINT)(esmQueryInfo.ui64TotalExtendedMemory / - (FLMUINT64)m_uiPageSize); - - if( m_uiAllocTableSize == 0) - { - goto Exit; - } - - if (RC_BAD( f_calloc( - m_uiAllocTableSize * sizeof( ECACHE_HDR), &m_pAllocTable))) - { - goto Exit; - } - - // Allocate a mutex - - if( RC_BAD( f_mutexCreate( &m_hMutex))) - { - goto Exit; - } - - // Round the maximum database file size up so that it - // is a multiple of the allocation page size. This makes - // it easier to calculate the location of pages that belong - // to a particular file. - - m_ui64MaxFileSize = uiMaxFileSize; - if( m_ui64MaxFileSize % (FLMUINT64)m_uiPageSize) - { - m_ui64MaxFileSize += ((FLMUINT64)m_uiPageSize) - - (m_ui64MaxFileSize % (FLMUINT64)m_uiPageSize); - } - m_uiDbBlockSize = uiBlockSize; - bSetupOk = TRUE; - -Exit: - - if( !bSetupOk) - { - cleanup(); - } - - return( bSetupOk); -} - -/**************************************************************************** -Desc: Retreives a block or partial block from ECache -****************************************************************************/ -RCODE FlmECache::getBlock( - FLMUINT uiBlockAddr, - FLMBYTE * pucBlock, - FLMUINT uiLength) -{ - RCODE rc = FERR_OK; - FLMUINT uiFileNum = FSGetFileNumber( uiBlockAddr); - FLMUINT uiExpectedStartOffset; - FLMUINT uiBlkOffsetInPage; - FLMBYTE * pucSrcBlk; - FLMBOOL bMutexLocked = FALSE; - ECACHE_HDR * pHeader = NULL; - -#ifdef FLM_DEBUG - flmAssert( uiLength >= BH_OVHD); - flmAssert( uiLength <= m_uiDbBlockSize); -#else - F_UNREFERENCED_PARM( uiLength); -#endif - - getPosition( uiBlockAddr, &uiBlkOffsetInPage, - &uiExpectedStartOffset, &pHeader); - - f_mutexLock( m_hMutex); - bMutexLocked = TRUE; - - if( !pHeader->esmAddr || - pHeader->uiStartBlkAddr != - FSBlkAddress( uiFileNum, uiExpectedStartOffset)) - { - m_ui64CacheFaults++; - rc = RC_SET( FERR_NOT_FOUND); - goto Exit; - } - - // Map the ESM page into our window - - if( !mapToWindow( pHeader)) - { - rc = RC_SET( FERR_NOT_FOUND); - goto Exit; - } - - // Copy the block into the destination buffer - - pucSrcBlk = ((FLMBYTE *)m_pvWindow) + uiBlkOffsetInPage; - if( FB2UD( &pucSrcBlk[ BH_ADDR]) != 0) - { - FLMUINT uiEncSize = getEncryptSize( pucSrcBlk); - - if( uiEncSize >= BH_OVHD && uiEncSize <= m_uiDbBlockSize) - { - f_memcpy( pucBlock, pucSrcBlk, uiEncSize); - if( uiFileNum > 0 && uiFileNum < MAX_DATA_FILE_NUM_VER40 && - (GET_BH_ADDR( pucBlock) & 0xFFFFFF00) != - (uiBlockAddr & 0xFFFFFF00)) - { - goto Invalidate_Block; - } - m_ui64CacheHits++; - } - else - { -Invalidate_Block: - - // Invalidate the block - - UD2FBA( 0, pucSrcBlk); - m_ui64CacheFaults++; - rc = RC_SET( FERR_NOT_FOUND); - goto Exit; - } - } - else - { - m_ui64CacheFaults++; - rc = RC_SET( FERR_NOT_FOUND); - goto Exit; - } - - f_mutexUnlock( m_hMutex); - bMutexLocked = FALSE; - -Exit: - - if( bMutexLocked) - { - f_mutexUnlock( m_hMutex); - } - - return( rc); -} - -/**************************************************************************** -Desc: Puts a block or partial block into ECache -****************************************************************************/ -void FlmECache::putBlock( - FLMUINT uiBlockAddr, - FLMBYTE * pucBlock, - FLMBOOL bCalcChecksum) -{ - FLMUINT uiFileNum = FSGetFileNumber( uiBlockAddr); - FLMUINT uiExpectedStartOffset; - FLMUINT uiBlkOffsetInPage; - FLMUINT uiEncSize = getEncryptSize( pucBlock); - FLMBYTE * pucDestBlk; - FLMBOOL bMutexLocked = FALSE; - FLMBOOL bBlockWritten = FALSE; - ECACHE_HDR * pHeader = NULL; - - getPosition( uiBlockAddr, &uiBlkOffsetInPage, - &uiExpectedStartOffset, &pHeader); - - if( uiEncSize < BH_OVHD || uiEncSize > m_uiDbBlockSize) - { - goto Exit; - } - - f_mutexLock( m_hMutex); - bMutexLocked = TRUE; - - if( !pHeader->esmAddr || - pHeader->uiStartBlkAddr != - FSBlkAddress( uiFileNum, uiExpectedStartOffset)) - { - if( !pHeader->esmAddr) - { - if( m_fnESMAlloc( m_uiPageSize, 0, &pHeader->esmAddr) != 0) - { - pHeader->esmAddr = 0; - goto Exit; - } - m_ui64BytesAllocated += m_uiPageSize; - } - - // Map the page into our local window - - if( !mapToWindow( pHeader)) - { - goto Exit; - } - - // Fill the block with zeros - - f_memset( m_pvWindow, 0, m_uiPageSize); - - // Update the cache header - - pHeader->uiStartBlkAddr = FSBlkAddress( uiFileNum, - uiExpectedStartOffset); - } - else - { - // Map the page into our local window - - if( !mapToWindow( pHeader)) - { - goto Exit; - } - } - - flmAssert( uiFileNum == FSGetFileNumber( pHeader->uiStartBlkAddr)); - - pucDestBlk = ((FLMBYTE *)m_pvWindow) + uiBlkOffsetInPage; - f_memcpy( pucDestBlk, pucBlock, uiEncSize); - bBlockWritten = TRUE; - - if( bCalcChecksum) - { - if( RC_BAD( BlkCheckSum( pucDestBlk, - CHECKSUM_SET, uiBlockAddr, uiEncSize))) - { - // Invalidate this block since we had an error. - UD2FBA( 0, pucDestBlk); - goto Exit; - } - } - - f_mutexUnlock( m_hMutex); - bMutexLocked = FALSE; - -Exit: - - // If we had an error, invalidate the entire page - - if( !bBlockWritten && pHeader && pHeader->esmAddr != 0) - { - if( !bMutexLocked) - { - f_mutexLock( m_hMutex); - bMutexLocked = TRUE; - } - - // Invalidate the entire page - - m_fnESMFree( pHeader->esmAddr); - pHeader->esmAddr = 0; - pHeader->uiStartBlkAddr = 0; - m_ui64BytesAllocated -= m_uiPageSize; - } - - if( bMutexLocked) - { - f_mutexUnlock( m_hMutex); - } -} - -/**************************************************************************** -Desc: Invalidates a block in ECache so that it will not be returned via - a call to getBlock() -****************************************************************************/ -void FlmECache::invalidateBlock( - FLMUINT uiBlockAddr) -{ - FLMUINT uiFileNum = FSGetFileNumber( uiBlockAddr); - FLMUINT uiExpectedStartOffset; - FLMUINT uiBlkOffsetInPage; - FLMBOOL bMutexLocked = FALSE; - FLMBOOL bBlockWritten = FALSE; - ECACHE_HDR * pHeader = NULL; - - getPosition( uiBlockAddr, &uiBlkOffsetInPage, - &uiExpectedStartOffset, &pHeader); - - f_mutexLock( m_hMutex); - bMutexLocked = TRUE; - - if( pHeader->esmAddr != 0 && - pHeader->uiStartBlkAddr == - FSBlkAddress( uiFileNum, uiExpectedStartOffset)) - { - flmAssert( uiBlkOffsetInPage < m_uiPageSize); - flmAssert( (uiBlkOffsetInPage % m_uiDbBlockSize) == 0); - - // Map the page into our local window - - if( mapToWindow( pHeader)) - { - // Set the block address to 0 - - bBlockWritten = TRUE; - UD2FBA( 0, ((FLMBYTE *)m_pvWindow) + uiBlkOffsetInPage); - } - } - - f_mutexUnlock( m_hMutex); - bMutexLocked = FALSE; -} - -/**************************************************************************** -Desc: Returns ECache statistics -****************************************************************************/ -void FlmECache::getStats( - FLM_ECACHE_USAGE * pUsage, - FLMBOOL bAddToCurrent) -{ - ESMQueryInfo esmQueryInfo; - - if( !bAddToCurrent) - { - f_memset( pUsage, 0, sizeof( FLM_ECACHE_USAGE)); - } - - // Query to get ESM info - - if( m_fnESMQuery( (unsigned)sizeof( ESMQueryInfo), &esmQueryInfo) == 0) - { - pUsage->ui64TotalExtendedMemory = - esmQueryInfo.ui64TotalExtendedMemory; - pUsage->ui64RemainingExtendedMemory = - esmQueryInfo.ui64RemainingExtendedMemory; - } - - f_mutexLock( m_hMutex); - - pUsage->ui64TotalBytesAllocated += m_ui64BytesAllocated; - pUsage->ui64CacheHits += m_ui64CacheHits; - pUsage->ui64CacheFaults += m_ui64CacheFaults; - - f_mutexUnlock( m_hMutex); -} - -/**************************************************************************** -Desc: Determines the position of a block in ECache (memory page, etc.) -****************************************************************************/ -void FlmECache::getPosition( - FLMUINT uiBlockAddr, - FLMUINT * puiBlkOffsetInPage, - FLMUINT * puiExpectedPageStartOffset, - ECACHE_HDR ** ppECacheHdr) -{ - FLMUINT uiPage; - FLMUINT uiFileNum = FSGetFileNumber( uiBlockAddr); - FLMUINT uiFileOffset = FSGetFileOffset( uiBlockAddr); - FLMUINT uiTableOffset; - FLMUINT64 ui64BitAddr; - - ui64BitAddr = ((FLMUINT64)uiFileNum * m_ui64MaxFileSize) + - (FLMUINT64)uiFileOffset; - - uiPage = (FLMUINT)(ui64BitAddr / (FLMUINT64)m_uiPageSize); - - uiTableOffset = uiPage % m_uiAllocTableSize; - - flmAssert( uiTableOffset < m_uiAllocTableSize); - - *ppECacheHdr = &m_pAllocTable[ uiTableOffset]; - - *puiBlkOffsetInPage = uiFileOffset % m_uiPageSize; - flmAssert( (*puiBlkOffsetInPage % m_uiDbBlockSize) == 0); - - *puiExpectedPageStartOffset = - (uiFileOffset / m_uiPageSize) * m_uiPageSize; -} - -/**************************************************************************** -Desc: Maps a specified ESM page into our local address space -Notes: This method assumes that the ECache mutex is locked -****************************************************************************/ -FLMBOOL FlmECache::mapToWindow( - ECACHE_HDR * pHeader) -{ - FLMUINT64 ui64ESMAddr = pHeader->esmAddr; - FLMBOOL bMapped = FALSE; - - flmAssert( ui64ESMAddr != 0); - - if( ui64ESMAddr == m_ui64MappedESMAddr) - { - bMapped = TRUE; - goto Exit; - } - - if( !m_pvWindow) - { - FLMUINT32 ui32LogicalAddr; - - if( m_fnESMAllocWindow( (unsigned)m_uiPageSize, &ui32LogicalAddr, 0) != 0) - { - goto Exit; - } - - m_pvWindow = (void *)((FLMUINT)ui32LogicalAddr); - } - -#ifdef ECACHE_TEST - m_pvWindow = (void *)ui64ESMAddr; -#else - if( m_fnESMMapMemory( (FLMUINT32)((FLMUINT)m_pvWindow), - ui64ESMAddr, (unsigned)m_uiPageSize) != 0) - { - flmAssert( 0); - m_ui64MappedESMAddr = 0; - goto Exit; - } - - m_ui64MappedESMAddr = ui64ESMAddr; - bMapped = TRUE; -#endif - -Exit: - - if( !bMapped) - { - // Invalidate the entire page - m_fnESMFree( pHeader->esmAddr); - pHeader->esmAddr = 0; - pHeader->uiStartBlkAddr = 0; - m_ui64BytesAllocated -= m_uiPageSize; - } - - return( bMapped); -} diff --git a/flaim/src/ecache.h b/flaim/src/ecache.h deleted file mode 100644 index 388bedd..0000000 --- a/flaim/src/ecache.h +++ /dev/null @@ -1,164 +0,0 @@ -//------------------------------------------------------------------------- -// Desc: Extended cache manager structures. -// Tabs: 3 -// -// Copyright (c) 2001-2006 Novell, Inc. All Rights Reserved. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of version 2 of the GNU General Public -// License as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, contact Novell, Inc. -// -// To contact Novell about this file by physical or electronic mail, -// you may find current contact information at www.novell.com -// -// $Id: ecache.h 12245 2006-01-19 14:29:51 -0700 (Thu, 19 Jan 2006) dsanders $ -//------------------------------------------------------------------------- - -#ifndef ECACHE_H -#define ECACHE_H - -#include "fpackon.h" -// IMPORTANT NOTE: No other include files should follow this one except -// for fpackoff.h - -typedef FLMUINT64 ESMADDR64; - -// Prototypes - -#ifdef FLM_NLM - #pragma pack(push, 1) -#endif - -typedef struct ESMQueryInfo -{ - FLMUINT64 ui64TotalExtendedMemory; - FLMUINT64 ui64RemainingExtendedMemory; - FLMUINT32 ui32TotalMemoryBelow4Gig; -} ESMQueryInfo; - -#ifdef FLM_NLM - #pragma pack(pop) -#endif - -typedef FLMUINT (* ESM_ALLOC_FUNC)( - FLMUINT64 size, - FLMUINT options, - ESMADDR64 * esmAddress); - -typedef FLMUINT (* ESM_FREE_FUNC)( - ESMADDR64 esmAddress); - -typedef FLMUINT (* ESM_QUERY_FUNC)( - FLMUINT32 ui32BufferSize, - ESMQueryInfo * pBuffer); - -typedef FLMUINT (* ESM_ALLOC_WIN_FUNC)( - FLMUINT32 ui32Size, - FLMUINT32 * pui32LogicalAddress, - FLMUINT32 ui32Caller); - -typedef FLMUINT (* ESM_FREE_WIN_FUNC)( - FLMUINT32 ui32LogicalAddress, - FLMUINT32 ui32Caller); - -typedef FLMUINT (* ESM_MAP_MEM_FUNC)( - FLMUINT32 ui32WindowAddress, - ESMADDR64 esmAddress, - FLMUINT32 ui32Size); - -typedef struct ECACHE_HDR -{ - ESMADDR64 esmAddr; - FLMUINT uiStartBlkAddr; -} ECACHE_HDR; - -/**************************************************************************** -Desc: Class which provides database caching in extended server memory -****************************************************************************/ -class FlmECache : public F_Base -{ -public: - - // Constructor and Destructor - - FlmECache(); - - virtual ~FlmECache(); - - // Setup - - FLMBOOL setupECache( - FLMUINT uiBlockSize, - FLMUINT uiMaxFileSize); - - // Storage methods - - void putBlock( - FLMUINT uiBlockAddr, - FLMBYTE * pucBlock, - FLMBOOL bCalcChecksum = FALSE); - - void invalidateBlock( - FLMUINT uiBlockAddr); - - // Retrieval methods - - RCODE getBlock( - FLMUINT uiBlockAddr, - FLMBYTE * pucBlock, - FLMUINT uiLength); - - // Statistics - - void getStats( - FLM_ECACHE_USAGE * pUsage, - FLMBOOL bAddToCurrent = FALSE); - - FINLINE FLMUINT getPageSize( void) - { - return( m_uiPageSize); - } - -private: - - void cleanup( void); - - void getPosition( - FLMUINT uiBlockAddr, - FLMUINT * puiBlkOffsetInPage, - FLMUINT * puiExpectedPageStartOffset, - ECACHE_HDR ** ppECacheHdr); - - FLMBOOL mapToWindow( - ECACHE_HDR * pHeader); - - FLMUINT m_uiDbBlockSize; - F_MUTEX m_hMutex; - ECACHE_HDR * m_pAllocTable; - FLMUINT m_uiAllocTableSize; - FLMUINT m_uiPageSize; - void * m_pvWindow; - FLMUINT64 m_ui64MappedESMAddr; - FLMUINT64 m_ui64MaxFileSize; - FLMUINT64 m_ui64BytesAllocated; - FLMUINT64 m_ui64CacheHits; - FLMUINT64 m_ui64CacheFaults; - ESM_ALLOC_FUNC m_fnESMAlloc; - ESM_FREE_FUNC m_fnESMFree; - ESM_QUERY_FUNC m_fnESMQuery; - ESM_ALLOC_WIN_FUNC m_fnESMAllocWindow; - ESM_FREE_WIN_FUNC m_fnESMFreeWindow; - ESM_MAP_MEM_FUNC m_fnESMMapMemory; -}; - -#include "fpackoff.h" - -#endif // ECACHE_H diff --git a/flaim/src/f64bitfh.cpp b/flaim/src/f64bitfh.cpp deleted file mode 100644 index 3f7cc6a..0000000 --- a/flaim/src/f64bitfh.cpp +++ /dev/null @@ -1,856 +0,0 @@ -//------------------------------------------------------------------------- -// Desc: Abstraction class for 64 bit files. -// Tabs: 3 -// -// Copyright (c) 2001,2003,2005-2006 Novell, Inc. All Rights Reserved. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of version 2 of the GNU General Public -// License as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, contact Novell, Inc. -// -// To contact Novell about this file by physical or electronic mail, -// you may find current contact information at www.novell.com -// -// $Id: f64bitfh.cpp 12329 2006-01-20 17:49:30 -0700 (Fri, 20 Jan 2006) ahodgkinson $ -//------------------------------------------------------------------------- - -#include "flaimsys.h" - -/**************************************************************************** -Desc: -****************************************************************************/ -F_64BitFileHandle::F_64BitFileHandle( - FLMUINT uiMaxFileSize) -{ - m_bOpen = FALSE; - m_ucPath[ 0] = 0; - m_ui64EOF = 0; - m_pLockFileHdl = NULL; - f_memset( m_pFileHdlList, 0, sizeof( FH_INFO) * F_64BIT_FHDL_LIST_SIZE); - m_uiMaxFileSize = uiMaxFileSize; - if( !m_uiMaxFileSize) - { - m_uiMaxFileSize = F_64BIT_FHDL_DEFAULT_MAX_FILE_SIZE; - } -} - -/**************************************************************************** -Desc: -****************************************************************************/ -F_64BitFileHandle::~F_64BitFileHandle() -{ - if( m_bOpen) - { - Close(); - } - - flmAssert( !m_pLockFileHdl); -} - -/**************************************************************************** -Desc: -****************************************************************************/ -void F_64BitFileHandle::ReleaseLockFile( - const char * pszBasePath, - FLMBOOL bDelete) -{ -#ifndef FLM_UNIX - F_UNREFERENCED_PARM( bDelete); - F_UNREFERENCED_PARM( pszBasePath); -#endif - - if( m_pLockFileHdl) - { - // Release the lock file - - (void)m_pLockFileHdl->Close(); - m_pLockFileHdl->Release(); - m_pLockFileHdl = NULL; - -#ifdef FLM_UNIX - if( bDelete) - { - char szTmpPath[ F_PATH_MAX_SIZE]; - - // Delete the lock file - - f_strcpy( szTmpPath, pszBasePath); - f_pathAppend( szTmpPath, "64.LCK"); - gv_FlmSysData.pFileSystem->Delete( szTmpPath); - } -#endif - } -} - -/**************************************************************************** -Desc: Closes all data files associated with the object -****************************************************************************/ -void F_64BitFileHandle::Close( - FLMBOOL bDelete) -{ - RCODE rc = FERR_OK; - FLMUINT uiLoop; - F_DirHdl * pDir = NULL; - char szTmpPath[ F_PATH_MAX_SIZE]; - - if( !m_bOpen) - { - return; - } - - for( uiLoop = 0; uiLoop < F_64BIT_FHDL_LIST_SIZE; uiLoop++) - { - if( m_pFileHdlList[ uiLoop].pFileHdl) - { - if( m_pFileHdlList[ uiLoop].bDirty) - { - (void)m_pFileHdlList[ uiLoop].pFileHdl->Flush(); - } - m_pFileHdlList[ uiLoop].pFileHdl->Close(); - m_pFileHdlList[ uiLoop].pFileHdl->Release(); - f_memset( &m_pFileHdlList[ uiLoop], 0, sizeof( FH_INFO)); - } - } - - m_ui64EOF = 0; - m_bOpen = FALSE; - - if( bDelete) - { - if( RC_OK( gv_FlmSysData.pFileSystem->OpenDir( - m_ucPath, "*.64", &pDir))) - { - // Remove all data files - - for( rc = pDir->Next(); !RC_BAD( rc) ; rc = pDir->Next() ) - { - pDir->CurrentItemPath( szTmpPath); - flmAssert( f_strstr( szTmpPath, ".64") != 0); - (void)gv_FlmSysData.pFileSystem->Delete( szTmpPath); - } - - pDir->Release(); - pDir = NULL; - } - - // Release and delete the lock file - - (void)ReleaseLockFile( m_ucPath, TRUE); - - // Remove the directory - - (void)gv_FlmSysData.pFileSystem->RemoveDir( m_ucPath); - } - else - { - (void)ReleaseLockFile( m_ucPath, FALSE); - } -} - -/**************************************************************************** -Desc: Removes a 64-bit file -****************************************************************************/ -RCODE F_64BitFileHandle::Delete( - const char * pszPath) -{ - RCODE rc = FERR_OK; - F_DirHdl * pDir = NULL; - char szTmpPath[ F_PATH_MAX_SIZE]; - - // Can't use this handle to delete something if we already - // have a file open. - - if( m_bOpen) - { - // Can't jump to exit, because it calls ReleaseLockFile - - return( RC_SET( FERR_FAILURE)); - } - - if( RC_BAD( rc = gv_FlmSysData.pFileSystem->Exists( pszPath))) - { - goto Exit; - } - - if( !gv_FlmSysData.pFileSystem->IsDir( pszPath)) - { - // If the path specifies a single file rather than a - // 64-bit directory, just go ahead and delete the file. - - rc = gv_FlmSysData.pFileSystem->Delete( pszPath); - goto Exit; - } - - if( RC_BAD( rc = CreateLockFile( pszPath))) - { - goto Exit; - } - - if( RC_OK( gv_FlmSysData.pFileSystem->OpenDir( - pszPath, "*.64", &pDir))) - { - // Remove all data files - - for( rc = pDir->Next(); !RC_BAD( rc) ; rc = pDir->Next()) - { - pDir->CurrentItemPath( szTmpPath); - flmAssert( f_strstr( szTmpPath, ".64") != 0); - (void)gv_FlmSysData.pFileSystem->Delete( szTmpPath); - } - - pDir->Release(); - pDir = NULL; - rc = FERR_OK; - } - - // Release and delete the lock file - - (void)ReleaseLockFile( pszPath, TRUE); - - // Remove the directory - - (void)gv_FlmSysData.pFileSystem->RemoveDir( pszPath); - -Exit: - - (void)ReleaseLockFile( pszPath, FALSE); - return( rc); -} - -/**************************************************************************** -Desc: Creates a new 64-bit "file" -****************************************************************************/ -RCODE F_64BitFileHandle::Create( - const char * pszPath) -{ - RCODE rc = FERR_OK; - FLMBOOL bCreatedDir = FALSE; - - if( m_bOpen) - { - rc = RC_SET( FERR_FAILURE); - goto Exit; - } - - if( RC_BAD( rc = gv_FlmSysData.pFileSystem->CreateDir( pszPath))) - { - goto Exit; - } - - f_strcpy( m_ucPath, pszPath); - bCreatedDir = TRUE; - - // Create the lock file - - if( RC_BAD( rc = CreateLockFile( m_ucPath))) - { - goto Exit; - } - - // Initialize the EOF to 0 and set the state to open - - m_ui64EOF = 0; - m_bOpen = TRUE; - -Exit: - - // Release the lock file - - if( RC_BAD( rc)) - { - (void)ReleaseLockFile( m_ucPath, TRUE); - if( bCreatedDir) - { - (void)gv_FlmSysData.pFileSystem->RemoveDir( m_ucPath); - } - } - - return( rc); -} - -/**************************************************************************** -Desc: Creates a new 64-bit file with a unique, generated name -****************************************************************************/ -RCODE F_64BitFileHandle::CreateUnique( - char * pszPath, - const char * pszFileExtension) -{ - RCODE rc = FERR_OK; - FLMUINT uiCount; - FLMBOOL bModext = TRUE; - FLMBOOL bCreatedDir = FALSE; - FLMUINT uiBaseTime = 0; - char ucHighByte = 0; - char szDirName[ F_FILENAME_SIZE]; - char szTmpPath[ F_PATH_MAX_SIZE]; - char szBasePath[ F_PATH_MAX_SIZE]; - - if( m_bOpen) - { - rc = RC_SET( FERR_FAILURE); - goto Exit; - } - - if( !pszPath || pszPath[ 0] == '\0') - { -#if defined( FLM_UNIX) - f_strcpy( szBasePath, "./"); -#elif defined( FLM_NLM) - f_strcpy( szBasePath, "SYS:_NETWARE"); -#else - szBasePath[ 0] = '\0'; -#endif - } - else - { - f_strcpy( szBasePath, pszPath); - } - - if ((pszFileExtension) && (f_strlen( pszFileExtension) >= 3)) - { - bModext = FALSE; - } - - uiCount = 0; - szDirName[ 0] = '\0'; - do - { - f_pathCreateUniqueName( &uiBaseTime, szDirName, pszFileExtension, - &ucHighByte, bModext); - - f_strcpy( szTmpPath, szBasePath); - f_pathAppend( szTmpPath, szDirName); - rc = gv_FlmSysData.pFileSystem->CreateDir( szTmpPath); - } while ((rc != FERR_OK) && (uiCount++ < 20)); - - if( RC_BAD( rc)) - { - goto Exit; - } - - f_strcpy( m_ucPath, szTmpPath); - bCreatedDir = TRUE; - - // Create the lock file - - if( RC_BAD( rc = CreateLockFile( m_ucPath))) - { - goto Exit; - } - - // Initialize the EOF to 0 and set the state to open - - m_ui64EOF = 0; - m_bOpen = TRUE; - -Exit: - - // Release the lock file - - if( RC_BAD( rc)) - { - ReleaseLockFile( m_ucPath, TRUE); - - if( bCreatedDir) - { - (void)gv_FlmSysData.pFileSystem->RemoveDir( m_ucPath); - } - } - - return( rc); -} - -/**************************************************************************** -Desc: Opens an existing 64-bit file -****************************************************************************/ -RCODE F_64BitFileHandle::Open( - const char * pszPath) -{ - RCODE rc = FERR_OK; - F_DirHdl * pDir = NULL; - FLMUINT uiTmp; - FLMUINT uiHighFileNum = 0; - FLMUINT uiHighOffset = 0; - - if( m_bOpen) - { - rc = RC_SET( FERR_FAILURE); - goto Exit; - } - - if( RC_BAD( gv_FlmSysData.pFileSystem->Exists( pszPath)) || - !gv_FlmSysData.pFileSystem->IsDir( pszPath)) - { - rc = RC_SET( FERR_IO_PATH_NOT_FOUND); - goto Exit; - } - - f_strcpy( m_ucPath, pszPath); - - // Create the lock file - - if( RC_BAD( rc = CreateLockFile( m_ucPath))) - { - goto Exit; - } - - // Need to determine the current EOF - - if( RC_BAD( rc = gv_FlmSysData.pFileSystem->OpenDir( - m_ucPath, "*.64", &pDir))) - { - goto Exit; - } - - // Find all data files to determine the EOF - - for( rc = pDir->Next(); !RC_BAD( rc) ; rc = pDir->Next() ) - { - if( RC_OK( GetFileNum( pDir->CurrentItemName(), &uiTmp))) - { - if( uiTmp >= uiHighFileNum) - { - uiHighFileNum = uiTmp; - uiHighOffset = pDir->CurrentItemSize(); - } - } - } - rc = FERR_OK; - - m_ui64EOF = (((FLMUINT64)uiHighFileNum) * (FLMUINT64)m_uiMaxFileSize) + - (FLMUINT64)uiHighOffset; - m_bOpen = TRUE; - -Exit: - - if( pDir) - { - pDir->Release(); - } - - // Release the lock file - - if( RC_BAD( rc)) - { - ReleaseLockFile( m_ucPath, FALSE); - } - - return( rc); -} - -/**************************************************************************** -Desc: Flushes cached data to the data file(s) -****************************************************************************/ -RCODE F_64BitFileHandle::Flush( void) -{ - RCODE rc = FERR_OK; - FLMUINT uiLoop; - - if( !m_bOpen) - { - rc = RC_SET( FERR_FAILURE); - goto Exit; - } - - for( uiLoop = 0; uiLoop < F_64BIT_FHDL_LIST_SIZE; uiLoop++) - { - if( m_pFileHdlList[ uiLoop].bDirty) - { - if( RC_BAD( rc = m_pFileHdlList[ uiLoop].pFileHdl->Flush())) - { - goto Exit; - } - m_pFileHdlList[ uiLoop].bDirty = FALSE; - } - } - -Exit: - - return( rc); -} - -/**************************************************************************** -Desc: Reads data from the file -****************************************************************************/ -RCODE F_64BitFileHandle::Read( - FLMUINT64 ui64Offset, // Offset to begin reading - FLMUINT uiLength, // Number of bytes to read - void * pvBuffer, // Buffer - FLMUINT * puiBytesRead) // [out] Number of bytes read -{ - RCODE rc = FERR_OK; - FLMUINT uiFileNum = GetFileNum( ui64Offset); - FLMUINT uiFileOffset = GetFileOffset( ui64Offset); - FLMUINT uiTmp; - FLMUINT uiTotalBytesRead = 0; - FLMUINT uiBytesToRead; - FLMUINT uiMaxReadLen; - F_FileHdl * pFileHdl; - - // Handle the case of a 0-byte read - - if( !uiLength) - { - if( ui64Offset >= m_ui64EOF) - { - rc = RC_SET( FERR_IO_END_OF_FILE); - } - goto Exit; - } - - // Read the data file(s), moving to new files as needed. - - for( ;;) - { - if( ui64Offset >= m_ui64EOF) - { - rc = RC_SET( FERR_IO_END_OF_FILE); - goto Exit; - } - - uiMaxReadLen = m_uiMaxFileSize - uiFileOffset; - flmAssert( uiMaxReadLen != 0); - uiTmp = (uiLength >= uiMaxReadLen ? uiMaxReadLen : uiLength); - uiBytesToRead = (((FLMUINT64)uiTmp > (FLMUINT64)(m_ui64EOF - ui64Offset)) - ? (FLMUINT)(m_ui64EOF - ui64Offset) - : uiTmp); - - if( RC_BAD( rc = GetFileHdl( uiFileNum, FALSE, &pFileHdl))) - { - if( rc == FERR_IO_PATH_NOT_FOUND) - { - // Handle the case of a sparse file by filling the unread - // portion of the buffer with zeros. - - f_memset( pvBuffer, 0, uiBytesToRead); - uiTmp = uiBytesToRead; - rc = FERR_OK; - } - else - { - goto Exit; - } - } - else - { - if( RC_BAD( rc = pFileHdl->Read( uiFileOffset, uiBytesToRead, - pvBuffer, &uiTmp))) - { - if( rc == FERR_IO_END_OF_FILE) - { - // Handle the case of a sparse file by filling the unread - // portion of the buffer with zeros. - - f_memset( &(((FLMBYTE *)(pvBuffer))[ uiTmp]), - 0, (FLMUINT)(uiBytesToRead - uiTmp)); - uiTmp = uiBytesToRead; - rc = FERR_OK; - } - else - { - goto Exit; - } - } - } - - uiTotalBytesRead += uiTmp; - uiLength -= uiTmp; - if( !uiLength) - { - break; - } - - // Set up for next read - - pvBuffer = ((FLMBYTE *)pvBuffer) + uiTmp; - ui64Offset += uiTmp; - uiFileNum = GetFileNum( ui64Offset); - uiFileOffset = GetFileOffset( ui64Offset); - } - -Exit: - - *puiBytesRead = uiTotalBytesRead; - return( rc); -} - -/**************************************************************************** -Desc: Writes data to the file -****************************************************************************/ -RCODE F_64BitFileHandle::Write( - FLMUINT64 ui64Offset, // Offset - FLMUINT uiLength, // Number of bytes to write. - void * pvBuffer, // Buffer that contains bytes to be written - FLMUINT * puiBytesWritten) // Number of bytes written. -{ - RCODE rc = FERR_OK; - FLMUINT uiFileNum = GetFileNum( ui64Offset); - FLMUINT uiFileOffset = GetFileOffset( ui64Offset); - FLMUINT uiTmp; - FLMUINT uiTotalBytesWritten = 0; - FLMUINT uiBytesToWrite; - FLMUINT uiMaxWriteLen; - F_FileHdl * pFileHdl; - - // Don't allow zero-length writes - - flmAssert( uiLength); - - // Write to the data file(s), moving to new files as needed. - - for( ;;) - { - if( RC_BAD( rc = GetFileHdl( uiFileNum, TRUE, &pFileHdl))) - { - goto Exit; - } - - uiMaxWriteLen = m_uiMaxFileSize - uiFileOffset; - flmAssert( uiMaxWriteLen != 0); - uiBytesToWrite = uiLength >= uiMaxWriteLen ? uiMaxWriteLen : uiLength; - - uiTmp = 0; - rc = pFileHdl->Write( uiFileOffset, uiBytesToWrite, pvBuffer, &uiTmp); - - uiTotalBytesWritten += uiTmp; - uiLength -= uiTmp; - ui64Offset += uiTmp; - - if( RC_BAD( rc)) - { - goto Exit; - } - - if( !uiLength) - { - break; - } - - // Set up for next write - - pvBuffer = ((FLMBYTE *)pvBuffer) + uiTmp; - uiFileNum = GetFileNum( ui64Offset); - uiFileOffset = GetFileOffset( ui64Offset); - } - -Exit: - - if( ui64Offset > m_ui64EOF) - { - m_ui64EOF = ui64Offset; - } - - *puiBytesWritten = uiTotalBytesWritten; - return( rc); -} - -/**************************************************************************** -Desc: Returns the requested file handle -****************************************************************************/ -RCODE F_64BitFileHandle::GetFileHdl( - FLMUINT uiFileNum, - FLMBOOL bGetForWrite, - F_FileHdl ** ppFileHdl) -{ - RCODE rc = FERR_OK; - FLMUINT uiSlot; - F_FileHdl * pTmpHdl; - char ucPath[ F_PATH_MAX_SIZE]; - - flmAssert( m_bOpen); - - *ppFileHdl = NULL; - - uiSlot = uiFileNum % F_64BIT_FHDL_LIST_SIZE; - pTmpHdl = m_pFileHdlList[ uiSlot].pFileHdl; - - if( pTmpHdl && m_pFileHdlList[ uiSlot].uiFileNum != uiFileNum) - { - if( RC_BAD( rc = pTmpHdl->Flush())) - { - goto Exit; - } - - pTmpHdl->Close(); - pTmpHdl->Release(); - pTmpHdl = NULL; - - f_memset( &m_pFileHdlList[ uiSlot], 0, sizeof( FH_INFO)); - } - - if( !pTmpHdl) - { - DataFilePath( uiFileNum, ucPath); - if( RC_BAD( rc = gv_FlmSysData.pFileSystem->Open( ucPath, F_IO_RDWR, - &pTmpHdl))) - { - if( rc == FERR_IO_PATH_NOT_FOUND && bGetForWrite) - { - if( RC_BAD( rc = gv_FlmSysData.pFileSystem->Create( ucPath, - F_IO_RDWR | F_IO_EXCL, &pTmpHdl))) - { - goto Exit; - } - } - else - { - goto Exit; - } - } - - m_pFileHdlList[ uiSlot].pFileHdl = pTmpHdl; - m_pFileHdlList[ uiSlot].uiFileNum = uiFileNum; - flmAssert( !m_pFileHdlList[ uiSlot].bDirty); - } - - *ppFileHdl = m_pFileHdlList[ uiSlot].pFileHdl; - if( bGetForWrite) - { - m_pFileHdlList[ uiSlot].bDirty = TRUE; - } - -Exit: - - return( rc); -} - -/**************************************************************************** -Desc: Given a data file name, returns the file's number -****************************************************************************/ -RCODE F_64BitFileHandle::GetFileNum( - const char * pucFileName, - FLMUINT * puiFileNum) -{ - RCODE rc = FERR_OK; - FLMUINT uiCnt = 0; - FLMUINT uiDigit; - FLMUINT uiFileNum = 0; - - if( f_strlen( pucFileName) != 11) // XXXXXXXX.64 - { - rc = RC_SET( FERR_IO_INVALID_PATH); - goto Exit; - } - - if( f_strcmp( &pucFileName[ 8], ".64") != 0) - { - rc = RC_SET( FERR_IO_INVALID_PATH); - goto Exit; - } - - while( uiCnt < 8) - { - uiDigit = pucFileName[ uiCnt]; - if( uiDigit >= NATIVE_LOWER_A && uiDigit <= NATIVE_LOWER_F) - { - uiDigit = (FLMUINT)(uiDigit - NATIVE_LOWER_A) + 10; - } - else if( uiDigit >= NATIVE_UPPER_A && uiDigit <= NATIVE_UPPER_F) - { - uiDigit = (FLMUINT)(uiDigit - NATIVE_UPPER_A) + 10; - } - else if( uiDigit >= NATIVE_ZERO && uiDigit <= NATIVE_NINE) - { - uiDigit -= NATIVE_ZERO; - } - else - { - // Invalid character found in the file name - - rc = RC_SET( FERR_IO_INVALID_PATH); - goto Exit; - } - - uiFileNum <<= 4; - uiFileNum += uiDigit; - uiCnt++; - } - - *puiFileNum = uiFileNum; - -Exit: - - return( rc); -} - -/**************************************************************************** -Desc: This routine obtains exclusive access to a 64-bit file by creating - a .lck file. The object holds the .lck file open as long as the - 64-bit file is open. -****************************************************************************/ -RCODE F_64BitFileHandle::CreateLockFile( - const char * pszBasePath) -{ - RCODE rc = FERR_OK; - char szLockPath [F_PATH_MAX_SIZE]; - F_FileHdlImp * pLockFileHdl = NULL; - - f_strcpy( szLockPath, pszBasePath); - f_pathAppend( szLockPath, "64.LCK"); - - // Attempt to create the lock file. If it fails, the lock file - // may have been left because of a crash. Hence, we first try - // to delete the file. If that succeeds, we then attempt to - // create the file again. If it, or the 2nd create fail, we simply - // return an access denied error. - -#ifndef FLM_UNIX - if( RC_BAD( gv_FlmSysData.pFileSystem->Create( szLockPath, - F_IO_RDWR | F_IO_EXCL | F_IO_SH_DENYRW | F_IO_DELETE_ON_CLOSE, - (F_FileHdl **)&pLockFileHdl))) - { - if( RC_BAD( gv_FlmSysData.pFileSystem->Delete( szLockPath))) - { - rc = RC_SET( FERR_IO_ACCESS_DENIED); - goto Exit; - } - else if (RC_BAD( gv_FlmSysData.pFileSystem->Create( szLockPath, - F_IO_RDWR | F_IO_EXCL | F_IO_SH_DENYRW | F_IO_DELETE_ON_CLOSE, - (F_FileHdl **)&pLockFileHdl))) - { - rc = RC_SET( FERR_IO_ACCESS_DENIED); - goto Exit; - } - } -#else - if( RC_BAD( gv_FlmSysData.pFileSystem->Create( szLockPath, - F_IO_RDWR | F_IO_EXCL | F_IO_SH_DENYRW, - (F_FileHdl **)&pLockFileHdl))) - { - if( RC_BAD( gv_FlmSysData.pFileSystem->Open( szLockPath, - F_IO_RDWR | F_IO_SH_DENYRW, - (F_FileHdl **)&pLockFileHdl))) - { - rc = RC_SET( FERR_IO_ACCESS_DENIED); - goto Exit; - } - } - - if( RC_BAD( pLockFileHdl->Lock())) - { - rc = RC_SET( FERR_IO_ACCESS_DENIED); - goto Exit; - } -#endif - - m_pLockFileHdl = pLockFileHdl; - pLockFileHdl = NULL; - -Exit: - - if (pLockFileHdl) - { - (void)pLockFileHdl->Close(); - pLockFileHdl->Release(); - pLockFileHdl = NULL; - } - return( rc); -} diff --git a/flaim/src/f64bitfh.h b/flaim/src/f64bitfh.h deleted file mode 100644 index 40fd00c..0000000 --- a/flaim/src/f64bitfh.h +++ /dev/null @@ -1,154 +0,0 @@ -//------------------------------------------------------------------------- -// Desc: Abstraction class for 64 bit files - class definition. -// Tabs: 3 -// -// Copyright (c) 2001-2006 Novell, Inc. All Rights Reserved. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of version 2 of the GNU General Public -// License as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, contact Novell, Inc. -// -// To contact Novell about this file by physical or electronic mail, -// you may find current contact information at www.novell.com -// -// $Id: f64bitfh.h 12329 2006-01-20 17:49:30 -0700 (Fri, 20 Jan 2006) ahodgkinson $ -//------------------------------------------------------------------------- - -#ifndef F64BITFH_H -#define F64BITFH_H - -#include "fpackon.h" - -// IMPORTANT NOTE: No other include files should follow this one except -// for fpackoff.h - -#define F_64BIT_FHDL_LIST_SIZE 8 -#define F_64BIT_FHDL_DEFAULT_MAX_FILE_SIZE ((FLMUINT)0xFFFFFFFF) - -typedef struct FH_INFO -{ - F_FileHdl * pFileHdl; - FLMUINT uiFileNum; - FLMBOOL bDirty; -} FH_INFO; - -/**************************************************************************** -Desc: This object is used to simulate a 64-bit file system. -****************************************************************************/ -class F_64BitFileHandle : public F_Base -{ -public: - - F_64BitFileHandle( - FLMUINT uiMaxFileSize = F_64BIT_FHDL_DEFAULT_MAX_FILE_SIZE); - - virtual ~F_64BitFileHandle(); - - void Close( - FLMBOOL bDelete = FALSE); - - - RCODE Create( - const char * pIoPath); - - RCODE CreateUnique( - char * pIoPath, - const char * pszFileExtension); - - RCODE Delete( - const char * pIoPath); - - RCODE Open( - const char * pIoPath); - - RCODE Flush( void); - - RCODE Read( - FLMUINT64 ui64Offset, - FLMUINT uiLength, - void * pvBuffer, - FLMUINT * puiBytesRead); - - RCODE Write( - FLMUINT64 ui64Offset, - FLMUINT uiLength, - void * pvBuffer, - FLMUINT * puiBytesWritten); - - RCODE GetPath( - char * pszFilePath); - - FINLINE RCODE Size( - FLMUINT64 * pui64FileSize) - { - *pui64FileSize = m_ui64EOF; - return( FERR_OK); - } - -private: - - RCODE GetFileHdl( - FLMUINT uiFileNum, - FLMBOOL bGetForWrite, - F_FileHdl ** ppFileHdl); - - RCODE CreateLockFile( - const char * pszBasePath); - - void ReleaseLockFile( - const char * pszBasePath, - FLMBOOL bDelete); - - FINLINE void FormatFileNum( - FLMUINT uiFileNum, - char * pucStr) - { - f_sprintf( pucStr, "%08X.64", (unsigned)uiFileNum); - } - - RCODE GetFileNum( - const char * pucFileName, - FLMUINT * puiFileNum); - - FINLINE void DataFilePath( - FLMUINT uiFileNum, - char * pszPath) - { - char ucFileName[ F_FILENAME_SIZE]; - - f_strcpy( pszPath, m_ucPath); - FormatFileNum( uiFileNum, ucFileName); - f_pathAppend( pszPath, ucFileName); - } - - FINLINE FLMUINT GetFileNum( - FLMUINT64 ui64Offset) - { - return( (FLMUINT)(ui64Offset / (FLMUINT64)m_uiMaxFileSize)); - } - - FINLINE FLMUINT GetFileOffset( - FLMUINT64 ui64Offset) - { - return( (FLMUINT)(ui64Offset % (FLMUINT64)m_uiMaxFileSize)); - } - - FH_INFO m_pFileHdlList[ F_64BIT_FHDL_LIST_SIZE]; - char m_ucPath[ F_PATH_MAX_SIZE]; - FLMBOOL m_bOpen; - FLMUINT64 m_ui64EOF; - FLMUINT m_uiMaxFileSize; - F_FileHdl * m_pLockFileHdl; -}; - -#include "fpackoff.h" - -#endif diff --git a/flaim/src/f_nici.cpp b/flaim/src/f_nici.cpp index aae95a3..3ca1f4e 100644 --- a/flaim/src/f_nici.cpp +++ b/flaim/src/f_nici.cpp @@ -24,64 +24,6 @@ #include "flaimsys.h" -// Global data - -char F_Base64Encoder::m_ucEncodeTable[ 64] = -{ - ASCII_UPPER_A, ASCII_UPPER_B, ASCII_UPPER_C, ASCII_UPPER_D, - ASCII_UPPER_E, ASCII_UPPER_F, ASCII_UPPER_G, ASCII_UPPER_H, - ASCII_UPPER_I, ASCII_UPPER_J, ASCII_UPPER_K, ASCII_UPPER_L, - ASCII_UPPER_M, ASCII_UPPER_N, ASCII_UPPER_O, ASCII_UPPER_P, - ASCII_UPPER_Q, ASCII_UPPER_R, ASCII_UPPER_S, ASCII_UPPER_T, - ASCII_UPPER_U, ASCII_UPPER_V, ASCII_UPPER_W, ASCII_UPPER_X, - ASCII_UPPER_Y, ASCII_UPPER_Z, ASCII_LOWER_A, ASCII_LOWER_B, - ASCII_LOWER_C, ASCII_LOWER_D, ASCII_LOWER_E, ASCII_LOWER_F, - ASCII_LOWER_G, ASCII_LOWER_H, ASCII_LOWER_I, ASCII_LOWER_J, - ASCII_LOWER_K, ASCII_LOWER_L, ASCII_LOWER_M, ASCII_LOWER_N, - ASCII_LOWER_O, ASCII_LOWER_P, ASCII_LOWER_Q, ASCII_LOWER_R, - ASCII_LOWER_S, ASCII_LOWER_T, ASCII_LOWER_U, ASCII_LOWER_V, - ASCII_LOWER_W, ASCII_LOWER_X, ASCII_LOWER_Y, ASCII_LOWER_Z, - ASCII_ZERO, ASCII_ONE, ASCII_TWO, ASCII_THREE, - ASCII_FOUR, ASCII_FIVE, ASCII_SIX, ASCII_SEVEN, - ASCII_EIGHT, ASCII_NINE, ASCII_PLUS, ASCII_SLASH -}; - -FLMBYTE F_Base64Decoder::m_ucDecodeTable[ 256] = -{ - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0 .. 7 - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 8 .. 15 - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 16 .. 23 - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 24 .. 31 - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 32 .. 39 - 0xFF, 0xFF, 0xFF, 0x3E, 0xFF, 0xFF, 0xFF, 0x3F, // 40 .. 47 - 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, // 48 .. 55 - 0x3C, 0x3D, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, // 56 .. 63 - 0xFF, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, // 64 .. 71 - 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, // 72 .. 79 - 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, // 80 .. 87 - 0x17, 0x18, 0x19, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 88 .. 95 - 0xFF, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, // 96 .. 103 - 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, // 104 .. 111 - 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30, // 112 .. 119 - 0x31, 0x32, 0x33, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 120 .. 127 - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 128 .. 135 - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 136 .. 143 - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 144 .. 151 - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 152 .. 159 - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 160 .. 167 - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 168 .. 175 - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 176 .. 183 - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 184 .. 191 - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 192 .. 199 - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 200 .. 207 - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 208 .. 215 - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 216 .. 223 - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 224 .. 231 - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 232 .. 239 - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 240 .. 247 - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF // 248 .. 255 -}; - #ifdef FLM_USE_NICI FSTATIC void GetIV( FLMBYTE * pucIV, @@ -1326,7 +1268,8 @@ RCODE F_CCS::getKeyToStore( void * pvB64Buffer = NULL; FLMUINT32 ui32PaddedLength; NICI_CC_HANDLE context = 0; - F_Base64Encoder * pB64Encoder = NULL; + IF_PosIStream * pBufferIStream = NULL; + IF_IStream * pB64Encoder = NULL; FLMBYTE * pucWrappedKey = NULL; FLMUINT32 ui32WrappedKeyLen = 0; char * pszFormattedEncKeyPasswd = NULL; @@ -1446,17 +1389,21 @@ RCODE F_CCS::getKeyToStore( { goto ExitCtx; } - - if( (pB64Encoder = f_new F_Base64Encoder( FALSE)) == NULL) + + if( RC_BAD( rc = FlmOpenBufferIStream( pucTmp, + ui32PaddedLength, &pBufferIStream))) { - rc = RC_SET( FERR_MEM); - goto ExitCtx; + goto Exit; + } + + if( RC_BAD( rc = FlmOpenBase64EncoderIStream( pBufferIStream, + FALSE, &pB64Encoder))) + { + goto Exit; } - // Only encode the data. - - if (RC_BAD( rc = pB64Encoder->read( pucTmp, ui32PaddedLength, - pvB64Buffer, ui32PaddedLength, &ui32B64Length))) + if (RC_BAD( rc = pB64Encoder->read( pvB64Buffer, + ui32PaddedLength, &ui32B64Length))) { goto ExitCtx; } @@ -1497,7 +1444,12 @@ Exit: if (pB64Encoder) { - delete pB64Encoder; + pB64Encoder->Release(); + } + + if (pBufferIStream) + { + pBufferIStream->Release(); } if (pucWrappedKey) @@ -2228,262 +2180,6 @@ Exit: return(rc); } - -/***************************************************************************** -Desc: Reads decoded binary from the base64 ASCII source buffer. -*****************************************************************************/ -RCODE F_Base64Decoder::read( - FLMBYTE * psSource, - FLMUINT uiSourceLen, - void * pvBuffer, - FLMUINT32 ui32BytesToRead, - FLMUINT32 * pui32BytesRead) -{ - RCODE rc = FERR_OK; - FLMBYTE * pucOutBuf = (FLMBYTE *)pvBuffer; - FLMBYTE ucQuadBuffer[ 4]; - FLMBYTE * pTmp = psSource; - FLMUINT uiOffset = 0; - FLMUINT uiBytesToCopy; - - if( pui32BytesRead) - { - *pui32BytesRead = 0; - } - - if( !psSource) - { - rc = RC_SET( FERR_EOF_HIT); - goto Exit; - } - - while( ui32BytesToRead) - { - if( !m_uiAvailBytes) - { - m_uiBufOffset = 0; - - for( uiOffset = 0; uiOffset < 4;) - { - if (pTmp > psSource + uiSourceLen) - { - if( uiOffset) - { - rc = RC_SET( FERR_BAD_BASE64_ENCODING); - } - goto Exit; - } - else - { - ucQuadBuffer[ uiOffset] = *pTmp; - pTmp++; - } - - if( m_ucDecodeTable[ ucQuadBuffer[ uiOffset]] == 0xFF) - { - FLMBYTE ucTmp = ucQuadBuffer[ uiOffset]; - - if( ucTmp == ASCII_TAB || ucTmp == ASCII_SPACE || - ucTmp == ASCII_NEWLINE || ucTmp == ASCII_CR) - { - continue; - } - - rc = RC_SET( FERR_BAD_BASE64_ENCODING); - goto Exit; - } - - uiOffset++; - } - - m_ucBuffer[ 0] = - (m_ucDecodeTable[ ucQuadBuffer[ 0]] << 2) | - (m_ucDecodeTable[ ucQuadBuffer[ 1]] >> 4); - m_uiAvailBytes++; - - if( ucQuadBuffer[ 2] != '=') - { - m_ucBuffer[ 1] = - (m_ucDecodeTable[ ucQuadBuffer[ 1]] << 4) | - (m_ucDecodeTable[ ucQuadBuffer[ 2]] >> 2); - m_uiAvailBytes++; - } - - if( ucQuadBuffer[ 3] != '=') - { - m_ucBuffer[ 2] = - (m_ucDecodeTable[ ucQuadBuffer[ 2]] << 6) | - m_ucDecodeTable[ ucQuadBuffer[ 3]]; - m_uiAvailBytes++; - } - } - - uiBytesToCopy = f_min( m_uiAvailBytes, ui32BytesToRead); - - if( pucOutBuf) - { - f_memcpy( pucOutBuf, &m_ucBuffer[ m_uiBufOffset], uiBytesToCopy); - } - - ui32BytesToRead -= (FLMUINT32)uiOffset; - m_uiAvailBytes -= uiBytesToCopy; - m_uiBufOffset += uiBytesToCopy; - pucOutBuf += uiBytesToCopy; - - if( pui32BytesRead) - { - *pui32BytesRead += (FLMUINT32)uiBytesToCopy; - } - } - -Exit: - - return( rc); -} - -/***************************************************************************** -Desc: Reads ASCII base64 encoded binary from the source buffer. -*****************************************************************************/ -RCODE F_Base64Encoder::read( - FLMBYTE * psSource, - FLMUINT uiSourceLen, - void * pvBuffer, - FLMUINT32 ui32BytesToRead, - FLMUINT32 * pui32BytesRead) -{ - RCODE rc = FERR_OK; - FLMBYTE * pucOutBuf = (FLMBYTE *)pvBuffer; - FLMUINT uiBytesToCopy = 0; - FLMUINT uiBytesToEncode = 0; - FLMBYTE ucTriBuffer[ 3]; - FLMBYTE * pTmp = psSource; - - if( *pui32BytesRead) - { - *pui32BytesRead = 0; - } - - if( !psSource) - { - rc = RC_SET( FERR_EOF_HIT); - goto Exit; - } - - while( ui32BytesToRead) - { - if( !m_uiAvailBytes) - { - // Reset the buffer - - f_memset( ucTriBuffer, 0, 3); - - if( m_bInputExhausted) - { - rc = RC_SET( FERR_EOF_HIT); - goto Exit; - } - - if (pTmp > psSource + uiSourceLen) - { - m_bInputExhausted = TRUE; - } - else if ((psSource + uiSourceLen) - pTmp >= 3) - { - f_memcpy( ucTriBuffer, pTmp, 3); - pTmp += 3; - uiBytesToEncode = 3; - } - else - { - uiBytesToEncode = (psSource + uiSourceLen) - pTmp; - f_memcpy( ucTriBuffer, pTmp, uiBytesToEncode); - pTmp += uiBytesToEncode; - m_bInputExhausted = TRUE; - } - - if( uiBytesToEncode) - { - m_ucBuffer[ m_uiAvailBytes++] = - m_ucEncodeTable[ ucTriBuffer[ 0] >> 2]; - - m_ucBuffer[ m_uiAvailBytes++] = - m_ucEncodeTable[ ((ucTriBuffer[ 0] & 0x03) << 4) | - (ucTriBuffer[ 1] >> 4)]; - - if( uiBytesToEncode >= 2) - { - m_ucBuffer[ m_uiAvailBytes++] = - m_ucEncodeTable[ ((ucTriBuffer[ 1] & 0x0F) << 2) | - (ucTriBuffer[ 2] >> 6)]; - } - else - { - m_ucBuffer[ m_uiAvailBytes++] = ASCII_EQUAL; - } - - if( uiBytesToEncode == 3) - { - m_ucBuffer[ m_uiAvailBytes++] = - m_ucEncodeTable[ ucTriBuffer[ 2] & 0x3F]; - } - else - { - m_ucBuffer[ m_uiAvailBytes++] = ASCII_EQUAL; - } - - m_uiBase64Count += 4; - } - - if( m_bLineBreaks) - { - if( (m_uiBase64Count % 72) == 0 || - (m_bInputExhausted && !m_bPriorLineEnd)) - { -#if defined( FLM_OSX) - m_ucBuffer[ m_uiAvailBytes++] = ASCII_CR; -#elif defined( FLM_UNIX) - m_ucBuffer[ m_uiAvailBytes++] = ASCII_NEWLINE; -#else - m_ucBuffer[ m_uiAvailBytes++] = ASCII_CR; - m_ucBuffer[ m_uiAvailBytes++] = ASCII_NEWLINE; -#endif - m_bPriorLineEnd = TRUE; - } - else - { - m_bPriorLineEnd = FALSE; - } - } - - if( !m_uiAvailBytes) - { - rc = RC_SET( FERR_EOF_HIT); - goto Exit; - } - } - - uiBytesToCopy = m_uiAvailBytes; - - if( pucOutBuf != NULL) - { - f_memcpy( pucOutBuf, &m_ucBuffer[ 0], uiBytesToCopy); - pucOutBuf += uiBytesToCopy; - } - - ui32BytesToRead -= (FLMUINT32)uiBytesToEncode; - m_uiAvailBytes -= uiBytesToCopy; - - if( pui32BytesRead) - { - *pui32BytesRead += (FLMUINT32)uiBytesToCopy; - } - } - -Exit: - - return( rc); -} - /**************************************************************************** Desc: flmDecryptBuffer - assumes aes ****************************************************************************/ diff --git a/flaim/src/f_nici.h b/flaim/src/f_nici.h index 99f98b0..351d543 100644 --- a/flaim/src/f_nici.h +++ b/flaim/src/f_nici.h @@ -120,7 +120,7 @@ public: /**************************************************************************** Desc: ****************************************************************************/ -class F_CCS : public IF_CCS, public F_Base +class F_CCS : public IF_CCS, public F_Object { public: @@ -187,14 +187,14 @@ public: return m_uiAlgType; } - FINLINE FLMINT AddRef( void) + FINLINE FLMINT FLMAPI AddRef( void) { - return( flmAtomicInc( &m_refCnt, m_hMutex, FALSE)); + return( f_atomicInc( &m_refCnt)); } - FINLINE FLMINT Release( void) + FINLINE FLMINT FLMAPI Release( void) { - FLMINT iRefCnt = flmAtomicDec( &m_refCnt, m_hMutex, FALSE); + FLMINT iRefCnt = f_atomicDec( &m_refCnt); if( !iRefCnt) { @@ -280,95 +280,6 @@ private: FLMBYTE m_pucIV[ IV_SZ]; // Used when the algorithm type is DES, 3DES or AES }; -/**************************************************************************** -Desc: Decodes an ASCII base64 stream to binary -****************************************************************************/ -class F_Base64Decoder : public F_Base -{ -public: - - F_Base64Decoder( void ) - { - m_uiBufOffset = 0; - m_uiAvailBytes = 0; - } - - ~F_Base64Decoder() - { - } - - RCODE read( - FLMBYTE * psSource, - FLMUINT uiSourceLen, - void * pvBuffer, - FLMUINT32 ui32BytesToRead, - FLMUINT32 * pui32BytesRead); - - FINLINE void close( void) - { - m_uiAvailBytes = 0; - m_uiBufOffset = 0; - } - -private: - - FLMUINT m_uiBufOffset; - FLMUINT m_uiAvailBytes; - FLMBYTE m_ucBuffer[ 8]; - static FLMBYTE m_ucDecodeTable[ 256]; -}; - -/**************************************************************************** -Desc: Encodes a binary input stream into ASCII base64. -****************************************************************************/ -class F_Base64Encoder : public F_Base -{ -public: - - F_Base64Encoder( - FLMBOOL bLineBreaks = FALSE) - { - m_uiBase64Count = 0; - m_uiBufOffset = 0; - m_uiAvailBytes = 0; - m_bLineBreaks = bLineBreaks; - m_bInputExhausted = FALSE; - m_bPriorLineEnd = FALSE; - } - - ~F_Base64Encoder() - { - } - - RCODE read( - FLMBYTE * psSource, - FLMUINT uiSourceLen, - void * pvBuffer, - FLMUINT32 ui32BytesToRead, - FLMUINT32 * pui32BytesRead); - - FINLINE void close( void) - { - - m_uiBufOffset = 0; - m_uiAvailBytes = 0; - m_uiBase64Count = 0; - m_bPriorLineEnd = FALSE; - m_bInputExhausted = TRUE; - } - -private: - - FLMBOOL m_bLineBreaks; - FLMBOOL m_bPriorLineEnd; - FLMBOOL m_bInputExhausted; - FLMUINT m_uiBase64Count; - FLMUINT m_uiBufOffset; - FLMUINT m_uiAvailBytes; - FLMBYTE m_ucBuffer[ 8]; - static char m_ucEncodeTable[ 64]; -}; - RCODE flmDecryptBuffer( FLMBYTE * pucBuffer, FLMUINT * puiBufLen); diff --git a/flaim/src/fblob.cpp b/flaim/src/fblob.cpp index 9394e50..362fac4 100644 --- a/flaim/src/fblob.cpp +++ b/flaim/src/fblob.cpp @@ -59,16 +59,15 @@ RCODE FlmBlobImp::referenceFile( FLMUINT uiFlags; FDB * pDb = (FDB *)hDb; - flmAssert( m_pHeaderBuf == NULL); - - // See if the database is being forced to close + flmAssert( !m_pHeaderBuf); if( RC_BAD( rc = flmCheckDatabaseState( pDb))) { goto Exit; } - if( RC_BAD( rc = f_pathToStorageString( pszFileName, szUnportablePath))) + if( RC_BAD( rc = gv_FlmSysData.pFileSystem->pathToStorageString( + pszFileName, szUnportablePath))) { goto Exit; } @@ -82,17 +81,17 @@ RCODE FlmBlobImp::referenceFile( { m_uiStorageType = BLOB_REFERENCE_TYPE | BLOB_OWNED_TYPE; } - else if( uiFlags & BLOB_UNOWNED_REFERENCE_FLAG ) + else if( uiFlags & BLOB_UNOWNED_REFERENCE_FLAG) { m_uiStorageType = BLOB_REFERENCE_TYPE; } else { - // Type not support with VER41 code. flmAssert(0); rc = RC_SET( FERR_SYNTAX); goto Exit; } + m_uiFlags = uiFlags; m_uiAction = BLOB_CREATE_ACTION; @@ -102,6 +101,7 @@ RCODE FlmBlobImp::referenceFile( } Exit: + return( rc); } @@ -254,7 +254,7 @@ RCODE FlmBlobImp::closeFile() { if( m_pFileHdl) { - m_pFileHdl->Close(); + m_pFileHdl->close(); m_bFileAccessed = FALSE; m_pFileHdl->Release(); @@ -276,10 +276,10 @@ RCODE FlmBlobImp::openFile() { buildFileName( szFileName); - if( RC_BAD( rc = gv_FlmSysData.pFileSystem->Open( szFileName, - F_IO_SH_DENYNONE | - (m_bReadWriteAccess ? F_IO_RDWR : F_IO_RDONLY), - (F_FileHdl **)&m_pFileHdl))) + if( RC_BAD( rc = gv_FlmSysData.pFileSystem->openFile( szFileName, + FLM_IO_SH_DENYNONE | + (m_bReadWriteAccess ? FLM_IO_RDWR : FLM_IO_RDONLY), + &m_pFileHdl))) { goto Exit; } @@ -300,6 +300,7 @@ RCODE FlmBlobImp::buildFileName( FLMUINT uiNameLength; // Be carefull not to do a string copy - this is not null terminated. + uiNameLength = m_uiHeaderLen - BLOB_R_PATH_POS; f_memcpy( pszFileName, &m_pHeaderBuf[ BLOB_R_PATH_POS], uiNameLength); pszFileName[ uiNameLength ] = '\0'; @@ -312,7 +313,8 @@ RCODE FlmBlobImp::buildFileName( char szBlobBaseName [F_FILENAME_SIZE]; char * pszFileExt; - if( RC_BAD( rc = f_pathReduce( pszFileName, szBlobPath, szBlobBaseName))) + if( RC_BAD( rc = gv_FlmSysData.pFileSystem->pathReduce( + pszFileName, szBlobPath, szBlobBaseName))) { goto Exit; } @@ -335,7 +337,7 @@ RCODE FlmBlobImp::buildFileName( pszFileExt++; f_strcpy( pszFileExt, (const char *)gv_FlmSysData.ucBlobExt); f_strcpy( pszFileName, szBlobPath); - f_pathAppend( pszFileName, szBlobBaseName); + gv_FlmSysData.pFileSystem->pathAppend( pszFileName, szBlobBaseName); } Exit: @@ -609,9 +611,7 @@ void FBListAfterCommit( if( RC_OK( pBlob->buildFileName( szFileName))) { - F_FileSystem * pFileSystem = gv_FlmSysData.pFileSystem; - - (void)pFileSystem->Delete( szFileName); + gv_FlmSysData.pFileSystem->deleteFile( szFileName); } } diff --git a/flaim/src/fbuff.cpp b/flaim/src/fbuff.cpp deleted file mode 100644 index 266694e..0000000 --- a/flaim/src/fbuff.cpp +++ /dev/null @@ -1,518 +0,0 @@ -//------------------------------------------------------------------------- -// Desc: Buffer management for asynchronous I/O. -// Tabs: 3 -// -// Copyright (c) 2001-2003,2005-2006 Novell, Inc. All Rights Reserved. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of version 2 of the GNU General Public -// License as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, contact Novell, Inc. -// -// To contact Novell about this file by physical or electronic mail, -// you may find current contact information at www.novell.com -// -// $Id: fbuff.cpp 12246 2006-01-19 14:30:28 -0700 (Thu, 19 Jan 2006) dsanders $ -//------------------------------------------------------------------------- - -#include "flaimsys.h" - -/**************************************************************************** -Desc: -****************************************************************************/ -F_IOBufferMgr::F_IOBufferMgr() -{ - m_pFirstPending = NULL; - m_pFirstAvail = NULL; - m_pFirstUsed = NULL; - m_uiMaxBuffers = 0; - m_uiMaxBufferBytesToUse = 0; - m_uiBufferBytesInUse = 0; - m_uiBuffersInUse = 0; - m_completionRc = FERR_OK; - m_bKeepBuffers = FALSE; -} - -/**************************************************************************** -Desc: -****************************************************************************/ -F_IOBufferMgr::~F_IOBufferMgr() -{ - flmAssert( !m_pFirstPending && !m_pFirstUsed); - while (m_pFirstPending) - { - m_pFirstPending->Release(); - } - while (m_pFirstAvail) - { - m_pFirstAvail->Release(); - } - while (m_pFirstUsed) - { - m_pFirstUsed->Release(); - } -} - -/**************************************************************************** -Desc: -****************************************************************************/ -RCODE F_IOBufferMgr::waitForAllPendingIO( void) -{ - RCODE rc = FERR_OK; - F_IOBuffer * pBuf; - - while( (pBuf = m_pFirstPending) != NULL) - { - (void)pBuf->waitToComplete(); - } - - rc = m_completionRc; - m_completionRc = FERR_OK; - - return( rc); -} - -/**************************************************************************** -Desc: -****************************************************************************/ -void F_IOBufferMgr::linkToList( - F_IOBuffer ** ppListHead, - F_IOBuffer * pIOBuffer) -{ - flmAssert( pIOBuffer->m_eList == F_IOBuffer::MGR_LIST_NONE); - - pIOBuffer->m_pPrev = NULL; - if ((pIOBuffer->m_pNext = *ppListHead) != NULL) - { - (*ppListHead)->m_pPrev = pIOBuffer; - } - - *ppListHead = pIOBuffer; - if (ppListHead == &m_pFirstPending || - ppListHead == &m_pFirstUsed) - { - pIOBuffer->m_eList = (ppListHead == &m_pFirstPending - ? F_IOBuffer::MGR_LIST_PENDING - : F_IOBuffer::MGR_LIST_USED); - pIOBuffer->m_bDeleteOnNotify = (m_bKeepBuffers - ? FALSE - : TRUE); - m_uiBuffersInUse++; - m_uiBufferBytesInUse += pIOBuffer->m_uiBufferSize; - } - else - { - pIOBuffer->m_eList = F_IOBuffer::MGR_LIST_AVAIL; - } -} - -/**************************************************************************** -Desc: -****************************************************************************/ -void F_IOBufferMgr::unlinkFromList( - F_IOBuffer * pIOBuffer) -{ - if (pIOBuffer->m_pNext) - { - pIOBuffer->m_pNext->m_pPrev = pIOBuffer->m_pPrev; - } - if (pIOBuffer->m_pPrev) - { - pIOBuffer->m_pPrev->m_pNext = pIOBuffer->m_pNext; - } - else if (pIOBuffer->m_eList == F_IOBuffer::MGR_LIST_AVAIL) - { - m_pFirstAvail = pIOBuffer->m_pNext; - } - else if (pIOBuffer->m_eList == F_IOBuffer::MGR_LIST_PENDING) - { - m_pFirstPending = pIOBuffer->m_pNext; - } - else if (pIOBuffer->m_eList == F_IOBuffer::MGR_LIST_USED) - { - m_pFirstUsed = pIOBuffer->m_pNext; - } - else - { - flmAssert( 0); - } - if (pIOBuffer->m_eList == F_IOBuffer::MGR_LIST_PENDING || - pIOBuffer->m_eList == F_IOBuffer::MGR_LIST_USED) - { - m_uiBuffersInUse--; - flmAssert( m_uiBufferBytesInUse >= pIOBuffer->m_uiBufferSize); - m_uiBufferBytesInUse -= pIOBuffer->m_uiBufferSize; - } - pIOBuffer->m_eList = F_IOBuffer::MGR_LIST_NONE; -} - -/**************************************************************************** -Desc: -****************************************************************************/ -RCODE F_IOBufferMgr::getBuffer( - F_IOBuffer ** ppIOBuffer, - FLMUINT uiBufferSize, - FLMUINT uiBlockSize) -{ - RCODE rc = FERR_OK; - F_IOBuffer * pIOBuffer = NULL; - F_IOBuffer * pBuf; - - if( RC_BAD( m_completionRc)) - { - rc = m_completionRc; - goto Exit; - } - - if ((m_uiBufferBytesInUse + uiBufferSize > m_uiMaxBufferBytesToUse && - m_pFirstPending) || - m_uiBuffersInUse == m_uiMaxBuffers) - { - pBuf = m_pFirstPending; - for (;;) - { - if( pBuf->isIOComplete()) - { - if( RC_BAD( rc = pBuf->waitToComplete())) - { - goto Exit; - } - pBuf = m_pFirstPending; - if (m_uiBufferBytesInUse + uiBufferSize > m_uiMaxBufferBytesToUse && - m_pFirstPending) - { - continue; - } - else - { - flmAssert( m_uiBuffersInUse < m_uiMaxBuffers); - break; - } - } - if ((pBuf = pBuf->m_pNext) == NULL) - { -#ifdef FLM_WIN - f_sleep( 0); -#else - f_yieldCPU(); -#endif - pBuf = m_pFirstPending; - } - } - } - - // If we are set up to keep buffers, caller better always ask - // for the same size. - - if (m_pFirstAvail) - { - pIOBuffer = m_pFirstAvail; - unlinkFromList( pIOBuffer); - flmAssert( pIOBuffer->getBufferSize() == uiBufferSize); - } - else - { - if ((pIOBuffer = f_new F_IOBuffer) == NULL) - { - rc = RC_SET( FERR_MEM); - goto Exit; - } - pIOBuffer->m_pIOBufferMgr = this; - if (RC_BAD( rc = pIOBuffer->setupBuffer( uiBufferSize, - uiBlockSize))) - { - goto Exit; - } - } - - // An F_IOBuffer object, once created must ALWAYS be linked - // into the buffer manager's used list. - - linkToList( &m_pFirstUsed, pIOBuffer); - -Exit: - - if (RC_BAD( rc) && pIOBuffer) - { - pIOBuffer->Release(); - pIOBuffer = NULL; - } - *ppIOBuffer = pIOBuffer; - return( rc); -} - -/**************************************************************************** -Desc: -****************************************************************************/ -F_IOBuffer::F_IOBuffer() -{ - m_pIOBufferMgr = NULL; - m_pucBuffer = NULL; -#ifdef FLM_DEBUG - f_memset( m_UserData, 0, sizeof( m_UserData)); -#endif - m_uiBufferSize = 0; - m_uiBlockSize = 0; - m_eList = MGR_LIST_NONE; - m_bDeleteOnNotify = TRUE; - m_pNext = NULL; - m_pPrev = NULL; - m_fnCompletion = NULL; - m_completionRc = FERR_OK; -#if defined( FLM_WIN) - m_FileHandle = INVALID_HANDLE_VALUE; - m_Overlapped.hEvent = 0; -#endif -#ifdef FLM_NLM - m_hSem = F_SEM_NULL; -#endif - m_pDbStats = NULL; -} - -/**************************************************************************** -Desc: -****************************************************************************/ -F_IOBuffer::~F_IOBuffer() -{ - // Unlink from list object is in, if any. - - if (m_eList != MGR_LIST_NONE) - { - flmAssert( m_pIOBufferMgr); - m_pIOBufferMgr->unlinkFromList( this); - } - -#if defined( FLM_WIN) - if( m_Overlapped.hEvent) - { - CloseHandle( m_Overlapped.hEvent); - } -#endif - -#ifdef FLM_NLM - if (m_hSem != F_SEM_NULL) - { - f_semDestroy( &m_hSem); - } -#endif - - if (m_pucBuffer) - { -#ifdef FLM_WIN - (void)VirtualFree( m_pucBuffer, 0, MEM_RELEASE); - m_pucBuffer = NULL; -#elif defined( FLM_LINUX) || defined( FLM_SOLARIS) - free( m_pucBuffer); - m_pucBuffer = NULL; -#else - f_free( &m_pucBuffer); -#endif - } -} - -/**************************************************************************** -Desc: -****************************************************************************/ -void F_IOBuffer::makePending( void) -{ - flmAssert( m_eList == MGR_LIST_USED); - - // Unlink from used list - - m_pIOBufferMgr->unlinkFromList( this); - - // Link into pending list. - - m_pIOBufferMgr->linkToList( &m_pIOBufferMgr->m_pFirstPending, this); -} - -/**************************************************************************** -Desc: -****************************************************************************/ -RCODE F_IOBuffer::setupBuffer( - FLMUINT uiBufferSize, - FLMUINT uiBlockSize) -{ - RCODE rc = FERR_OK; - -#if defined( FLM_WIN) - if( (m_Overlapped.hEvent = CreateEvent( NULL, TRUE, - FALSE, NULL)) == NULL) - { - rc = MapWinErrorToFlaim( GetLastError(), - FERR_SETTING_UP_FOR_WRITE); - goto Exit; - } -#endif - -#ifdef FLM_NLM - if (RC_BAD( rc = f_semCreate( &m_hSem))) - { - goto Exit; - } -#endif - - // Allocate a buffer - -#ifdef FLM_WIN - if ((m_pucBuffer = (FLMBYTE *)VirtualAlloc( NULL, - (DWORD)uiBufferSize, - MEM_COMMIT, PAGE_READWRITE)) == NULL) - { - rc = MapWinErrorToFlaim( GetLastError(), FERR_MEM); - goto Exit; - } -#elif defined( FLM_LINUX) || defined( FLM_SOLARIS) - if( (m_pucBuffer = (FLMBYTE *)memalign( - sysconf(_SC_PAGESIZE), uiBufferSize)) == NULL) - { - rc = MapErrnoToFlaimErr(errno, FERR_MEM); - goto Exit; - } -#else - if (RC_BAD( rc = f_alloc( uiBufferSize, &m_pucBuffer))) - { - goto Exit; - } -#endif - - m_uiBufferSize = uiBufferSize; - m_uiBlockSize = uiBlockSize; - -Exit: - - return( rc); -} - -/**************************************************************************** -Desc: -****************************************************************************/ -void F_IOBuffer::notifyComplete( - RCODE rc) -{ - flmAssert( m_eList == MGR_LIST_PENDING || - m_eList == MGR_LIST_USED); - - m_completionRc = rc; - endTimer(); - if( m_fnCompletion) - { - m_fnCompletion( this); - - // Fix so completion callback won't be called twice. - - m_fnCompletion = NULL; - } - - if (RC_BAD( rc) && RC_OK( m_pIOBufferMgr->m_completionRc)) - { - m_pIOBufferMgr->m_completionRc = rc; - } - - if (m_bDeleteOnNotify) - { - Release(); - } - else - { - m_pIOBufferMgr->unlinkFromList( this); - m_pIOBufferMgr->linkToList( &m_pIOBufferMgr->m_pFirstAvail, this); - } -} - -/**************************************************************************** -Desc: -****************************************************************************/ -FLMBOOL F_IOBuffer::isIOComplete( void) -{ - FLMBOOL bComplete = FALSE; -#ifdef FLM_NLM - FLMUINT uiSemCount; -#endif - - if( m_eList != MGR_LIST_PENDING) - { - bComplete = TRUE; - goto Exit; - } - - #ifdef FLM_WIN - if (m_FileHandle == INVALID_HANDLE_VALUE || - HasOverlappedIoCompleted( &m_Overlapped)) - { - bComplete = TRUE; - } - #endif - -#ifdef FLM_NLM - if( (uiSemCount = (FLMUINT)kSemaphoreExamineCount( (SEMAPHORE)m_hSem)) != 0) - { - flmAssert( uiSemCount == 1); - bComplete = TRUE; - } -#endif - -Exit: - - return( bComplete); -} - -/**************************************************************************** -Desc: -****************************************************************************/ -RCODE F_IOBuffer::waitToComplete( void) -{ - RCODE rc = FERR_OK; - - // IMPORTANT NOTE! The call to notifyComplete will destroy this - // object, so nothing in the object can be accessed after notifyComplete - // is called. - -#ifdef FLM_WIN - if (m_FileHandle != INVALID_HANDLE_VALUE) - { - DWORD udBytesWritten; - - if (!GetOverlappedResult( m_FileHandle, &m_Overlapped, - &udBytesWritten, TRUE)) - { - rc = MapWinErrorToFlaim( GetLastError(), - FERR_WRITING_FILE); - } - - notifyComplete( rc); - } -#endif - -#ifdef FLM_NLM - if( kSemaphoreWait( (SEMAPHORE)m_hSem) != 0) - { - flmAssert( 0); - } - flmAssert( kSemaphoreExamineCount( (SEMAPHORE)m_hSem) == 0); - rc = m_completionRc; - notifyComplete( m_completionRc); -#endif - - return( rc); -} - -/**************************************************************************** -Desc: -****************************************************************************/ -#ifdef FLM_NLM -void F_IOBuffer::signalComplete( - RCODE rc) -{ - m_completionRc = rc; - flmAssert( kSemaphoreExamineCount( (SEMAPHORE)m_hSem) == 0); - kSemaphoreSignal( (SEMAPHORE)m_hSem); -} -#endif diff --git a/flaim/src/fbuff.h b/flaim/src/fbuff.h deleted file mode 100644 index f858c51..0000000 --- a/flaim/src/fbuff.h +++ /dev/null @@ -1,276 +0,0 @@ -//------------------------------------------------------------------------- -// Desc: Buffer management for asynchronous I/O - class definition. -// Tabs: 3 -// -// Copyright (c) 2001-2006 Novell, Inc. All Rights Reserved. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of version 2 of the GNU General Public -// License as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, contact Novell, Inc. -// -// To contact Novell about this file by physical or electronic mail, -// you may find current contact information at www.novell.com -// -// $Id: fbuff.h 12329 2006-01-20 17:49:30 -0700 (Fri, 20 Jan 2006) ahodgkinson $ -//------------------------------------------------------------------------- - -#ifndef FBUFF_H -#define FBUFF_H - -#include "fpackon.h" -// IMPORTANT NOTE: No other include files should follow this one except -// for fpackoff.h - -class F_IOBuffer; - -#define F_MAX_BUFFER_BLOCKS 16 - -typedef void (* WRITE_COMPLETION_CB)( - F_IOBuffer * pWriteBuffer); - -class F_IOBufferMgr : public F_Base -{ -public: - - // Constructor - - F_IOBufferMgr(); - - // Destructor - - virtual ~F_IOBufferMgr(); - - RCODE waitForAllPendingIO( void); - - FINLINE void setMaxBuffers( - FLMUINT uiMaxBuffers) - { - m_uiMaxBuffers = uiMaxBuffers; - } - - FINLINE void setMaxBytes( - FLMUINT uiMaxBytes) - { - m_uiMaxBufferBytesToUse = uiMaxBytes; - } - - FINLINE void enableKeepBuffer( void) - { - m_bKeepBuffers = TRUE; - } - - RCODE getBuffer( - F_IOBuffer ** ppIOBuffer, - FLMUINT uiBufferSize, - FLMUINT uiBlockSize); - - FINLINE FLMBOOL havePendingIO( void) - { - return( m_pFirstPending ? TRUE : FALSE); - } - - FINLINE FLMBOOL haveUsed( void) - { - return( m_pFirstUsed ? TRUE : FALSE); - } - -private: - - F_IOBuffer * m_pFirstPending; - F_IOBuffer * m_pFirstAvail; - F_IOBuffer * m_pFirstUsed; - FLMUINT m_uiMaxBuffers; - FLMUINT m_uiMaxBufferBytesToUse; - FLMUINT m_uiBufferBytesInUse; - FLMUINT m_uiBuffersInUse; - RCODE m_completionRc; - FLMBOOL m_bKeepBuffers; - - void linkToList( - F_IOBuffer ** ppListHead, - F_IOBuffer * pIOBuffer); - - void unlinkFromList( - F_IOBuffer * pIOBuffer); - - friend class F_IOBuffer; -}; - -class F_IOBuffer : public F_Base -{ -public: - - typedef enum - { - MGR_LIST_NONE, - MGR_LIST_AVAIL, - MGR_LIST_PENDING, - MGR_LIST_USED - } eBufferMgrList; - - // Constructor - - F_IOBuffer(); - - // Destructor - - virtual ~F_IOBuffer(); - - RCODE setupBuffer( - FLMUINT uiBufferSize, - FLMUINT uiBlockSize); - - FINLINE FLMUINT getBufferSize( void) - { - return( m_uiBufferSize); - } - - FINLINE FLMUINT getBlockSize( void) - { - return( m_uiBlockSize); - } - - void notifyComplete( - RCODE rc); - - FINLINE void setCompletionCallback( - WRITE_COMPLETION_CB fnCompletion) - { - m_fnCompletion = fnCompletion; - } - - FINLINE void startTimer( - DB_STATS * pDbStats ) - { - if ((m_pDbStats = pDbStats) != NULL) - { - m_ui64ElapMilli = 0; - f_timeGetTimeStamp( &m_StartTime); - } - } - - FINLINE void endTimer( void) - { - if (m_pDbStats) - { - flmAddElapTime( &m_StartTime, &m_ui64ElapMilli); - } - } - - FINLINE FLMUINT64 getElapTime( void) - { - return( m_ui64ElapMilli); - } - - FINLINE DB_STATS * getDbStats( void) - { - return( m_pDbStats); - } - - FINLINE void setCompletionCallbackData( - FLMUINT uiBlockNumber, - void * pvData) - { - flmAssert( uiBlockNumber < F_MAX_BUFFER_BLOCKS); - m_UserData [uiBlockNumber] = pvData; - } - - FINLINE void * getCompletionCallbackData( - FLMUINT uiBlockNumber) - { - flmAssert( uiBlockNumber < F_MAX_BUFFER_BLOCKS); - return( m_UserData [uiBlockNumber]); - } - - FINLINE RCODE getCompletionCode( void) - { - return( m_completionRc); - } - - FINLINE eBufferMgrList getList( void) - { - return( m_eList); - } - - FINLINE FLMBYTE * getBuffer( void) - { - return( m_pucBuffer); - } - - void makePending( void); - -#ifdef FLM_WIN - FINLINE OVERLAPPED * getOverlapped( void) - { - return( &m_Overlapped); - } - - FINLINE void setFileHandle( - HANDLE FileHandle) - { - m_FileHandle = FileHandle; - } -#endif - -#if defined( FLM_UNIX) - FINLINE struct aiocb * getAIOStruct( void) - { - return( &m_aio); - } -#endif - -#ifdef FLM_NLM - void signalComplete( - RCODE rc); -#endif - -private: - - RCODE setupIOBuffer( - F_IOBufferMgr * pIOBufferMgr); - - FLMBOOL isIOComplete( void); - - RCODE waitToComplete( void); - - F_IOBufferMgr * m_pIOBufferMgr; - F_IOBuffer * m_pNext; - F_IOBuffer * m_pPrev; - WRITE_COMPLETION_CB m_fnCompletion; - RCODE m_completionRc; - FLMBYTE * m_pucBuffer; - void * m_UserData[ F_MAX_BUFFER_BLOCKS]; - FLMUINT m_uiBufferSize; - FLMUINT m_uiBlockSize; - eBufferMgrList m_eList; - FLMBOOL m_bDeleteOnNotify; - DB_STATS * m_pDbStats; - F_TMSTAMP m_StartTime; - FLMUINT64 m_ui64ElapMilli; - -#ifdef FLM_WIN - HANDLE m_FileHandle; - OVERLAPPED m_Overlapped; -#endif -#if defined( FLM_UNIX) - struct aiocb m_aio; -#endif -#ifdef FLM_NLM - F_SEM m_hSem; -#endif - -friend class F_IOBufferMgr; -friend class F_Rfl; -}; - -#include "fpackoff.h" - -#endif diff --git a/flaim/src/fcs.cpp b/flaim/src/fcs.cpp index 119b3c6..d610103 100644 --- a/flaim/src/fcs.cpp +++ b/flaim/src/fcs.cpp @@ -22,39 +22,19 @@ // $Id: fcs_bios.cpp 12329 2006-01-20 17:49:30 -0700 (Fri, 20 Jan 2006) ahodgkinson $ //------------------------------------------------------------------------- -// These must be defined BEFORE any includes. Unfortunately, this -// also means that we can't use our FLM_HPUX define because it hasn't -// been set yet... - -#if defined( __hpux) || defined( hpux) - #define _XOPEN_SOURCE_EXTENDED 1 - #define _INCLUDE_HPUX_SOURCE -#endif - #include "flaimsys.h" -#if defined( FLM_NLM) && !defined ( __MWERKS__) - // Disable errors for "expression for 'while' is always false" - // Needed for FD_SET macro - #pragma warning 555 9 -#endif - -#ifdef FLM_WIN - // conditional expression is constant (from FD_SET()) - #pragma warning( disable : 4127) -#endif - FSTATIC FLMBOOL flmGetNextHexPacketSlot( FLMBYTE * pucUsedMap, FLMUINT uiMapSize, - f_randomGenerator * pRandGen, + IF_RandomGenerator * pRandGen, FLMUINT * puiSlot); FSTATIC RCODE flmGetNextHexPacketBytes( FLMBYTE * pucUsedMap, FLMUINT uiMapSize, FLMBYTE * pucPacket, - f_randomGenerator * pRandGen, + IF_RandomGenerator * pRandGen, FLMBYTE * pucBuf, FLMUINT uiCount); @@ -63,7 +43,7 @@ Desc: *****************************************************************************/ FCS_BIOS::FCS_BIOS( void) { - GedPoolInit( &m_pool, (FCS_BIOS_BLOCK_SIZE + sizeof( FCSBIOSBLOCK)) * 2); + m_pool.poolInit( (FCS_BIOS_BLOCK_SIZE + sizeof( FCSBIOSBLOCK)) * 2); m_bMessageActive = FALSE; m_pRootBlock = NULL; m_pCurrWriteBlock = NULL; @@ -78,7 +58,7 @@ Desc: *****************************************************************************/ FCS_BIOS::~FCS_BIOS() { - GedPoolFree( &m_pool); + m_pool.poolFree(); } /**************************************************************************** @@ -96,7 +76,7 @@ RCODE FCS_BIOS::close( void) { RCODE rc = FERR_OK; - GedPoolReset( &m_pool, NULL); + m_pool.poolReset(); m_bMessageActive = FALSE; m_pRootBlock = NULL; m_pCurrWriteBlock = NULL; @@ -120,7 +100,7 @@ RCODE FCS_BIOS::write( if( !m_bAcceptingData) { - GedPoolReset( &m_pool, NULL); + m_pool.poolReset(); m_pCurrWriteBlock = NULL; m_pCurrReadBlock = NULL; m_pRootBlock = NULL; @@ -133,20 +113,16 @@ RCODE FCS_BIOS::write( m_pCurrWriteBlock->uiCurrWriteOffset == FCS_BIOS_BLOCK_SIZE) { pPrevBlock = m_pCurrWriteBlock; - m_pCurrWriteBlock = - (FCSBIOSBLOCK *)GedPoolCalloc( &m_pool, sizeof( FCSBIOSBLOCK)); - if( !m_pCurrWriteBlock) + + if( RC_BAD( rc = m_pool.poolCalloc( sizeof( FCSBIOSBLOCK), + (void **)&m_pCurrWriteBlock))) { - rc = RC_SET( FERR_MEM); goto Exit; } - - m_pCurrWriteBlock->pucBlock = - (FLMBYTE *)GedPoolAlloc( &m_pool, FCS_BIOS_BLOCK_SIZE); - - if( !m_pCurrWriteBlock->pucBlock) + + if( RC_BAD( rc = m_pool.poolAlloc( FCS_BIOS_BLOCK_SIZE, + (void **)&m_pCurrWriteBlock->pucBlock))) { - rc = RC_SET( FERR_MEM); goto Exit; } @@ -241,7 +217,7 @@ RCODE FCS_BIOS::read( if( !m_pCurrReadBlock) { - GedPoolReset( &m_pool, NULL); + m_pool.poolReset(); rc = RC_SET( FERR_EOF_HIT); goto Exit; } @@ -381,7 +357,7 @@ RCODE FCS_DIS::readShort( if( RC_OK( rc = read( (FLMBYTE *)pValue, 2, NULL))) { - *pValue = flmBigEndianToINT16( (FLMBYTE *)pValue); + *pValue = f_bigEndianToINT16( (FLMBYTE *)pValue); } return( rc); @@ -397,7 +373,7 @@ RCODE FCS_DIS::readUShort( if( RC_OK( rc = read( (FLMBYTE *)pValue, 2, NULL))) { - *pValue = flmBigEndianToUINT16( (FLMBYTE *)pValue); + *pValue = f_bigEndianToUINT16( (FLMBYTE *)pValue); } return( rc); @@ -413,7 +389,7 @@ RCODE FCS_DIS::readInt( if( RC_OK( rc = read( (FLMBYTE *)pValue, 4, NULL))) { - *pValue = flmBigEndianToINT32( (FLMBYTE *)pValue); + *pValue = f_bigEndianToINT32( (FLMBYTE *)pValue); } return( rc); @@ -429,7 +405,7 @@ RCODE FCS_DIS::readUInt( if( RC_OK( rc = read( (FLMBYTE *)pValue, 4, NULL))) { - *pValue = flmBigEndianToUINT32( (FLMBYTE *)pValue); + *pValue = f_bigEndianToUINT32( (FLMBYTE *)pValue); } return( rc); @@ -445,7 +421,7 @@ RCODE FCS_DIS::readInt64( if( RC_OK( rc = read( (FLMBYTE *)pValue, 8, NULL))) { - *pValue = flmBigEndianToINT64( (FLMBYTE *)pValue); + *pValue = f_bigEndianToINT64( (FLMBYTE *)pValue); } return( rc); @@ -461,7 +437,7 @@ RCODE FCS_DIS::readUInt64( if( RC_OK( rc = read( (FLMBYTE *)pValue, 8, NULL))) { - *pValue = flmBigEndianToUINT64( (FLMBYTE *)pValue); + *pValue = f_bigEndianToUINT64( (FLMBYTE *)pValue); } return( rc); @@ -646,26 +622,7 @@ RCODE FCS_DIS::read( if( pucPos) { -#if defined( FLM_NLM) || defined( FLM_WIN) - if( uiCopySize == 1) - { - *pucPos = m_pucBuffer[ m_uiBOffset]; - } - else if( uiLength == 2) - { - *(FLMUINT16 *)pucPos = *((FLMUINT16 *)&m_pucBuffer[ m_uiBOffset]); - } - else if( uiLength == 4) - { - *(FLMUINT32 *)pucPos = *((FLMUINT32 *)&m_pucBuffer[ m_uiBOffset]); - } - else - { - f_memcpy( pucPos, &(m_pucBuffer[ m_uiBOffset]), uiCopySize); - } -#else - f_memcpy( pucPos, &(m_pucBuffer[ m_uiBOffset]), uiCopySize); -#endif + f_memcpy( pucPos, &(m_pucBuffer[ m_uiBOffset]), uiCopySize); pucPos += uiCopySize; } @@ -695,7 +652,7 @@ Desc: Reads a binary token from the stream. The token is tagged with a length. ****************************************************************************/ RCODE FCS_DIS::readBinary( - POOL * pPool, + F_Pool * pPool, FLMBYTE ** ppValue, FLMUINT * puiDataSize) { @@ -714,12 +671,11 @@ RCODE FCS_DIS::readBinary( if( ui16DataSize) { - if( (*ppValue = (FLMBYTE *)GedPoolAlloc( pPool, ui16DataSize)) == NULL) + if( RC_BAD( rc = pPool->poolAlloc( ui16DataSize, (void **)ppValue))) { - rc = RC_SET( FERR_MEM); goto Exit; } - + if( RC_BAD( rc = read( *ppValue, ui16DataSize, NULL))) { goto Exit; @@ -757,7 +713,7 @@ Desc: Reads a large binary token from the stream. The token is tagged with a length. ****************************************************************************/ RCODE FCS_DIS::readLargeBinary( - POOL * pPool, + F_Pool * pPool, FLMBYTE ** ppValue, FLMUINT * puiDataSize) { @@ -776,12 +732,11 @@ RCODE FCS_DIS::readLargeBinary( if( ui32DataSize) { - if( (*ppValue = (FLMBYTE *)GedPoolAlloc( pPool, ui32DataSize)) == NULL) + if( RC_BAD(rc = pPool->poolAlloc( ui32DataSize, (void **)ppValue))) { - rc = RC_SET( FERR_MEM); goto Exit; } - + if( RC_BAD( rc = read( *ppValue, ui32DataSize, NULL))) { goto Exit; @@ -817,7 +772,7 @@ Exit: Desc: Reads a UTF-8 string from the stream. ****************************************************************************/ RCODE FCS_DIS::readUTF( - POOL * pPool, + F_Pool * pPool, FLMUNICODE ** ppValue) { FLMBYTE ucByte1; @@ -849,8 +804,12 @@ RCODE FCS_DIS::readUTF( if( pPool) { - *ppValue = (FLMUNICODE *)GedPoolAlloc( pPool, - (FLMUINT)((FLMUINT)sizeof( FLMUNICODE) * (FLMUINT)(ui16UTFLen + 1))); + if( RC_BAD( rc = pPool->poolAlloc( + (FLMUINT)((FLMUINT)sizeof( FLMUNICODE) * (FLMUINT)(ui16UTFLen + 1)), + (void **)ppValue))) + { + goto Exit; + } } else if( ppValue) { @@ -921,7 +880,7 @@ Exit: Desc: Reads an Hierarchical Tagged Data record from the stream. ****************************************************************************/ RCODE FCS_DIS::readHTD( - POOL * pPool, + F_Pool * pPool, FLMUINT uiContainer, FLMUINT uiDrn, NODE ** ppNode, @@ -948,7 +907,7 @@ RCODE FCS_DIS::readHTD( if( pPool) { - pvMark = GedPoolMark( pPool); + pvMark = pPool->poolMark(); } for( ;;) @@ -1601,7 +1560,7 @@ RCODE FCS_DIS::readHTD( if( pPool && !ppNode) { - GedPoolReset( pPool, pvMark); + pPool->poolReset( pvMark); } } @@ -1624,7 +1583,7 @@ Exit: if( pPool && !ppNode) { - GedPoolReset( pPool, pvMark); + pPool->poolReset( pvMark); } return( rc); @@ -1637,7 +1596,7 @@ FCS_DOS::FCS_DOS( void) { m_pOStream = NULL; m_uiBOffset = 0; - GedPoolInit( &m_tmpPool, 512); + m_tmpPool.poolInit( 512); m_bSetupCalled = FALSE; } @@ -1651,7 +1610,8 @@ FCS_DOS::~FCS_DOS( void) { (void)close(); } - GedPoolFree( &m_tmpPool); + + m_tmpPool.poolFree(); } /**************************************************************************** @@ -1674,31 +1634,8 @@ Retry_Write: if( FCS_DOS_BUFFER_SIZE - m_uiBOffset >= uiLength) { -#if defined( FLM_NLM) || defined( FLM_WIN) - if( uiLength == 1) - { - m_pucBuffer[ m_uiBOffset] = *pucData; - m_uiBOffset++; - } - else if( uiLength == 2) - { - *(FLMUINT16 *)&(m_pucBuffer[ m_uiBOffset]) = *((FLMUINT16 *)pucData); - m_uiBOffset += 2; - } - else if( uiLength == 4) - { - *(FLMUINT32 *)&(m_pucBuffer[ m_uiBOffset]) = *((FLMUINT32 *)pucData); - m_uiBOffset += 4; - } - else - { - f_memcpy( &(m_pucBuffer[ m_uiBOffset]), pucData, uiLength); - m_uiBOffset += uiLength; - } -#else f_memcpy( &(m_pucBuffer[ m_uiBOffset]), pucData, uiLength); m_uiBOffset += uiLength; -#endif } else { @@ -1878,7 +1815,7 @@ RCODE FCS_DOS::writeHTD( FLMBOOL bRightTruncated; FLMBYTE * pucCurData = NULL; FLMBYTE pucTmpBuf[ 32]; - void * pvMark = GedPoolMark( &m_tmpPool); + void * pvMark = m_tmpPool.poolMark(); NODE * pCurNode = NULL; void * pCurField = NULL; RCODE rc = FERR_OK; @@ -1915,11 +1852,11 @@ RCODE FCS_DOS::writeHTD( if( pCurNode) { - flmUINT16ToBigEndian( (FLMUINT16)GedTagNum( pCurNode), pucTmpBuf); + f_UINT16ToBigEndian( (FLMUINT16)GedTagNum( pCurNode), pucTmpBuf); } else if( pCurField) { - flmUINT16ToBigEndian( (FLMUINT16)pRecord->getFieldID( pCurField), pucTmpBuf); + f_UINT16ToBigEndian( (FLMUINT16)pRecord->getFieldID( pCurField), pucTmpBuf); } if( RC_BAD( rc = write( pucTmpBuf, 2))) @@ -2085,7 +2022,7 @@ RCODE FCS_DOS::writeHTD( flmAssert( uiCurDataLen <= 0x0000FFFF); - flmUINT16ToBigEndian( (FLMUINT16)uiCurDataLen, pucTmpBuf); + f_UINT16ToBigEndian( (FLMUINT16)uiCurDataLen, pucTmpBuf); if( RC_BAD( rc = write( pucTmpBuf, 2))) { goto Exit; @@ -2116,7 +2053,7 @@ RCODE FCS_DOS::writeHTD( // Reset the temporary pool. - GedPoolReset( &m_tmpPool, pvMark); + m_tmpPool.poolReset( pvMark); if( uiCurDataLen <= 32751) { // Allocate a buffer that is twice the size of the @@ -2135,11 +2072,10 @@ RCODE FCS_DOS::writeHTD( uiBufSize = 65535; } - - if( (puzValue = (FLMUNICODE *)GedPoolAlloc( &m_tmpPool, - uiBufSize)) == NULL) + + if( RC_BAD( rc = m_tmpPool.poolAlloc( uiBufSize, + (void **)&puzValue))) { - rc = RC_SET( FERR_MEM); goto Exit; } @@ -2170,17 +2106,16 @@ RCODE FCS_DOS::writeHTD( // Reset the pool to clear the prior allocation. - GedPoolReset( &m_tmpPool, pvMark); + m_tmpPool.poolReset( pvMark); // Allocate the new buffer. - if( (puzValue = (FLMUNICODE *)GedPoolAlloc( - &m_tmpPool, uiBufSize)) == NULL) + if( RC_BAD( rc = m_tmpPool.poolAlloc( uiBufSize, + (void **)&puzValue))) { - rc = RC_SET( FERR_MEM); goto Exit; } - + // Extract the UNICODE string. if( (pCurNode && RC_BAD( rc = GedGetUNICODE( @@ -2333,7 +2268,7 @@ RCODE FCS_DOS::writeHTD( Exit: - GedPoolReset( &m_tmpPool, pvMark); + m_tmpPool.poolReset( pvMark); return( rc); } @@ -2464,8 +2399,8 @@ RCODE FCS_FIS::setup( goto Exit; } - if( RC_BAD( rc = gv_FlmSysData.pFileSystem->Open( pszFilePath, - F_IO_RDONLY | F_IO_SH_DENYNONE, &m_pFileHdl))) + if( RC_BAD( rc = gv_FlmSysData.pFileSystem->openFile( pszFilePath, + FLM_IO_RDONLY | FLM_IO_SH_DENYNONE, &m_pFileHdl))) { goto Exit; } @@ -2489,7 +2424,6 @@ RCODE FCS_FIS::close( void) { if( m_pFileHdl) { - m_pFileHdl->Close(); m_pFileHdl->Release(); m_pFileHdl = NULL; } @@ -2594,7 +2528,7 @@ RCODE FCS_FIS::getNextPacket( void) { RCODE rc = FERR_OK; - if( RC_BAD( rc = m_pFileHdl->Read( m_uiFileOffset, m_uiBlockSize, + if( RC_BAD( rc = m_pFileHdl->read( m_uiFileOffset, m_uiBlockSize, m_pucBuffer, &m_uiBlockEnd))) { if( rc == FERR_IO_END_OF_FILE) @@ -2618,1304 +2552,12 @@ Exit: return( rc); } -/**************************************************************************** -Desc: Constructor -*****************************************************************************/ -FCS_IPIS::FCS_IPIS( FCS_TCP * pTcpObj) -{ - m_pTcpObj = pTcpObj; - m_pucBufPos = m_pucBuffer; - m_bStreamInvalid = FALSE; - m_bMessageActive = FALSE; - m_bGotLastPacket = FALSE; - m_uiPacketSize = 0; -} - -/**************************************************************************** -Desc: -*****************************************************************************/ -FCS_IPIS::~FCS_IPIS( void) -{ - (void)close(); -} - -/**************************************************************************** -Desc: -*****************************************************************************/ -FLMBOOL FCS_IPIS::isOpen( void) -{ - return( TRUE); -} - -/**************************************************************************** -Desc: -*****************************************************************************/ -RCODE FCS_IPIS::close( void) -{ - (void)endMessage(); - m_bStreamInvalid = FALSE; - return( FERR_OK); -} - -/**************************************************************************** -Desc: Reads the requested amount of data from the stream. -*****************************************************************************/ -RCODE FCS_IPIS::read( - FLMBYTE * pucData, - FLMUINT uiLength, - FLMUINT * puiBytesRead) -{ - FLMUINT uiBytesRead = 0; - FLMUINT uiMaxSize; - RCODE rc = FERR_OK; - - if( puiBytesRead) - { - *puiBytesRead = 0; - } - - if( !m_bStreamInvalid) - { - while( uiLength) - { - uiMaxSize = m_uiPacketSize - (FLMUINT)(m_pucBufPos - m_pucBuffer); - - if( !uiMaxSize) - { - if( RC_BAD( rc = getNextPacket())) - { - goto Exit; - } - } - else if( uiLength <= uiMaxSize) - { - f_memcpy( pucData, m_pucBufPos, uiLength); - m_pucBufPos += uiLength; - uiBytesRead += uiLength; - uiLength = 0; - } - else - { - f_memcpy( pucData, m_pucBufPos, uiMaxSize); - m_pucBufPos += uiMaxSize; - pucData += uiMaxSize; - uiLength -= uiMaxSize; - uiBytesRead += uiMaxSize; - } - } - } - else - { - rc = RC_SET( FERR_READING_FILE); - } - -Exit: - - if( puiBytesRead) - { - *puiBytesRead = uiBytesRead; - } - - return( rc); -} - -/**************************************************************************** -Desc: Flushes any pending data. -*****************************************************************************/ -RCODE FCS_IPIS::flush( void) -{ - RCODE rc = FERR_OK; - - if( !m_bMessageActive) - { - goto Exit; - } - - for( ;;) - { - if( RC_BAD( rc = getNextPacket())) - { - if( rc == FERR_EOF_HIT) - { - rc = FERR_OK; - } - goto Exit; - } - } - -Exit: - - m_pucBufPos = m_pucBuffer; - return( rc); -} - - -/**************************************************************************** -Desc: Flushes any pending data. -*****************************************************************************/ -RCODE FCS_IPIS::endMessage( void) -{ - RCODE rc = FERR_OK; - - if( !m_bMessageActive) - { - goto Exit; - } - - if( RC_BAD( rc = flush())) - { - goto Exit; - } - -Exit: - - m_bMessageActive = FALSE; - m_bGotLastPacket = FALSE; - return( rc); -} - - -/**************************************************************************** -Desc: Reads the next packet off the wire. -*****************************************************************************/ -RCODE FCS_IPIS::getNextPacket( void) -{ - FLMBYTE pucDescriptor[ 2]; - FLMUINT uiDescriptor; - FLMUINT uiActualCnt = 0; - RCODE rc = FERR_OK; - - if( !m_bStreamInvalid) - { - if( !m_bMessageActive) - { - m_bMessageActive = TRUE; - } - - if( m_bGotLastPacket) - { - rc = RC_SET( FERR_EOF_HIT); - goto Exit; - } - - if( RC_BAD( rc = m_pTcpObj->readAll( pucDescriptor, - 2, &uiActualCnt))) - { - goto Exit; - } - - uiDescriptor = flmBigEndianToUINT16( pucDescriptor); - m_uiPacketSize = uiDescriptor & 0x7FFF; - - if( uiDescriptor & 0x8000) - { - m_bGotLastPacket = TRUE; - } - - if( m_uiPacketSize > FCS_IPIS_BUFFER_SIZE) - { - m_uiPacketSize = 0; - rc = RC_SET( FERR_READING_FILE); - goto Exit; - } - - if( m_uiPacketSize > 0) - { - if( RC_BAD( rc = m_pTcpObj->readAll( m_pucBuffer, - m_uiPacketSize, &uiActualCnt))) - { - goto Exit; - } - } - else - { - if( m_bGotLastPacket) - { - rc = RC_SET( FERR_EOF_HIT); - } - else - { - rc = RC_SET( FERR_READING_FILE); - } - goto Exit; - } - - m_pucBufPos = m_pucBuffer; - } - else - { - rc = RC_SET( FERR_READING_FILE); - } - -Exit: - - if( RC_BAD( rc) && rc != FERR_EOF_HIT) - { - m_bStreamInvalid = TRUE; - } - - return( rc); -} - -/**************************************************************************** -Desc: -*****************************************************************************/ -FCS_IPOS::FCS_IPOS( FCS_TCP * pTcpObj) -{ - m_pTcpObj = pTcpObj; - m_pucBufPos = &(m_pucBuffer[ 2]); - m_bOpen = TRUE; - m_bMessageActive = FALSE; -} - -/**************************************************************************** -Desc: Flushes any pending data and closes the stream. -*****************************************************************************/ -RCODE FCS_IPOS::close( void) -{ - RCODE rc = FERR_OK; - - if( m_bOpen) - { - rc = endMessage(); - m_bOpen = FALSE; - } - - return( rc); -} - -/**************************************************************************** -Desc: Writes the requested amount of data to the stream. -*****************************************************************************/ -RCODE FCS_IPOS::write( - FLMBYTE * pucData, - FLMUINT uiLength) -{ - FLMUINT uiMaxSize; - RCODE rc = FERR_OK; - - if( !uiLength) - { - goto Exit; - } - - if( m_bOpen) - { - while( uiLength) - { - uiMaxSize = - (FLMUINT)(FCS_IPOS_BUFFER_SIZE - (m_pucBufPos - m_pucBuffer)); - - if( !uiMaxSize) - { - if( RC_BAD( rc = flush())) - { - goto Exit; - } - } - else if( uiLength <= uiMaxSize) - { - f_memcpy( m_pucBufPos, pucData, uiLength); - m_pucBufPos += uiLength; - uiLength = 0; - } - else - { - f_memcpy( m_pucBufPos, pucData, uiMaxSize); - m_pucBufPos += uiMaxSize; - pucData += uiMaxSize; - uiLength -= uiMaxSize; - if( RC_BAD( rc = flush())) - { - goto Exit; - } - } - } - m_bMessageActive = TRUE; - } - else - { - rc = RC_SET( FERR_WRITING_FILE); - } - -Exit: - - return( rc); -} - -/**************************************************************************** -Desc: Flushes any pending data and optionally ends the current message. -*****************************************************************************/ -RCODE FCS_IPOS::_flush( - FLMBOOL bEndMessage) -{ - FLMUINT uiActualCnt; - FLMUINT uiLength; - FLMUINT uiDescriptor; - RCODE rc = FERR_OK; - - if( (uiLength = (FLMUINT)(m_pucBufPos - m_pucBuffer)) != 0) - { - uiDescriptor = uiLength - 2; - if( bEndMessage) - { - uiDescriptor |= 0x8000; - } - - if( uiDescriptor) - { - flmUINT16ToBigEndian( (FLMUINT16)uiDescriptor, m_pucBuffer); - - if( RC_BAD( rc = m_pTcpObj->write( m_pucBuffer, - uiLength, &uiActualCnt))) - { - goto Exit; - } - } - } - -Exit: - - m_pucBufPos = &(m_pucBuffer[ 2]); - return( rc); -} - -/**************************************************************************** -Desc: Terminates the current message -*****************************************************************************/ -RCODE FCS_IPOS::endMessage( void) -{ - RCODE rc = FERR_OK; - - - if( !m_bMessageActive) - { - goto Exit; - } - - if( RC_BAD( rc = _flush( TRUE))) - { - goto Exit; - } - -Exit: - - m_bMessageActive = FALSE; - return( rc); -} - -/******************************************************************** -Desc: Constructor -*********************************************************************/ -FCS_TCP::FCS_TCP( void) -{ - m_pszIp[ 0] = '\0'; - m_pszName[ 0] = '\0'; - m_pszPeerIp[ 0] = '\0'; - m_pszPeerName[ 0] = '\0'; - m_uiIOTimeout = 10; - m_iSocket = INVALID_SOCKET; - m_ulRemoteAddr = 0; - m_bInitialized = FALSE; - m_bConnected = FALSE; - -#ifndef FLM_UNIX - if( !WSAStartup( MAKEWORD(2, 0), &m_wsaData)) - { - m_bInitialized = TRUE; - } -#endif -} - -/******************************************************************** -Desc: Destructor -*********************************************************************/ -FCS_TCP::~FCS_TCP( void ) -{ - if( m_bConnected) - { - close(); - } - -#ifndef FLM_UNIX - if( m_bInitialized) - { - WSACleanup(); - } -#endif -} - -/******************************************************************** -Desc: Gets information about the local host machine. -*********************************************************************/ -RCODE FCS_TCP::_GetLocalInfo( void) -{ - struct hostent * pHostEnt; - FLMUINT32 ui32IPAddr; - RCODE rc = FERR_OK; - - m_pszIp[ 0] = '\0'; - m_pszName[ 0] = '\0'; - - if( m_pszName[ 0] == '\0') - { - if( gethostname( m_pszName, (unsigned)sizeof( m_pszName))) - { - rc = RC_SET( FERR_SVR_SOCK_FAIL); - goto Exit; - } - } - - if( m_pszIp[ 0] == '\0' && - (pHostEnt = gethostbyname( m_pszName)) != NULL) - { - ui32IPAddr = (FLMUINT32)(*((unsigned long *)pHostEnt->h_addr)); - if( ui32IPAddr != (FLMUINT32)-1) - { - struct in_addr InAddr; - - InAddr.s_addr = ui32IPAddr; - f_strcpy( m_pszIp, inet_ntoa( InAddr)); - } - } - -Exit: - - return( rc); -} - -/******************************************************************** -Desc: Gets information about the remote machine. -*********************************************************************/ -RCODE FCS_TCP::_GetRemoteInfo( void) -{ - struct sockaddr_in SockAddrIn; - char * InetAddr = NULL; - struct hostent * HostsName; - RCODE rc = FERR_OK; - - m_pszPeerIp[ 0] = '\0'; - m_pszPeerName[ 0] = '\0'; - - SockAddrIn.sin_addr.s_addr = (unsigned)m_ulRemoteAddr; - - // inet_ntoa() - converts a 32-bit value in in_addr format into an ASCII - // string representing the address in dotted notation. - // VISIT: - // NetWare: Macro in arpa/inet.h. "Apps with multiple threads should use - // NWinet_ntoa instead of inet_ntoa. Then we can get rid of the semaphore! - - InetAddr = inet_ntoa( SockAddrIn.sin_addr ); - f_strcpy( m_pszPeerIp, InetAddr ); - - // Try to get the peer's host name by looking up his IP - // address. If found, copy IP Host name "BEVIS@NOVELL.COM" to TCPInfo - // otherwise, use his IP address as IP name. - // VISIT: - // Netware: "If your app has multiple threads, use either NWgethostbyaddr - // or NetDBgethostbyaddr(). This does the blocking? This may be done - // already in netdb.h - it is hard to tell. - - HostsName = gethostbyaddr( (char *)&SockAddrIn.sin_addr.s_addr, - (unsigned)sizeof( unsigned long), AF_INET ); - - if( HostsName != NULL) - { - f_strcpy( m_pszPeerName, (char*) HostsName->h_name ); - } - else - { - if (!InetAddr) - { - InetAddr = inet_ntoa( SockAddrIn.sin_addr); - } - f_strcpy( m_pszPeerName, InetAddr ); - } - - return( rc); -} - -/******************************************************************** -Desc: Tests for socket data readiness -*********************************************************************/ -RCODE FCS_TCP::_SocketPeek( - FLMINT iTimeoutVal, - FLMBOOL bPeekRead) -{ - struct timeval TimeOut; - int iMaxDescs; - fd_set GenDescriptors; - fd_set * DescrRead; - fd_set * DescrWrt; - RCODE rc = FERR_OK; - - if( m_iSocket != INVALID_SOCKET) - { - FD_ZERO( &GenDescriptors ); - FD_SET( m_iSocket, &GenDescriptors ); - - iMaxDescs = (int)(m_iSocket + 1); - DescrRead = bPeekRead ? &GenDescriptors : NULL; - DescrWrt = bPeekRead ? NULL : &GenDescriptors; - - TimeOut.tv_sec = (long)iTimeoutVal; - TimeOut.tv_usec = (long)0; - - if( select( iMaxDescs, DescrRead, DescrWrt, NULL, &TimeOut) < 0 ) - { - rc = RC_SET( FERR_SVR_SELECT_ERR); - goto Exit; - } - else - { - if( !FD_ISSET( m_iSocket, &GenDescriptors)) - { - rc = bPeekRead - ? RC_SET( FERR_SVR_READ_TIMEOUT) - : RC_SET( FERR_SVR_WRT_TIMEOUT); - } - } - } - else - { - rc = RC_SET( FERR_SVR_CONNECT_FAIL); - } - -Exit: - - return( rc); -} - -/******************************************************************** -Desc: Writes data to the connection. -*********************************************************************/ -RCODE FCS_TCP::write( - FLMBYTE * pucDataBuffer, - FLMUINT uiDataCnt, - FLMUINT * puiWrtCnt) -{ - FLMUINT uiPartialCnt; - FLMUINT uiToWrite; - FLMUINT uiHaveWritten = 0; - RCODE rc = FERR_OK; - - if( m_iSocket == INVALID_SOCKET) - { - rc = RC_SET( FERR_SVR_CONNECT_FAIL); - } - - uiToWrite = uiDataCnt; - *puiWrtCnt = 0; - while( uiToWrite > 0) - { - // The internal write call checks the arguments - - if( RC_BAD( rc = _write( pucDataBuffer, - uiToWrite, &uiPartialCnt))) - { - goto Exit; - } - - pucDataBuffer += uiPartialCnt; - uiHaveWritten += uiPartialCnt; - uiToWrite = (FLMUINT)(uiDataCnt - uiHaveWritten); - *puiWrtCnt = uiHaveWritten; - } - -Exit: - - return( rc); -} - -/******************************************************************** -Desc: -*********************************************************************/ -RCODE FCS_TCP::_write( - FLMBYTE * pucBuffer, - FLMUINT uiDataCnt, - FLMUINT *puiWrtCnt) -{ - FLMINT iRetryCount = 0; - FLMINT iWrtCnt = 0; - RCODE rc = FERR_OK; - - flmAssert( m_iSocket != INVALID_SOCKET && pucBuffer && uiDataCnt); - -Retry: - - *puiWrtCnt = 0; - if( RC_OK( rc = _SocketPeek( m_uiIOTimeout, FALSE))) - { - iWrtCnt = send( m_iSocket, (char *)pucBuffer, (int)uiDataCnt, 0 ); - switch ( iWrtCnt ) - { - case -1: - { - *puiWrtCnt = 0; - rc = RC_SET( FERR_SVR_WRT_FAIL); - break; - } - - case 0: - { - rc = RC_SET( FERR_SVR_DISCONNECT); - break; - } - - default: - { - *puiWrtCnt = (FLMUINT)iWrtCnt; - break; - } - } - } - - if( RC_BAD( rc) && rc != FERR_SVR_WRT_TIMEOUT) - { -#ifndef FLM_UNIX - FLMINT iSockErr = WSAGetLastError(); -#else - FLMINT iSockErr = errno; -#endif - -#if defined( FLM_WIN) || defined( FLM_NLM) - if( iSockErr == WSAECONNABORTED) -#else - if( iSockErr == ECONNABORTED) -#endif - { - rc = RC_SET( FERR_SVR_DISCONNECT); - } -#if defined( FLM_WIN) || defined( FLM_NLM) - else if( iSockErr == WSAEWOULDBLOCK && iRetryCount < 5) -#else - else if( iSockErr == EWOULDBLOCK && iRetryCount < 5) -#endif - { - iRetryCount++; - f_sleep( (FLMUINT)(100 * iRetryCount)); - goto Retry; - } - } - - return( rc); -} - -/******************************************************************** -Desc: Reads data from the connection -*********************************************************************/ -RCODE FCS_TCP::read( - FLMBYTE * pucBuffer, - FLMUINT uiDataCnt, - FLMUINT * puiReadCnt) -{ - FLMINT iReadCnt = 0; - RCODE rc = FERR_OK; - - flmAssert( m_bConnected && pucBuffer && uiDataCnt); - - if( RC_OK( rc = _SocketPeek( m_uiIOTimeout, TRUE))) - { - iReadCnt = (FLMINT)recv( m_iSocket, - (char *)pucBuffer, (int)uiDataCnt, 0); - switch ( iReadCnt) - { - case -1: - { - iReadCnt = 0; -#if defined( FLM_WIN) || defined( FLM_NLM) - if ( WSAGetLastError() == WSAECONNRESET) -#else - if( errno == ECONNRESET) -#endif - { - rc = RC_SET( FERR_SVR_DISCONNECT); - } - else - { - rc = RC_SET( FERR_SVR_READ_FAIL); - } - break; - } - - case 0: - { - rc = RC_SET( FERR_SVR_DISCONNECT); - break; - } - - default: - { - break; - } - } - } - - if( puiReadCnt) - { - *puiReadCnt = (FLMUINT)iReadCnt; - } - - return( rc); -} - -/******************************************************************** -Desc: Reads data from the connection - Timeout valkue is zero, no error - is generated if timeout occurs. -*********************************************************************/ -RCODE FCS_TCP::readNoWait( - FLMBYTE * pucBuffer, - FLMUINT uiDataCnt, - FLMUINT * puiReadCnt) -{ - FLMINT iReadCnt = 0; - RCODE rc = FERR_OK; - - flmAssert( m_bConnected && pucBuffer && uiDataCnt); - - if( puiReadCnt) - { - *puiReadCnt = 0; - } - - if( RC_OK( rc = _SocketPeek( (FLMUINT)0, TRUE))) - { - iReadCnt = recv( m_iSocket, (char *)pucBuffer, (int)uiDataCnt, 0); - switch ( iReadCnt) - { - case -1: - { - *puiReadCnt = 0; -#if defined( FLM_WIN) || defined( FLM_NLM) - if ( WSAGetLastError() == WSAECONNRESET) -#else - if( errno == ECONNRESET) -#endif - { - rc = RC_SET( FERR_SVR_DISCONNECT); - } - else - { - rc = RC_SET( FERR_SVR_READ_FAIL); - } - goto Exit; - } - - case 0: - { - rc = RC_SET( FERR_SVR_DISCONNECT); - goto Exit; - } - - default: - { - break; - } - } - } - else if (rc == FERR_SVR_READ_TIMEOUT) - { - rc = FERR_OK; - } - - if( puiReadCnt) - { - *puiReadCnt = (FLMUINT)iReadCnt; - } - -Exit: - - return( rc); -} - -/******************************************************************** -Desc: Reads data and does not return until all requested data has - been read or a timeout error has been encountered. -*********************************************************************/ -RCODE FCS_TCP::readAll( - FLMBYTE * pucBuffer, - FLMUINT uiDataCnt, - FLMUINT * puiReadCnt) -{ - FLMUINT uiToRead = 0; - FLMUINT uiHaveRead = 0; - FLMUINT uiPartialCnt; - RCODE rc = FERR_OK; - - flmAssert( m_bConnected && pucBuffer && uiDataCnt); - - uiToRead = uiDataCnt; - while( uiToRead) - { - if( RC_BAD( rc = read( pucBuffer, uiToRead, &uiPartialCnt))) - { - goto Exit; - } - - pucBuffer += uiPartialCnt; - uiHaveRead += uiPartialCnt; - uiToRead = (FLMUINT)(uiDataCnt - uiHaveRead); - - if( puiReadCnt) - { - *puiReadCnt = uiHaveRead; - } - } - -Exit: - - return( rc); -} - -/******************************************************************** -Desc: Enables or disables Nagle's algorithm -*********************************************************************/ -RCODE FCS_TCP::setTcpDelay( - FLMBOOL bOn) -{ - RCODE rc = FERR_OK; - int iOn; - - if( m_iSocket != INVALID_SOCKET) - { - iOn = bOn ? 1 : 0; - - if( (setsockopt( m_iSocket, IPPROTO_TCP, TCP_NODELAY, (char *)&iOn, - (unsigned)sizeof( iOn) )) < 0) - { - rc = RC_SET( FERR_SVR_SOCKOPT_FAIL); - goto Exit; - } - } - else - { - rc = RC_SET( FERR_SVR_ALREADY_CLOSED); - } - -Exit: - - return( rc); -} - -/******************************************************************** -Desc: Closes any open connections -*********************************************************************/ -void FCS_TCP::close( - FLMBOOL bForce) -{ - if( m_iSocket == INVALID_SOCKET) - { - goto Exit; - } - -#ifdef FLM_NLM - F_UNREFERENCED_PARM( bForce); -#else - if( !bForce) - { - char ucTmpBuf[ 128]; - struct timeval tv; - fd_set fds; - fd_set fds_read; - fd_set fds_err; - - // Close our half of the connection - - shutdown( m_iSocket, 1); - - // Set up to wait for readable data on the socket - - FD_ZERO( &fds); - FD_SET( m_iSocket, &fds); - - tv.tv_sec = 10; - tv.tv_usec = 0; - - fds_read = fds; - fds_err = fds; - - // Wait for data or an error - - while( select( m_iSocket + 1, &fds_read, NULL, &fds_err, &tv) > 0) - { - if( recv( m_iSocket, ucTmpBuf, sizeof( ucTmpBuf), 0) <= 0) - { - break; - } - fds_read = fds; - fds_err = fds; - } - - shutdown( m_iSocket, 2); - } -#endif - -#ifndef FLM_UNIX - closesocket( m_iSocket); -#else - ::close( m_iSocket); -#endif - -Exit: - - m_iSocket = INVALID_SOCKET; - m_bConnected = FALSE; -} - -/******************************************************************** -Desc: Creates a client object -*********************************************************************/ -FCS_TCP_CLIENT::FCS_TCP_CLIENT( void) : FCS_TCP() -{ - m_bConnected = FALSE; -} - -/******************************************************************** -Desc: Closes any connections and frees client resources -*********************************************************************/ -FCS_TCP_CLIENT::~FCS_TCP_CLIENT( void ) -{ - (void)close(); -} - -/******************************************************************** -Desc: Opens a new connection -*********************************************************************/ -RCODE FCS_TCP_CLIENT::openConnection( - const char * pucHostName, - FLMUINT uiPort, - FLMUINT uiConnectTimeout, - FLMUINT uiDataTimeout) -{ - FLMINT iSockErr; - FLMINT iTries; - FLMINT iMaxTries = 5; - struct sockaddr_in address; - struct hostent * pHostEntry; - unsigned long ulIPAddr; - RCODE rc = FERR_OK; - - flmAssert( !m_bConnected); - m_iSocket = INVALID_SOCKET; - - if( pucHostName && pucHostName[ 0] != '\0') - { - ulIPAddr = inet_addr( (char *)pucHostName); - if( ulIPAddr == (unsigned long)INADDR_NONE) - { - pHostEntry = gethostbyname( (char *)pucHostName); - - if( !pHostEntry) - { - rc = RC_SET( FERR_SVR_NOIP_ADDR); - goto Exit; - } - else - { - ulIPAddr = *((unsigned long *)pHostEntry->h_addr); - } - - } - } - else - { - ulIPAddr = inet_addr( (char *)"127.0.0.1"); - } - - // Fill in the Socket structure with family type - - f_memset( (char*)&address, 0, sizeof( struct sockaddr_in)); - address.sin_family = AF_INET; - address.sin_addr.s_addr = (unsigned)ulIPAddr; - address.sin_port = htons( (unsigned short)uiPort); - - // Allocate a socket, then attempt to connect to it! - - if( (m_iSocket = socket( AF_INET, - SOCK_STREAM, IPPROTO_TCP)) == INVALID_SOCKET) - { - rc = RC_SET( FERR_SVR_SOCK_FAIL); - goto Exit; - } - - // Now attempt to connect with the specified partner host, - // time-out if connection doesn't complete within alloted time - -#ifdef FLM_WIN - - if( uiConnectTimeout) - { - if ( uiConnectTimeout < 5 ) - { - iMaxTries = (iMaxTries * uiConnectTimeout) / 5; - uiConnectTimeout = 5; - } - } - else - { - iMaxTries = 1; - } -#endif - - for( iTries = 0; iTries < iMaxTries; iTries++ ) - { - iSockErr = 0; - if( connect( m_iSocket, (struct sockaddr *)&address, - (unsigned)sizeof(struct sockaddr)) >= 0) - { - break; - } - - #ifndef FLM_UNIX - iSockErr = WSAGetLastError(); - #else - iSockErr = errno; - #endif - - #ifdef FLM_WIN - - // In WIN, we sometimes get WSAEINVAL when, if we keep - // trying, we will eventually connect. Therefore, - // here we'll treat WSAEINVAL as EINPROGRESS. - - if( iSockErr == WSAEINVAL) - { - #ifndef FLM_UNIX - closesocket( m_iSocket); - #else - ::close( m_iSocket); - #endif - if( (m_iSocket = socket( AF_INET, - SOCK_STREAM, IPPROTO_TCP)) == INVALID_SOCKET) - { - rc = RC_SET( FERR_SVR_SOCK_FAIL); - goto Exit; - } - #if defined( FLM_WIN) || defined( FLM_NLM) - iSockErr = WSAEINPROGRESS; - #else - iSockErr = EINPROGRESS; - #endif - continue; - } - #endif - - #if defined( FLM_WIN) || defined( FLM_NLM) - if( iSockErr == WSAEISCONN ) - #else - if( iSockErr == EISCONN ) - #endif - { - break; - } - #if defined( FLM_WIN) || defined( FLM_NLM) - else if( iSockErr == WSAEWOULDBLOCK) - #else - else if( iSockErr == EWOULDBLOCK) - #endif - { - // Let's wait a split second to give the connection - // request a chance. - - f_sleep( 100 ); - continue; - } - #if defined( FLM_WIN) || defined( FLM_NLM) - else if( iSockErr == WSAEINPROGRESS) - #else - else if( iSockErr == EINPROGRESS) - #endif - { - if( RC_OK( rc = _SocketPeek( uiConnectTimeout, FALSE))) - { - // Let's wait a split second to give the connection - // request a chance. - - f_sleep( 100 ); - continue; - } - } - - rc = RC_SET( FERR_SVR_CONNECT_FAIL); - } - - if( RC_BAD( rc)) - { - if( m_iSocket != INVALID_SOCKET) - { - #ifndef FLM_UNIX - closesocket( m_iSocket); - #else - ::close( m_iSocket); - #endif - m_iSocket = INVALID_SOCKET; - } - - goto Exit; - } - - m_uiIOTimeout = uiDataTimeout; - - setTcpDelay( TRUE); - m_bConnected = TRUE; - -Exit: - - return( rc); -} - -/******************************************************************** -Desc: Constructor -*********************************************************************/ -FCS_TCP_SERVER::FCS_TCP_SERVER( void) : FCS_TCP() -{ - m_bBound = FALSE; -} - -/******************************************************************** -Desc: Destructor -*********************************************************************/ -FCS_TCP_SERVER::~FCS_TCP_SERVER( void) -{ - if( m_bBound) - { - close( TRUE); - } -} - -/******************************************************************** -Desc: Bind to a port prior to listening for connections -*********************************************************************/ -RCODE FCS_TCP_SERVER::bind( - FLMUINT uiBindPort, - FLMBYTE * pucBindAddr) -{ - struct sockaddr_in address; - RCODE rc = FERR_OK; - - if( m_bBound) - { - rc = RC_SET( FERR_SVR_SOCK_FAIL); - goto Exit; - } - - if( (m_iSocket = socket( AF_INET, - SOCK_STREAM, IPPROTO_TCP)) == INVALID_SOCKET) - { - rc = RC_SET( FERR_SVR_SOCK_FAIL); - goto Exit; - } - - f_memset( &address, 0, sizeof( address)); - address.sin_family = AF_INET; - if( !pucBindAddr) - { - address.sin_addr.s_addr = htonl( INADDR_ANY); - } - else - { - address.sin_addr.s_addr = inet_addr( (char *)pucBindAddr); - } - address.sin_port = htons( (unsigned short)uiBindPort); - - // Bind to the address+port - - if( ::bind( m_iSocket, (struct sockaddr *)&address, - (unsigned)sizeof( address)) != 0) - { - rc = RC_SET( FERR_SVR_BIND_FAIL); - goto Exit; - } - - // Bind succeeded! - // listen() prepares a socket to accept a connection and specifies a - // queue limit for incoming connections. The accept() accepts the connection. - // Listen returns immediatly. - -#ifdef FLM_NLM - if( listen( m_iSocket, 32 ) < 0) -#endif - { - if( listen( m_iSocket, 5 ) < 0) - { - rc = RC_SET( FERR_SVR_LISTEN_FAIL); - goto Exit; - } - } - - // Disable the packet send delay. - - setTcpDelay( TRUE); - m_bBound = TRUE; - -Exit: - - if( RC_BAD( rc) && m_iSocket != INVALID_SOCKET) - { -#ifndef FLM_UNIX - closesocket( m_iSocket); -#else - ::close( m_iSocket); -#endif - m_iSocket = INVALID_SOCKET; - } - - return( rc); -} - -/******************************************************************** -Desc: Wait for and accept a client connection -*********************************************************************/ -RCODE FCS_TCP_SERVER::connectClient( - FCS_TCP * pClient, - FLMINT uiConnectTimeout, - FLMINT uiDataTimeout) -{ - SOCKET iSocket; -#if defined( FLM_UNIX) - socklen_t iAddrLen; -#else - int iAddrLen; -#endif - struct sockaddr_in address; - RCODE rc = FERR_OK; - - if( !m_bBound) - { - rc = RC_SET( FERR_SVR_BIND_FAIL); - goto Exit; - } - - if( RC_BAD( rc = _SocketPeek( uiConnectTimeout, TRUE))) - { - goto Exit; - } - - iAddrLen = (int)sizeof( struct sockaddr); - if( (iSocket = accept( m_iSocket, - (struct sockaddr *)&address, &iAddrLen)) == INVALID_SOCKET) - { - rc = RC_SET( FERR_SVR_ACCEPT_FAIL); - goto Exit; - } - - pClient->m_ulRemoteAddr = address.sin_addr.s_addr; - pClient->m_iSocket = iSocket; - pClient->m_bConnected = TRUE; - pClient->m_uiIOTimeout = uiDataTimeout; - pClient->setTcpDelay( TRUE); - -Exit: - - return( rc); -} - /**************************************************************************** Desc: Converts a UNICODE string consisting of 7-bit ASCII characters to a native string. *****************************************************************************/ RCODE fcsConvertUnicodeToNative( - POOL * pPool, + F_Pool * pPool, const FLMUNICODE * puzUnicode, char ** ppucNative) { @@ -3933,11 +2575,9 @@ RCODE fcsConvertUnicodeToNative( } uiCount++; } - - if( (pucDest = (char *)GedPoolAlloc( pPool, - (FLMUINT)(uiCount + 1))) == NULL) + + if( RC_BAD( rc = pPool->poolAlloc( uiCount + 1, (void **)&pucDest))) { - rc = RC_SET( FERR_MEM); goto Exit; } @@ -3960,7 +2600,7 @@ Exit: Desc: Converts a native string to a double-byte UNICODE string. *****************************************************************************/ RCODE fcsConvertNativeToUnicode( - POOL * pPool, + F_Pool * pPool, const char * pszNative, FLMUNICODE ** ppuzUnicode) { @@ -3970,14 +2610,11 @@ RCODE fcsConvertNativeToUnicode( uiCount = f_strlen( pszNative); - if( (puzDest = (FLMUNICODE *)GedPoolAlloc( pPool, - (FLMUINT)((FLMUINT)sizeof( FLMUNICODE) * - (FLMUINT)(uiCount + 1)))) == NULL) + if( RC_BAD( rc = pPool->poolAlloc( uiCount + 1, (void **)&puzDest))) { - rc = RC_SET( FERR_MEM); goto Exit; } - + uiCount = 0; while( pszNative[ uiCount]) { @@ -4016,11 +2653,11 @@ Desc: Converts a CHECKPOINT_INFO structure to an HTD tree *****************************************************************************/ RCODE fcsBuildCheckpointInfo( CHECKPOINT_INFO * pChkptInfo, - POOL * pPool, + F_Pool * pPool, NODE ** ppTree) { NODE * pRootNd = NULL; - void * pMark = GedPoolMark( pPool); + void * pMark = pPool->poolMark(); FLMUINT uiTmp; RCODE rc = FERR_OK; @@ -4159,24 +2796,24 @@ Exit: if( RC_BAD( rc)) { - GedPoolReset( pPool, pMark); + pPool->poolReset( pMark); } return( rc); } /**************************************************************************** -Desc: Converts a LOCK_USER structure (or list of structures) to an HTD tree +Desc: Converts a F_LOCK_USER structure (or list of structures) to an HTD tree *****************************************************************************/ RCODE fcsBuildLockUser( - LOCK_USER * pLockUser, + F_LOCK_USER * pLockUser, FLMBOOL bList, - POOL * pPool, + F_Pool * pPool, NODE ** ppTree) { NODE * pRootNd = NULL; NODE * pContextNd = NULL; - void * pMark = GedPoolMark( pPool); + void * pMark = pPool->poolMark(); RCODE rc = FERR_OK; *ppTree = NULL; @@ -4236,14 +2873,14 @@ Exit: if( RC_BAD( rc)) { - GedPoolReset( pPool, pMark); + pPool->poolReset( pMark); } return( rc); } /**************************************************************************** -Desc: Converts an HTD tree to a LOCK_USER structure (or list of structures) +Desc: Converts an HTD tree to a F_LOCK_USER structure (or list of structures) *****************************************************************************/ RCODE fcsExtractLockUser( NODE * pTree, @@ -4253,7 +2890,7 @@ RCODE fcsExtractLockUser( NODE * pTmpNd; FLMUINT uiItemCount = 0; FLMUINT fieldPath[ 8]; - LOCK_USER * pLockUser = NULL; + F_LOCK_USER * pLockUser = NULL; FLMUINT uiLoop; RCODE rc = FERR_OK; @@ -4261,11 +2898,11 @@ RCODE fcsExtractLockUser( { if( bExtractAsList) { - *((LOCK_USER **)pvLockUser) = NULL; + *((F_LOCK_USER **)pvLockUser) = NULL; } else { - f_memset( (LOCK_USER *)pvLockUser, 0, sizeof( LOCK_USER)); + f_memset( (F_LOCK_USER *)pvLockUser, 0, sizeof( F_LOCK_USER)); } goto Exit; } @@ -4283,17 +2920,17 @@ RCODE fcsExtractLockUser( } if( RC_BAD( rc = f_alloc( - sizeof( LOCK_USER) * (uiItemCount + 1), &pLockUser))) + sizeof( F_LOCK_USER) * (uiItemCount + 1), &pLockUser))) { goto Exit; } - *((LOCK_USER **)pvLockUser) = pLockUser; + *((F_LOCK_USER **)pvLockUser) = pLockUser; } else { - pLockUser = (LOCK_USER *)pvLockUser; - f_memset( pLockUser, 0, sizeof( LOCK_USER)); + pLockUser = (F_LOCK_USER *)pvLockUser; + f_memset( pLockUser, 0, sizeof( F_LOCK_USER)); uiItemCount = 1; } @@ -4324,7 +2961,7 @@ RCODE fcsExtractLockUser( if( bExtractAsList) { - f_memset( &(pLockUser[ uiItemCount]), 0, sizeof( LOCK_USER)); + f_memset( &(pLockUser[ uiItemCount]), 0, sizeof( F_LOCK_USER)); } Exit: @@ -4637,11 +3274,11 @@ Desc: Converts an FINDEX_STATUS structure to an HTD tree *****************************************************************************/ RCODE fcsBuildIndexStatus( FINDEX_STATUS * pIndexStatus, - POOL * pPool, + F_Pool * pPool, NODE ** ppTree) { NODE * pContextNd = NULL; - void * pMark = GedPoolMark( pPool); + void * pMark = pPool->poolMark(); FLMUINT uiTmp; RCODE rc = FERR_OK; @@ -4763,7 +3400,7 @@ Exit: if( RC_BAD( rc)) { - GedPoolReset( pPool, pMark); + pPool->poolReset( pMark); } return( rc); @@ -4844,13 +3481,13 @@ Desc: Converts an FLM_MEM_INFO structure to an HTD tree *****************************************************************************/ RCODE fcsBuildMemInfo( FLM_MEM_INFO * pMemInfo, - POOL * pPool, + F_Pool * pPool, NODE ** ppTree) { FLMUINT uiTmp; NODE * pContextNd = NULL; NODE * pSubContext = NULL; - void * pMark = GedPoolMark( pPool); + void * pMark = pPool->poolMark(); FLM_CACHE_USAGE * pUsage; RCODE rc = FERR_OK; @@ -5054,7 +3691,7 @@ Exit: if( RC_BAD( rc)) { - GedPoolReset( pPool, pMark); + pPool->poolReset( pMark); } return( rc); @@ -5200,12 +3837,12 @@ Exit: Desc: Builds a GEDCOM tree containing information on all FLAIM threads *****************************************************************************/ RCODE fcsBuildThreadInfo( - POOL * pPool, + F_Pool * pPool, NODE ** ppTree) { NODE * pContextNd = NULL; NODE * pRootNd = NULL; - void * pMark = GedPoolMark( pPool); + void * pMark = pPool->poolMark(); F_THREAD_INFO * pThreadInfo = NULL; FLMUINT uiNumThreads; FLMUINT uiLoop; @@ -5312,7 +3949,7 @@ Exit: if( RC_BAD( rc)) { - GedPoolReset( pPool, pMark); + pPool->poolReset( pMark); } return( rc); @@ -5323,13 +3960,13 @@ Desc: Extracts a list of F_THREAD_INFO structure from an HTD tree. *****************************************************************************/ RCODE fcsExtractThreadInfo( NODE * pTree, - POOL * pPool, + F_Pool * pPool, F_THREAD_INFO ** ppThreadInfo, FLMUINT * puiNumThreads) { NODE * pTmpNd; NODE * pContextNd; - void * pMark = GedPoolMark( pPool); + void * pMark = pPool->poolMark(); FLMUINT uiTmp; F_THREAD_INFO * pThreadInfo; F_THREAD_INFO * pCurThread; @@ -5355,11 +3992,10 @@ RCODE fcsExtractThreadInfo( { goto Exit; } - - if( (pThreadInfo = (F_THREAD_INFO *)GedPoolCalloc( pPool, - uiNumThreads * sizeof( F_THREAD_INFO))) == NULL) + + if( RC_BAD( rc = pPool->poolAlloc( uiNumThreads * sizeof( F_THREAD_INFO), + (void **)&pThreadInfo))) { - rc = RC_SET( FERR_MEM); goto Exit; } @@ -5410,10 +4046,10 @@ RCODE fcsExtractThreadInfo( if( uiTmp) { uiTmp++; - if( (pCurThread->pszThreadName = (char *)GedPoolAlloc( - pPool, uiTmp)) == NULL) + + if( RC_BAD( rc = pPool->poolAlloc( uiTmp, + (void **)&pCurThread->pszThreadName))) { - rc = RC_SET( FERR_MEM); goto Exit; } } @@ -5436,10 +4072,10 @@ RCODE fcsExtractThreadInfo( if( uiTmp) { uiTmp++; - if( (pCurThread->pszThreadStatus = (char *)GedPoolAlloc( - pPool, uiTmp)) == NULL) + + if( RC_BAD( rc = pPool->poolAlloc( uiTmp, + (void **)pCurThread->pszThreadStatus))) { - rc = RC_SET( FERR_MEM); goto Exit; } } @@ -5468,7 +4104,7 @@ Exit: if( RC_BAD( rc)) { - GedPoolReset( pPool, pMark); + pPool->poolReset( pMark); } return( rc); @@ -5745,7 +4381,7 @@ RCODE flmGenerateHexPacket( FLMUINT uiDataSize, FLMBYTE ** ppucPacket) { - FLMUINT32 * pui32CRCTbl = NULL; + RCODE rc = FERR_OK; FLMBYTE * pucBinPacket = NULL; FLMBYTE * pucHexPacket = NULL; FLMBYTE * pucUsedMap = NULL; @@ -5755,8 +4391,7 @@ RCODE flmGenerateHexPacket( FLMBYTE ucTmp[ 32]; FLMUINT uiBinPacketSize; FLMBOOL bTmp; - f_randomGenerator randGen; - RCODE rc = FERR_OK; + IF_RandomGenerator * pRandGen = NULL; // Determine the packet size. Make the minimum packet size 128 bytes // to account for the 64-byte "header" and for the overhead of the @@ -5785,43 +4420,39 @@ RCODE flmGenerateHexPacket( f_memset( pucUsedMap, 0xFF, 64); - // Initialize the CRC table. - - if( RC_BAD( rc = f_initCRCTable( &pui32CRCTbl))) + // Initialize the random number generator and seed with the current + // time. + + if( RC_BAD( rc = FlmAllocRandomGenerator( &pRandGen))) { goto Exit; } - // Initialize the random number generator and seed with the current - // time. - - f_randomize( &randGen); - // Fill the packet with random "noise" for( uiLoop = 0; uiLoop < uiBinPacketSize; uiLoop += 4) { - ui32Tmp = f_randomLong( &randGen); + ui32Tmp = pRandGen->getUINT32(); UD2FBA( ui32Tmp, &pucBinPacket[ uiLoop]); } for( uiLoop = 0; uiLoop < 512; uiLoop++) { - ui32Tmp = f_randomLong( &randGen); - UD2FBA( ui32Tmp, &pucBinPacket[ f_randomChoice( - &randGen, 1, (int)(uiBinPacketSize / 4)) - 1]); + ui32Tmp = pRandGen->getUINT32(); + UD2FBA( ui32Tmp, &pucBinPacket[ + pRandGen->getUINT32( 1, (int)(uiBinPacketSize / 4)) - 1]); } // Determine a new random seed based on bytes in the // packet header if( (ui32Tmp = (FLMUINT32)FB2UD( &pucBinPacket[ - f_randomChoice( &randGen, 1, 61) - 1])) == 0) + pRandGen->getUINT32( 1, 61) - 1])) == 0) { ui32Tmp = 1; } - f_randomSetSeed( &randGen, ui32Tmp); + pRandGen->setSeed( ui32Tmp); // Use the CRC of the header and the also first four bytes // of the header as an 8-byte validation signature. This will @@ -5832,7 +4463,7 @@ RCODE flmGenerateHexPacket( // "standard" CRC used by PKZIP, etc. ui32Tmp = 0xFFFFFFFF; - f_updateCRC( pui32CRCTbl, pucBinPacket, 64, &ui32Tmp); + f_updateCRC( pucBinPacket, 64, &ui32Tmp); ui32Tmp = ~ui32Tmp; UD2FBA( ui32Tmp, &ucTmp[ 0]); f_memcpy( &ucTmp[ 4], pucBinPacket, 4); @@ -5840,7 +4471,7 @@ RCODE flmGenerateHexPacket( for( uiLoop = 0; uiLoop < 8; uiLoop++) { bTmp = flmGetNextHexPacketSlot( pucUsedMap, uiBinPacketSize, - &randGen, &uiSlot); + pRandGen, &uiSlot); flmAssert( bTmp); pucBinPacket[ uiSlot] = ucTmp[ uiLoop]; @@ -5852,7 +4483,7 @@ RCODE flmGenerateHexPacket( for( uiLoop = 0; uiLoop < 4; uiLoop++) { bTmp = flmGetNextHexPacketSlot( pucUsedMap, uiBinPacketSize, - &randGen, &uiSlot); + pRandGen, &uiSlot); flmAssert( bTmp); pucBinPacket[ uiSlot] = ucTmp[ uiLoop]; @@ -5864,7 +4495,7 @@ RCODE flmGenerateHexPacket( for( uiLoop = 0; uiLoop < uiDataSize; uiLoop++) { bTmp = flmGetNextHexPacketSlot( pucUsedMap, uiBinPacketSize, - &randGen, &uiSlot); + pRandGen, &uiSlot); flmAssert( bTmp); pucBinPacket[ uiSlot] = pucData[ uiLoop] ^ pucBinPacket[ uiLoop % 64]; @@ -5873,14 +4504,14 @@ RCODE flmGenerateHexPacket( // Calculate and encode the data CRC ui32Tmp = 0xFFFFFFFF; - f_updateCRC( pui32CRCTbl, pucData, uiDataSize, &ui32Tmp); + f_updateCRC( pucData, uiDataSize, &ui32Tmp); ui32Tmp = ~ui32Tmp; UD2FBA( ui32Tmp, &ucTmp[ 0]); for( uiLoop = 0; uiLoop < 4; uiLoop++) { bTmp = flmGetNextHexPacketSlot( pucUsedMap, uiBinPacketSize, - &randGen, &uiSlot); + pRandGen, &uiSlot); flmAssert( bTmp); pucBinPacket[ uiSlot] = ucTmp[ uiLoop]; @@ -5914,11 +4545,6 @@ RCODE flmGenerateHexPacket( Exit: - if( pui32CRCTbl) - { - f_freeCRCTable( &pui32CRCTbl); - } - if( pucUsedMap) { f_free( &pucUsedMap); @@ -5933,6 +4559,11 @@ Exit: { f_free( &pucHexPacket); } + + if( pRandGen) + { + pRandGen->Release(); + } return( rc); } @@ -5946,7 +4577,7 @@ RCODE flmExtractHexPacketData( FLMBYTE ** ppucData, FLMUINT * puiDataSize) { - FLMUINT32 * pui32CRCTbl = NULL; + RCODE rc = FERR_OK; FLMBYTE * pucUsedMap = NULL; FLMBYTE * pucData = NULL; FLMBYTE * pucBinPacket = NULL; @@ -5960,9 +4591,13 @@ RCODE flmExtractHexPacketData( FLMBYTE ucTmp[ 32]; FLMBYTE ucVal = 0; FLMBOOL bValid; - f_randomGenerator randGen; - RCODE rc = FERR_OK; + IF_RandomGenerator * pRandGen = NULL; + if( RC_BAD( rc = FlmAllocRandomGenerator( &pRandGen))) + { + goto Exit; + } + // Determine the packet size, ignoring all characters except 0-9, A-F uiPacketSize = 0; @@ -6037,17 +4672,10 @@ RCODE flmExtractHexPacketData( f_memset( pucUsedMap, 0xFF, 64); - // Initialize the CRC table - - if( RC_BAD( rc = f_initCRCTable( &pui32CRCTbl))) - { - goto Exit; - } - // Determine the CRC of the 1st 64-bytes ui32FirstCRC = 0xFFFFFFFF; - f_updateCRC( pui32CRCTbl, pucBinPacket, 64, &ui32FirstCRC); + f_updateCRC( pucBinPacket, 64, &ui32FirstCRC); ui32FirstCRC = ~ui32FirstCRC; // Search for the random seed within the first 64 bytes @@ -6056,10 +4684,10 @@ RCODE flmExtractHexPacketData( for( uiLoop = 0; uiLoop < 61; uiLoop++) { ui32Tmp = FB2UD( &pucBinPacket[ uiLoop]); - f_randomSetSeed( &randGen, ui32Tmp); + pRandGen->setSeed( ui32Tmp); if( RC_BAD( rc = flmGetNextHexPacketBytes( pucUsedMap, uiPacketSize, - pucBinPacket, &randGen, ucTmp, 8))) + pucBinPacket, pRandGen, ucTmp, 8))) { goto Exit; } @@ -6086,7 +4714,7 @@ RCODE flmExtractHexPacketData( // Get the data size if( RC_BAD( rc = flmGetNextHexPacketBytes( pucUsedMap, uiPacketSize, - pucBinPacket, &randGen, ucTmp, 4))) + pucBinPacket, pRandGen, ucTmp, 4))) { goto Exit; } @@ -6108,8 +4736,7 @@ RCODE flmExtractHexPacketData( // Get the data if( RC_BAD( rc = flmGetNextHexPacketBytes( - pucUsedMap, uiPacketSize, - pucBinPacket, &randGen, pucData, uiDataSize))) + pucUsedMap, uiPacketSize, pucBinPacket, pRandGen, pucData, uiDataSize))) { goto Exit; } @@ -6124,8 +4751,7 @@ RCODE flmExtractHexPacketData( // Get the data CRC if( RC_BAD( rc = flmGetNextHexPacketBytes( - pucUsedMap, uiPacketSize, - pucBinPacket, &randGen, ucTmp, 4))) + pucUsedMap, uiPacketSize, pucBinPacket, pRandGen, ucTmp, 4))) { goto Exit; } @@ -6133,7 +4759,7 @@ RCODE flmExtractHexPacketData( // Verify the data CRC ui32Tmp = 0xFFFFFFFF; - f_updateCRC( pui32CRCTbl, pucData, uiDataSize, &ui32Tmp); + f_updateCRC( pucData, uiDataSize, &ui32Tmp); ui32Tmp = ~ui32Tmp; if( ui32Tmp != FB2UD( &ucTmp[ 0])) @@ -6148,11 +4774,6 @@ RCODE flmExtractHexPacketData( Exit: - if( pui32CRCTbl) - { - f_freeCRCTable( &pui32CRCTbl); - } - if( pucUsedMap) { f_free( &pucUsedMap); @@ -6167,6 +4788,11 @@ Exit: { f_free( &pucBinPacket); } + + if( pRandGen) + { + pRandGen->Release(); + } return( rc); } @@ -6177,7 +4803,7 @@ Desc: Used by flmGenerateHexPacket to find an unused byte in the packet FLMBOOL flmGetNextHexPacketSlot( FLMBYTE * pucUsedMap, FLMUINT uiMapSize, - f_randomGenerator * pRandGen, + IF_RandomGenerator * pRandGen, FLMUINT * puiSlot) { FLMUINT uiLoop; @@ -6186,7 +4812,7 @@ FLMBOOL flmGetNextHexPacketSlot( for( uiLoop = 0; uiLoop < 100; uiLoop++) { - uiSlot = ((FLMUINT)f_randomLong( pRandGen)) % uiMapSize; + uiSlot = ((FLMUINT)pRandGen->getUINT32()) % uiMapSize; if( !pucUsedMap[ uiSlot]) { bFound = TRUE; @@ -6225,7 +4851,7 @@ RCODE flmGetNextHexPacketBytes( FLMBYTE * pucUsedMap, FLMUINT uiMapSize, FLMBYTE * pucPacket, - f_randomGenerator * pRandGen, + IF_RandomGenerator * pRandGen, FLMBYTE * pucBuf, FLMUINT uiCount) { @@ -6235,8 +4861,7 @@ RCODE flmGetNextHexPacketBytes( for( uiLoop = 0; uiLoop < uiCount; uiLoop++) { - if( !flmGetNextHexPacketSlot( pucUsedMap, uiMapSize, - pRandGen, &uiSlot)) + if( !flmGetNextHexPacketSlot( pucUsedMap, uiMapSize, pRandGen, &uiSlot)) { rc = RC_SET( FERR_INVALID_CRC); goto Exit; @@ -6257,7 +4882,7 @@ Desc: Decodes a string containing %XX sequences and does it in place. void fcsDecodeHttpString( char * pszSrc) { - char * pszDest; + char * pszDest; pszDest = pszSrc; while( *pszSrc) @@ -6265,10 +4890,11 @@ void fcsDecodeHttpString( if( *pszSrc == '%') { pszSrc++; - if( f_isHexChar( pszSrc[ 0]) && f_isHexChar( pszSrc[ 1])) + if( f_isHexChar( (FLMBYTE)pszSrc[ 0]) && + f_isHexChar( (FLMBYTE)pszSrc[ 1])) { - *pszDest = (f_getHexVal( pszSrc[ 0]) << 4) | - f_getHexVal( pszSrc[ 1]); + *pszDest = (f_getHexVal( (FLMBYTE)pszSrc[ 0]) << 4) | + f_getHexVal( (FLMBYTE)pszSrc[ 1]); pszSrc += 2; pszDest++; @@ -6299,7 +4925,7 @@ Desc: *****************************************************************************/ FCS_WIRE::FCS_WIRE( FCS_DIS * pDIStream, FCS_DOS * pDOStream) { - GedPoolInit( &m_pool, 2048); + m_pool.poolInit( 2048); m_pPool = &m_pool; m_pDIStream = pDIStream; m_pDOStream = pDOStream; @@ -6333,7 +4959,7 @@ FCS_WIRE::~FCS_WIRE( void) m_pUntilKey = NULL; } - GedPoolFree( &m_pool); + m_pool.poolFree(); } /**************************************************************************** @@ -6382,7 +5008,7 @@ void FCS_WIRE::resetCommon( void) m_uiBlockSize = 0; m_bIncludesAsync = FALSE; fcsInitCreateOpts( &m_CreateOpts); - GedPoolReset( m_pPool, NULL); + m_pPool->poolReset(); m_bFlag = FALSE; m_ui64Number1 = 0; m_ui64Number2 = 0; @@ -6404,10 +5030,6 @@ RCODE FCS_WIRE::readOpcode( void) FLMBYTE ucOp; RCODE rc = FERR_OK; - /* - Read the opcode. - */ - if( RC_BAD( rc = m_pDIStream->read( &ucClass, 1, NULL))) { goto Exit; @@ -6764,8 +5386,7 @@ RCODE FCS_WIRE::readNumber( FLMUINT64 * pui64Number, FLMINT64 * pi64Number) { - - RCODE rc = FERR_OK; + RCODE rc = FERR_OK; flmAssert( !(puiNumber && piNumber)); @@ -7150,8 +5771,8 @@ Exit: Desc: Sends an opcode to the client *****************************************************************************/ RCODE FCS_WIRE::sendOpcode( - FLMUINT uiClass, - FLMUINT uiOp) + FLMUINT uiClass, + FLMUINT uiOp) { FLMBYTE ucClass = (FLMBYTE)uiClass; FLMBYTE ucOp = (FLMBYTE)uiOp; @@ -7203,7 +5824,7 @@ RCODE FCS_WIRE::sendNumber( FLMUINT64 ui64Value, FLMINT64 i64Value) { - RCODE rc = FERR_OK; + RCODE rc = FERR_OK; // Send the parameter tag and value. @@ -7276,7 +5897,7 @@ RCODE FCS_WIRE::sendBinary( FLMBYTE * pData, FLMUINT uiLength) { - RCODE rc = FERR_OK; + RCODE rc = FERR_OK; // Send the parameter tag and value. @@ -7340,11 +5961,11 @@ RCODE FCS_WIRE::sendRecord( FLMUINT uiTag, FlmRecord * pRecord) { + RCODE rc = FERR_OK; #define RECORD_OUTPUT_BUFFER_SIZE 64 - FLMBYTE pucBuffer[ RECORD_OUTPUT_BUFFER_SIZE]; - FLMBYTE * pucBufPos; - FLMBYTE ucDescriptor; - RCODE rc = FERR_OK; + FLMBYTE pucBuffer[ RECORD_OUTPUT_BUFFER_SIZE]; + FLMBYTE * pucBufPos; + FLMBYTE ucDescriptor; // Send the parameter tag and value. @@ -7384,10 +6005,10 @@ RCODE FCS_WIRE::sendRecord( // // 4-byte container ID, 4-byte DRN - flmUINT32ToBigEndian( (FLMUINT32)pRecord->getContainerID(), pucBufPos); + f_UINT32ToBigEndian( (FLMUINT32)pRecord->getContainerID(), pucBufPos); pucBufPos += 4; - flmUINT32ToBigEndian( (FLMUINT32)pRecord->getID(), pucBufPos); + f_UINT32ToBigEndian( (FLMUINT32)pRecord->getID(), pucBufPos); pucBufPos += 4; // Send the descriptor and record source. @@ -7400,7 +6021,8 @@ RCODE FCS_WIRE::sendRecord( // Send the record. - if( RC_BAD( rc = m_pDOStream->writeHTD( NULL, pRecord, FALSE, m_bSendGedcom))) + if( RC_BAD( rc = m_pDOStream->writeHTD( NULL, pRecord, + FALSE, m_bSendGedcom))) { goto Exit; } @@ -7529,7 +6151,7 @@ RCODE FCS_WIRE::sendString( FLMUINT uiTag, FLMUNICODE * puzString) { - RCODE rc = FERR_OK; + RCODE rc = FERR_OK; // Send the parameter tag and value. @@ -7581,7 +6203,7 @@ RCODE FCS_WIRE::sendHTD( FLMUINT uiTag, NODE * pHTD) { - RCODE rc = FERR_OK; + RCODE rc = FERR_OK; // Send the parameter tag and value. @@ -7631,7 +6253,7 @@ RCODE FCS_WIRE::sendHTD( FLMUINT uiTag, FlmRecord * pRecord) { - RCODE rc = FERR_OK; + RCODE rc = FERR_OK; // Send the parameter tag and value. @@ -7675,10 +6297,10 @@ Exit: Desc: Copies the current HTD tree to the application's pool *****************************************************************************/ RCODE FCS_WIRE::getHTD( - POOL * pPool, + F_Pool * pPool, NODE ** ppTreeRV) { - RCODE rc = FERR_OK; + RCODE rc = FERR_OK; if( !m_pHTD) { @@ -7705,7 +6327,7 @@ RCODE FCS_WIRE::sendCreateOpts( CREATE_OPTS * pCreateOpts) { NODE * pRootNd = NULL; - void * pvMark = GedPoolMark( m_pPool); + void * pvMark = m_pPool->poolMark(); RCODE rc = FERR_OK; FLMUINT uiTmp; @@ -7827,7 +6449,7 @@ RCODE FCS_WIRE::sendCreateOpts( Exit: - GedPoolReset( m_pPool, pvMark); + m_pPool->poolReset( pvMark); return( rc); } @@ -7838,7 +6460,7 @@ RCODE FCS_WIRE::sendNameTable( FLMUINT uiTag, F_NameTable * pNameTable) { - void * pvMark = GedPoolMark( m_pPool); + void * pvMark = m_pPool->poolMark(); NODE * pRootNd; NODE * pNd; NODE * pItemIdNd; @@ -7859,11 +6481,10 @@ RCODE FCS_WIRE::sendNameTable( } // Allocate a temporary name buffer - - if( (puzItemName = (FLMUNICODE *)GedPoolAlloc( m_pPool, - uiMaxNameChars * sizeof( FLMUNICODE))) == NULL) + + if( RC_BAD( rc = m_pPool->poolAlloc( uiMaxNameChars * sizeof( FLMUNICODE), + (void **)&puzItemName))) { - rc = RC_SET( FERR_MEM); goto Exit; } @@ -7977,7 +6598,7 @@ RCODE FCS_WIRE::sendNameTable( Exit: - GedPoolReset( m_pPool, pvMark); + m_pPool->poolReset( pvMark); return( rc); } @@ -7991,7 +6612,7 @@ RCODE FCS_WIRE::receiveRecord( FLMUINT uiIdLen = 0; FLMUINT32 ui32Container; FLMUINT32 ui32Drn; - void * pvMark = GedPoolMark( m_pPool); + void * pvMark = m_pPool->poolMark(); FLMBOOL bHasId = FALSE; RCODE rc = FERR_OK; @@ -8048,7 +6669,7 @@ Exit: *ppRecord = NULL; } - GedPoolReset( m_pPool, pvMark); + m_pPool->poolReset( pvMark); return( rc); } @@ -8064,7 +6685,7 @@ RCODE FCS_WIRE::receiveCreateOpts( void) FLMUINT uiTmp; RCODE rc = FERR_OK; - pPoolMark = GedPoolMark( m_pPool); + pPoolMark = m_pPool->poolMark(); // Initialize the CREATE_OPTS structure to its default values. @@ -8169,7 +6790,7 @@ RCODE FCS_WIRE::receiveCreateOpts( void) Exit: - GedPoolReset( m_pPool, pPoolMark); + m_pPool->poolReset( pPoolMark); return( rc); } @@ -8182,7 +6803,7 @@ RCODE FCS_WIRE::receiveNameTable( NODE * pRootNd; NODE * pItemIdNd; NODE * pNd = NULL; - void * pvMark = GedPoolMark( m_pPool); + void * pvMark = m_pPool->poolMark(); FLMUINT uiMaxNameChars = 1024; FLMUNICODE * puzItemName; FLMUINT uiItemId; @@ -8194,13 +6815,12 @@ RCODE FCS_WIRE::receiveNameTable( // Allocate a temporary name buffer - if( (puzItemName = (FLMUNICODE *)GedPoolAlloc( m_pPool, - uiMaxNameChars * sizeof( FLMUNICODE))) == NULL) + if( RC_BAD( rc = m_pPool->poolAlloc( uiMaxNameChars * sizeof( FLMUNICODE), + (void **)&puzItemName))) { - rc = RC_SET( FERR_MEM); goto Exit; } - + // Initialize the name table. if( (pNameTable = *ppNameTable) == NULL) @@ -8309,7 +6929,7 @@ Exit: pNameTable->Release(); } - GedPoolReset( m_pPool, pvMark); + m_pPool->poolReset( pvMark); return( rc); } diff --git a/flaim/src/fcs.h b/flaim/src/fcs.h index ee973f0..2a0377a 100644 --- a/flaim/src/fcs.h +++ b/flaim/src/fcs.h @@ -485,7 +485,7 @@ /**************************************************************************** Desc: ****************************************************************************/ -class FCS_OSTM : public virtual F_Base +class FCS_OSTM : public virtual F_Object { public: @@ -503,7 +503,7 @@ public: /**************************************************************************** Desc: ****************************************************************************/ -class FCS_ISTM : public virtual F_Base +class FCS_ISTM : public virtual F_Object { public: @@ -559,21 +559,21 @@ public: FLMUINT64 * pValue); RCODE readBinary( - POOL * pPool, + F_Pool * pPool, FLMBYTE ** ppValue, FLMUINT * puiDataSize); RCODE readLargeBinary( - POOL * pPool, + F_Pool * pPool, FLMBYTE ** ppValue, FLMUINT * puiDataSize); RCODE readUTF( - POOL * pPool, + F_Pool * pPool, FLMUNICODE ** ppValue); RCODE readHTD( - POOL * pPool, + F_Pool * pPool, FLMUINT uiContainer, FLMUINT uiDrn, NODE ** ppNode, @@ -616,7 +616,7 @@ class FCS_DOS : public FCS_OSTM FLMBYTE m_pucBuffer[ FCS_DOS_BUFFER_SIZE]; FLMUINT m_uiBOffset; FLMBOOL m_bSetupCalled; - POOL m_tmpPool; + F_Pool m_tmpPool; public: @@ -643,7 +643,7 @@ public: { FLMBYTE tmpBuf[ 2]; - flmINT16ToBigEndian( i16Value, tmpBuf); + f_INT16ToBigEndian( i16Value, tmpBuf); return( write( tmpBuf, 2)); } @@ -652,7 +652,7 @@ public: { FLMBYTE tmpBuf[ 2]; - flmUINT16ToBigEndian( ui16Value, tmpBuf); + f_UINT16ToBigEndian( ui16Value, tmpBuf); return( write( tmpBuf, 2)); } @@ -661,7 +661,7 @@ public: { FLMBYTE tmpBuf[ 4]; - flmINT32ToBigEndian( i32Value, tmpBuf); + f_INT32ToBigEndian( i32Value, tmpBuf); return( write( tmpBuf, 4)); } @@ -670,7 +670,7 @@ public: { FLMBYTE tmpBuf[ 4]; - flmUINT32ToBigEndian( ui32Value, tmpBuf); + f_UINT32ToBigEndian( ui32Value, tmpBuf); return( write( tmpBuf, 4)); } @@ -679,7 +679,7 @@ public: { FLMBYTE tmpBuf[ 8]; - flmINT64ToBigEndian( i64Value, tmpBuf); + f_INT64ToBigEndian( i64Value, tmpBuf); return( write( tmpBuf, 8)); } @@ -688,7 +688,7 @@ public: { FLMBYTE tmpBuf[ 8]; - flmUINT64ToBigEndian( ui64Value, tmpBuf); + f_UINT64ToBigEndian( ui64Value, tmpBuf); return( write( tmpBuf, 8)); } @@ -723,7 +723,7 @@ public: /**************************************************************************** Desc: ****************************************************************************/ -class FCS_WIRE : public F_Base +class FCS_WIRE : public F_Object { protected: @@ -763,8 +763,8 @@ protected: FLMUINT m_uiFlaimVersion; HFDB m_hDb; - POOL m_pool; - POOL * m_pPool; + F_Pool m_pool; + F_Pool * m_pPool; FLMBOOL m_bSendGedcom; FCS_DIS * m_pDIStream; FCS_DOS * m_pDOStream; @@ -967,7 +967,7 @@ public: } RCODE getHTD( - POOL * pPool, + F_Pool * pPool, NODE ** ppTreeRV); void copyCreateOpts( @@ -1119,12 +1119,12 @@ public: } FINLINE void setPool( - POOL * pPool) + F_Pool * pPool) { m_pPool = pPool; } - FINLINE POOL * getPool( void) + FINLINE F_Pool * getPool( void) { return( m_pPool); } @@ -1235,7 +1235,7 @@ class FCS_FIS : public FCS_ISTM { private: - F_FileHdl * m_pFileHdl; + IF_FileHdl * m_pFileHdl; FLMBYTE * m_pucBuffer; FLMBYTE * m_pucBufPos; FLMUINT m_uiFileOffset; @@ -1325,7 +1325,7 @@ private: FCSBIOSBLOCK * m_pCurrReadBlock; FCS_BIOS_EVENT_HOOK m_pEventHook; void * m_pvUserData; - POOL m_pool; + F_Pool m_pool; }; /**************************************************************************** @@ -1417,287 +1417,19 @@ private: class FCS_TCP_SERVER; class FCS_TCP_CLIENT; -/**************************************************************************** -Desc: -****************************************************************************/ -class FCS_TCP : public F_Base -{ -protected: -#ifndef FLM_UNIX - WSADATA m_wsaData; -#endif - FLMBOOL m_bInitialized; - SOCKET m_iSocket; - FLMUINT m_uiIOTimeout; - FLMBOOL m_bConnected; - char m_pszIp[ 256]; - char m_pszName[ 256]; - char m_pszPeerIp[ 256]; - char m_pszPeerName[ 256]; - unsigned long m_ulRemoteAddr; - - RCODE _SocketPeek( - FLMINT iTimoutVal, - FLMBOOL bPeekRead); - -private: - - RCODE _GetLocalInfo( void); - RCODE _GetRemoteInfo( void); - - RCODE _write( - FLMBYTE * pucBuffer, - FLMUINT uiDataCnt, - FLMUINT * puiWrtCnt); - -public: - - FCS_TCP( void); - - virtual ~FCS_TCP( void); - - - // Verify that the connection is ready to accept data - - RCODE socketPeekWrt( FLMINT iTimeOut) - { - return( _SocketPeek( iTimeOut, FALSE)); - }; - - - // Verify that the connection has data waiting to be read - - RCODE socketPeekRead( FLMINT iTimeOut) - { - return( _SocketPeek( iTimeOut, TRUE)); - }; - - // Return object's IP name (in ASCII form) - - const char * ipNameTxt( void ) - { - _GetLocalInfo(); - return( (const char *)m_pszName); - }; - - // Return object's assigned address number (in ASCII form) - - const char * ipAddrTxt( void ) - { - _GetLocalInfo(); - return( (const char *)m_pszIp); - }; - - // Return object's peer IP name (in ASCII form) - - const char * peerIpNameTxt( void ) - { - _GetRemoteInfo(); - return( (const char *)m_pszPeerName); - }; - - // Return object's peer address number (in ASCII form) - - const char * peerIpAddrTxt( void ) - { - _GetRemoteInfo(); - return( (const char *)m_pszPeerIp); - }; - - // Read data from TCP/IP connection (won't necessarily - // return requested number of bytes) - - RCODE read( - FLMBYTE * pucBuffer, - FLMUINT uiDataCnt, - FLMUINT * puiReadCnt); - - // Read data from TCP/IP connection with a timeout of zero - // (won't necessarily return requested number of bytes) - - RCODE readNoWait( - FLMBYTE * pucBuffer, - FLMUINT uiDataCnt, - FLMUINT * puiReadCnt); - - // Read data from TCP/IP connection (returns requested - // number of bytes, unless error occurs) - - RCODE readAll( - FLMBYTE * pucBuffer, - FLMUINT uiDataCnt, - FLMUINT * puiReadCnt); - - // Write data to TCP/IP connection - - RCODE write( - FLMBYTE * pucDataBuffer, - FLMUINT uiDataCnt, - FLMUINT * puiWrtCntRV); - - RCODE setTcpDelay( - FLMBOOL bOn); - - // Close any open sockets - - void close( - FLMBOOL bForce = FALSE); - - // Friend classes - - friend class FCS_TCP_SERVER; - friend class FCS_TCP_CLIENT; -}; - -/**************************************************************************** -Desc: -****************************************************************************/ -class FCS_TCP_SERVER : public FCS_TCP -{ - private: - FLMBOOL m_bBound; - - public: - - FCS_TCP_SERVER( void); - virtual ~FCS_TCP_SERVER( void ); - - // Bind service to port, in preparation for allowing - // client connections - - RCODE bind( - FLMUINT uiBindPort, - FLMBYTE * pucBindAddr = NULL); - - // Accept incoming client connection (time-out if - // connection not received before specified time, or - // block for incoming connection (if ConnectTimeOut = - // svBLOCKING_IO) - - RCODE connectClient( - FCS_TCP * pClientConnection, - FLMINT iConnectTimeout = 3, - FLMINT iDataTimeout = 15); -}; - -/**************************************************************************** -Desc: -****************************************************************************/ -class FCS_TCP_CLIENT : public FCS_TCP -{ - public: - - // Constructor - Will attempt to connect to server if - // valid IP-address is supplied along with either a - // valid port number or service name (which equates to a - // port number) - - FCS_TCP_CLIENT( void); - - virtual ~FCS_TCP_CLIENT( void ); - - - // Attempt to connect to server (if a valid IP-address is - // supplied along with either a valid port number or - // service name (which a name service lookup can equate - // to a valid port number) - - RCODE openConnection( - const char * pucHostName, - FLMUINT uiPort, - FLMUINT uiConnectTimeout = 3, - FLMUINT uiDataTimeout = 15); -}; - -#define FCS_IPOS_BUFFER_SIZE 1024 - -/**************************************************************************** -Desc: -****************************************************************************/ -class FCS_IPOS : public FCS_OSTM -{ -public: - - FCS_IPOS( FCS_TCP * pTcpObj); - - RCODE close( void); - - FINLINE RCODE flush( void) - { - return( _flush()); - } - - RCODE endMessage( void); - - RCODE write( - FLMBYTE * pucData, - FLMUINT uiLength); - -private: - - FCS_TCP * m_pTcpObj; - FLMBOOL m_bOpen; - FLMBOOL m_bMessageActive; - FLMBYTE m_pucBuffer[ FCS_IPOS_BUFFER_SIZE]; - FLMBYTE * m_pucBufPos; - - RCODE _flush( - FLMBOOL bEndMessage = FALSE); -}; - -#define FCS_IPIS_BUFFER_SIZE 1024 - -/**************************************************************************** -Desc: -****************************************************************************/ -class FCS_IPIS : public FCS_ISTM -{ -public: - - FCS_IPIS( FCS_TCP * tcpObj); - - virtual ~FCS_IPIS( void); - - FLMBOOL isOpen( void); - - RCODE close( void); - - RCODE flush( void); - - RCODE endMessage( void); - - RCODE read( - FLMBYTE * pucData, - FLMUINT uiLength, - FLMUINT * puiBytesRead); - -private: - - FCS_TCP * m_pTcpObj; - FLMBYTE m_pucBuffer[ FCS_IPIS_BUFFER_SIZE]; - FLMBYTE * m_pucBufPos; - FLMUINT m_uiPacketSize; - FLMBOOL m_bStreamInvalid; - FLMBOOL m_bOpen; - FLMBOOL m_bMessageActive; - FLMBOOL m_bGotLastPacket; - - RCODE getNextPacket( void); -}; - RCODE fcsConvertUnicodeToNative( - POOL * pPool, + F_Pool * pPool, const FLMUNICODE * puzUnicode, char ** ppucNative); RCODE fcsConvertNativeToUnicode( - POOL * pPool, + F_Pool * pPool, const char * pucNative, FLMUNICODE ** ppuzUnicode); RCODE fcsBuildCheckpointInfo( CHECKPOINT_INFO * pChkptInfo, - POOL * pPool, + F_Pool * pPool, NODE ** ppTree); RCODE fcsExtractCheckpointInfo( @@ -1705,9 +1437,9 @@ RCODE fcsExtractCheckpointInfo( CHECKPOINT_INFO * pChkptInfo); RCODE fcsBuildLockUser( - LOCK_USER * pLockUser, + F_LOCK_USER * pLockUser, FLMBOOL bList, - POOL * pPool, + F_Pool * pPool, NODE ** ppTree); RCODE fcsExtractLockUser( @@ -1728,7 +1460,7 @@ RCODE fcsTranslateQCSToQFlmOp( RCODE fcsBuildIndexStatus( FINDEX_STATUS * pIndexStatus, - POOL * pPool, + F_Pool * pPool, NODE ** ppTree); RCODE fcsExtractIndexStatus( @@ -1737,7 +1469,7 @@ RCODE fcsExtractIndexStatus( RCODE fcsBuildMemInfo( FLM_MEM_INFO * pMemInfo, - POOL * pPool, + F_Pool * pPool, NODE ** ppTree); RCODE fcsExtractMemInfo( @@ -1745,12 +1477,12 @@ RCODE fcsExtractMemInfo( FLM_MEM_INFO * pMemInfo); RCODE fcsBuildThreadInfo( - POOL * pPool, + F_Pool * pPool, NODE ** ppTree); RCODE fcsExtractThreadInfo( NODE * pTree, - POOL * pPool, + F_Pool * pPool, F_THREAD_INFO ** ppThreadInfo, FLMUINT * puiNumThreads); diff --git a/flaim/src/fdb.cpp b/flaim/src/fdb.cpp index f250b3f..1ffe1bd 100644 --- a/flaim/src/fdb.cpp +++ b/flaim/src/fdb.cpp @@ -34,7 +34,7 @@ Desc: This function will use the FDB for use by the current thread. If another thread already has the FDB used, it will go into the debugger. ****************************************************************************/ -#if defined( FLM_DEBUG) && (defined( FLM_WIN) || defined( FLM_NLM)) +#if defined( FLM_DEBUG) void fdbUseCheck( FDB * pDb) { @@ -61,7 +61,7 @@ void fdbUseCheck( /**************************************************************************** Desc: This function will unuse the FDB for use by the current thread. ****************************************************************************/ -#if defined( FLM_DEBUG) && (defined( FLM_WIN) || defined( FLM_NLM)) +#if defined( FLM_DEBUG) void fdbUnuse( FDB * pDb) { @@ -450,7 +450,7 @@ void flmExit( // Keep the main pool block around inbetween FLAIM calls. - GedPoolReset( &pDb->TempPool, NULL); + pDb->TempPool.poolReset(); } fdbExit( pDb); } @@ -482,18 +482,17 @@ Desc: Logs messages ****************************************************************************/ void flmLogMessage( FlmLogMessageSeverity eMsgSeverity, - FlmColorType eForground, - FlmColorType eBackground, + eColorType foreground, + eColorType background, const char * pszFormat, ...) { FLMINT iLen; f_va_list args; - F_LogMessage * pLogMsg = NULL; + F_LogMessage * pLogMsg = NULL; char * pszMsgBuf = NULL; - if (( pLogMsg = flmBeginLogMessage( FLM_GENERAL_MESSAGE, - eMsgSeverity)) != NULL) + if( (pLogMsg = flmBeginLogMessage( FLM_GENERAL_MESSAGE, eMsgSeverity)) != NULL) { if( RC_OK( f_alloc( 1024, &pszMsgBuf))) { @@ -501,9 +500,10 @@ void flmLogMessage( iLen = f_vsprintf( pszMsgBuf, pszFormat, &args); f_va_end( args); - pLogMsg->changeColor( eForground, eBackground); + pLogMsg->changeColor( foreground, background); pLogMsg->appendString( pszMsgBuf); } + flmEndLogMessage( &pLogMsg); if( pszMsgBuf) diff --git a/flaim/src/fdbcnfig.cpp b/flaim/src/fdbcnfig.cpp index 804e3f6..7884358 100644 --- a/flaim/src/fdbcnfig.cpp +++ b/flaim/src/fdbcnfig.cpp @@ -424,7 +424,7 @@ Transmission_Error: if (pszNewRflDir && *pszNewRflDir) { - if( !gv_FlmSysData.pFileSystem->IsDir( pszNewRflDir)) + if( !gv_FlmSysData.pFileSystem->isDir( pszNewRflDir)) { rc = RC_SET( FERR_IO_INVALID_PATH); goto Exit; @@ -745,22 +745,22 @@ Desc: Returns database, rollback, and rollforward sizes. We are guaranteed to be inside an update transaction at this point. ****************************************************************************/ FSTATIC RCODE flmDbGetSizes( - FDB * pDb, - FLMUINT64 * pui64DbFileSize, - FLMUINT64 * pui64RollbackFileSize, - FLMUINT64 * pui64RflFileSize) + FDB * pDb, + FLMUINT64 * pui64DbFileSize, + FLMUINT64 * pui64RollbackFileSize, + FLMUINT64 * pui64RflFileSize) { - RCODE rc = FERR_OK; - FFILE * pFile = pDb->pFile; - FLMUINT uiDbVersion = pFile->FileHdr.uiVersionNum; - FLMUINT uiEndAddress; - FLMUINT uiLastFileNumber; - FLMUINT uiLastFileSize; - char szTmpName[ F_PATH_MAX_SIZE]; - char szRflDir[ F_PATH_MAX_SIZE]; - char szPrefix[ F_FILENAME_SIZE]; - F_FileHdlImp * pFileHdl = NULL; - F_DirHdl * pDirHdl = NULL; + RCODE rc = FERR_OK; + FFILE * pFile = pDb->pFile; + FLMUINT uiDbVersion = pFile->FileHdr.uiVersionNum; + FLMUINT uiEndAddress; + FLMUINT uiLastFileNumber; + FLMUINT64 ui64LastFileSize; + char szTmpName[ F_PATH_MAX_SIZE]; + char szRflDir[ F_PATH_MAX_SIZE]; + char szPrefix[ F_FILENAME_SIZE]; + IF_FileHdl * pFileHdl = NULL; + IF_DirHdl * pDirHdl = NULL; // Better be inside an update transaction at this point. @@ -780,8 +780,8 @@ FSTATIC RCODE flmDbGetSizes( // Get the actual size of the last file. - if (RC_BAD( rc = pDb->pSFileHdl->GetFileSize( uiLastFileNumber, - &uiLastFileSize))) + if (RC_BAD( rc = pDb->pSFileHdl->getFileSize( uiLastFileNumber, + &ui64LastFileSize))) { if (rc == FERR_IO_PATH_NOT_FOUND || rc == FERR_IO_INVALID_PATH) @@ -789,7 +789,7 @@ FSTATIC RCODE flmDbGetSizes( if (uiLastFileNumber > 1) { rc = FERR_OK; - uiLastFileSize = 0; + ui64LastFileSize = 0; } else { @@ -812,9 +812,9 @@ FSTATIC RCODE flmDbGetSizes( // extended beyond what the logical EOF shows. We want // the larger of these two possibilities. - if (FSGetFileOffset( uiEndAddress) > uiLastFileSize) + if (FSGetFileOffset( uiEndAddress) > ui64LastFileSize) { - uiLastFileSize = FSGetFileOffset( uiEndAddress); + ui64LastFileSize = FSGetFileOffset( uiEndAddress); } if (uiLastFileNumber == 1) @@ -822,7 +822,7 @@ FSTATIC RCODE flmDbGetSizes( // Only one file - use last file's size. - *pui64DbFileSize = (FLMUINT64)uiLastFileSize; + *pui64DbFileSize = ui64LastFileSize; } else { @@ -832,7 +832,7 @@ FSTATIC RCODE flmDbGetSizes( (*pui64DbFileSize) = (FLMUINT64)(uiLastFileNumber - 1) * (FLMUINT64)pFile->uiMaxFileSize + - (FLMUINT64)uiLastFileSize; + ui64LastFileSize; } } @@ -854,8 +854,8 @@ FSTATIC RCODE flmDbGetSizes( // Get the size of the last file number. - if (RC_BAD( rc = pDb->pSFileHdl->GetFileSize( uiLastFileNumber, - &uiLastFileSize))) + if (RC_BAD( rc = pDb->pSFileHdl->getFileSize( uiLastFileNumber, + &ui64LastFileSize))) { if (rc == FERR_IO_PATH_NOT_FOUND || rc == FERR_IO_INVALID_PATH) @@ -863,7 +863,7 @@ FSTATIC RCODE flmDbGetSizes( if (uiLastFileNumber) { rc = FERR_OK; - uiLastFileSize = 0; + ui64LastFileSize = 0; } else { @@ -883,9 +883,9 @@ FSTATIC RCODE flmDbGetSizes( // If the EOF offset for the last file is greater than the // actual file size, use it instead of the actual file size. - if (FSGetFileOffset( uiEndAddress) > uiLastFileSize) + if (FSGetFileOffset( uiEndAddress) > ui64LastFileSize) { - uiLastFileSize = FSGetFileOffset( uiEndAddress); + ui64LastFileSize = FSGetFileOffset( uiEndAddress); } // Special case handling here because rollback file numbers start with @@ -895,7 +895,7 @@ FSTATIC RCODE flmDbGetSizes( if (!uiLastFileNumber) { - *pui64RollbackFileSize = (FLMUINT64)uiLastFileSize; + *pui64RollbackFileSize = ui64LastFileSize; } else { @@ -908,7 +908,7 @@ FSTATIC RCODE flmDbGetSizes( (*pui64RollbackFileSize) = (FLMUINT64)(uiLastFileNumber - uiFirstLogFileNum + 1) * (FLMUINT64)pFile->uiMaxFileSize + - (FLMUINT64)uiLastFileSize; + ui64LastFileSize; } } @@ -933,14 +933,14 @@ FSTATIC RCODE flmDbGetSizes( // Open the file and get its size. - if (RC_BAD( rc = gv_FlmSysData.pFileSystem->OpenBlockFile( szTmpName, - F_IO_RDWR | F_IO_SH_DENYNONE | F_IO_DIRECT, - 512, &pFileHdl))) + if (RC_BAD( rc = gv_FlmSysData.pFileSystem->openFile( szTmpName, + FLM_IO_RDWR | FLM_IO_SH_DENYNONE | FLM_IO_DIRECT, + &pFileHdl))) { if (rc == FERR_IO_PATH_NOT_FOUND || rc == FERR_IO_INVALID_PATH) { rc = FERR_OK; - uiLastFileSize = 0; + ui64LastFileSize = 0; } else { @@ -949,17 +949,19 @@ FSTATIC RCODE flmDbGetSizes( } else { - if (RC_BAD( rc = pFileHdl->Size( &uiLastFileSize))) + if (RC_BAD( rc = pFileHdl->size( &ui64LastFileSize))) { goto Exit; } } + if (pFileHdl) { pFileHdl->Release(); pFileHdl = NULL; } - *pui64RflFileSize = (FLMUINT64)uiLastFileSize; + + *pui64RflFileSize = ui64LastFileSize; } else { @@ -984,19 +986,19 @@ FSTATIC RCODE flmDbGetSizes( // See if the directory exists. If not, we are done. - if (gv_FlmSysData.pFileSystem->IsDir( szRflDir)) + if (gv_FlmSysData.pFileSystem->isDir( szRflDir)) { // Open the directory and scan for RFL files. - if (RC_BAD( rc = gv_FlmSysData.pFileSystem->OpenDir( + if (RC_BAD( rc = gv_FlmSysData.pFileSystem->openDir( szRflDir, "*", &pDirHdl))) { goto Exit; } for (;;) { - if (RC_BAD( rc = pDirHdl->Next())) + if (RC_BAD( rc = pDirHdl->next())) { if (rc == FERR_IO_NO_MORE_FILES) { @@ -1008,28 +1010,28 @@ FSTATIC RCODE flmDbGetSizes( goto Exit; } } - pDirHdl->CurrentItemPath( szTmpName); + pDirHdl->currentItemPath( szTmpName); // If the item looks like an RFL file name, get // its size. - if (!pDirHdl->CurrentItemIsDir() && + if (!pDirHdl->currentItemIsDir() && rflGetFileNum( uiDbVersion, szPrefix, szTmpName, &uiLastFileNumber)) { // Open the file and get its size. - if (RC_BAD( rc = gv_FlmSysData.pFileSystem->OpenBlockFile( + if (RC_BAD( rc = gv_FlmSysData.pFileSystem->openFile( szTmpName, - F_IO_RDWR | F_IO_SH_DENYNONE | F_IO_DIRECT, - 512, &pFileHdl))) + FLM_IO_RDWR | FLM_IO_SH_DENYNONE | FLM_IO_DIRECT, + &pFileHdl))) { if (rc == FERR_IO_PATH_NOT_FOUND || rc == FERR_IO_INVALID_PATH) { rc = FERR_OK; - uiLastFileSize = 0; + ui64LastFileSize = 0; } else { @@ -1038,17 +1040,19 @@ FSTATIC RCODE flmDbGetSizes( } else { - if (RC_BAD( rc = pFileHdl->Size( &uiLastFileSize))) + if (RC_BAD( rc = pFileHdl->size( &ui64LastFileSize))) { goto Exit; } } + if (pFileHdl) { pFileHdl->Release(); pFileHdl = NULL; } - (*pui64RflFileSize) += (FLMUINT64)uiLastFileSize; + + (*pui64RflFileSize) += ui64LastFileSize; } } } @@ -1155,16 +1159,17 @@ FLMEXP RCODE FLMAPI FlmDbGetConfig( case FDB_GET_RFL_DIR: { char * pszPath; - POOL * pPool = Wire.getPool(); - void * pvMark = GedPoolMark( pPool); + F_Pool * pPool = Wire.getPool(); + void * pvMark = pPool->poolMark(); if( RC_BAD( rc = fcsConvertUnicodeToNative( pPool, (FLMUNICODE *)Wire.getFilePath(), &pszPath))) { goto Exit; } + f_strcpy( (char *)pvValue1, pszPath); - GedPoolReset( pPool, pvMark); + pPool->poolReset( pvMark); break; } @@ -1215,7 +1220,8 @@ FLMEXP RCODE FLMAPI FlmDbGetConfig( case FDB_GET_LOCK_HOLDER: { - rc = fcsExtractLockUser( Wire.getHTD(), FALSE, ((LOCK_USER *)pvValue1)); + rc = fcsExtractLockUser( Wire.getHTD(), FALSE, + ((F_LOCK_USER *)pvValue1)); break; } @@ -1350,14 +1356,17 @@ Transmission_Error: case FDB_GET_LOCK_HOLDER: { + F_LOCK_USER * pLockUser = (F_LOCK_USER *)pvValue1; + if (pFile->pFileLockObj) { - rc = pFile->pFileLockObj->GetLockInfo( FALSE, (void *)pvValue1); + rc = pFile->pFileLockObj->getLockInfo( 0, NULL, + &pLockUser->uiThreadId, &pLockUser->uiThreadId); } else { - ((LOCK_USER *)pvValue1)->uiThreadId = 0; - ((LOCK_USER *)pvValue1)->uiTime = 0; + ((F_LOCK_USER *)pvValue1)->uiThreadId = 0; + ((F_LOCK_USER *)pvValue1)->uiTime = 0; } break; } @@ -1366,22 +1375,22 @@ Transmission_Error: { if (pFile->pFileLockObj) { - rc = pFile->pFileLockObj->GetLockInfo( TRUE, (void *)pvValue1); + rc = pFile->pFileLockObj->getLockQueue( (F_LOCK_USER **)pvValue1); } else { - *((LOCK_USER **)pvValue1) = NULL; + *((F_LOCK_USER **)pvValue1) = NULL; } break; } case FDB_GET_LOCK_WAITERS_EX: { - FlmLockInfo * pLockInfo = (FlmLockInfo *)pvValue1; + IF_LockInfoClient * pLockInfo = (IF_LockInfoClient *)pvValue1; if (pFile->pFileLockObj) { - rc = pFile->pFileLockObj->GetLockInfo( pLockInfo); + rc = pFile->pFileLockObj->getLockInfo( pLockInfo); } else { @@ -1656,7 +1665,8 @@ void flmGetCPInfo( uiElapTime = FLM_ELAPSED_TIME( uiCurrTime, pFile->pCPInfo->uiStartTime); - FLM_TIMER_UNITS_TO_MILLI( uiElapTime, pCheckpointInfo->uiRunningTime); + pCheckpointInfo->uiRunningTime = + FLM_TIMER_UNITS_TO_MILLI( uiElapTime); } else { @@ -1669,8 +1679,8 @@ void flmGetCPInfo( uiCurrTime = FLM_GET_TIMER(); uiElapTime = FLM_ELAPSED_TIME( uiCurrTime, pFile->pCPInfo->uiForceCheckpointStartTime); - FLM_TIMER_UNITS_TO_MILLI( uiElapTime, - pCheckpointInfo->uiForceCheckpointRunningTime); + pCheckpointInfo->uiForceCheckpointRunningTime = + FLM_TIMER_UNITS_TO_MILLI( uiElapTime); } else { @@ -1698,8 +1708,8 @@ void flmGetCPInfo( uiElapTime = FLM_ELAPSED_TIME( uiCurrTime, pFile->pCPInfo->uiStartWaitTruncateTime); - FLM_TIMER_UNITS_TO_MILLI( uiElapTime, - pCheckpointInfo->uiWaitTruncateTime); + pCheckpointInfo->uiWaitTruncateTime = + FLM_TIMER_UNITS_TO_MILLI( uiElapTime); } else { diff --git a/flaim/src/fdbcopy.cpp b/flaim/src/fdbcopy.cpp index e835206..5258cb2 100644 --- a/flaim/src/fdbcopy.cpp +++ b/flaim/src/fdbcopy.cpp @@ -42,7 +42,7 @@ FSTATIC RCODE flmCopyDb( void * UserData); FSTATIC RCODE flmCopyFile( - F_FileSystemImp * pFileSystem, + IF_FileSystem * pFileSystem, FLMUINT uiStartOffset, FLMUINT uiEndOffset, DB_COPY_INFO * pDbCopyInfo, @@ -162,25 +162,27 @@ FSTATIC RCODE flmCopyDb( FLMUINT uiFileNumber; FLMUINT uiHighFileNumber; FLMUINT uiHighLogFileNumber; - FLMUINT uiFileSize; - FFILE * pFile; + FLMUINT64 ui64FileSize; + FFILE * pFile = NULL; FLMBOOL bMutexLocked = FALSE; - F_FileHdlImp * pLockFileHdl = NULL; - F_FileHdlImp * pTmpFileHdl = NULL; - F_DirHdl * pDirHdl = NULL; + IF_FileHdl * pLockFileHdl = NULL; + IF_FileHdl * pTmpFileHdl = NULL; + IF_DirHdl * pDirHdl = NULL; FLMBOOL bFileLocked = FALSE; FLMBOOL bWriteLocked = FALSE; - ServerLockObject * pWriteLockObj = NULL; - ServerLockObject * pFileLockObj = NULL; + IF_LockObject * pWriteLockObj = NULL; + IF_LockObject * pFileLockObj = NULL; COPIED_NAME * pCopiedList = NULL; FLMBOOL bUsedFFile = FALSE; FLMBYTE * pucInMemLogHdr = NULL; - FLOCK_INFO LockInfo; + eLockType currLockType; + FLMUINT uiLockThreadId; char * pszActualSrcRflPath = NULL; char * pszSrcPrefix = NULL; char * pszActualDestRflPath = NULL; char * pszDestPrefix = NULL; FLMBOOL bCreatedDestRflDir = FALSE; + F_SEM hWaitSem = F_SEM_NULL; f_memset( &DbCopyInfo, 0, sizeof( DbCopyInfo)); @@ -191,7 +193,14 @@ FSTATIC RCODE flmCopyDb( { goto Exit; } + + // Allocate a semaphore + if( RC_BAD( rc = f_semCreate( &hWaitSem))) + { + goto Exit; + } + // Allocate memory for paths we don't want to push onto the stack. if (RC_BAD( rc = f_calloc( @@ -207,13 +216,12 @@ FSTATIC RCODE flmCopyDb( // Set up the super file object for the source database. // Must at least open the control file. - if (RC_BAD( rc = SrcSFileHdl.Setup( NULL, pszSrcDbName, pszSrcDataDir))) + if (RC_BAD( rc = SrcSFileHdl.setup( pszSrcDbName, pszSrcDataDir, + uiDbVersion))) { goto Exit; } - SrcSFileHdl.SetDbVersion( uiDbVersion); - // Lock the destination database, if not already locked. // This is so we can overwrite it without necessarily // deleting it. May unlock and re-lock the global mutex. @@ -266,14 +274,15 @@ FSTATIC RCODE flmCopyDb( // Lock the destination file object and transaction // object, if not already locked. - - pFile->pFileLockObj->GetLockInfo( (FLMINT)0, &LockInfo); - if ((LockInfo.eCurrLockType != FLM_LOCK_EXCLUSIVE) || - (LockInfo.uiThreadId != f_threadId())) + + pFile->pFileLockObj->getLockInfo( 0, &currLockType, &uiLockThreadId, NULL); + if (currLockType != FLM_LOCK_EXCLUSIVE || uiLockThreadId != f_threadId()) { pFileLockObj = pFile->pFileLockObj; pFileLockObj->AddRef(); - if (RC_BAD( rc = pFileLockObj->Lock( TRUE, NULL, FALSE, TRUE, FLM_NO_TIMEOUT, 0))) + + if (RC_BAD( rc = pFileLockObj->lock( hWaitSem, + TRUE, FLM_NO_TIMEOUT, 0))) { goto Exit; } @@ -282,52 +291,45 @@ FSTATIC RCODE flmCopyDb( // Lock the write object, if not already locked - pFile->pWriteLockObj->GetLockInfo( (FLMINT)0, &LockInfo); - if ((LockInfo.eCurrLockType != FLM_LOCK_EXCLUSIVE) || - (LockInfo.uiThreadId != (FLMUINT)f_threadId())) + pFile->pWriteLockObj->getLockInfo( 0, &currLockType, &uiLockThreadId, NULL); + if( currLockType != FLM_LOCK_EXCLUSIVE || + uiLockThreadId != f_threadId()) { pWriteLockObj = pFile->pWriteLockObj; pWriteLockObj->AddRef(); // Only contention here is with the checkpoint thread - wait // forever until the checkpoint thread gives it up. - - if (RC_BAD( rc = dbWriteLock( pFile))) + + if( RC_BAD( rc = pWriteLockObj->lock( hWaitSem, + TRUE, FLM_NO_TIMEOUT, 0))) { goto Exit; } + bWriteLocked = TRUE; } } // Set up the super file object for the destination database. - if (RC_BAD( rc = DestSFileHdl.Setup( NULL, pszDestDbName, - pszDestDataDir))) + if (RC_BAD( rc = DestSFileHdl.setup( pszDestDbName, pszDestDataDir, + uiDbVersion))) { goto Exit; } - DestSFileHdl.SetDbVersion( uiDbVersion); - - // Setup the ECache manager - - if( pFile && pFile->pECacheMgr) - { - DestSFileHdl.setECacheMgr( pFile->pECacheMgr); - } - // See how many files we have and calculate the total size. uiHighFileNumber = 0; for (;;) { - if ((RC_BAD( rc = SrcSFileHdl.GetFileSize( - uiHighFileNumber, &uiFileSize))) || !uiFileSize ) + if ((RC_BAD( rc = SrcSFileHdl.getFileSize( + uiHighFileNumber, &ui64FileSize))) || !ui64FileSize ) { if (rc == FERR_IO_PATH_NOT_FOUND || rc == FERR_IO_INVALID_PATH || - !uiFileSize) + !ui64FileSize) { // If the control file doesn't exist, we will return // path not found. @@ -343,7 +345,7 @@ FSTATIC RCODE flmCopyDb( goto Exit; } - DbCopyInfo.ui64BytesToCopy += (FLMUINT64)uiFileSize; + DbCopyInfo.ui64BytesToCopy += ui64FileSize; if (uiHighFileNumber == MAX_DATA_BLOCK_FILE_NUMBER( uiDbVersion)) { break; @@ -357,12 +359,12 @@ FSTATIC RCODE flmCopyDb( uiHighLogFileNumber = FIRST_LOG_BLOCK_FILE_NUMBER( uiDbVersion); for (;;) { - if ((RC_BAD( rc = SrcSFileHdl.GetFileSize( - uiHighLogFileNumber, &uiFileSize))) || !uiFileSize) + if ((RC_BAD( rc = SrcSFileHdl.getFileSize( + uiHighLogFileNumber, &ui64FileSize))) || !ui64FileSize) { if (rc == FERR_IO_PATH_NOT_FOUND || rc == FERR_IO_INVALID_PATH || - !uiFileSize) + !ui64FileSize) { if (uiHighLogFileNumber == FIRST_LOG_BLOCK_FILE_NUMBER( uiDbVersion)) @@ -379,7 +381,7 @@ FSTATIC RCODE flmCopyDb( goto Exit; } - DbCopyInfo.ui64BytesToCopy += (FLMUINT64)uiFileSize; + DbCopyInfo.ui64BytesToCopy += ui64FileSize; if (uiHighLogFileNumber == MAX_LOG_BLOCK_FILE_NUMBER( uiDbVersion)) { break; @@ -399,10 +401,10 @@ FSTATIC RCODE flmCopyDb( goto Exit; } - if (RC_BAD( rc = gv_FlmSysData.pFileSystem->Open( + if (RC_BAD( rc = gv_FlmSysData.pFileSystem->openFile( pszActualSrcRflPath, - F_IO_RDWR | F_IO_SH_DENYNONE | F_IO_DIRECT, - (F_FileHdl **)&pTmpFileHdl))) + FLM_IO_RDWR | FLM_IO_SH_DENYNONE | FLM_IO_DIRECT, + &pTmpFileHdl))) { if (rc == FERR_IO_PATH_NOT_FOUND || rc == FERR_IO_INVALID_PATH) @@ -416,13 +418,13 @@ FSTATIC RCODE flmCopyDb( } else { - if (RC_BAD( rc = pTmpFileHdl->Size( &uiFileSize))) + if (RC_BAD( rc = pTmpFileHdl->size( &ui64FileSize))) { goto Exit; } - DbCopyInfo.ui64BytesToCopy += (FLMUINT64)uiFileSize; - pTmpFileHdl->Close(); + DbCopyInfo.ui64BytesToCopy += ui64FileSize; + pTmpFileHdl->Release(); pTmpFileHdl = NULL; } @@ -435,7 +437,7 @@ FSTATIC RCODE flmCopyDb( goto Exit; } - if (RC_BAD( rc = gv_FlmSysData.pFileSystem->OpenDir( + if (RC_BAD( rc = gv_FlmSysData.pFileSystem->openDir( pszActualSrcRflPath, (char *)"*", &pDirHdl))) { goto Exit; @@ -443,7 +445,7 @@ FSTATIC RCODE flmCopyDb( for (;;) { - if( RC_BAD( rc = pDirHdl->Next())) + if( RC_BAD( rc = pDirHdl->next())) { if (rc == FERR_IO_NO_MORE_FILES) { @@ -459,9 +461,9 @@ FSTATIC RCODE flmCopyDb( // If the current file is an RFL file, increment ui64BytesToCopy if( rflGetFileNum( uiDbVersion, pszSrcPrefix, - pDirHdl->CurrentItemName(), &uiFileNumber)) + pDirHdl->currentItemName(), &uiFileNumber)) { - DbCopyInfo.ui64BytesToCopy += (FLMUINT64)pDirHdl->CurrentItemSize(); + DbCopyInfo.ui64BytesToCopy += pDirHdl->currentItemSize(); } } @@ -471,8 +473,8 @@ FSTATIC RCODE flmCopyDb( // Close all file handles in the source and destination - SrcSFileHdl.ReleaseFiles( TRUE); - DestSFileHdl.ReleaseFiles( TRUE); + SrcSFileHdl.releaseFiles( TRUE); + DestSFileHdl.releaseFiles( TRUE); // Copy the database files. @@ -481,12 +483,12 @@ FSTATIC RCODE flmCopyDb( // Get the source file path and destination file path. - if( RC_BAD( rc = SrcSFileHdl.GetFilePath( + if( RC_BAD( rc = SrcSFileHdl.getFilePath( uiFileNumber, DbCopyInfo.szSrcFileName))) { goto Exit; } - if( RC_BAD( rc = DestSFileHdl.GetFilePath( + if( RC_BAD( rc = DestSFileHdl.getFilePath( uiFileNumber, DbCopyInfo.szDestFileName))) { goto Exit; @@ -529,13 +531,13 @@ FSTATIC RCODE flmCopyDb( // Get the source file path and destination file path. - if (RC_BAD( rc = SrcSFileHdl.GetFilePath( uiFileNumber, + if (RC_BAD( rc = SrcSFileHdl.getFilePath( uiFileNumber, DbCopyInfo.szSrcFileName))) { goto Exit; } - if (RC_BAD( rc = DestSFileHdl.GetFilePath( uiFileNumber, + if (RC_BAD( rc = DestSFileHdl.getFilePath( uiFileNumber, DbCopyInfo.szDestFileName))) { goto Exit; @@ -594,18 +596,19 @@ FSTATIC RCODE flmCopyDb( goto Exit; } - if( RC_OK( gv_FlmSysData.pFileSystem->Exists( pszActualDestRflPath))) + if( RC_OK( gv_FlmSysData.pFileSystem->doesFileExist( + pszActualDestRflPath))) { - if( gv_FlmSysData.pFileSystem->IsDir( pszActualDestRflPath)) + if( gv_FlmSysData.pFileSystem->isDir( pszActualDestRflPath)) { // Remove the existing directory and all files, etc. - (void)gv_FlmSysData.pFileSystem->RemoveDir( + (void)gv_FlmSysData.pFileSystem->removeDir( pszActualDestRflPath, TRUE); } else { - (void)gv_FlmSysData.pFileSystem->Delete( pszActualDestRflPath); + (void)gv_FlmSysData.pFileSystem->deleteFile( pszActualDestRflPath); } } @@ -616,14 +619,14 @@ FSTATIC RCODE flmCopyDb( // when we try to create the destination files (below), the FLAIM file // file system code will try to create any necessary directories. - (void)gv_FlmSysData.pFileSystem->CreateDir( pszActualDestRflPath); + (void)gv_FlmSysData.pFileSystem->createDir( pszActualDestRflPath); bCreatedDestRflDir = TRUE; // Copy the RFL files. NOTE: We need to copy all of the RFL files // in the source RFL directory so that they will be available // when performing a database restore operation. - if (RC_BAD( rc = gv_FlmSysData.pFileSystem->OpenDir( + if (RC_BAD( rc = gv_FlmSysData.pFileSystem->openDir( pszActualSrcRflPath, (char *)"*", &pDirHdl))) { goto Exit; @@ -631,7 +634,7 @@ FSTATIC RCODE flmCopyDb( for (;;) { - if( RC_BAD( rc = pDirHdl->Next())) + if( RC_BAD( rc = pDirHdl->next())) { if (rc == FERR_IO_NO_MORE_FILES) { @@ -647,7 +650,7 @@ FSTATIC RCODE flmCopyDb( // If the current file is an RFL file, copy it to the destination if( rflGetFileNum( uiDbVersion, pszSrcPrefix, - pDirHdl->CurrentItemName(), &uiFileNumber)) + pDirHdl->currentItemName(), &uiFileNumber)) { // Get the source file path and the destination file path. @@ -682,12 +685,12 @@ FSTATIC RCODE flmCopyDb( // Do one final copy on the control file to copy just the first 2K - if (RC_BAD( rc = SrcSFileHdl.GetFilePath( 0, DbCopyInfo.szSrcFileName))) + if (RC_BAD( rc = SrcSFileHdl.getFilePath( 0, DbCopyInfo.szSrcFileName))) { goto Exit; } - if (RC_BAD( rc = DestSFileHdl.GetFilePath( 0, DbCopyInfo.szDestFileName))) + if (RC_BAD( rc = DestSFileHdl.getFilePath( 0, DbCopyInfo.szDestFileName))) { goto Exit; } @@ -723,11 +726,13 @@ Exit: bMutexLocked = FALSE; } - /* Unlock the file, if it is locked. */ - if (bWriteLocked) { - dbWriteUnlock( pFile); + if( RC_BAD( rc = pWriteLockObj->unlock())) + { + goto Exit; + } + bWriteLocked = FALSE; } @@ -735,11 +740,12 @@ Exit: { RCODE rc3; - if (RC_BAD( rc3 = pFileLockObj->Unlock( TRUE, NULL))) + if (RC_BAD( rc3 = pFileLockObj->unlock())) { if (RC_OK( rc)) rc = rc3; } + bFileLocked = FALSE; } @@ -757,7 +763,6 @@ Exit: if (pLockFileHdl) { - (void)pLockFileHdl->Close(); pLockFileHdl->Release(); pLockFileHdl = NULL; } @@ -784,7 +789,7 @@ Exit: if (RC_BAD( rc)) { - (void)gv_FlmSysData.pFileSystem->Delete( pCopiedList->szPath); + (void)gv_FlmSysData.pFileSystem->deleteFile( pCopiedList->szPath); } f_free( &pCopiedList); @@ -793,13 +798,18 @@ Exit: if( RC_BAD( rc) && bCreatedDestRflDir) { - (void)gv_FlmSysData.pFileSystem->RemoveDir( pszActualDestRflPath); + (void)gv_FlmSysData.pFileSystem->removeDir( pszActualDestRflPath); } if( pszActualSrcRflPath) { f_free( &pszActualSrcRflPath); } + + if( hWaitSem != F_SEM_NULL) + { + f_semDestroy( &hWaitSem); + } return( rc); } @@ -808,7 +818,7 @@ Exit: Desc: Copy a file that is one of the files of the database. *****************************************************************************/ FSTATIC RCODE flmCopyFile( - F_FileSystemImp * pFileSystem, + IF_FileSystem * pFileSystem, FLMUINT uiStartOffset, FLMUINT uiEndOffset, DB_COPY_INFO * pDbCopyInfo, @@ -820,8 +830,8 @@ FSTATIC RCODE flmCopyFile( { RCODE rc = FERR_OK; FLMBYTE * pucBuffer = NULL; - F_FileHdlImp * pSrcFileHdl = NULL; - F_FileHdlImp * pDestFileHdl = NULL; + IF_FileHdl * pSrcFileHdl = NULL; + IF_FileHdl * pDestFileHdl = NULL; FLMUINT uiBufferSize = 32768; FLMUINT uiBytesToRead; FLMUINT uiBytesRead; @@ -833,9 +843,10 @@ FSTATIC RCODE flmCopyFile( // Open the source file. - if( RC_BAD( rc = gv_FlmSysData.pFileSystem->Open( pDbCopyInfo->szSrcFileName, - F_IO_RDWR | F_IO_SH_DENYNONE | F_IO_DIRECT, - (F_FileHdl **)&pSrcFileHdl))) + if( RC_BAD( rc = gv_FlmSysData.pFileSystem->openFile( + pDbCopyInfo->szSrcFileName, + FLM_IO_RDWR | FLM_IO_SH_DENYNONE | FLM_IO_DIRECT, + &pSrcFileHdl))) { goto Exit; } @@ -843,9 +854,10 @@ FSTATIC RCODE flmCopyFile( // First attempt to open the destination file. If it does // not exist, attempt to create it. - if (RC_BAD( rc = gv_FlmSysData.pFileSystem->Open( pDbCopyInfo->szDestFileName, - F_IO_RDWR | F_IO_SH_DENYNONE | F_IO_DIRECT, - (F_FileHdl **)&pDestFileHdl))) + if (RC_BAD( rc = gv_FlmSysData.pFileSystem->openFile( + pDbCopyInfo->szDestFileName, + FLM_IO_RDWR | FLM_IO_SH_DENYNONE | FLM_IO_DIRECT, + &pDestFileHdl))) { if (rc != FERR_IO_PATH_NOT_FOUND && rc != FERR_IO_INVALID_PATH) @@ -853,10 +865,11 @@ FSTATIC RCODE flmCopyFile( goto Exit; } - if( RC_BAD( rc = gv_FlmSysData.pFileSystem->Create( pDbCopyInfo->szDestFileName, - F_IO_RDWR | F_IO_EXCL | F_IO_SH_DENYNONE | - F_IO_CREATE_DIR | F_IO_DIRECT, - (F_FileHdl **)&pDestFileHdl))) + if( RC_BAD( rc = gv_FlmSysData.pFileSystem->createFile( + pDbCopyInfo->szDestFileName, + FLM_IO_RDWR | FLM_IO_EXCL | FLM_IO_SH_DENYNONE | + FLM_IO_CREATE_DIR | FLM_IO_DIRECT, + &pDestFileHdl))) { goto Exit; } @@ -880,7 +893,7 @@ FSTATIC RCODE flmCopyFile( { // Read the first 2K of the source file. - if (RC_BAD( rc = pSrcFileHdl->SectorRead( 0L, 2048, + if (RC_BAD( rc = pSrcFileHdl->sectorRead( 0L, 2048, pucBuffer, &uiBytesRead))) { if (rc == FERR_IO_END_OF_FILE) @@ -905,7 +918,7 @@ FSTATIC RCODE flmCopyFile( // destination file, these bytes may not be present. if ((bCreatedDestFile) || - (RC_BAD( pDestFileHdl->Read( 16L, LOG_HEADER_SIZE, + (RC_BAD( pDestFileHdl->read( 16L, LOG_HEADER_SIZE, ucLogHdr, &uiBytesRead)))) { f_memset( ucLogHdr, 0, sizeof(ucLogHdr)); @@ -934,7 +947,7 @@ FSTATIC RCODE flmCopyFile( // The real first 2K from the source file will be copied in // at a later time. - if (RC_BAD( rc = pDestFileHdl->Write( 0L, 2048, + if (RC_BAD( rc = pDestFileHdl->write( 0L, 2048, pucBuffer, &uiBytesWritten))) { goto Exit; @@ -963,7 +976,7 @@ FSTATIC RCODE flmCopyFile( // Read data from source file. - if (RC_BAD( rc = pSrcFileHdl->SectorRead( uiOffset, uiBytesToRead, + if (RC_BAD( rc = pSrcFileHdl->sectorRead( uiOffset, uiBytesToRead, pucBuffer, &uiBytesRead))) { if (rc == FERR_IO_END_OF_FILE) @@ -982,7 +995,7 @@ FSTATIC RCODE flmCopyFile( // Write data to destination file. - if (RC_BAD( rc = pDestFileHdl->Write( uiOffset, + if (RC_BAD( rc = pDestFileHdl->write( uiOffset, uiBytesRead, pucBuffer, &uiBytesWritten))) { goto Exit; @@ -1029,7 +1042,7 @@ FSTATIC RCODE flmCopyFile( if (!bCreatedDestFile && bOkToTruncate) { - if (RC_BAD( rc = pDestFileHdl->Truncate( uiOffset))) + if (RC_BAD( rc = pDestFileHdl->truncate( uiOffset))) { goto Exit; } @@ -1068,7 +1081,7 @@ Exit: if (pDestFileHdl) { - pDestFileHdl->Flush(); + pDestFileHdl->flush(); pDestFileHdl->Release(); } @@ -1077,7 +1090,7 @@ Exit: if (RC_BAD( rc)) { - (void)pFileSystem->Delete( pDbCopyInfo->szDestFileName); + (void)pFileSystem->deleteFile( pDbCopyInfo->szDestFileName); } return( rc); diff --git a/flaim/src/fdbremov.cpp b/flaim/src/fdbremov.cpp index c1309ba..fcd36fa 100644 --- a/flaim/src/fdbremov.cpp +++ b/flaim/src/fdbremov.cpp @@ -34,7 +34,7 @@ FLMEXP RCODE FLMAPI FlmDbRemove( FLMBOOL bRemoveRflFiles) { RCODE rc = FERR_OK; - F_FileHdlImp * pFileHdl = NULL; + IF_FileHdl * pFileHdl = NULL; FLMBYTE * pucBuffer = NULL; FLMUINT uiFileNumber; FILE_HDR FileHdr; @@ -46,7 +46,7 @@ FLMEXP RCODE FLMAPI FlmDbRemove( char szPrefix[ F_FILENAME_SIZE]; char * pszExt; char * pszDataExt; - F_DirHdl * pDirHdl = NULL; + IF_DirHdl * pDirHdl = NULL; // Cannot handle empty database name. @@ -79,9 +79,9 @@ FLMEXP RCODE FLMAPI FlmDbRemove( // Open the file so we can get the log header. - if( RC_BAD( rc = gv_FlmSysData.pFileSystem->Open( - pszDbName, F_IO_RDWR | F_IO_SH_DENYNONE | F_IO_DIRECT, - (F_FileHdl **)&pFileHdl))) + if( RC_BAD( rc = gv_FlmSysData.pFileSystem->openFile( + pszDbName, FLM_IO_RDWR | FLM_IO_SH_DENYNONE | FLM_IO_DIRECT, + &pFileHdl))) { goto Exit; } @@ -113,12 +113,16 @@ FLMEXP RCODE FLMAPI FlmDbRemove( if (pszDataDir && *pszDataDir) { - if (RC_BAD( rc = f_pathReduce( pszDbName, pszDataName, pszBaseName))) + if (RC_BAD( rc = gv_FlmSysData.pFileSystem->pathReduce( + pszDbName, pszDataName, pszBaseName))) { goto Exit; } + f_strcpy( pszDataName, pszDataDir); - if (RC_BAD( rc = f_pathAppend( pszDataName, pszBaseName))) + + if (RC_BAD( rc = gv_FlmSysData.pFileSystem->pathAppend( + pszDataName, pszBaseName))) { goto Exit; } @@ -131,7 +135,7 @@ FLMEXP RCODE FLMAPI FlmDbRemove( // Start deleting files, beginning with the main DB file. - if (RC_BAD( rc = gv_FlmSysData.pFileSystem->Delete( pszDbName))) + if (RC_BAD( rc = gv_FlmSysData.pFileSystem->deleteFile( pszDbName))) { if (rc == FERR_IO_PATH_NOT_FOUND || rc == FERR_IO_INVALID_PATH) { @@ -166,7 +170,7 @@ FLMEXP RCODE FLMAPI FlmDbRemove( // Delete the .lck file, if any f_strcpy( pszExt, ".lck"); - if (RC_BAD( rc = gv_FlmSysData.pFileSystem->Delete( pszTmpName))) + if (RC_BAD( rc = gv_FlmSysData.pFileSystem->deleteFile( pszTmpName))) { if (rc == FERR_IO_PATH_NOT_FOUND || rc == FERR_IO_INVALID_PATH) { @@ -185,7 +189,7 @@ FLMEXP RCODE FLMAPI FlmDbRemove( { bldSuperFileExtension( uiVersionNum, uiFileNumber, pszDataExt); - if (RC_BAD( rc = gv_FlmSysData.pFileSystem->Delete( pszDataName))) + if (RC_BAD( rc = gv_FlmSysData.pFileSystem->deleteFile( pszDataName))) { if (rc == FERR_IO_PATH_NOT_FOUND || rc == FERR_IO_INVALID_PATH) { @@ -212,7 +216,7 @@ FLMEXP RCODE FLMAPI FlmDbRemove( { bldSuperFileExtension( uiVersionNum, uiFileNumber, pszExt); - if (RC_BAD( rc = gv_FlmSysData.pFileSystem->Delete( pszTmpName))) + if (RC_BAD( rc = gv_FlmSysData.pFileSystem->deleteFile( pszTmpName))) { if (rc == FERR_IO_PATH_NOT_FOUND || rc == FERR_IO_INVALID_PATH) { @@ -249,7 +253,7 @@ FLMEXP RCODE FLMAPI FlmDbRemove( goto Exit; } - if (RC_BAD( rc = gv_FlmSysData.pFileSystem->Delete( pszTmpName))) + if (RC_BAD( rc = gv_FlmSysData.pFileSystem->deleteFile( pszTmpName))) { if (rc == FERR_IO_PATH_NOT_FOUND || rc == FERR_IO_INVALID_PATH) { @@ -276,7 +280,7 @@ FLMEXP RCODE FLMAPI FlmDbRemove( // See if the directory exists. If not, we are done. - if (!gv_FlmSysData.pFileSystem->IsDir( pszRflDirName)) + if (!gv_FlmSysData.pFileSystem->isDir( pszRflDirName)) { goto Exit; // Should return FERR_OK } @@ -287,7 +291,7 @@ FLMEXP RCODE FLMAPI FlmDbRemove( // Look specifically for files that match our expected // name format for RFL files. - if (RC_BAD( rc = gv_FlmSysData.pFileSystem->OpenDir( pszRflDirName, + if (RC_BAD( rc = gv_FlmSysData.pFileSystem->openDir( pszRflDirName, "*", &pDirHdl))) { goto Exit; @@ -300,7 +304,7 @@ FLMEXP RCODE FLMAPI FlmDbRemove( bCanDeleteDir = TRUE; for (;;) { - if (RC_BAD( rc = pDirHdl->Next())) + if (RC_BAD( rc = pDirHdl->next())) { if (rc == FERR_IO_NO_MORE_FILES) { @@ -312,8 +316,10 @@ FLMEXP RCODE FLMAPI FlmDbRemove( goto Exit; } } - pDirHdl->CurrentItemPath( pszTmpName); - if (pDirHdl->CurrentItemIsDir()) + + pDirHdl->currentItemPath( pszTmpName); + + if (pDirHdl->currentItemIsDir()) { bCanDeleteDir = FALSE; } @@ -325,7 +331,7 @@ FLMEXP RCODE FLMAPI FlmDbRemove( else { if( RC_BAD( rc = - gv_FlmSysData.pFileSystem->Delete( pszTmpName))) + gv_FlmSysData.pFileSystem->deleteFile( pszTmpName))) { if (rc == FERR_IO_PATH_NOT_FOUND || rc == FERR_IO_INVALID_PATH) @@ -355,7 +361,8 @@ FLMEXP RCODE FLMAPI FlmDbRemove( pDirHdl = NULL; } - if (RC_BAD( rc = gv_FlmSysData.pFileSystem->RemoveDir( pszRflDirName))) + if (RC_BAD( rc = gv_FlmSysData.pFileSystem->removeDir( + pszRflDirName))) { if (rc == FERR_IO_PATH_NOT_FOUND || rc == FERR_IO_INVALID_PATH) { diff --git a/flaim/src/fdbrenam.cpp b/flaim/src/fdbrenam.cpp index 7427747..bbf7f32 100644 --- a/flaim/src/fdbrenam.cpp +++ b/flaim/src/fdbrenam.cpp @@ -24,12 +24,10 @@ #include "flaimsys.h" -typedef struct DBRenameInfoTag * DBRenameInfo_p; - -typedef struct DBRenameInfoTag +typedef struct DBRenameInfo { - DB_RENAME_INFO Info; - DBRenameInfo_p pNext; + DB_RENAME_INFO Info; + DBRenameInfo * pNext; } DBRenameInfo; FSTATIC RCODE flmRenameFile( @@ -65,7 +63,7 @@ FSTATIC RCODE flmRenameFile( if (f_stricmp( pszSrcFileName, pszDstFileName) == 0) { - if (gv_FlmSysData.pFileSystem->Exists( pszSrcFileName) == FERR_OK) + if (RC_OK( gv_FlmSysData.pFileSystem->doesFileExist( pszSrcFileName))) { *pbFileFound = TRUE; } @@ -83,9 +81,9 @@ FSTATIC RCODE flmRenameFile( if (bOverwriteDestOk) { - if (gv_FlmSysData.pFileSystem->IsDir( pszDstFileName)) + if (gv_FlmSysData.pFileSystem->isDir( pszDstFileName)) { - if (RC_BAD( rc = gv_FlmSysData.pFileSystem->RemoveDir( + if (RC_BAD( rc = gv_FlmSysData.pFileSystem->removeDir( pszDstFileName, TRUE))) { goto Exit; @@ -93,7 +91,7 @@ FSTATIC RCODE flmRenameFile( } else { - if (RC_BAD( rc = gv_FlmSysData.pFileSystem->Delete( + if (RC_BAD( rc = gv_FlmSysData.pFileSystem->deleteFile( pszDstFileName))) { if (rc == FERR_IO_PATH_NOT_FOUND || rc == FERR_IO_INVALID_PATH) @@ -111,8 +109,8 @@ FSTATIC RCODE flmRenameFile( // If names are the same, no need to actually do the // rename. - if (RC_BAD( rc = gv_FlmSysData.pFileSystem->Rename( pszSrcFileName, - pszDstFileName))) + if (RC_BAD( rc = gv_FlmSysData.pFileSystem->renameFile( + pszSrcFileName, pszDstFileName))) { if (rc == FERR_IO_PATH_NOT_FOUND || rc == FERR_IO_INVALID_PATH) { @@ -179,7 +177,7 @@ FLMEXP RCODE FLMAPI FlmDbRename( void * UserData) { RCODE rc = FERR_OK; - F_FileHdlImp * pFileHdl = NULL; + IF_FileHdl * pFileHdl = NULL; FLMUINT uiFileNumber; FILE_HDR FileHdr; LOG_HDR LogHdr; @@ -222,12 +220,14 @@ FLMEXP RCODE FLMAPI FlmDbRename( // There must be either no directory specified for the new name, or // it must be identical to the old directory. - if (RC_BAD( rc = f_pathReduce( pszDbName, pszOldName, szOldBase))) + if (RC_BAD( rc = gv_FlmSysData.pFileSystem->pathReduce( + pszDbName, pszOldName, szOldBase))) { goto Exit; } - if (RC_BAD( rc = f_pathReduce( pszNewDbName, pszNewName, szNewBase))) + if (RC_BAD( rc = gv_FlmSysData.pFileSystem->pathReduce( + pszNewDbName, pszNewName, szNewBase))) { goto Exit; } @@ -242,7 +242,8 @@ FLMEXP RCODE FLMAPI FlmDbRename( f_strcpy( pszNewName, pszOldName); - if (RC_BAD( rc = f_pathAppend( pszNewName, szNewBase))) + if (RC_BAD( rc = gv_FlmSysData.pFileSystem->pathAppend( + pszNewName, szNewBase))) { goto Exit; } @@ -255,12 +256,14 @@ FLMEXP RCODE FLMAPI FlmDbRename( f_strcpy( pszOldDataName, pszDataDir); f_strcpy( pszNewDataName, pszDataDir); - if (RC_BAD( rc = f_pathAppend( pszOldDataName, szOldBase))) + if (RC_BAD( rc = gv_FlmSysData.pFileSystem->pathAppend( + pszOldDataName, szOldBase))) { goto Exit; } - if (RC_BAD( rc = f_pathAppend( pszNewDataName, szNewBase))) + if (RC_BAD( rc = gv_FlmSysData.pFileSystem->pathAppend( + pszNewDataName, szNewBase))) { goto Exit; } @@ -288,9 +291,9 @@ FLMEXP RCODE FLMAPI FlmDbRename( // Open the file so we can get the log header. - if( RC_BAD( rc = gv_FlmSysData.pFileSystem->Open( pszDbName, - F_IO_RDWR | F_IO_SH_DENYNONE | F_IO_DIRECT, - (F_FileHdl **)&pFileHdl))) + if( RC_BAD( rc = gv_FlmSysData.pFileSystem->openFile( pszDbName, + FLM_IO_RDWR | FLM_IO_SH_DENYNONE | FLM_IO_DIRECT, + &pFileHdl))) { goto Exit; } @@ -511,8 +514,8 @@ Exit: if (RC_BAD( rc)) { - gv_FlmSysData.pFileSystem->Rename( pRenameFile->Info.szDstFileName, - pRenameFile->Info.szSrcFileName); + gv_FlmSysData.pFileSystem->renameFile( + pRenameFile->Info.szDstFileName, pRenameFile->Info.szSrcFileName); } f_free( &pRenameFile); diff --git a/flaim/src/fdict.cpp b/flaim/src/fdict.cpp index 2b1ba07..9338b72 100644 --- a/flaim/src/fdict.cpp +++ b/flaim/src/fdict.cpp @@ -84,8 +84,7 @@ FSTATIC RCODE DDParseStateOptions( FSTATIC RCODE DDEncDefParse( TDICT * pTDict, DDENTRY * pDDEntry, - FlmRecord * pRecord, - FLMUINT uiDictRecNum); + FlmRecord * pRecord); FSTATIC RCODE DDGetEncKey( TDICT * pTDict, @@ -244,7 +243,7 @@ RCODE fdictProcessAllDictRecs( FSInitStackCache( &stackBuf [0], BH_MAX_LEVELS); stack->pKeyBuf = btKeyBuf; - flmUINT32ToBigEndian( 0, key); + f_UINT32ToBigEndian( 0, key); if( RC_BAD(rc = FSBtSearch( pDb, pLFile, &stack, key, DRN_KEY_SIZ, 0 ))) { @@ -258,7 +257,7 @@ RCODE fdictProcessAllDictRecs( do { - uiDrn = flmBigEndianToUINT32( btKeyBuf); + uiDrn = f_bigEndianToUINT32( btKeyBuf); if( uiDrn == DRN_LAST_MARKER) { @@ -323,12 +322,12 @@ RCODE fdictAddDictIndex( goto Exit; } pDDEntry->uiType = ITT_INDEX_TYPE; - - if( (pTIxd = (TIXD *) GedPoolAlloc( &pTDict->pool, sizeof( TIXD))) == NULL) + + if( RC_BAD( rc = pTDict->pool.poolAlloc( sizeof( TIXD), (void **)&pTIxd))) { - rc = RC_SET( FERR_MEM); goto Exit; } + pTDict->uiNewIxds++; pDDEntry->vpDef = (void *) pTIxd; pTIxd->uiFlags = IXD_UNIQUE; @@ -337,11 +336,11 @@ RCODE fdictAddDictIndex( pTIxd->uiLanguage = pTDict->uiDefaultLanguage; pTIxd->uiEncId = 0; - if( (pTIfd = (TIFD *) GedPoolAlloc( &pTDict->pool, sizeof( TIFD))) == NULL) + if( RC_BAD( rc = pTDict->pool.poolAlloc( sizeof( TIFD), (void **)&pTIfd))) { - rc = RC_SET( FERR_MEM); goto Exit; } + pTIxd->pNextTIfd = pTIfd; pTDict->uiNewIfds++; pTIfd->pTIfp = NULL; @@ -351,11 +350,11 @@ RCODE fdictAddDictIndex( pTIfd->uiLimit = IFD_DEFAULT_LIMIT; pTIfd->uiCompoundPos = 0; - if( (pTIfp = (TIFP *) GedPoolAlloc( &pTDict->pool, sizeof( TIFP ))) == NULL) + if( RC_BAD( rc = pTDict->pool.poolAlloc( sizeof( TIFP), (void **)&pTIfp))) { - rc = RC_SET( FERR_MEM); goto Exit; } + pTDict->uiNewFldPaths += 2; pTIfd->pTIfp = pTIfp; @@ -364,6 +363,7 @@ RCODE fdictAddDictIndex( pTIfp->uiFldNum = FLM_NAME_TAG; Exit: + return( rc); } @@ -448,7 +448,7 @@ RCODE fdictProcessRec( goto Exit; } pDDEntry->uiType = ITT_ENCDEF_TYPE; - if (RC_BAD( rc = DDEncDefParse( pTDict, pDDEntry, pRecord, uiDictRecNum))) + if (RC_BAD( rc = DDEncDefParse( pTDict, pDDEntry, pRecord))) { goto Exit; } @@ -484,13 +484,12 @@ FSTATIC RCODE DDAllocEntry( RCODE rc = FERR_OK; DDENTRY * pNewEntry; - pNewEntry = (DDENTRY *)GedPoolAlloc( &pTDict->pool, sizeof(DDENTRY)); - if( !pNewEntry) + if( RC_BAD( rc = pTDict->pool.poolAlloc( sizeof( DDENTRY), + (void **)&pNewEntry))) { - rc = RC_SET( FERR_MEM); goto Exit; } - + pNewEntry->pNextEntry = NULL; pNewEntry->vpDef = NULL; pNewEntry->uiEntryNum = uiDictRecNum; @@ -527,20 +526,21 @@ Exit: Desc: Parse field definition ****************************************************************************/ FSTATIC RCODE DDFieldParse( - TDICT * pTDict, - DDENTRY * pDDEntry, - FlmRecord * pRecord, - FLMUINT uiDictRecNum) + TDICT * pTDict, + DDENTRY * pDDEntry, + FlmRecord * pRecord, + FLMUINT uiDictRecNum) { - RCODE rc = FERR_OK; - TFIELD * pTField; - void * pvField; + RCODE rc = FERR_OK; + TFIELD * pTField; + void * pvField = NULL; - if( (pTField = (TFIELD *)GedPoolAlloc( &pTDict->pool, sizeof(TFIELD))) == NULL) + if( RC_BAD( rc = pTDict->pool.poolAlloc( sizeof( TFIELD), + (void **)&pTField))) { - return( RC_SET( FERR_MEM)); + goto Exit; } - + pTField->uiFldNum = uiDictRecNum; pTField->uiFldInfo = FLM_CONTEXT_TYPE; pDDEntry->vpDef = (void *) pTField; @@ -767,14 +767,12 @@ FSTATIC RCODE DDGetEncKey( } uiLength++; - // Allocate the buffer from the pool so it will be easily freed later. - - if( (pucBuffer = (char *)GedPoolAlloc( &pTDict->pool, uiLength)) == NULL) + if( RC_BAD( rc = pTDict->pool.poolAlloc( uiLength, + (void **)&pucBuffer))) { - rc = RC_SET( FERR_MEM); goto Exit; } - + if (RC_BAD( rc = pRecord->getNative( pvField, pucBuffer, &uiLength))) { goto Exit; @@ -847,11 +845,12 @@ FSTATIC RCODE DDIxParse( FLMBOOL bHasRequiredTag = TRUE; FLMBOOL bOld11Mode = FALSE; - if( (pTIxd = (TIXD *) GedPoolAlloc( &pTDict->pool, sizeof( TIXD))) == NULL) + if( RC_BAD( rc = pTDict->pool.poolAlloc( sizeof( TIXD), + (void **)&pTIxd))) { - rc = RC_SET( FERR_MEM); goto Exit; } + pTIxd->pNextTIfd = NULL; pTIxd->uiFlags = 0; pTIxd->uiContainerNum = FLM_DATA_CONTAINER; @@ -868,9 +867,9 @@ FSTATIC RCODE DDIxParse( pLastTIfd = NULL; for( ; pvField; pvField = pRecord->nextSibling( pvField)) { - switch ( pRecord->getFieldID( pvField)) + switch( pRecord->getFieldID( pvField)) { - case FLM_CONTAINER_TAG: + case FLM_CONTAINER_TAG: { char szTmpBuf [50]; FLMUINT uiLen = sizeof( szTmpBuf); @@ -900,26 +899,31 @@ FSTATIC RCODE DDIxParse( { goto Exit; } + if( pTIxd->uiContainerNum == 0) { pTIxd->uiContainerNum = FLM_DATA_CONTAINER; } } + break; } - case FLM_COUNT_TAG: + case FLM_COUNT_TAG: + { pTIxd->uiFlags |= IXD_COUNT; break; + } - case FLM_LANGUAGE_TAG: + case FLM_LANGUAGE_TAG: + { uiNLen = sizeof( szNativeBuf); (void) pRecord->getNative( pvField, szNativeBuf, &uiNLen); - pTIxd->uiLanguage = FlmLanguage( szNativeBuf); + pTIxd->uiLanguage = f_languageToNum( szNativeBuf); break; + } - - case FLM_ENCDEF_TAG: + case FLM_ENCDEF_TAG: { uiNLen = sizeof( szNativeBuf); (void) pRecord->getNative( pvField, szNativeBuf, &uiNLen); @@ -928,12 +932,14 @@ FSTATIC RCODE DDIxParse( break; } - case FLM_TYPE_TAG: - // Is only compound for NDS definitions. This parsers default. + case FLM_TYPE_TAG: + { bOld11Mode = TRUE; break; + } - case FLM_POSITIONING_TAG: + case FLM_POSITIONING_TAG: + { if (pTDict->pDb->pFile->FileHdr.uiVersionNum >= FLM_FILE_FORMAT_VER_4_3) { @@ -941,15 +947,15 @@ FSTATIC RCODE DDIxParse( } else { - - // Positioning indexes not allowed prior to 4.3 - rc = RC_SET( FERR_SYNTAX); goto Exit; } + break; + } - case FLM_FIELD_TAG: + case FLM_FIELD_TAG: + { uiCompoundPos = 0; uiBaseNum = 0; uiIfdFlags = IFD_FIELD; @@ -957,8 +963,10 @@ FSTATIC RCODE DDIxParse( pvTempField = pvField; bOld11Mode = TRUE; goto Parse_Fields; + } - case FLM_KEY_TAG: + case FLM_KEY_TAG: + { uiCompoundPos = 0; uiBaseNum = 0; uiIfdFlags = IFD_FIELD | IFD_OPTIONAL; @@ -983,257 +991,294 @@ Parse_Fields: { switch( pRecord->getFieldID( pvTempField)) { - case FLM_BASE_TAG: - if( RC_BAD( rc = DDGetReference( pRecord, - pvTempField, NULL, &uiBaseNum))) + case FLM_BASE_TAG: { - goto Exit; - } - break; - - case FLM_COMBINATIONS_TAG: - rc = RC_SET( FERR_SYNTAX); - goto Exit; - - case FLM_POST_TAG: - pTIxd->uiFlags |= IXD_HAS_POST; - uiIfdFlags |= IFD_POST; - break; - - case FLM_REQUIRED_TAG: // Default - doesn't mean anything - break; - - case FLM_OPTIONAL_TAG: - rc = RC_SET( FERR_SYNTAX); - goto Exit; - - case FLM_UNIQUE_TAG : - pTIxd->uiFlags |= IXD_UNIQUE; - uiIfdFlags |= IFD_UNIQUE_PIECE; // Set the Unique Index Flag - break; - - case FLM_FIELD_TAG: - pTIxd->uiNumFlds++; - - if( bOld11Mode) - { - pvField = pvTempField; - } - - // Need to set IFD_COMPOUND if there is more than one field. - - if( pTIxd->uiNumFlds == 1 && - (pRecord->find( pvTempField, FLM_FIELD_TAG, 2) != NULL)) - { - uiIfdFlags |= IFD_COMPOUND; - } - - pTIfd = pLastTIfd; - if( RC_BAD(rc = DDBuildFldPath( pTDict, &pLastTIfd, - pRecord, pvTempField, uiBaseNum))) - { - goto Exit; - } - - pLastTIfd->uiCompoundPos = uiCompoundPos++; - - if( !pTIfd) // First time? - { - pTIxd->pNextTIfd = pLastTIfd; // Link first IFD - } - else - { - pTIfd->pNextTIfd = pLastTIfd; - } - uiTempIfdFlags = uiIfdFlags; - if( bOld11Mode) - { - // Default is required for each field. - uiTempIfdFlags &= ~IFD_OPTIONAL; - uiTempIfdFlags |= (IFD_REQUIRED_PIECE | IFD_REQUIRED_IN_SET); - } - - for( pvIfdField = pRecord->firstChild( pvTempField); - pvIfdField; pvIfdField = pRecord->nextSibling( pvIfdField)) - { - switch ( pRecord->getFieldID( pvIfdField)) + if( RC_BAD( rc = DDGetReference( pRecord, + pvTempField, NULL, &uiBaseNum))) { - // - // General IFD options only for this field GROUP - // - case FLM_CASE_TAG: - uiNLen = sizeof( szNativeBuf); - (void) pRecord->getNative( pvIfdField, szNativeBuf, &uiNLen); - - if( f_strnicmp( szNativeBuf, "UPPE", 4) == 0) - { - uiTempIfdFlags |= IFD_UPPER; - } - break; - - case FLM_FIELD_TAG: - break; - - case FLM_OPTIONAL_TAG: - if( bOld11Mode) - { - // Old 11 format - default for each field is required. - uiTempIfdFlags |= IFD_OPTIONAL; - uiTempIfdFlags &= ~(IFD_REQUIRED_PIECE | IFD_REQUIRED_IN_SET); - } - // New format default is optional - break; - - case FLM_PAIRED_TAG: - uiTempIfdFlags |= IFD_FIELDID_PAIR; - break; - - case FLM_POST_TAG: - // FUTURE: Post piece where other pieces are not - uiTempIfdFlags |= IFD_POST; - break; - - case FLM_REQUIRED_TAG: - bHasRequiredTag = TRUE; - uiTempIfdFlags &= ~IFD_OPTIONAL; - uiTempIfdFlags |= (IFD_REQUIRED_PIECE | IFD_REQUIRED_IN_SET); - break; - - case FLM_LIMIT_TAG: - if( RC_BAD( pRecord->getUINT( pvIfdField, &uiTemp)) || - uiTemp > IFD_DEFAULT_LIMIT) - { - pLastTIfd->uiLimit = IFD_DEFAULT_LIMIT; - } - else - { - pLastTIfd->uiLimit = uiTemp; - } - break; - - case FLM_UNIQUE_TAG: - // FUTURE: option to select specific unique fields. - uiTempIfdFlags |= IFD_UNIQUE_PIECE; - pTIxd->uiFlags |= IXD_UNIQUE; - break; - - case FLM_USE_TAG: - // All these are exclusive values. Take the last value. - uiNLen = sizeof( szNativeBuf); - (void) pRecord->getNative( pvIfdField, szNativeBuf, &uiNLen); - - if( f_strnicmp( szNativeBuf, "EACH", 4) == 0) - { - uiTempIfdFlags |= IFD_EACHWORD; - uiTempIfdFlags &= ~(IFD_VALUE|IFD_SUBSTRING); - } - else if( f_strnicmp( szNativeBuf, "SUBS", 4) == 0) - { - pTIxd->uiFlags |= IXD_HAS_SUBSTRING; - uiTempIfdFlags |= IFD_SUBSTRING; - uiTempIfdFlags &= ~(IFD_VALUE|IFD_EACHWORD); - if( pLastTIfd->uiLimit == IFD_DEFAULT_LIMIT) - { - pLastTIfd->uiLimit = IFD_DEFAULT_SUBSTRING_LIMIT; - } - } - else if( f_strnicmp( szNativeBuf, "VALU", 4) == 0) - { - uiTempIfdFlags |= IFD_VALUE; - uiTempIfdFlags &= ~(IFD_EACHWORD|IFD_SUBSTRING); - } - else if( f_strnicmp( szNativeBuf, "FIEL", 4) == 0) - { - uiTempIfdFlags |= IFD_CONTEXT; - uiTempIfdFlags &= ~(IFD_VALUE|IFD_EACHWORD|IFD_SUBSTRING); - } - break; - - case FLM_FILTER_TAG: - uiNLen = sizeof( szNativeBuf); - (void) pRecord->getNative( pvIfdField, szNativeBuf, &uiNLen); - - if( f_strnicmp( szNativeBuf, "MINS", 4) == 0) - { - uiTempIfdFlags |= IFD_MIN_SPACES; - } - else if( f_strnicmp( szNativeBuf, "NOUN", 4) == 0) - { - uiTempIfdFlags |= IFD_NO_UNDERSCORE; - } - else if( f_strnicmp( szNativeBuf, "NOSP", 4) == 0) - { - uiTempIfdFlags |= IFD_NO_SPACE; - } - else if( f_strnicmp( szNativeBuf, "NODA", 4) == 0) - { - uiTempIfdFlags |= IFD_NO_DASH; - } - else - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - break; - - default: - if( pRecord->getFieldID( pvIfdField) < FLM_UNREGISTERED_TAGS && - pRecord->getFieldID( pvIfdField) != FLM_COMMENT_TAG) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - break; - } // end switch - } // end for loop parsing all level 3 tags - - // Parse again the level 3 field definitions. Now we - // have the IFD uiFlags value to assign each piece that - // will have the same compound position. - - pLastTIfd->uiFlags |= uiTempIfdFlags; - - for( pvIfdField = pRecord->firstChild( pvTempField); - pvIfdField; pvIfdField = pRecord->nextSibling( pvIfdField)) - { - if( pRecord->getFieldID( pvIfdField) == FLM_FIELD_TAG ) - { - rc = RC_SET( FERR_SYNTAX); goto Exit; } - } - break; // Done parsing "2 field xx yy zz" - - default: - if( bOld11Mode) - { break; } - - if( pRecord->getFieldID( pvTempField) < FLM_UNREGISTERED_TAGS && - pRecord->getFieldID( pvTempField) != FLM_COMMENT_TAG) - + + case FLM_COMBINATIONS_TAG: { rc = RC_SET( FERR_SYNTAX); goto Exit; } - break; - } // end switch - - } // end for loop + + case FLM_POST_TAG: + { + pTIxd->uiFlags |= IXD_HAS_POST; + uiIfdFlags |= IFD_POST; + break; + } + + case FLM_REQUIRED_TAG: + { + break; + } + + case FLM_OPTIONAL_TAG: + { + rc = RC_SET( FERR_SYNTAX); + goto Exit; + } + + case FLM_UNIQUE_TAG: + { + pTIxd->uiFlags |= IXD_UNIQUE; + uiIfdFlags |= IFD_UNIQUE_PIECE; + break; + } + + case FLM_FIELD_TAG: + { + pTIxd->uiNumFlds++; + + if( bOld11Mode) + { + pvField = pvTempField; + } + + // Need to set IFD_COMPOUND if there is more than one field. + + if( pTIxd->uiNumFlds == 1 && + (pRecord->find( pvTempField, FLM_FIELD_TAG, 2) != NULL)) + { + uiIfdFlags |= IFD_COMPOUND; + } + + pTIfd = pLastTIfd; + if( RC_BAD(rc = DDBuildFldPath( pTDict, &pLastTIfd, + pRecord, pvTempField, uiBaseNum))) + { + goto Exit; + } + + pLastTIfd->uiCompoundPos = uiCompoundPos++; + + if( !pTIfd) + { + pTIxd->pNextTIfd = pLastTIfd; + } + else + { + pTIfd->pNextTIfd = pLastTIfd; + } + + uiTempIfdFlags = uiIfdFlags; + + if( bOld11Mode) + { + uiTempIfdFlags &= ~IFD_OPTIONAL; + uiTempIfdFlags |= (IFD_REQUIRED_PIECE | IFD_REQUIRED_IN_SET); + } + + for( pvIfdField = pRecord->firstChild( pvTempField); + pvIfdField; pvIfdField = pRecord->nextSibling( pvIfdField)) + { + switch ( pRecord->getFieldID( pvIfdField)) + { + case FLM_CASE_TAG: + { + uiNLen = sizeof( szNativeBuf); + (void) pRecord->getNative( pvIfdField, szNativeBuf, &uiNLen); + + if( f_strnicmp( szNativeBuf, "UPPE", 4) == 0) + { + uiTempIfdFlags |= IFD_UPPER; + } + break; + } + + case FLM_FIELD_TAG: + { + break; + } + + case FLM_OPTIONAL_TAG: + { + if( bOld11Mode) + { + // Old 11 format - default for each field is required. + uiTempIfdFlags |= IFD_OPTIONAL; + uiTempIfdFlags &= ~(IFD_REQUIRED_PIECE | IFD_REQUIRED_IN_SET); + } + // New format default is optional + break; + } + + case FLM_PAIRED_TAG: + { + uiTempIfdFlags |= IFD_FIELDID_PAIR; + break; + } + + case FLM_POST_TAG: + { + uiTempIfdFlags |= IFD_POST; + break; + } + + case FLM_REQUIRED_TAG: + { + bHasRequiredTag = TRUE; + uiTempIfdFlags &= ~IFD_OPTIONAL; + uiTempIfdFlags |= (IFD_REQUIRED_PIECE | IFD_REQUIRED_IN_SET); + break; + } + + case FLM_LIMIT_TAG: + { + if( RC_BAD( pRecord->getUINT( pvIfdField, &uiTemp)) || + uiTemp > IFD_DEFAULT_LIMIT) + { + pLastTIfd->uiLimit = IFD_DEFAULT_LIMIT; + } + else + { + pLastTIfd->uiLimit = uiTemp; + } + break; + } + + case FLM_UNIQUE_TAG: + { + uiTempIfdFlags |= IFD_UNIQUE_PIECE; + pTIxd->uiFlags |= IXD_UNIQUE; + break; + } + + case FLM_USE_TAG: + { + uiNLen = sizeof( szNativeBuf); + (void) pRecord->getNative( pvIfdField, szNativeBuf, &uiNLen); + + if( f_strnicmp( szNativeBuf, "EACH", 4) == 0) + { + uiTempIfdFlags |= IFD_EACHWORD; + uiTempIfdFlags &= ~(IFD_VALUE|IFD_SUBSTRING); + } + else if( f_strnicmp( szNativeBuf, "SUBS", 4) == 0) + { + pTIxd->uiFlags |= IXD_HAS_SUBSTRING; + uiTempIfdFlags |= IFD_SUBSTRING; + uiTempIfdFlags &= ~(IFD_VALUE|IFD_EACHWORD); + if( pLastTIfd->uiLimit == IFD_DEFAULT_LIMIT) + { + pLastTIfd->uiLimit = IFD_DEFAULT_SUBSTRING_LIMIT; + } + } + else if( f_strnicmp( szNativeBuf, "VALU", 4) == 0) + { + uiTempIfdFlags |= IFD_VALUE; + uiTempIfdFlags &= ~(IFD_EACHWORD|IFD_SUBSTRING); + } + else if( f_strnicmp( szNativeBuf, "FIEL", 4) == 0) + { + uiTempIfdFlags |= IFD_CONTEXT; + uiTempIfdFlags &= ~(IFD_VALUE|IFD_EACHWORD|IFD_SUBSTRING); + } + break; + } + + case FLM_FILTER_TAG: + { + uiNLen = sizeof( szNativeBuf); + (void) pRecord->getNative( pvIfdField, szNativeBuf, &uiNLen); + + if( f_strnicmp( szNativeBuf, "MINS", 4) == 0) + { + uiTempIfdFlags |= IFD_MIN_SPACES; + } + else if( f_strnicmp( szNativeBuf, "NOUN", 4) == 0) + { + uiTempIfdFlags |= IFD_NO_UNDERSCORE; + } + else if( f_strnicmp( szNativeBuf, "NOSP", 4) == 0) + { + uiTempIfdFlags |= IFD_NO_SPACE; + } + else if( f_strnicmp( szNativeBuf, "NODA", 4) == 0) + { + uiTempIfdFlags |= IFD_NO_DASH; + } + else + { + rc = RC_SET( FERR_SYNTAX); + goto Exit; + } + break; + } + + default: + { + if( pRecord->getFieldID( pvIfdField) < FLM_UNREGISTERED_TAGS && + pRecord->getFieldID( pvIfdField) != FLM_COMMENT_TAG) + { + rc = RC_SET( FERR_SYNTAX); + goto Exit; + } + break; + } + } + } + + // Parse again the level 3 field definitions. Now we + // have the IFD uiFlags value to assign each piece that + // will have the same compound position. + + pLastTIfd->uiFlags |= uiTempIfdFlags; + + for( pvIfdField = pRecord->firstChild( pvTempField); + pvIfdField; pvIfdField = pRecord->nextSibling( pvIfdField)) + { + if( pRecord->getFieldID( pvIfdField) == FLM_FIELD_TAG ) + { + rc = RC_SET( FERR_SYNTAX); + goto Exit; + } + } + break; + } + + default: + { + if( bOld11Mode) + { + break; + } + + if( pRecord->getFieldID( pvTempField) < FLM_UNREGISTERED_TAGS && + pRecord->getFieldID( pvTempField) != FLM_COMMENT_TAG) + + { + rc = RC_SET( FERR_SYNTAX); + goto Exit; + } + + break; + } + } + } - // Special case for optional + // Special case for optional + if( !bHasRequiredTag) { // Set all of the IFD flags to IFD_REQUIRED_IN_SET + for( pTIfd = pTIxd->pNextTIfd; pTIfd; pTIfd = pTIfd->pNextTIfd) { pTIfd->uiFlags |= IFD_REQUIRED_IN_SET; } } break; + } default: + { if( pRecord->getFieldID( pvField) < FLM_UNREGISTERED_TAGS && pRecord->getFieldID( pvField) != FLM_COMMENT_TAG) { @@ -1241,6 +1286,7 @@ Parse_Fields: goto Exit; } break; + } } } pDDEntry->vpDef = (void *) pTIxd; @@ -1250,11 +1296,17 @@ Exit: if( RC_BAD(rc)) { if( pvIfdField) + { pTDict->uiBadField = pRecord->getFieldID( pvIfdField); + } else if( pvTempField) + { pTDict->uiBadField = pRecord->getFieldID( pvTempField); + } else if( pvField) + { pTDict->uiBadField = pRecord->getFieldID( pvField); + } } else { @@ -1262,7 +1314,8 @@ Exit: pTDict->uiNewIfds += pTIxd->uiNumFlds; pTDict->uiNewLFiles++; } - return( rc ); + + return( rc); } /**************************************************************************** @@ -1281,18 +1334,18 @@ FSTATIC RCODE DDBuildFldPath( TIFP * pLastFldPath; TIFP * pTIfp; FLMUINT uiNumInFldPath; - char szNameBuf[ 32 ]; + char szNameBuf[ 32]; char * pszCurrent; char szNativeBuf[ FDD_MAX_VALUE_SIZE]; FLMUINT uiBufLen; FLMUINT uiPos; pTDict->uiTotalIfds++; - if( (pTIfd = (TIFD *) GedPoolAlloc( &pTDict->pool, sizeof( TIFD))) == NULL) + if( RC_BAD( rc = pTDict->pool.poolAlloc( sizeof( TIFD), (void **)&pTIfd))) { - rc = RC_SET( FERR_MEM); goto Exit; } + pTIfd->pTIfp = NULL; pTIfd->pNextTIfd = NULL; pTIfd->uiFlags = 0; @@ -1311,13 +1364,11 @@ FSTATIC RCODE DDBuildFldPath( pszCurrent = szNativeBuf; uiNumInFldPath = uiPos = 0; - if( uiBaseNum ) + if( uiBaseNum) { uiNumInFldPath++; - if( (pTIfp = (TIFP *) GedPoolAlloc( &pTDict->pool, - sizeof( TIFP ))) == NULL) + if( RC_BAD( rc = pTDict->pool.poolAlloc( sizeof( TIFP), (void **)&pTIfp))) { - rc = RC_SET( FERR_MEM); goto Exit; } @@ -1337,10 +1388,8 @@ FSTATIC RCODE DDBuildFldPath( break; } - if( (pTIfp = (TIFP *) GedPoolAlloc( &pTDict->pool, - sizeof( TIFP ))) == NULL) + if( RC_BAD( rc = pTDict->pool.poolAlloc( sizeof( TIFP), (void **)&pTIfp))) { - rc = RC_SET( FERR_MEM); goto Exit; } @@ -1463,8 +1512,7 @@ Desc: Parse a data dictionary domain definition for correct syntax & FSTATIC RCODE DDEncDefParse( TDICT * pTDict, DDENTRY * pDDEntry, - FlmRecord * pRecord, - FLMUINT uiDictRecNum) + FlmRecord * pRecord) { RCODE rc = FERR_OK; void * pvField = NULL; @@ -1478,14 +1526,12 @@ FSTATIC RCODE DDEncDefParse( goto Exit; } - if( (pTEncDef = (TENCDEF *)GedPoolAlloc( &pTDict->pool, - sizeof(TENCDEF))) == NULL) + if( RC_BAD( rc = pTDict->pool.poolAlloc( sizeof( TENCDEF), + (void **)&pTEncDef))) { - rc = RC_SET( FERR_MEM); goto Exit; } - pTEncDef->uiRecNum = uiDictRecNum; pTEncDef->uiAlgType = 0; pTEncDef->uiState = 0; pTEncDef->pucKeyInfo = NULL; @@ -1695,7 +1741,7 @@ RCODE fdictReadLFiles( RCODE rc = FERR_OK; LFILE * pLFiles = NULL; LFILE * pLFile; - SCACHE * pSCache; + SCACHE * pSCache = NULL; FLMBOOL bReleaseCache = FALSE; FLMBYTE * pucBlk; FLMUINT uiBlkAddress; @@ -1849,7 +1895,7 @@ RCODE fdictCreate( const char * pDictBuf) { RCODE rc = FERR_OK; - F_FileHdl * pDictFileHdl = NULL; + IF_FileHdl * pDictFileHdl = NULL; FlmRecord * pDictRec = NULL; void * pvField; const char * pucGedBuf; @@ -1858,7 +1904,6 @@ RCODE fdictCreate( FLMUINT uiDrn = 0; FLMUINT uiCurrDictNum; FLMUINT uiLFileCount; - FLMBOOL bFileOpen = FALSE; LFILE DictContLFile; LFILE DictIxLFile; LFILE TempLFile; @@ -1912,12 +1957,11 @@ RCODE fdictCreate( else if( pszDictPath) { pucGedBuf = ucTempBuf; - if( RC_BAD( rc = gv_FlmSysData.pFileSystem->Open( - pszDictPath, F_IO_RDONLY, &pDictFileHdl))) + if( RC_BAD( rc = gv_FlmSysData.pFileSystem->openFile( + pszDictPath, FLM_IO_RDONLY, &pDictFileHdl))) { goto Exit; } - bFileOpen = TRUE; } else { @@ -2045,11 +2089,6 @@ Done_Getting_Dict: Exit: - if( bFileOpen) - { - pDictFileHdl->Close(); - } - if( pDictFileHdl) { pDictFileHdl->Release(); @@ -2147,7 +2186,7 @@ Exit: if( bTDictInitialized) { - GedPoolFree( &tDict.pool); + tDict.pool.poolFree(); } // If we allocated an FDICT and there was an error, free the FDICT. @@ -3057,7 +3096,7 @@ Exit: if( bTDictInitialized) { - GedPoolFree( &tDict.pool); + tDict.pool.poolFree(); } return( rc ); @@ -3072,8 +3111,8 @@ RCODE fdictInitTDict( { RCODE rc = FERR_OK; - f_memset( pTDict, 0, sizeof( TDICT)); // Set elements to zeros. - GedSmartPoolInit( &pTDict->pool, &g_TDictPoolStats); + f_memset( pTDict, 0, sizeof( TDICT)); + pTDict->pool.smartPoolInit( &g_TDictPoolStats); pTDict->pDb = pDb; pTDict->uiVersionNum = pDb->pFile->FileHdr.uiVersionNum; @@ -4268,7 +4307,7 @@ Exit: if( bTDictInitialized) { - GedPoolFree( &tDict.pool); + tDict.pool.poolFree(); } // If we allocated an FDICT and there was an error, free the FDICT. diff --git a/flaim/src/fdict.h b/flaim/src/fdict.h index efc10c3..68dc20c 100644 --- a/flaim/src/fdict.h +++ b/flaim/src/fdict.h @@ -191,7 +191,7 @@ Desc: Contains the dictionary entries through parsing all of the dictionary typedef struct TDICT { FDB * pDb; - POOL pool; // Pool for the DDENTRY allocations. + F_Pool pool; // Pool for the DDENTRY allocations. LFILE * pLFile; // Dictionary container LFile FDICT * pDict; // Pointer to new dictionary. FLMBOOL bWriteToDisk; // Flag indicating if PCODE should be diff --git a/flaim/src/fdir.h b/flaim/src/fdir.h deleted file mode 100644 index 831b47b..0000000 --- a/flaim/src/fdir.h +++ /dev/null @@ -1,186 +0,0 @@ -//------------------------------------------------------------------------- -// Desc: File system directory class - definitions. -// Tabs: 3 -// -// Copyright (c) 1998-2006 Novell, Inc. All Rights Reserved. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of version 2 of the GNU General Public -// License as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, contact Novell, Inc. -// -// To contact Novell about this file by physical or electronic mail, -// you may find current contact information at www.novell.com -// -// $Id: fdir.h 12329 2006-01-20 17:49:30 -0700 (Fri, 20 Jan 2006) ahodgkinson $ -//------------------------------------------------------------------------- - -#ifndef FDIR_H -#define FDIR_H - -#include "fpackon.h" -// IMPORTANT NOTE: No other include files should follow this one except -// for fpackoff.h - -class F_DirHdl; // Forward Reference -typedef F_DirHdl * F_DirHdl_p; - -#if defined( FLM_WIN) - - typedef struct F_IO_FIND_DATA - { - HANDLE findHandle; - WIN32_FIND_DATA findBuffer; - char szSearchPath[ F_PATH_MAX_SIZE]; - FLMUINT uiSearchAttrib; - } F_IO_FIND_DATA; - - #define F_IO_FA_NORMAL FILE_ATTRIBUTE_NORMAL /* Normal file */ - #define F_IO_FA_RDONLY FILE_ATTRIBUTE_READONLY /* Read only attribute */ - #define F_IO_FA_HIDDEN FILE_ATTRIBUTE_HIDDEN /* Hidden file */ - #define F_IO_FA_SYSTEM FILE_ATTRIBUTE_SYSTEM /* System file */ - #define F_IO_FA_VOLUME FILE_ATTRIBUTE_VOLUME /* Volume label */ - #define F_IO_FA_DIRECTORY FILE_ATTRIBUTE_DIRECTORY /* Directory */ - #define F_IO_FA_ARCHIVE FILE_ATTRIBUTE_ARCHIVE /* Archive */ - -#elif defined( FLM_UNIX) - - typedef struct F_IO_FIND_DATA - { - mode_t mode_flag; - struct stat FileStat; - char name[ F_PATH_MAX_SIZE+1]; - char search_path[ F_PATH_MAX_SIZE+1]; - char full_path[ F_PATH_MAX_SIZE]; - char pattern_str[ F_PATH_MAX_SIZE]; - char dirpath[ F_PATH_MAX_SIZE]; - glob_t globbuf; - } F_IO_FIND_DATA; - - #define F_IO_FA_NORMAL 0x01 /* Normal file, no attributes */ - #define F_IO_FA_RDONLY 0x02 /* Read only attribute */ - #define F_IO_FA_HIDDEN 0x04 /* Hidden file */ - #define F_IO_FA_SYSTEM 0x08 /* System file */ - #define F_IO_FA_VOLUME 0x10 /* Volume label */ - #define F_IO_FA_DIRECTORY 0x20 /* Directory */ - #define F_IO_FA_ARCHIVE 0x40 /* Archive */ - -#elif !defined( FLM_NLM) - - #error Platform not supported - -#endif - -#if defined( FLM_WIN) || defined( FLM_UNIX) -RCODE f_fileFindFirst( - const char * pszSearchPath, - FLMUINT uiSearchAttrib, - F_IO_FIND_DATA * find_data, - char * pszFoundPath, - FLMUINT * puiFoundAttrib); - -RCODE f_fileFindNext( - F_IO_FIND_DATA * pFindData, - char * pszFoundPath, - FLMUINT * puiFoundAttrib); - -void f_fileFindClose( - F_IO_FIND_DATA * pFindData); -#endif - -/**************************************************************************** -Desc: Implementation of the F_Directory interface for Win and Unix -****************************************************************************/ -class F_DirHdlImp : public F_DirHdl -{ -public: - - F_DirHdlImp() - { - m_rc = FERR_OK; - m_bFirstTime = TRUE; - m_bFindOpen = FALSE; - m_uiAttrib = 0; - m_ucPattern[ 0] = '\0'; -#ifdef FLM_NLM - m_lVolumeNumber = 0; - m_lCurrentEntryNumber = 0xFFFFFFFFL; -#endif - } - - virtual ~F_DirHdlImp() - { -#ifndef FLM_NLM - if( m_bFindOpen) - { - f_fileFindClose( &m_FindData); - } -#endif - } - - virtual RCODE Next( void); - - const char * CurrentItemName( void); - - FLMUINT CurrentItemSize( void); - - FLMBOOL CurrentItemIsDir( void); - - FINLINE void CurrentItemPath( - char * pszPath) - { - if( RC_OK( m_rc)) - { - f_strcpy( pszPath, m_DirectoryPath); -#ifdef FLM_NLM - f_pathAppend( pszPath, CurrentItemName()); -#else - f_pathAppend( pszPath, m_szFileName); -#endif - } - } - - RCODE OpenDir( - const char * pszPath, - const char * pszPattern); - - RCODE CreateDir( - const char * pszDirPath); - - RCODE RemoveDir( - const char * pszDirPath); - -private: - - RCODE _CreateDir( - const char * pszDirPath); - - char m_DirectoryPath[ F_PATH_MAX_SIZE]; - char m_ucPattern[ F_PATH_MAX_SIZE]; - RCODE m_rc; - FLMBOOL m_bFirstTime; - FLMBOOL m_bFindOpen; - FLMBOOL m_EOF; - char m_szFileName[ F_PATH_MAX_SIZE]; - FLMUINT m_uiAttrib; -#ifndef FLM_NLM - F_IO_FIND_DATA m_FindData; -#else - LONG m_lVolumeNumber; - LONG m_lDirectoryNumber; - LONG m_lCurrentEntryNumber; - struct DirectoryStructure * m_pCurrentItem; - char m_ucTempBuffer[ F_FILENAME_SIZE]; -#endif -}; - -#include "fpackoff.h" - -#endif diff --git a/flaim/src/fdynbtre.cpp b/flaim/src/fdynbtre.cpp deleted file mode 100644 index 648adfc..0000000 --- a/flaim/src/fdynbtre.cpp +++ /dev/null @@ -1,1069 +0,0 @@ -//------------------------------------------------------------------------- -// Desc: Dynamic result set - b-tree implementation. -// Tabs: 3 -// -// Copyright (c) 1998-2001,2003,2005-2006 Novell, Inc. All Rights Reserved. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of version 2 of the GNU General Public -// License as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, contact Novell, Inc. -// -// To contact Novell about this file by physical or electronic mail, -// you may find current contact information at www.novell.com -// -// $Id: fdynbtre.cpp 12329 2006-01-20 17:49:30 -0700 (Fri, 20 Jan 2006) ahodgkinson $ -//------------------------------------------------------------------------- - -#include "flaimsys.h" - -// Make sure that the extension is in lower case characters. - -#define FRSET_FILENAME_EXTENSION "frs" - -/**************************************************************************** -Desc: -****************************************************************************/ -FFixedBlk::FFixedBlk() -{ - m_fnCompare = NULL; - m_UserValue = (void *) 4; - m_uiPosition = DYNSSET_POSITION_NOT_SET; - m_bDirty = FALSE; - m_pucBlkBuf = NULL; -} - -/**************************************************************************** -Desc: -****************************************************************************/ -FBtreeRoot::FBtreeRoot() -{ - int i; - - m_pFileHdl = NULL; - m_szIoPath[ 0] = 0; - m_eBlkType = ACCESS_BTREE_ROOT; - m_uiEntryOvhd = 4; - m_uiLRUCount = 1; - m_uiLevels = 1; - m_uiNewBlkAddr = 0; - m_uiHighestWrittenBlkAddr = 0; - m_uiTotalEntries = 0; - - // Initialize the cache blocks. - - for( i = 0; i < FBTREE_CACHE_BLKS; i++) - { - m_CacheBlks[i].uiBlkAddr = 0xFFFFFFFF; - m_CacheBlks[i].uiLRUValue = 0; - m_CacheBlks[i].pBlk = NULL; - } -} - -/**************************************************************************** -Desc: -****************************************************************************/ -FBtreeRoot::~FBtreeRoot() -{ - int i; - - closeFile(); - - for( i = 0; i < FBTREE_CACHE_BLKS; i++) - { - if( m_CacheBlks[i].pBlk) - { - m_CacheBlks[i].pBlk->Release(); - } - } -} - -/**************************************************************************** -Desc: Allocate structures and set entry size. -****************************************************************************/ -RCODE FBtreeLeaf::setup( - FLMUINT uiEntrySize) -{ - RCODE rc = FERR_OK; - - if( RC_BAD( rc = f_calloc( DYNSSET_BLOCK_SIZE, &m_pucBlkBuf))) - goto Exit; - - m_uiEntrySize = uiEntrySize; - m_UserValue = (void *) uiEntrySize; - reset( ACCESS_BTREE_LEAF); - nextBlk( FBTREE_END); - prevBlk( FBTREE_END); - lemBlk( FBTREE_END); - reset( ACCESS_BTREE_LEAF); -Exit: - return( rc); -} - -/**************************************************************************** -Desc: Allocate structures and set entry size. -Ret: FERR_OK or memory error -****************************************************************************/ -RCODE FBtreeNonLeaf::setup( - FLMUINT uiEntrySize) -{ - RCODE rc; - - if( RC_BAD( rc = f_calloc( DYNSSET_BLOCK_SIZE, &m_pucBlkBuf))) - goto Exit; - - m_uiEntrySize = uiEntrySize; - m_UserValue = (void *) uiEntrySize; - reset( ACCESS_BTREE_NON_LEAF); - nextBlk( FBTREE_END); - prevBlk( FBTREE_END); - lemBlk( FBTREE_END); - -Exit: - - return( rc); -} - -/**************************************************************************** -Desc: Allocate structures and set entry size. -****************************************************************************/ -RCODE FBtreeRoot::setup( - FLMUINT uiEntrySize, - const char * pszIoPath) -{ - RCODE rc; - - if( RC_BAD( rc = f_calloc( DYNSSET_BLOCK_SIZE, &m_pucBlkBuf))) - goto Exit; - - m_uiEntrySize = uiEntrySize; - m_UserValue = (void *) uiEntrySize; - f_strcpy( m_szIoPath, pszIoPath); - reset( ACCESS_BTREE_ROOT); - nextBlk( FBTREE_END); - prevBlk( FBTREE_END); - lemBlk( FBTREE_END); - -Exit: - - return( rc); -} - -/**************************************************************************** -Desc: Setup the block as a new block -****************************************************************************/ -void FBtreeBlk::reset( - FBlkTypes blkType) -{ - - m_eBlkType = blkType; - if( (blkType == ACCESS_BTREE_ROOT) || - (blkType == ACCESS_BTREE_NON_LEAF )) - { - m_uiEntryOvhd = 4; - } - else - { - m_uiEntryOvhd = 0; - } - m_uiNumSlots = (DYNSSET_BLOCK_SIZE - sizeof( FixedBlkHdr)) / - ( m_uiEntrySize + m_uiEntryOvhd); - entryCount( 0); - m_uiPosition = DYNSSET_POSITION_NOT_SET; - m_bDirty = FALSE; -} - -/**************************************************************************** -Desc: Return the next entry in the result set. If the result set - is not positioned then the first entry will be returned. -****************************************************************************/ -RCODE FBtreeBlk::getNext( - void * vpEntryBuffer) -{ - RCODE rc = FERR_OK; - FLMUINT uiPos = m_uiPosition; - - // Position to the next/first entry. - if( uiPos == DYNSSET_POSITION_NOT_SET) - { - uiPos = 0; - } - else - { - if( ++uiPos > entryCount()) - { - rc = RC_SET( FERR_EOF_HIT); - goto Exit; - } - } - f_memcpy( vpEntryBuffer, ENTRY_POS(uiPos), m_uiEntrySize); - m_uiPosition = uiPos; - -Exit: - return( rc); -} - -/**************************************************************************** -Desc: Return the last entry in the result set. -****************************************************************************/ -RCODE FBtreeBlk::getLast( - void * vpEntryBuffer) -{ - RCODE rc = FERR_OK; - FLMUINT uiPos = entryCount(); - - // Position to the next/first entry. - - if( uiPos == 0) - { - rc = RC_SET( FERR_EOF_HIT); - goto Exit; - } - - uiPos--; - f_memcpy( vpEntryBuffer, ENTRY_POS(uiPos), m_uiEntrySize); - m_uiPosition = uiPos; - -Exit: - return( rc); -} - -/**************************************************************************** -Desc: Search a btree. Position for get* or for insert. -****************************************************************************/ -RCODE FBtreeRoot::search( - void * vpEntry, - void * vpFoundEntry) -{ - RCODE rc = FERR_OK; - FLMUINT uiCurLevel = m_uiLevels - 1; // Min 2 levels - FLMUINT uiBlkAddr; - - // Reset the stack - only needed for debugging. - //f_memset( m_BTStack, 0, sizeof(FBtreeBlk *) * FBTREE_MAX_LEVELS); - - // Search this root block. - m_BTStack[ uiCurLevel] = this; - (void) searchEntry( vpEntry, &uiBlkAddr); - - while( uiCurLevel--) - { - // Read the next block and place at uiCurLevel (backwards from FS). - if( RC_BAD( rc = readBlk( uiBlkAddr, - uiCurLevel ? ACCESS_BTREE_NON_LEAF : ACCESS_BTREE_LEAF, - &m_BTStack[ uiCurLevel] ))) - goto Exit; - - // Set the rc - only for the leaf block, otherwise rc should be ignored. - rc = m_BTStack[ uiCurLevel]->searchEntry( vpEntry, &uiBlkAddr, - uiCurLevel ? NULL : vpFoundEntry); - } - -Exit: - return( rc); -} - -/**************************************************************************** -Desc: Search a single block tree. Position for get* or for insert. - Do a binary search on all of the entries to find a match. - If no match then position to the entry where an insert - will take place. -****************************************************************************/ -RCODE FBtreeBlk::searchEntry( - void * vpEntry, - FLMUINT * puiChildAddr, - void * vpFoundEntry) -{ - RCODE rc = RC_SET( FERR_NOT_FOUND); - FLMUINT uiLow, uiMid, uiHigh, uiTblSize; - FLMINT iCompare; - - // check for zero entries. - if( !entryCount()) - { - uiMid = 0; - goto Exit; - } - uiHigh = uiTblSize = entryCount() - 1; - uiLow = 0; - for(;;) - { - uiMid = (uiLow + uiHigh) >> 1; // (uiLow + uiHigh) / 2 - - // Use compare routine - - if( m_fnCompare) - { - iCompare = m_fnCompare( vpEntry, ENTRY_POS( uiMid), (size_t)m_UserValue); - } - else - { - iCompare = f_memcmp( vpEntry, ENTRY_POS( uiMid), (size_t)m_UserValue); - } - - if( !iCompare) - { - if( vpFoundEntry) - { - f_memcpy( vpFoundEntry, ENTRY_POS( uiMid), m_uiEntrySize); - } - rc = FERR_OK; - goto Exit; - } - // Check if we are done - where wLow equals uiHigh or mid is at end. - - if( iCompare < 0) - { - if( (uiMid == uiLow) || (uiLow == uiHigh)) - break; - uiHigh = uiMid - 1; // Too high - } - else - { - if( (uiMid == uiHigh) || (uiLow == uiHigh)) - { - // Go up one for the correct position? - uiMid++; - break; - } - uiLow = uiMid + 1; /* Too low */ - } - } - -Exit: - m_uiPosition = uiMid; - if( puiChildAddr && blkType() != ACCESS_BTREE_LEAF) - { - if( uiMid == entryCount()) - { - *puiChildAddr = lemBlk(); - } - else - { - FLMBYTE * pChildAddr = ENTRY_POS( uiMid) + m_uiEntrySize; - *puiChildAddr = FB2UD( pChildAddr); - } - } - - return( rc); -} - -/**************************************************************************** -Desc: Insert the entry into the btree - should be positioned -****************************************************************************/ -RCODE FBtreeRoot::insert( - void * vpEntry) -{ - RCODE rc = FERR_OK; - FLMUINT uiCurLevel; - FLMBYTE ucEntryBuf[FBTREE_MAX_LEVELS][DYNSSET_MAX_FIXED_ENTRY_SIZE]; - FLMUINT uiNewBlkAddr; - - if( RC_OK( rc = m_BTStack[0]->insert( vpEntry))) - goto Exit; - - /* - Failed to input at the left level. Do block split(s). - This is an iterative and NOT a recursive split algorithm. - The debugging, and cases to test should be lots easier this way. - */ - - f_memcpy( ucEntryBuf[0], vpEntry, m_uiEntrySize); - uiCurLevel = 0; - uiNewBlkAddr = FBTREE_END; - for(;;) - { - // Split while adding the element. - if( RC_BAD( rc = (m_BTStack[uiCurLevel])->split( - this, - ucEntryBuf[ uiCurLevel], - uiNewBlkAddr, - ucEntryBuf[ uiCurLevel+1], - &uiNewBlkAddr))) - goto Exit; - - uiCurLevel++; - flmAssert( uiCurLevel < m_uiLevels); - - if( RC_OK( rc = m_BTStack[uiCurLevel]->insertEntry( - ucEntryBuf[uiCurLevel], uiNewBlkAddr))) - goto Exit; - // Only returns FERR_OK or FAILURE. - - // Root split? - if( uiCurLevel + 1 == m_uiLevels) - { - flmAssert( m_uiLevels + 1 <= FBTREE_MAX_LEVELS); - if( m_uiLevels + 1 > FBTREE_MAX_LEVELS) - { - rc = RC_SET( FERR_BTREE_FULL); - goto Exit; - } - - // Need to split the root block. - rc = ((FBtreeRoot *)m_BTStack[uiCurLevel])->split( - ucEntryBuf[uiCurLevel], uiNewBlkAddr ); - break; - } - } -Exit: - if( RC_OK(rc)) - { - m_uiTotalEntries++; - } - return( rc); -} - -/**************************************************************************** -Desc: Insert the entry into the buffer. -****************************************************************************/ -RCODE FBtreeBlk::insertEntry( - void * vpEntry, - FLMUINT uiChildAddr) -{ - RCODE rc = FERR_OK; - FLMBYTE * pucCurEntry; - FLMUINT uiShiftBytes; - - if( entryCount() >= m_uiNumSlots) // full - { - rc = RC_SET( FERR_FAILURE); - goto Exit; - } - flmAssert( m_uiPosition != DYNSSET_POSITION_NOT_SET); - pucCurEntry = ENTRY_POS( m_uiPosition); - if( (uiShiftBytes = (entryCount() - m_uiPosition) * - (m_uiEntrySize + m_uiEntryOvhd)) != 0) - { - // Big hairy assert. Finds coding bugs and corruptions. - flmAssert( m_uiPosition * (m_uiEntrySize + m_uiEntryOvhd) + - uiShiftBytes < DYNSSET_BLOCK_SIZE - sizeof( FixedBlkHdr)); - - f_memmove( pucCurEntry + m_uiEntrySize + m_uiEntryOvhd, - pucCurEntry, uiShiftBytes); - } - f_memcpy( pucCurEntry, vpEntry, m_uiEntrySize); - if( m_uiEntryOvhd) - { - UD2FBA( (FLMUINT32)uiChildAddr, &pucCurEntry[m_uiEntrySize]); - } - entryCount( entryCount() + 1); - m_uiPosition++; - m_bDirty = TRUE; - -Exit: - return( rc); -} - - -/**************************************************************************** -Desc: Move first half of entries into new block. Reset previous block - to point to new block. Add new last entry in new block to parent. - Fixup prev/next linkages. -****************************************************************************/ -RCODE FBtreeBlk::split( - FBtreeRoot * pRoot, - FLMBYTE * pCurEntry, // (in) Contains entry to insert - FLMUINT uiCurBlkAddr, // (in) Blk addr if non-leaf - FLMBYTE * pParentEntry, // (out) Entry to insert into parent. - FLMUINT * puiNewBlkAddr) // (out) New blk addr to insert into parent. -{ - RCODE rc; - FBtreeBlk * pPrevBlk; - FBtreeBlk * pNewBlk = NULL; - FLMBYTE * pEntry = NULL; - FLMBYTE * pMidEntry; - FLMBYTE * pChildAddr; - FLMUINT uiChildAddr; - FLMUINT uiPrevBlkAddr; - FLMUINT uiMid, uiPos; - FLMUINT uiMoveBytes; - FLMBOOL bInserted = FALSE; - - // Allocate a new block for the split. - if( RC_BAD( rc = pRoot->newBlk( &pNewBlk, blkType() ))) - goto Exit; - pNewBlk->AddRef(); // Pin the block - may get flushed out. - - /* - This moves the first half into the new block. It is easier to move - the last half into the new block, but that would force the parent - entry to be changed. This may take a little longer, but it is much - more easier to code. - */ - - // Call search entry once just to setup for insert. - (void) pNewBlk->searchEntry( ENTRY_POS( 0)); - - // get the count and move more then half into the new block. - uiMid = (entryCount() + 5) >> 1; - uiChildAddr = FBTREE_END; - - for( uiPos = 0; uiPos < uiMid; uiPos++) - { - pEntry = ENTRY_POS( uiPos); - if( blkType() != ACCESS_BTREE_LEAF) - { - pChildAddr = pEntry + m_uiEntrySize; - uiChildAddr = (FLMUINT)FB2UD(pChildAddr); - } - // m_uiPosition automatically gets incremented. - if( RC_BAD( rc = pNewBlk->insertEntry( pEntry, uiChildAddr))) - { - // Should not error. - flmAssert(0); - goto Exit; - } - } - if( m_uiPosition < uiMid) - { - // Insert this entry now - bInserted = TRUE; - (void) pNewBlk->searchEntry( pCurEntry); - if( RC_BAD( rc = pNewBlk->insertEntry( pCurEntry, uiCurBlkAddr))) - goto Exit; - } - - // Let caller insert into parent entry. This rids us of recursion. - f_memcpy( pParentEntry, pEntry, m_uiEntrySize); - - // Move the rest down - pEntry = ENTRY_POS( 0); - pMidEntry = ENTRY_POS( uiMid); - - entryCount( entryCount() - uiMid); - uiMoveBytes = entryCount() * (m_uiEntrySize + m_uiEntryOvhd); - flmAssert( uiMoveBytes < DYNSSET_BLOCK_SIZE - sizeof( FixedBlkHdr)); - f_memmove( pEntry, pMidEntry, uiMoveBytes); - - if( !bInserted) - { - //m_uiPosition -= uiMid; - (void) searchEntry( pCurEntry); - if( RC_BAD( rc = insertEntry( pCurEntry, uiCurBlkAddr))) - goto Exit; - } - - // VISIT: Could position stack to point to current element to insert. - - // Fixup the prev/next block linkages. - if( prevBlk() != FBTREE_END) - { - if( RC_BAD( rc = pRoot->readBlk( prevBlk(), blkType(), &pPrevBlk ))) - goto Exit; - - pPrevBlk->nextBlk( pNewBlk->blkAddr()); - uiPrevBlkAddr = pPrevBlk->blkAddr(); - } - else - { - uiPrevBlkAddr = FBTREE_END; - } - pNewBlk->prevBlk( uiPrevBlkAddr); - pNewBlk->nextBlk( blkAddr()); - prevBlk( pNewBlk->blkAddr()); - - *puiNewBlkAddr = pNewBlk->blkAddr(); - -Exit: - if( pNewBlk) - pNewBlk->Release(); - - return( rc); -} - -/**************************************************************************** -Desc: Reinsert all entries given a new root block. - Caller will release 'this'. Used ONLY for building the first - ROOT and two leaves of the tree. -****************************************************************************/ -RCODE FBtreeLeaf::split( - FBtreeRoot * pNewRoot) // New Non-leaf root -{ - RCODE rc; - FLMBYTE * pEntry; - FLMUINT uiPos; - FLMUINT uiEntryCount = entryCount(); - FLMUINT uiMid = (uiEntryCount + 1) >> 1; - - if( RC_BAD( rc = pNewRoot->setupTree( ENTRY_POS(uiMid), - ACCESS_BTREE_LEAF, NULL, NULL))) - goto Exit; - - for( uiPos = 0; uiPos < uiEntryCount; uiPos++) - { - pEntry = ENTRY_POS( uiPos); - if( (rc = pNewRoot->search( pEntry)) != FERR_NOT_FOUND) - { - rc = RC_SET( FERR_FAILURE); - goto Exit; - } - if( RC_BAD( rc = pNewRoot->insert( pEntry))) - goto Exit; - } - -Exit: - return( rc); -} - -/**************************************************************************** -Desc: Split the root block and make two new non-leaf blocks. - The secret here is that the root block never moves (cheers!). - This takes a little longer but is worth the work because the - root block never goes out to disk and is not in the cache. -****************************************************************************/ -RCODE FBtreeRoot::split( - void * vpCurEntry, - FLMUINT uiCurChildAddr) -{ - RCODE rc = FERR_OK; - FLMBYTE * pEntry; - FLMBYTE * pChildAddr; - FBtreeBlk * pLeftBlk; - FBtreeBlk * pRightBlk; - FBtreeBlk * pBlk; - FLMUINT uiChildAddr; - FLMUINT uiPos; - FLMUINT uiEntryCount = entryCount(); - FLMUINT uiMid = (uiEntryCount + 1) >> 1; - - if( RC_BAD( rc = setupTree( NULL, ACCESS_BTREE_NON_LEAF, - &pLeftBlk, &pRightBlk))) - goto Exit; - - // Call search entry once just to setup for insert. - (void) pLeftBlk->searchEntry( ENTRY_POS( 0)); - // Take the entries from the root block and move into leafs. - for( uiPos = 0; uiPos <= uiMid; uiPos++) - { - pEntry = ENTRY_POS( uiPos); - pChildAddr = pEntry + m_uiEntrySize; - uiChildAddr = (FLMUINT)FB2UD(pChildAddr); - - if( RC_BAD( rc = pLeftBlk->insertEntry( pEntry, uiChildAddr))) - goto Exit; - } - - // Call search entry once just to setup for insert. - (void) pRightBlk->searchEntry( ENTRY_POS( 0)); - - for( uiPos = uiMid + 1; uiPos < uiEntryCount; uiPos++) - { - pEntry = ENTRY_POS( uiPos); - pChildAddr = pEntry + m_uiEntrySize; - uiChildAddr = (FLMUINT)FB2UD(pChildAddr); - - if( (rc = pRightBlk->searchEntry( pEntry )) != FERR_NOT_FOUND) - { - rc = RC_SET( FERR_FAILURE); - goto Exit; - } - if( RC_BAD( rc = pRightBlk->insertEntry( pEntry, uiChildAddr))) - goto Exit; - } - - // Reset the root block and insert new midpoint. - entryCount( 0); - lemBlk( pRightBlk->blkAddr()); // Duplicated just in case. - pEntry = ENTRY_POS( uiMid); - - if( (rc = searchEntry( pEntry )) != FERR_NOT_FOUND) - { - rc = RC_SET( FERR_FAILURE); - goto Exit; - } - if( RC_BAD( rc = insertEntry( pEntry, pLeftBlk->blkAddr() ))) - goto Exit; - - // Insert the current entry (parameters) into the left or right blk. - // This could be done a number of different ways. - - (void) searchEntry( vpCurEntry, &uiChildAddr); - - if( RC_BAD( rc = readBlk( uiChildAddr, ACCESS_BTREE_NON_LEAF, &pBlk))) - { - goto Exit; - } - - (void) pBlk->searchEntry( vpCurEntry); - - if( RC_BAD( rc = pBlk->insertEntry( vpCurEntry, uiCurChildAddr))) - { - goto Exit; - } - -Exit: - - return( rc); -} - -/**************************************************************************** -Desc: Setup two child blocks for a root block. -****************************************************************************/ -RCODE FBtreeRoot::setupTree( - FLMBYTE * pMidEntry, - FBlkTypes blkType, - FBtreeBlk ** ppLeftBlk, - FBtreeBlk ** ppRightBlk) -{ - RCODE rc = FERR_OK; - FBtreeBlk * pLeftBlk = NULL; - FBtreeBlk * pRightBlk = NULL; - - if( RC_BAD( rc = newBlk( &pLeftBlk, blkType ))) - goto Exit; - - if( RC_BAD( rc = newBlk( &pRightBlk, blkType ))) - goto Exit; - - if( blkType == ACCESS_BTREE_NON_LEAF) - { - ((FBtreeNonLeaf *)pRightBlk)->lemBlk( lemBlk()); - } - - // Fix up the linkages - pLeftBlk->nextBlk( pRightBlk->blkAddr()); - pRightBlk->prevBlk( pLeftBlk->blkAddr()); - lemBlk( pRightBlk->blkAddr()); - - if( pMidEntry) - { - // Add the midentry to the root block. Search to position and insert. - searchEntry( pMidEntry); - insertEntry( pMidEntry, pLeftBlk->blkAddr()); - } - m_uiLevels++; - - if( ppLeftBlk) - { - *ppLeftBlk = pLeftBlk; - } - if( ppRightBlk) - { - *ppRightBlk = pRightBlk; - } - -Exit: - return( rc); -} - -/**************************************************************************** -Desc: Read in the block or get it from the cache. -****************************************************************************/ -RCODE FBtreeRoot::readBlk( - FLMUINT uiBlkAddr, // Blk address to read - FBlkTypes blkType, // Expected access type to read - FBtreeBlk **ppBlk) // (out) Return block -{ - RCODE rc = FERR_OK; - FLMUINT uiPos; - FLMUINT uiLRUValue = (FLMUINT)~0; - FLMUINT uiLRUPos = 0; - FBtreeBlk * pNewBlk; - - for( uiPos = 0; uiPos < FBTREE_CACHE_BLKS; uiPos++) - { - if( m_CacheBlks[uiPos].uiBlkAddr == uiBlkAddr) - { - goto Exit; - } - // The ref count is used for pinning the block. - if( (m_CacheBlks[uiPos].pBlk) && - (m_CacheBlks[uiPos].pBlk->getRefCount() == 1) && - (uiLRUValue > m_CacheBlks[uiPos].uiLRUValue)) - { - uiLRUValue = m_CacheBlks[uiPos].uiLRUValue; - uiLRUPos = uiPos; - } - // There better not be a hole by this point. - flmAssert( m_CacheBlks[uiPos].pBlk != NULL); - } - uiPos = uiLRUPos; - - // Read from disk? - flmAssert( m_pFileHdl != NULL); - - if( RC_BAD( rc = newCacheBlk( uiPos, &pNewBlk, blkType))) - goto Exit; - - // Pick the LRU block and make that object do the reading - // so it can reset all internals and get used to being a different blk. - - pNewBlk->blkAddr( uiBlkAddr); - m_CacheBlks[uiPos].uiBlkAddr = uiBlkAddr; - m_CacheBlks[uiPos].uiLRUValue = m_uiLRUCount++; - - if( RC_BAD( rc = pNewBlk->readBlk( m_pFileHdl, uiBlkAddr))) - { - // Release the block because the reset() changed the object type. - // May hit the assert above. - m_CacheBlks[uiPos].pBlk->Release(); - m_CacheBlks[uiPos].pBlk = NULL; - goto Exit; - } - -Exit: - if( RC_OK(rc)) - { - *ppBlk = m_CacheBlks[uiPos].pBlk; - m_CacheBlks[uiPos].uiLRUValue = m_uiLRUCount++; - } - return( rc); -} - -/**************************************************************************** -Desc: Get a new block using an exising or newly allocated block from - the cache. Initializes the block. May be leaf or non-leaf - but NOT the root block. -****************************************************************************/ -RCODE FBtreeRoot::newBlk( - FBtreeBlk ** ppBlk, - FBlkTypes blkType) -{ - RCODE rc = FERR_OK; - FLMUINT uiLRUValue = (FLMUINT)~0; - FLMUINT uiPos; - FLMUINT uiLRUPos = 0; - FBtreeBlk * pNewBlk; - - for( uiPos = 0; uiPos < FBTREE_CACHE_BLKS; uiPos++) - { - // The ref count is used for pinning the block. - if( (getRefCount() == 1) && - (uiLRUValue > m_CacheBlks[uiPos].uiLRUValue)) - { - uiLRUValue = m_CacheBlks[uiPos].uiLRUValue; - uiLRUPos = uiPos; - } - // use the first hole. - if( m_CacheBlks[uiPos].pBlk == NULL) - { - uiLRUPos = uiPos; - break; - } - } - uiPos = uiLRUPos; - if( RC_BAD( rc = newCacheBlk( uiPos, &pNewBlk, blkType))) - goto Exit; - - pNewBlk->blkAddr( newBlkAddr()); - m_CacheBlks[uiPos].uiBlkAddr = pNewBlk->blkAddr(); - m_CacheBlks[uiPos].uiLRUValue = m_uiLRUCount++; - - pNewBlk->entryCount(0); - pNewBlk->lemBlk( FBTREE_END); - pNewBlk->nextBlk( FBTREE_END); - pNewBlk->prevBlk( FBTREE_END); - *ppBlk = pNewBlk; - -Exit: - return( rc); -} - -/**************************************************************************** -Desc: Release the existing cache block and setup and alloc new blk. -****************************************************************************/ -RCODE FBtreeRoot::newCacheBlk( - FLMUINT uiCachePos, - FBtreeBlk ** ppBlk, - FBlkTypes blkType) -{ - RCODE rc = FERR_OK; - FBtreeBlk * pNewBlk = NULL; - - if( m_CacheBlks[uiCachePos].pBlk) - { - if( m_CacheBlks[uiCachePos].pBlk->isDirty()) - { - if( RC_BAD( rc = writeBlk( uiCachePos))) - goto Exit; - } - } - - if( (m_CacheBlks[uiCachePos].pBlk != NULL) && - m_CacheBlks[uiCachePos].pBlk->blkType() == blkType) - { - // If block is of the same type then reset it and use it. - pNewBlk = m_CacheBlks[uiCachePos].pBlk; - pNewBlk->reset( blkType); - *ppBlk = pNewBlk; - goto Exit; - } - - if( m_CacheBlks[uiCachePos].pBlk) - { - m_CacheBlks[uiCachePos].pBlk->Release(); - } - if( blkType == ACCESS_BTREE_LEAF) - { - FBtreeLeaf * pLeafBlk; - if( (pLeafBlk = f_new FBtreeLeaf) == NULL) - { - rc = RC_SET( FERR_MEM); - goto Exit; - } - if( RC_BAD( rc = pLeafBlk->setup( m_uiEntrySize))) - { - pLeafBlk->Release(); - goto Exit; - } - pLeafBlk->setCompareFunc( m_fnCompare, m_UserValue); - pNewBlk = (FBtreeBlk *) pLeafBlk; - } - else - { - FBtreeNonLeaf * pNonLeafBlk; - if( (pNonLeafBlk = f_new FBtreeNonLeaf) == NULL) - { - rc = RC_SET( FERR_MEM); - goto Exit; - } - if( RC_BAD( rc = pNonLeafBlk->setup( m_uiEntrySize))) - { - pNonLeafBlk->Release(); - goto Exit; - } - pNonLeafBlk->setCompareFunc( m_fnCompare, m_UserValue); - pNewBlk = (FBtreeBlk *) pNonLeafBlk; - } - m_CacheBlks[uiCachePos].pBlk = pNewBlk; - *ppBlk = pNewBlk; - -Exit: - return( rc); -} - -/**************************************************************************** -Desc: Read the block from disk. -****************************************************************************/ - -RCODE FBtreeBlk::readBlk( - F_FileHdl * pFileHdl, - FLMUINT uiBlkAddr) -{ - RCODE rc; - FLMUINT uwBytesRead; - - if( RC_BAD( rc = pFileHdl->Read( - uiBlkAddr * DYNSSET_BLOCK_SIZE, DYNSSET_BLOCK_SIZE, - m_pucBlkBuf, &uwBytesRead))) - { - flmAssert(0); - goto Exit; - } - if( blkAddr() != uiBlkAddr) - { - // Most likely a coding error rather than an I/O error. - goto Exit; - } - -Exit: - return( rc); -} - -/**************************************************************************** -Desc: Write the block to disk. -****************************************************************************/ -RCODE FBtreeBlk::writeBlk( - F_FileHdl * pFileHdl) -{ - RCODE rc; - FLMUINT uwBytesWritten; - FLMUINT uiBlkAddr = blkAddr(); - - if( RC_BAD( rc = pFileHdl->Write( - uiBlkAddr * DYNSSET_BLOCK_SIZE, - DYNSSET_BLOCK_SIZE, - m_pucBlkBuf, - &uwBytesWritten))) - { - // Most likely coding error rather than an I/O error. - goto Exit; - } - - m_bDirty = FALSE; -Exit: - return( rc); -} - -/**************************************************************************** -Desc: Write all blocks that are dirty and have an addrees lower - than the input block address and then write this block. - Write in order so that - we don't have to write zeros for any block. -****************************************************************************/ -RCODE FBtreeRoot::writeBlk( - FLMUINT uiWritePos) -{ - RCODE rc = FERR_OK; - - FLMUINT uiPos; - FLMUINT uiHighBlkAddr = m_CacheBlks[uiWritePos].uiBlkAddr; - - if( !m_pFileHdl) - { - if( RC_BAD( rc = openFile())) - goto Exit; - } - for( uiPos = 0; uiPos < FBTREE_CACHE_BLKS; uiPos++) - { - if( (uiWritePos != uiPos) && - (m_CacheBlks[uiPos].pBlk) && - (m_CacheBlks[uiPos].uiBlkAddr >= m_uiHighestWrittenBlkAddr) && - (m_CacheBlks[uiPos].uiBlkAddr < uiHighBlkAddr) && - (m_CacheBlks[uiPos].pBlk->isDirty()) ) - { - // Recursive call to write out lower blocks if needed. - if( RC_BAD( rc = writeBlk( uiPos))) - goto Exit; - } - } - m_CacheBlks[ uiWritePos].pBlk->writeBlk( m_pFileHdl); - if( m_CacheBlks[uiWritePos].uiBlkAddr > m_uiHighestWrittenBlkAddr) - { - m_uiHighestWrittenBlkAddr = m_CacheBlks[uiWritePos].uiBlkAddr; - } -Exit: - return( rc); -} - -/**************************************************************************** -Desc: Close the file if previously opened and creates the file. -VISIT: For now we use a temporary file system object on the stack - with a default configuration. In the future it would be better to - pass it in via an hSession or hShare file system object. -****************************************************************************/ -RCODE FBtreeRoot::openFile() -{ - RCODE rc = FERR_OK; - - if( !m_pFileHdl) - { - rc = gv_FlmSysData.pFileSystem->CreateUnique( m_szIoPath, - FRSET_FILENAME_EXTENSION, F_IO_RDWR | F_IO_CREATE_DIR, &m_pFileHdl); - } - - return( rc); -} - -/**************************************************************************** -Desc: Closes and deletes the tempoary file. -****************************************************************************/ -void FBtreeRoot::closeFile() -{ - if( m_pFileHdl) - { - m_pFileHdl->Close(); - gv_FlmSysData.pFileSystem->Delete( m_szIoPath); - m_szIoPath[ 0] = 0; - m_pFileHdl = NULL; - } - return; -} diff --git a/flaim/src/fdynsset.cpp b/flaim/src/fdynsset.cpp deleted file mode 100644 index 915208f..0000000 --- a/flaim/src/fdynsset.cpp +++ /dev/null @@ -1,339 +0,0 @@ -//------------------------------------------------------------------------- -// Desc: Dynamic result set - high level and hash implementation. -// Tabs: 3 -// -// Copyright (c) 1998-2001,2003,2005-2006 Novell, Inc. All Rights Reserved. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of version 2 of the GNU General Public -// License as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, contact Novell, Inc. -// -// To contact Novell about this file by physical or electronic mail, -// you may find current contact information at www.novell.com -// -// $Id: fdynsset.cpp 12329 2006-01-20 17:49:30 -0700 (Fri, 20 Jan 2006) ahodgkinson $ -//------------------------------------------------------------------------- - -#include "flaimsys.h" - -#define HASH_POS(vp) (((FLMUINT)(FB2UD((FLMBYTE*)vp)) % m_uiNumSlots) * m_uiEntrySize) - -static const FLMBYTE ucZeros [ DYNSSET_MAX_FIXED_ENTRY_SIZE ] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 -}; - -/**************************************************************************** -Desc: -****************************************************************************/ -FDynSearchSet::FDynSearchSet() -{ - // Let's just initialize all member variables. - - m_fnCompare = NULL; - m_UserValue = (void *) 4; - m_uiEntrySize = 4; - m_Access = NULL; -} - -/**************************************************************************** -Desc: Setup the result set with input values. - This method must be called and only called once. -****************************************************************************/ -RCODE FDynSearchSet::setup( - const char * pszIoPath, - FLMUINT uiEntrySize) -{ - RCODE rc = FERR_OK; - FHashBlk * pHashBlk; - - if( pszIoPath ) - { - f_strcpy( m_szFilePath, pszIoPath); - } - else - { - f_memset( m_szFilePath, 0, F_PATH_MAX_SIZE); - } - - m_uiEntrySize = uiEntrySize; - - if( (pHashBlk = f_new FHashBlk) == NULL) - { - rc = RC_SET( FERR_MEM); - goto Exit; - } - - pHashBlk->setup( uiEntrySize); - m_Access = (FFixedBlk *) pHashBlk; - m_UserValue = (void *) uiEntrySize; - -Exit: - - return( rc); -} - -/**************************************************************************** -Desc: Add a fixed length entry to the dynamic search result set. -Notes: This code will not work in UNIX land because of alignment issues. -****************************************************************************/ -RCODE FDynSearchSet::addEntry( - void * vpEntry) -{ - RCODE rc; - -Add_Again: - - if( RC_OK( rc = m_Access->search( vpEntry))) - { - rc = RC_SET( FERR_EXISTS); - } - else if( rc == FERR_NOT_FOUND) - { - - // Insert the entry. - if( (rc = m_Access->insert( vpEntry)) == FERR_FAILURE) - { - // Find the type of access method implemented - if( m_Access->blkType() == ACCESS_HASH) - { - FBtreeLeaf * pBtreeBlk; - FLMBYTE ucEntryBuffer[ DYNSSET_MAX_FIXED_ENTRY_SIZE]; - - // Go from a hash to a b-tree object. Alloc and move stuff over. - - if( (pBtreeBlk = f_new FBtreeLeaf) == NULL) - { - rc = RC_SET( FERR_MEM); - goto Exit; - } - pBtreeBlk->setup( m_uiEntrySize); - pBtreeBlk->setCompareFunc( m_fnCompare, m_UserValue); - for( rc = m_Access->getFirst( ucEntryBuffer ); - RC_OK(rc); - rc = m_Access->getNext( ucEntryBuffer) ) - { - // Call search to setup for insert. - (void) pBtreeBlk->search( ucEntryBuffer); - if( RC_BAD( rc = pBtreeBlk->insert( ucEntryBuffer))) - { - pBtreeBlk->Release(); - goto Exit; - } - } - rc = FERR_OK; - m_Access->Release(); - m_Access = pBtreeBlk; - goto Add_Again; - } - else if( m_Access->blkType() == ACCESS_BTREE_LEAF) - { - FBtreeRoot * pFullBtree; - - // Go from 1 block to 3 changing root blocks and free m_Access - // All new splits will be taken care of automatically. - - if( (pFullBtree = f_new FBtreeRoot) == NULL) - { - rc = RC_SET( FERR_MEM); - goto Exit; - } - - if( RC_BAD( rc = pFullBtree->setup( m_uiEntrySize, m_szFilePath))) - { - pFullBtree->Release(); - goto Exit; - } - - pFullBtree->setCompareFunc( m_fnCompare, m_UserValue); - - if( RC_BAD( rc = ((FBtreeLeaf *)m_Access)->split( pFullBtree))) - { - goto Exit; - } - - m_Access->Release(); - m_Access = pFullBtree; - goto Add_Again; - } - else - { - flmAssert(0); - } - } - } - -Exit: - - return( rc); -} - -/**************************************************************************** -Desc: Find matching entry. Position for Get* or for insert. -****************************************************************************/ -RCODE FHashBlk::search( - void * vpEntry, - void * vpFoundEntry) -{ - RCODE rc = FERR_OK; - FLMUINT uiHashPos = HASH_POS( vpEntry); - FLMINT iCompare; - - for(;;) - { - // If all zeros then setup to insert at this position. - if( !f_memcmp( &m_pucBlkBuf[ uiHashPos], ucZeros, m_uiEntrySize)) - { - rc = RC_SET( FERR_NOT_FOUND); - goto Exit; - } - - if( m_fnCompare) - { - iCompare = m_fnCompare( vpEntry, &m_pucBlkBuf[ uiHashPos], - (size_t) m_UserValue); - } - else - { - iCompare = f_memcmp( vpEntry, &m_pucBlkBuf[ uiHashPos], - (size_t) m_UserValue); - } - - if( !iCompare) - { - // Found match. - if( vpFoundEntry) - { - f_memcpy( vpFoundEntry, &m_pucBlkBuf[ uiHashPos], m_uiEntrySize); - } - break; - } - - // Go to the next entry - uiHashPos += m_uiEntrySize; - if( uiHashPos >= DYNSSET_HASH_BUFFER_SIZE) - uiHashPos = 0; - } - -Exit: - m_uiPosition = uiHashPos; - return( rc); -} - -/**************************************************************************** -Desc: Insert the entry into the buffer. -****************************************************************************/ -RCODE FHashBlk::insert( - void * vpEntry) -{ - RCODE rc = FERR_OK; - - if( getTotalEntries() > ((m_uiNumSlots * 7) / 10)) - { - rc = RC_SET( FERR_FAILURE); - goto Exit; - } - - f_memcpy( &m_pucBlkBuf[ m_uiPosition], vpEntry, m_uiEntrySize); - m_uiTotalEntries++; - -Exit: - return( rc); -} - -/**************************************************************************** -Desc: Return the next entry in the result set. If the result set - is not positioned then the first entry will be returned. -****************************************************************************/ -RCODE FHashBlk::getNext( - void * vpEntryBuffer) -{ - RCODE rc = FERR_OK; - FLMUINT uiHashPos; - - // Position to the next/first entry. - - if( m_uiPosition == DYNSSET_POSITION_NOT_SET) - { - uiHashPos = 0; - } - else - { - uiHashPos = m_uiPosition + m_uiEntrySize; - } - - for( ; ; uiHashPos += m_uiEntrySize) - { - if( uiHashPos >= DYNSSET_HASH_BUFFER_SIZE) - { - rc = RC_SET( FERR_EOF_HIT); - goto Exit; - } - - // If all zeros then setup to insert at this position. - if( f_memcmp( &m_pucBlkBuf[ uiHashPos], ucZeros, m_uiEntrySize)) - { - f_memcpy( vpEntryBuffer, &m_pucBlkBuf[ uiHashPos], m_uiEntrySize); - m_uiPosition = uiHashPos; - goto Exit; - } - } -Exit: - return( rc); -} - -/**************************************************************************** -Desc: Returns the last entry in the result set. Not implemented. -****************************************************************************/ -RCODE FHashBlk::getLast( - void * vpEntryBuffer) -{ - RCODE rc = FERR_OK; - FLMUINT uiHashPos; - - // Position to the next/first entry. - uiHashPos = DYNSSET_HASH_BUFFER_SIZE; - - for( ; ; ) - { - uiHashPos -= m_uiEntrySize; - - // If all zeros then setup to insert at this position. - if( f_memcmp( &m_pucBlkBuf[ uiHashPos], ucZeros, m_uiEntrySize)) - { - f_memcpy( vpEntryBuffer, &m_pucBlkBuf[ uiHashPos], m_uiEntrySize); - m_uiPosition = uiHashPos; - goto Exit; - } - if( uiHashPos == 0) - { - rc = RC_SET( FERR_EOF_HIT); - goto Exit; - } - } -Exit: - return( rc); -} - - -int DRNCompareFunc( - const void * vpData1, - const void * vpData2, - size_t UserValue) -{ - F_UNREFERENCED_PARM(UserValue); - if( *((FLMUINT *)vpData1) < *((FLMUINT *)vpData2)) - return -1; - else if( *((FLMUINT *)vpData1) > *((FLMUINT *)vpData2)) - return 1; - // else - return 0; -} diff --git a/flaim/src/fdynsset.h b/flaim/src/fdynsset.h deleted file mode 100644 index 12d2188..0000000 --- a/flaim/src/fdynsset.h +++ /dev/null @@ -1,601 +0,0 @@ -//------------------------------------------------------------------------- -// Desc: Dynamic result set - class definitions. -// Tabs: 3 -// -// Copyright (c) 1998-2000,2002-2006 Novell, Inc. All Rights Reserved. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of version 2 of the GNU General Public -// License as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, contact Novell, Inc. -// -// To contact Novell about this file by physical or electronic mail, -// you may find current contact information at www.novell.com -// -// $Id: fdynsset.h 12329 2006-01-20 17:49:30 -0700 (Fri, 20 Jan 2006) ahodgkinson $ -//------------------------------------------------------------------------- - -#ifndef FDYNSSET_H -#define FDYNSSET_H - -#include "fpackon.h" - -// IMPORTANT NOTE: No other include files should follow this one except -// for fpackoff.h - -class FDynSearchSet; -class FHashBlk; -class FBtreeBlk; -class FBtreeRoot; -class FBtreeNonLeaf; -class FBtreeLeaf; - -// A block size of 8K will perform well in minimizing the number of reads -// to obtain a block. A 6K may perform better if the file is located -// across the network. - -#define DYNSSET_BLOCK_SIZE 0x4000 -#define DYNSSET_HASH_BUFFER_SIZE 0x2000 -#define DYNSSET_MIN_FIXED_ENTRY_SIZE 4 - -// Change ucZeros in fdynsset.cpp if this changes. - -#define DYNSSET_MAX_FIXED_ENTRY_SIZE 32 -#define DYNSSET_POSITION_NOT_SET 0xFFFFFFFF - -#define FBTREE_CACHE_BLKS 32 -#define FBTREE_END 0xFFFFFFFF -#define FBTREE_MAX_LEVELS 4 - -// Default is to use the memcmp() function. - -typedef int (* FDYNSET_COMPARE_FUNC_p)( - const void * vpData1, - const void * vpData2, - size_t UserValue); - -typedef struct FixedBlkHdr -{ - FLMUINT uiBlkAddr; - FLMUINT uiPrevBlkAddr; - FLMUINT uiNextBlkAddr; - FLMUINT uiLEMAddr; - FLMUINT uiNumEntries; -} FixedBlkHdr; - -enum eBlkTypes -{ - ACCESS_HASH, - ACCESS_BTREE_LEAF, - ACCESS_BTREE_ROOT, - ACCESS_BTREE_NON_LEAF -}; - -typedef enum eBlkTypes FBlkTypes; - -int DRNCompareFunc( - const void * vpData1, - const void * vpData2, - size_t UserValue); - -/**************************************************************************** -Desc: -****************************************************************************/ -class FFixedBlk : public F_Base -{ -public: - - FFixedBlk(); - - virtual ~FFixedBlk() - { - } - - FBlkTypes blkType() - { - return m_eBlkType; - } - - virtual RCODE getCurrent( // SUCCESS or FRC_NOT_FOUND - void * vpEntryBuffer) = 0; - - virtual RCODE getFirst( // SUCCESS or FRC_EOF_HIT - void * vpEntryBuffer) = 0; - - virtual RCODE getLast( // SUCCESS or FRC_EOF_HIT - void * vpEntryBuffer) = 0; - - virtual RCODE getNext( // SUCCESS or FRC_EOF_HIT - void * vpEntryBuffer) = 0; - - virtual FLMUINT getTotalEntries() = 0; // Total entries - - virtual RCODE insert( // SUCCESS, FRC_FAILURE if full - void * vpEntry) = 0; - - FLMBOOL isDirty( void) - { - return( m_bDirty); - } - - virtual RCODE search( - void * vpEntry, - void * vpFoundEntry = NULL) = 0; - - void setCompareFunc( - FDYNSET_COMPARE_FUNC_p fnCompare, - void * UserValue) - { - m_fnCompare = fnCompare; - m_UserValue = UserValue; - } - -protected: - - FDYNSET_COMPARE_FUNC_p m_fnCompare; - void * m_UserValue; - FBlkTypes m_eBlkType; - FLMUINT m_uiEntrySize; - FLMUINT m_uiNumSlots; - FLMUINT m_uiPosition; - FLMBOOL m_bDirty; - FLMBYTE * m_pucBlkBuf; -}; - -/***************************************************************************** -Desc: -*****************************************************************************/ -class FDynSearchSet : public F_Base -{ -public: - - FDynSearchSet(); - - virtual ~FDynSearchSet() - { - if( m_Access) - { - m_Access->Release(); - } - } - - RCODE setup( - const char * pszIoPath, - FLMUINT uiEntrySize); - - FINLINE void setCompareFunc( - FDYNSET_COMPARE_FUNC_p fnCompare, - void * UserValue) - { - m_fnCompare = fnCompare; - m_UserValue = UserValue; - m_Access->setCompareFunc( fnCompare, UserValue); - } - - RCODE addEntry( - void * vpEntry); - - FINLINE RCODE findMatch( - void * vpEntry, - void * vpFoundEntry) - { - return m_Access->search( vpEntry, vpFoundEntry); - } - - FINLINE FLMUINT getEntrySize() - { - return( m_uiEntrySize); - } - - FINLINE FLMUINT getTotalEntries( void) - { - return( m_Access->getTotalEntries()); - } - -private: - - FDYNSET_COMPARE_FUNC_p m_fnCompare; - void * m_UserValue; - FLMUINT m_uiEntrySize; - FFixedBlk * m_Access; - char m_szFilePath[ F_PATH_MAX_SIZE]; -}; - -/**************************************************************************** -Desc: -****************************************************************************/ -class FHashBlk : public FFixedBlk -{ -public: - - FINLINE FHashBlk() - { - m_eBlkType = ACCESS_HASH; - m_pucBlkBuf = m_ucHashBlk; - f_memset( m_ucHashBlk, 0, sizeof( m_ucHashBlk)); - m_uiTotalEntries = 0; - } - - FINLINE ~FHashBlk() - { - m_pucBlkBuf = NULL; - } - - FINLINE RCODE setup( - FLMUINT uiEntrySize) - { - m_uiEntrySize = uiEntrySize; - m_uiNumSlots = DYNSSET_HASH_BUFFER_SIZE / uiEntrySize; - return( FERR_OK); - } - - FINLINE RCODE getCurrent( - void * vpEntryBuffer) - { - if( m_uiPosition == DYNSSET_POSITION_NOT_SET) - { - return( RC_SET( FERR_NOT_FOUND)); - } - - f_memcpy( vpEntryBuffer, &m_pucBlkBuf[ m_uiPosition], m_uiEntrySize); - return( FERR_OK); - } - - FINLINE RCODE getFirst( - void * vpEntryBuffer) - { - m_uiPosition = DYNSSET_POSITION_NOT_SET; - return getNext( vpEntryBuffer); - } - - RCODE getLast( - void * vpEntryBuffer); - - RCODE getNext( - void * vpEntryBuffer); - - FINLINE FLMUINT getTotalEntries( void) - { - return( m_uiTotalEntries); - } - - RCODE insert( - void * vpEntry); - - RCODE search( - void * vpEntry, - void * vpFoundEntry = NULL); - -private: - - FLMUINT m_uiTotalEntries; - FLMBYTE m_ucHashBlk[ DYNSSET_HASH_BUFFER_SIZE]; -}; - -#define ENTRY_POS(uiPos) (m_pucBlkBuf + sizeof( FixedBlkHdr) + \ - (uiPos * (m_uiEntrySize+m_uiEntryOvhd))) - -/**************************************************************************** -Desc: -****************************************************************************/ -class FBtreeBlk : public FFixedBlk -{ -public: - - FBtreeBlk() - { - } - - virtual ~FBtreeBlk() - { - if( m_pucBlkBuf) - { - f_free( &m_pucBlkBuf); - } - } - - FINLINE RCODE getCurrent( - void * vpEntryBuffer) - { - if( m_uiPosition == DYNSSET_POSITION_NOT_SET) - { - return( RC_SET( FERR_NOT_FOUND)); - } - - f_memcpy( vpEntryBuffer, ENTRY_POS( m_uiPosition), m_uiEntrySize); - return( FERR_OK); - } - - FINLINE RCODE getFirst( - void * vpEntryBuffer) - { - m_uiPosition = DYNSSET_POSITION_NOT_SET; - return getNext( vpEntryBuffer); - } - - RCODE getLast( - void * vpEntryBuffer); - - RCODE getNext( - void * vpEntryBuffer); - - RCODE readBlk( - F_FileHdl * pFileHdl, - FLMUINT uiBlkAddr); - - void reset( - FBlkTypes blkType); - - RCODE split( - FBtreeRoot * pParent, - FLMBYTE * pCurEntry, - FLMUINT uiCurBlkAddr, - FLMBYTE * pucParentEntry, - FLMUINT * puiNewBlkAddr); - - RCODE writeBlk( - F_FileHdl * pFileHdl); - - virtual FLMUINT getTotalEntries( void) = 0; - - virtual RCODE insert( - void * vpEntry) = 0; - - virtual RCODE search( - void * vpEntry, - void * vpFoundEntry = NULL) = 0; - - virtual RCODE searchEntry( - void * vpEntry, - FLMUINT * puiChildAddr = NULL, - void * vpFoundEntry = NULL); - - FINLINE FLMUINT blkAddr() - { - return( ((FixedBlkHdr *)m_pucBlkBuf)->uiBlkAddr); - } - - FINLINE void blkAddr( - FLMUINT uiBlkAddr) - { - ((FixedBlkHdr *)m_pucBlkBuf)->uiBlkAddr = uiBlkAddr; - m_bDirty = TRUE; - } - - FINLINE FLMUINT entryCount( void) - { - return( ((FixedBlkHdr *)m_pucBlkBuf)->uiNumEntries); - } - - FINLINE void entryCount( - FLMUINT uiNumEntries) - { - ((FixedBlkHdr *)m_pucBlkBuf)->uiNumEntries = uiNumEntries; - m_bDirty = TRUE; - } - - RCODE insertEntry( - void * vpEntry, - FLMUINT uiChildAddr = FBTREE_END); - - FINLINE FLMUINT lemBlk( void) - { - return( ((FixedBlkHdr *)m_pucBlkBuf)->uiLEMAddr); - } - - FINLINE void lemBlk( - FLMUINT uiLEMAddr) - { - ((FixedBlkHdr *)m_pucBlkBuf)->uiLEMAddr = uiLEMAddr; - m_bDirty = TRUE; - } - - FINLINE FLMUINT nextBlk( void) - { - return( ((FixedBlkHdr *)m_pucBlkBuf)->uiNextBlkAddr); - } - - FINLINE void nextBlk( - FLMUINT uiBlkAddr) - { - ((FixedBlkHdr *)m_pucBlkBuf)->uiNextBlkAddr = uiBlkAddr; - m_bDirty = TRUE; - } - - FINLINE FLMUINT prevBlk( void) - { - return( ((FixedBlkHdr *)m_pucBlkBuf)->uiPrevBlkAddr); - } - - FINLINE void prevBlk( - FLMUINT uiBlkAddr) - { - ((FixedBlkHdr *)m_pucBlkBuf)->uiPrevBlkAddr = uiBlkAddr; - m_bDirty = TRUE; - } - -protected: - - FLMUINT m_uiEntryOvhd; -}; - -/**************************************************************************** -Desc: -****************************************************************************/ -class FBtreeLeaf : public FBtreeBlk -{ -public: - - FINLINE FBtreeLeaf() - { - m_eBlkType = ACCESS_BTREE_LEAF; - m_uiEntryOvhd = 0; - } - - virtual ~FBtreeLeaf() - { - } - - RCODE setup( - FLMUINT uiEntrySize); - - FINLINE FLMUINT getTotalEntries( void) - { - return (FLMUINT) entryCount(); - } - - FINLINE RCODE insert( - void * vpEntry) - { - return insertEntry( vpEntry, FBTREE_END); - } - - FINLINE RCODE search( - void * vpEntry, - void * vpFoundEntry = NULL) - { - return searchEntry( vpEntry, NULL, vpFoundEntry); - } - - RCODE split( - FBtreeRoot * pNewRoot); -}; - -/**************************************************************************** -Desc: -****************************************************************************/ -typedef struct FBTREE_CACHE -{ - FLMUINT uiBlkAddr; - FLMUINT uiLRUValue; - FBtreeBlk * pBlk; -} FBTREE_CACHE; - -/**************************************************************************** -Desc: -****************************************************************************/ -class FBtreeNonLeaf : public FBtreeBlk -{ -public: - - FBtreeNonLeaf() - { - m_eBlkType = ACCESS_BTREE_NON_LEAF; - m_uiEntryOvhd = 4; - } - - virtual ~FBtreeNonLeaf() - { - } - - RCODE setup( - FLMUINT uiEntrySize); - - FINLINE FLMUINT getTotalEntries( void) - { - return( (FLMUINT) entryCount()); - } - - FINLINE RCODE insert( void *) - { - return( FERR_OK); - } - - FINLINE RCODE search( - void * vpEntry, - void * vpFoundEntry = NULL) - { - F_UNREFERENCED_PARM( vpEntry); - F_UNREFERENCED_PARM( vpFoundEntry); - - flmAssert(0); - return( FERR_OK); - } -}; - -/**************************************************************************** -Desc: -****************************************************************************/ -class FBtreeRoot : public FBtreeNonLeaf -{ -public: - - FBtreeRoot(); - - virtual ~FBtreeRoot(); - - RCODE setup( - FLMUINT uiEntrySize, - const char * pszIoPath); - - void closeFile( void); - - FLMUINT getTotalEntries( void) - { - return m_uiTotalEntries; - } - - RCODE insert( - void * vpEntry); - - RCODE newBlk( - FBtreeBlk ** ppBlk, - FBlkTypes blkType); - - FINLINE FLMUINT newBlkAddr( void) - { - return( m_uiNewBlkAddr++); - } - - RCODE newCacheBlk( - FLMUINT uiCachePos, - FBtreeBlk ** ppBlk, - FBlkTypes blkType); - - RCODE openFile( void); - - RCODE readBlk( - FLMUINT uiBlkAddr, - FBlkTypes blkType, - FBtreeBlk ** ppBlk); - - RCODE search( - void * vpEntry, - void * vpFoundEntry = NULL); - - RCODE setupTree( - FLMBYTE * pMidEntry, - FBlkTypes BlkType, - FBtreeBlk ** ppLeftBlk, - FBtreeBlk ** ppRightBlk); - - RCODE split( - void * vpCurEntry, - FLMUINT uiCurChildAddr); - - RCODE writeBlk( - FLMUINT uiWritePos); - -private: - - FLMUINT m_uiLevels; - FLMUINT m_uiTotalEntries; - FLMUINT m_uiNewBlkAddr; - FLMUINT m_uiHighestWrittenBlkAddr; - F_FileHdl * m_pFileHdl; - char m_szIoPath[ F_PATH_MAX_SIZE]; - FLMUINT m_uiLRUCount; - FBTREE_CACHE m_CacheBlks[ FBTREE_CACHE_BLKS]; - FBtreeBlk * m_BTStack[ FBTREE_MAX_LEVELS]; -}; - -#include "fpackoff.h" - -#endif diff --git a/flaim/src/ffilehdl.cpp b/flaim/src/ffilehdl.cpp deleted file mode 100644 index ac4748c..0000000 --- a/flaim/src/ffilehdl.cpp +++ /dev/null @@ -1,705 +0,0 @@ -//------------------------------------------------------------------------- -// Desc: File handle class. -// Tabs: 3 -// -// Copyright (c) 1997-2001,2003-2006 Novell, Inc. All Rights Reserved. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of version 2 of the GNU General Public -// License as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, contact Novell, Inc. -// -// To contact Novell about this file by physical or electronic mail, -// you may find current contact information at www.novell.com -// -// $Id: ffilehdl.cpp 12329 2006-01-20 17:49:30 -0700 (Fri, 20 Jan 2006) ahodgkinson $ -//------------------------------------------------------------------------- - -#include "flaimsys.h" - -RCODE gv_CriticalFSError = FERR_OK; - -/**************************************************************************** -Desc: Close all used and unused files in the file handle manager. -Note: This routine will tend to process as much as possible and keep - error codes around until complete. -****************************************************************************/ -RCODE flmCloseAllFiles( void) -{ - RCODE rc; - F_FileHdlMgr * pFileHdlMgr; - - pFileHdlMgr = gv_FlmSysData.pFileHdlMgr; - - // Close all available files. This will have to be done again - // because a file could be sent to the avail list between this call - // the the lockSem() call below. - - for(;;) - { - if( pFileHdlMgr->ReleaseOneAvail() != FERR_OK ) - { - break; - } - } - - // Visit all of the used file handles and unlink them from the used - // list. This will cause them to go away when the file handle is - // released. - - rc = pFileHdlMgr->ReleaseUsedFiles(); - - // Hold on to return code. - - // Close all available files again in case some used files joined - - for(;;) - { - if( pFileHdlMgr->ReleaseOneAvail() != FERR_OK ) - { - break; - } - } - - return( rc); -} - -/**************************************************************************** -Desc: Quick and easy way to write a string to a file. The contents of - pszSourceFile becomes pszData. -****************************************************************************/ -RCODE f_filecpy( - const char * pszSourceFile, - const char * pszData) -{ - RCODE rc = FERR_OK; - F_FileHdl * pFileHdl = NULL; - - if( RC_OK( rc = gv_FlmSysData.pFileSystem->Exists( pszSourceFile))) - { - if( RC_BAD( rc = gv_FlmSysData.pFileSystem->Delete( pszSourceFile))) - { - goto Exit; - } - } - - if( RC_BAD( rc = gv_FlmSysData.pFileSystem->Create( - pszSourceFile, F_IO_RDWR, &pFileHdl))) - { - goto Exit; - } - - { - FLMUINT uiBytesWritten = 0; - - if( RC_BAD( rc = pFileHdl->Write( 0, f_strlen( pszData), pszData, - &uiBytesWritten))) - { - goto Exit; - } - } - -Exit: - - if( pFileHdl) - { - pFileHdl->Close(); - pFileHdl->Release(); - } - - return( rc); -} - -/**************************************************************************** -Desc: Quick and easy way to append a string to a file. The contents of - pszData are appended to pszSourceFile. -****************************************************************************/ -RCODE f_filecat( - const char * pszSourceFile, - const char * pszData) -{ - RCODE rc = FERR_OK; - F_FileHdl * pFileHdl = NULL; - FLMUINT uiFileSize = 0; - FLMUINT uiBytesWritten = 0; - - if( RC_BAD( rc = gv_FlmSysData.pFileSystem->Exists( pszSourceFile))) - { - if( rc == FERR_IO_PATH_NOT_FOUND) - { - if( RC_BAD( rc = gv_FlmSysData.pFileSystem->Create( - pszSourceFile, F_IO_RDWR, &pFileHdl))) - { - goto Exit; - } - } - else - { - goto Exit; - } - } - else - { - if( RC_BAD( rc = gv_FlmSysData.pFileSystem->Open( - pszSourceFile, F_IO_RDWR, &pFileHdl))) - { - goto Exit; - } - } - - if( RC_BAD( rc = pFileHdl->Size( &uiFileSize))) - { - goto Exit; - } - - if( RC_BAD( rc = pFileHdl->Write( uiFileSize, f_strlen( pszData), - pszData, &uiBytesWritten))) - { - goto Exit; - } - -Exit: - - if( pFileHdl) - { - pFileHdl->Close(); - pFileHdl->Release(); - } - - return( rc); -} - -/**************************************************************************** -Desc: Initializes variables -****************************************************************************/ -F_FileHdlMgr::F_FileHdlMgr( - F_MUTEX * phMutex) -{ - m_phMutex = phMutex; - m_uiOpenThreshold = 0xFFFF; - FLM_SECS_TO_TIMER_UNITS( 30 * 60, m_uiMaxAvailTime); - m_bIsSetup = FALSE; - m_uiFileIdCounter = 0; -} - -/**************************************************************************** -Desc: Setup values for the File handle manager. -****************************************************************************/ -RCODE F_FileHdlMgr::Setup( - FLMUINT uiOpenThreshold, - FLMUINT uiMaxAvailTime) -{ - RCODE rc = FERR_OK; - - // Critical section may be needed here because some platforms (we think) - // may not set and get a variable as an atomic unit. - - m_uiOpenThreshold = uiOpenThreshold; - m_uiMaxAvailTime = uiMaxAvailTime; - - if( !m_bIsSetup) - { - rc = m_ListMgr.Setup( m_LNodes, FHM_LNODE_COUNT ); - m_bIsSetup = TRUE; - } - - return( rc); -} - -/**************************************************************************** -Desc: Returns a unique id that can be assigned to a F_FileHdlImp object. -****************************************************************************/ -FLMUINT F_FileHdlMgr::GetUniqueId() -{ - FLMUINT uiTemp; - F_MutexRef MutexRef( m_phMutex ); - - MutexRef.Lock(); - uiTemp = ++m_uiFileIdCounter; - MutexRef.Unlock(); - - return( uiTemp); -} - -/**************************************************************************** -Desc: Return the next available file handle that matches the uiFileId. - Remove all old opened file handles that have been available for - more the the max avail time. This will help to not keep files - opened for a long time if they are not used. -****************************************************************************/ -RCODE F_FileHdlMgr::FindAvail( - F_MutexRef * pMutexRef, - FLMUINT uiFileId, - FLMBOOL bReadOnlyFlag, - F_FileHdlImp ** ppFileHdl) -{ - RCODE rc = FERR_OK; - F_FileHdlImp * pFileHdl; - FLMBOOL bFound = FALSE; - - *ppFileHdl = NULL; - pMutexRef->Lock(); - - pFileHdl = (F_FileHdlImp *) m_ListMgr.GetItem( FHM_AVAIL_LIST, 0 ); - while( pFileHdl) - { - if( (pFileHdl->GetFileId() == uiFileId) && - (pFileHdl->IsOpenedReadOnly() == bReadOnlyFlag )) - { - // Move this file handle out of the available list into - // the used list. - // - // NOTE: To prevent this file handle from being freed this code - // performs an AddRef while its being relinked. This reference - // will be kept for the caller. - - pFileHdl->AddRef(); - bFound = TRUE; - - if( RC_OK( rc = pFileHdl->RemoveFromList( FHM_AVAIL_LIST))) - { - m_ListMgr.InsertAtFirst( FHM_USED_LIST, pFileHdl); - *ppFileHdl = pFileHdl; - } - - // NOTE: DO NOT CALL RELEASE -- Keep reference for caller. - - break; - } - - // Next pFileHdl in the list. - - pFileHdl = (F_FileHdlImp *)pFileHdl->GetNextListItem( FHM_AVAIL_LIST); - } - - if( !bFound) - { - rc = RC_SET( FERR_NOT_FOUND); - goto Exit; - } - -Exit: - - pMutexRef->Unlock(); - return( rc); -} - -/**************************************************************************** -Desc: Make the specified F_FileHdlImp available for someone else to use. -****************************************************************************/ -RCODE F_FileHdlMgr::MakeAvailAndRelease( - F_MutexRef * pMutexRef, - F_FileHdlImp * pFileHdl) -{ - RCODE rc = FERR_OK; - FLMINT iRefCnt; - - pFileHdl->SetAvailTime(); - pMutexRef->Lock(); - - // NOTE: To prevent this file handle from being freed this code - // performs an AddRef/Release while its being relinked. - - pFileHdl->AddRef(); - - if( RC_OK( rc = pFileHdl->RemoveFromList( FHM_USED_LIST))) - { - m_ListMgr.InsertAtEnd( FHM_AVAIL_LIST, (F_ListItem *) pFileHdl ); - } - - pFileHdl->Release(); - - // Release the caller's reference to the file handle - - iRefCnt = pFileHdl->Release(); - flmAssert( iRefCnt == 1); - - pMutexRef->Unlock(); - return( rc); -} - -/**************************************************************************** -Desc: Remove the input FileHdl from the avil and used lists. -****************************************************************************/ -RCODE F_FileHdlMgr::Remove( - F_FileHdlImp * pFileHdl) -{ - RCODE rc; - F_MutexRef MutexRef( m_phMutex ); - - MutexRef.Lock(); - rc = pFileHdl->RemoveFromList( FLM_ALL_LISTS); - MutexRef.Unlock(); - - return( rc); -} - -/**************************************************************************** -Desc: Remove (close&free) all FileHdl's that have the specified FileId. - Remove from the avail and used lists. -****************************************************************************/ - -RCODE F_FileHdlMgr::Remove( - F_MutexRef * pMutexRef, - FLMUINT uiFileId, - FLMBOOL bFreeUsedFiles) // Should used files be freed -{ - RCODE rc = FERR_OK; - F_FileHdlImp * pFileHdl; - F_FileHdlImp * pNextFileHdl; - - pMutexRef->Lock(); - - // Free all matching file handles in the available list. - - for( pFileHdl = (F_FileHdlImp *) m_ListMgr.GetItem( FHM_AVAIL_LIST, 0 ); - pFileHdl; - pFileHdl = pNextFileHdl ) - { - pNextFileHdl = (F_FileHdlImp *) pFileHdl->GetNextListItem( FHM_AVAIL_LIST ); - if( pFileHdl->GetFileId() == uiFileId ) - { - // Match found - remove from list. - - if( RC_BAD( rc = pFileHdl->RemoveFromList( FHM_AVAIL_LIST ))) - goto Exit; - } - } - - if( bFreeUsedFiles == TRUE) - { - // Free all matching file handles in the used list. - - for( pFileHdl = (F_FileHdlImp *) m_ListMgr.GetItem( FHM_USED_LIST, 0 ); - pFileHdl; - pFileHdl = pNextFileHdl ) - { - pNextFileHdl = (F_FileHdlImp *) pFileHdl->GetNextListItem( FHM_USED_LIST ); - if( pFileHdl->GetFileId() == uiFileId ) - { - // Match found - remove from list. - - if( RC_BAD( rc = pFileHdl->RemoveFromList( FHM_USED_LIST ))) - goto Exit; - } - } - } - -Exit: - - pMutexRef->Unlock(); - return( rc); -} - -/**************************************************************************** -Desc: Check items in the avail list and if over the input certain age then - remove them from the avail list. -****************************************************************************/ -RCODE F_FileHdlMgr::CheckAgedItems( - FLMUINT uiMinTimeOpened) -{ - RCODE rc = FERR_OK; - FLMUINT uiMaxAvailTime = m_uiMaxAvailTime; - F_MutexRef MutexRef( m_phMutex ); - - m_uiMaxAvailTime = uiMinTimeOpened; - rc = CheckAgedItems( &MutexRef ); - m_uiMaxAvailTime = uiMaxAvailTime; - - return( rc); -} - -/**************************************************************************** -Desc: Returns the total number of opened file handles. This includes all - FileHdls found within both the USED and AVAIL list. -****************************************************************************/ -FLMUINT F_FileHdlMgr::GetOpenedFiles( void) -{ - F_MutexRef MutexRef( m_phMutex); - FLMUINT uiTemp; - - MutexRef.Lock(); - uiTemp = m_ListMgr.GetCount( FLM_ALL_LISTS); - MutexRef.Unlock(); - - return uiTemp; -} - -/**************************************************************************** -Desc: Release one available file handle. -****************************************************************************/ -RCODE F_FileHdlMgr::ReleaseOneAvail( - F_MutexRef * pMutexRef) -{ - RCODE rc = FERR_OK; - F_FileHdlImp * pFileHdl; - - pMutexRef->Lock(); - - // Free all matching file handles in the available list. - - pFileHdl = (F_FileHdlImp *) m_ListMgr.GetItem( FHM_AVAIL_LIST, 0 ); - - if( pFileHdl != NULL) - { - rc = pFileHdl->RemoveFromList( FHM_AVAIL_LIST ); - } - else - { - rc = RC_SET( FERR_NOT_FOUND); - } - - pMutexRef->Unlock(); - return( rc); -} - -/**************************************************************************** -Desc: Release ALL used files so that they close when released. -****************************************************************************/ -RCODE F_FileHdlMgr::ReleaseUsedFiles( void) -{ - RCODE rc = FERR_OK; - F_FileHdlImp * pFileHdl; - F_FileHdlImp * pNextFileHdl; - F_MutexRef MutexRef( m_phMutex); - - MutexRef.Lock(); - - // Free all matching file handles in the used list. - - for( pFileHdl = (F_FileHdlImp *) m_ListMgr.GetItem( FHM_USED_LIST, 0 ); - pFileHdl; - pFileHdl = pNextFileHdl) - { - pNextFileHdl = (F_FileHdlImp *)pFileHdl->GetNextListItem( FHM_USED_LIST ); - - if( RC_BAD( rc = pFileHdl->RemoveFromList( FHM_USED_LIST ))) - { - goto Exit; - } - } - -Exit: - - MutexRef.Unlock(); - return( rc); -} - -/**************************************************************************** -Desc: Check items in the avail list and if over a certain age then - remove them from the avail list. This will cause file handles - that have been opened for a long time to be closed. Also added - code to reduce the total number of file handles if it is more - than the open threshold. -****************************************************************************/ -RCODE F_FileHdlMgr::CheckAgedItems( - F_MutexRef * pMutexRef) -{ - RCODE rc = FERR_OK; - F_FileHdlImp * pFileHdl; - FLMUINT uiTime; - FLMUINT uiMaxAvailTicks; - - uiTime = (FLMUINT)FLM_GET_TIMER(); - - pMutexRef->Lock(); - - FLM_SECS_TO_TIMER_UNITS( m_uiMaxAvailTime, uiMaxAvailTicks); - - // Loop while the open count is greater than the open threshold. - - while( m_ListMgr.GetCount( FLM_ALL_LISTS) > m_uiOpenThreshold) - { - // Release until the threshold is down. Only returns FERR_OK - // if it released one avail handle, otherwise returns FERR_NOT_FOUND. - - if( RC_BAD( rc = ReleaseOneAvail( pMutexRef ))) - { - if( FERR_NOT_FOUND == rc) - rc = FERR_OK; - break; - } - } - - // Reduce all items older than the specified time. - - for(;;) - { - FLMUINT uiTmp; - - pFileHdl = (F_FileHdlImp *) m_ListMgr.GetItem( FHM_AVAIL_LIST, 0 ); - if( !pFileHdl ) - break; - - // All file handles are in order of oldest first. - // m_uiMaxAvailTime may be a zero value. - - uiTmp = pFileHdl->GetAvailTime(); - if( uiMaxAvailTicks > FLM_ELAPSED_TIME( uiTime, uiTmp) ) - { - // All files are newer so we are done. - - break; - } - - // Remove the file handle from the list and get first item. - - if( RC_BAD( rc = pFileHdl->RemoveFromList( FHM_AVAIL_LIST))) - { - goto Exit; - } - } - -Exit: - - pMutexRef->Unlock(); - return( rc); -} - -/**************************************************************************** -Desc: Do a partial copy from one file into another file. -****************************************************************************/ -RCODE flmCopyPartial( - F_FileHdl * pSrcFileHdl, - FLMUINT uiSrcOffset, - FLMUINT uiSrcSize, - F_FileHdl * pDestFileHdl, - FLMUINT uiDestOffset, - FLMUINT * puiBytesCopiedRV) -{ - RCODE rc = FERR_OK; - FLMBYTE * pucBuffer = NULL; - FLMUINT uiAllocSize = 65536; - FLMUINT uiBytesToRead; - FLMUINT uiCopySize; - FLMUINT uiFileOffset; - FLMUINT uiBytesRead; - FLMUINT uiBytesWritten; - - uiCopySize = uiSrcSize; - *puiBytesCopiedRV = 0; - - // Set the buffer size for use during the file copy - - if (uiCopySize < uiAllocSize) - { - uiAllocSize = uiCopySize; - } - - // Allocate a buffer - - if( RC_BAD( rc = f_alloc( uiAllocSize, &pucBuffer))) - { - goto Exit; - } - - // Position the file pointers - - if( RC_BAD( rc = pSrcFileHdl->Seek( uiSrcOffset, F_IO_SEEK_SET, - &uiFileOffset))) - { - goto Exit; - } - - if( RC_BAD( rc = pDestFileHdl->Seek( uiDestOffset, F_IO_SEEK_SET, - &uiFileOffset))) - { - goto Exit; - } - - // Begin copying the data - - while (uiCopySize) - { - if (uiCopySize > uiAllocSize) - { - uiBytesToRead = uiAllocSize; - } - else - { - uiBytesToRead = uiCopySize; - } - - rc = pSrcFileHdl->Read( F_IO_CURRENT_POS, uiBytesToRead, - pucBuffer, &uiBytesRead); - - if( rc == FERR_IO_END_OF_FILE) - { - rc = FERR_OK; - } - - if( RC_BAD( rc)) - { - rc = RC_SET( FERR_IO_COPY_ERR); - goto Exit; - } - - uiBytesWritten = 0; - if( RC_BAD( rc = pDestFileHdl->Write( F_IO_CURRENT_POS, uiBytesRead, - pucBuffer, &uiBytesWritten))) - { - if( rc == FERR_IO_DISK_FULL) - { - *puiBytesCopiedRV += uiBytesWritten; - } - else - { - rc = RC_SET( FERR_IO_COPY_ERR); - } - - goto Exit; - } - - *puiBytesCopiedRV += uiBytesWritten; - - if( uiBytesRead < uiBytesToRead) - { - rc = RC_SET( FERR_IO_END_OF_FILE); - goto Exit; - } - - uiCopySize -= uiBytesRead; - } - -Exit: - - if (pucBuffer) - { - (void)f_free( &pucBuffer); - } - - return( rc); -} - -/**************************************************************************** -Desc: Setup (Initialize) a FileHdl object -****************************************************************************/ -RCODE F_FileHdlImp::Setup( - FLMUINT uiFileId) -{ - RCODE rc = FERR_OK; - - if( RC_BAD( rc = GET_FS_ERROR())) - { - goto Exit; - } - - m_uiFileId = uiFileId; - - if (uiFileId) - { - F_ListItem::Setup( gv_FlmSysData.pFileHdlMgr->GetListMgr(), - m_LNode, FHM_LNODE_COUNT); - } - -Exit: - - return( rc); -} diff --git a/flaim/src/ffilehdl.h b/flaim/src/ffilehdl.h deleted file mode 100644 index 5879d25..0000000 --- a/flaim/src/ffilehdl.h +++ /dev/null @@ -1,344 +0,0 @@ -//------------------------------------------------------------------------- -// Desc: File handle class - definitions. -// Tabs: 3 -// -// Copyright (c) 1997-2006 Novell, Inc. All Rights Reserved. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of version 2 of the GNU General Public -// License as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, contact Novell, Inc. -// -// To contact Novell about this file by physical or electronic mail, -// you may find current contact information at www.novell.com -// -// $Id: ffilehdl.h 12329 2006-01-20 17:49:30 -0700 (Fri, 20 Jan 2006) ahodgkinson $ -//------------------------------------------------------------------------- - -#ifndef FFILEHDL_H -#define FFILEHDL_H - -#include "fpackon.h" -// IMPORTANT NOTE: No other include files should follow this one except -// for fpackoff.h - -#define DEFAULT_OPEN_THRESHOLD 100 // 100 file handles to cache -#define DEFAULT_MAX_AVAIL_TIME 900 // 15 minutes - -class F_FileHdlImp; -class F_FileHdlMgr; -class F_FileHdlMgrPage; -class F_FileHdlPage; -class F_ListMgr; -class F_MutexRef; - -#define FHM_AVAIL_LIST 0 -#define FHM_USED_LIST 1 -#define FHM_LNODE_COUNT 2 - -RCODE flmCloseAllFiles(); - -RCODE DetermineLockMgr( - FFILE * pFile, - F_FileHdlImp * pFileHdl); - -RCODE flmCopyPartial( - F_FileHdl * pSrcFileHdl, - FLMUINT uiSrcOffset, - FLMUINT uiSrcSize, - F_FileHdl * pDestFileHdl, - FLMUINT uiDestOffset, - FLMUINT * puiBytesCopiedRV); - -#ifdef FLM_DEBUG - #define GET_FS_ERROR() (gv_CriticalFSError) -#else - #define GET_FS_ERROR() (FERR_OK) -#endif - -RCODE f_filecpy( - const char * pszSourceFile, - const char * pszData); - -RCODE f_filecat( - const char * pszSourceFile, - const char * pszData); - -/**************************************************************************** -Desc: The F_FileHdlMgr class manages F_FileHdlImp objects. - The F_FileHdlMgr maintains two lists: - 1) Available F_FileHdlImp's - F_FileHdlImp's not currently - being used. - 2) Used F_FileHdlImp's - F_FileHdlImp's that have been - checked out. -****************************************************************************/ -class F_FileHdlMgr : public F_Base -{ -public: - - F_FileHdlMgr( - F_MUTEX * phMutex); - - FINLINE virtual ~F_FileHdlMgr() - { - // Free all file handles in the available and used lists - - (void) m_ListMgr.ClearList( FHM_USED_LIST); - (void) m_ListMgr.ClearList( FHM_AVAIL_LIST); - } - - RCODE Setup( - FLMUINT uiOpenThreshold = DEFAULT_OPEN_THRESHOLD, - FLMUINT uiMaxAvailTime = DEFAULT_MAX_AVAIL_TIME); - - FINLINE void SetMutexPtr( - F_MUTEX * phMutex) - { - m_phMutex = phMutex; - } - - FINLINE RCODE SetOpenThreshold( - FLMUINT uiOpenThreshold) - { - return Setup( uiOpenThreshold, m_uiMaxAvailTime); - } - - FINLINE RCODE SetMaxAvailTime( - FLMUINT uiMaxAvailTime) - { - return Setup( m_uiOpenThreshold, uiMaxAvailTime); - } - - FLMUINT GetUniqueId(); // Returns a unique id that can be assigned - // to a F_FileHdlImp. - - /* - Methods for Avail & Used List Management - */ - - FINLINE RCODE FindAvail( - FLMUINT uiFileId, // Desired FileHdr's ID - FLMBOOL bReadOnlyFlag, // TRUE if file is read only - F_FileHdlImp ** ppFileHdl) // [out] returned FileHdl object. - { - F_MutexRef MutexRef( m_phMutex ); - - return FindAvail( &MutexRef, uiFileId, bReadOnlyFlag, - ppFileHdl); - } - - FINLINE RCODE InsertNew( - F_FileHdlImp * pFileHdl) // FileHdl to add to this manager. - { - F_MutexRef MutexRef( m_phMutex); - return InsertNew( &MutexRef, pFileHdl); - } - - FINLINE RCODE MakeAvailAndRelease( - F_FileHdlImp * pFileHdl) // FileHdl to move to the avail list. - { - F_MutexRef MutexRef( m_phMutex); - return MakeAvailAndRelease( &MutexRef, pFileHdl); - } - - FINLINE RCODE Remove( - FLMUINT uiFileId) - { - F_MutexRef MutexRef( m_phMutex); - return Remove( &MutexRef, uiFileId, TRUE); - } - - RCODE Remove( // Remove specific file handle. - F_FileHdlImp * pFileHdl); - - FINLINE RCODE RemoveAvail( - FLMUINT uiFileId) - { - F_MutexRef MutexRef( m_phMutex); - return Remove( &MutexRef, uiFileId, FALSE); - } - - RCODE CheckAgedItems( // Remove aged items older than - FLMUINT uiMinSecondsOpened);// minimum seconds opened. - - FINLINE RCODE ReleaseOneAvail() - { - F_MutexRef MutexRef( m_phMutex); - return ReleaseOneAvail( &MutexRef); - } - - RCODE ReleaseUsedFiles(); // Release all used files. - - FINLINE FLMUINT GetOpenThreshold() - { - return m_uiOpenThreshold; - } - - FLMUINT GetOpenedFiles(); - - FINLINE FLMUINT GetMaxAvailTime() - { - return m_uiMaxAvailTime; - } - - // Misc. Methods - - FINLINE F_ListMgr * GetListMgr() - { - return &m_ListMgr; - } - -private: - - F_MUTEX * m_phMutex; // Points to owning mutex - FLMUINT m_uiOpenThreshold; // FileHdl open threshold. - FLMUINT m_uiMaxAvailTime; // Time to close any available files. - - F_ListMgr m_ListMgr; // List manager - F_ListNode m_LNodes[ FHM_LNODE_COUNT]; - FLMBOOL m_bIsSetup; // TRUE when list manager is set up. - FLMUINT m_uiFileIdCounter; // Used for GetUniqueId() call. - - // Methods for Avail & Used List Management - - RCODE FindAvail( // Determines if the F_FileHdlMgr has an - // available F_FileHdlImp for the specified FileId - F_MutexRef * pMutexRef, - FLMUINT uiFileId, // Desired FileHdr's ID - FLMBOOL bReadOnlyFlag, // TRUE if looking for read only file - F_FileHdlImp ** ppFileHdl); // [out] returned F_FileHdlImp object. - - FINLINE RCODE InsertNew( - F_MutexRef * pMutexRef, - F_FileHdlImp * pFileHdl) // FileHdl to add to this manager. - { - pMutexRef->Lock(); // ENTER CRITICAL SECTION - m_ListMgr.InsertAtEnd( FHM_USED_LIST, (F_ListItem *)pFileHdl); - pMutexRef->Unlock(); // EXIT CRITICAL SECTION - return( FERR_OK); - } - - RCODE MakeAvailAndRelease( // Make the specified F_FileHdlImp available for - // someone else to use. - F_MutexRef * pMutexRef, - F_FileHdlImp * pFileHdl); // F_FileHdlImp to move to the avail list. - - RCODE Remove( // Remove (close&free) all FileHdl's that - // have the specified FileId. - F_MutexRef * pMutexRef, - FLMUINT uiFileId, - FLMBOOL bFreeUsedFiles);// Should used files be freed - - RCODE ReleaseOneAvail( // FERR_OK or FERR_NOT_FOUND. Releases - // a single file handle on the avail list. - F_MutexRef * pMutexRef); - - // Misc. Methods - - RCODE CheckAgedItems( // Remove aged items older than - F_MutexRef * pMutexRef); // m_udMaxAvailTime. - - // Manager Statistics Methods - - FLMUINT GetOpenedFiles( // Return number of opened file handles - F_MutexRef * pMutexRef); - - friend class F_FileHdlMgrPage; -}; - -/**************************************************************************** -Desc: Base class for file handle implementations -****************************************************************************/ -class F_FileHdlImpBase : public F_FileHdl -{ -public: - - F_FileHdlImpBase() - { - m_uiAvailTime = 0; - m_bFileOpened = FALSE; - m_bDeleteOnClose = FALSE; - m_bOpenedReadOnly = FALSE; - m_pszIoPath = NULL; - } - - virtual ~F_FileHdlImpBase() - { - if( m_pszIoPath) - { - f_free( &m_pszIoPath); - } - } - - FINLINE FLMUINT GetFileId() - { - return m_uiFileId; - } - - FINLINE FLMUINT GetAvailTime( void) - { - return m_uiAvailTime; - } - - FINLINE void SetAvailTime( void) - { - m_uiAvailTime = (FLMUINT)FLM_GET_TIMER(); - } - - FINLINE FLMBOOL IsOpenedReadOnly( void) - { - return( m_bOpenedReadOnly); - } - - FINLINE FLMBOOL IsOpenedExclusive( void) - { - return( m_bOpenedExclusive); - } - - virtual RCODE SectorRead( // Allows sector reads to be done. - FLMUINT uiReadOffset, // Offset to being reading at. - FLMUINT uiBytesToRead, // Number of bytes to read - void * pvBuffer, // Buffer to place read bytes into - FLMUINT * puiBytesReadRV) = 0; // [out] number of bytes read - - virtual RCODE SectorWrite( // Allows sector writes to be done. - FLMUINT uiWriteOffset, // Offset to seek to. - FLMUINT uiBytesToWrite, // Number of bytes to write. - const void * pvBuffer, // Buffer that contains bytes to be written - FLMUINT uiBufferSize, // Actual buffer size. - F_IOBuffer * pBufferObj, // Do asynchronous write if non-NULL. - FLMUINT * puiBytesWrittenRV, // Number of bytes written. - FLMBOOL bZeroFill = TRUE) = 0; // Zero fill the buffer? - -protected: - - FLMBOOL m_bOpenedReadOnly; // Opened the file read only - FLMBOOL m_bOpenedExclusive; // Opened the file in exclusive mode - F_ListNode m_LNode[2]; // List Item Node, used by FListItem object. - FLMBOOL m_bFileOpened; // Is the file currently opened/closed. - FLMUINT m_uiAvailTime; // Time when placed in avail list. - FLMUINT m_uiFileId; // FFILE Unique File Id - FLMBOOL m_bDeleteOnClose; // Delete this file when it is released. - char * m_pszIoPath; // Path of this FileHdl - -friend class F_FileHdlPage; -}; - -#include "fpackoff.h" - -#ifdef FLM_NLM - #include "fnlm.h" -#elif defined( FLM_WIN) - #include "fwin.h" -#elif defined( FLM_UNIX) - #include "fposix.h" -#endif - -#endif // FFILEHDL_H diff --git a/flaim/src/ffilehdr.cpp b/flaim/src/ffilehdr.cpp index 6f6f650..62f50e7 100644 --- a/flaim/src/ffilehdr.cpp +++ b/flaim/src/ffilehdr.cpp @@ -224,7 +224,7 @@ Desc: This routine reads and verifies the information contained in the *****************************************************************************/ RCODE flmReadAndVerifyHdrInfo( DB_STATS * pDbStats, - F_FileHdl * pFileHdl, + IF_FileHdl * pFileHdl, FLMBYTE * pReadBuf, FILE_HDR * pFileHdrRV, LOG_HDR * pLogHdrRV, @@ -242,7 +242,7 @@ RCODE flmReadAndVerifyHdrInfo( f_memset( pReadBuf, 0, 2048); - rc0 = pFileHdl->Read( 1L, 2047, &pReadBuf [1], &uiBytesRead); + rc0 = pFileHdl->read( 1L, 2047, &pReadBuf [1], &uiBytesRead); // Increment bytes read - to account for byte zero, which // was not really read in. @@ -349,12 +349,12 @@ RCODE flmWriteVersionNum( szVersionStr[ 3] = (FLMBYTE)(uiVersionNum % 10) + '0'; szVersionStr[ 4] = 0; - if (RC_OK( rc = pSFileHdl->WriteHeader( + if (RC_OK( rc = pSFileHdl->writeHeader( FLAIM_HEADER_START + FLM_FILE_FORMAT_VER_POS, FLM_FILE_FORMAT_VER_LEN, szVersionStr, &uiWriteBytes))) { - if (RC_BAD( rc = pSFileHdl->Flush())) + if (RC_BAD( rc = pSFileHdl->flush())) { goto Exit; } @@ -371,29 +371,25 @@ Desc: This routine reads the header information in a FLAIM database, header information. *****************************************************************************/ RCODE flmGetHdrInfo( - F_SuperFileHdl * pSFileHdl, /* Pointer to file handle. */ - FILE_HDR * pFileHdrRV, /* Returns file header information. */ - LOG_HDR * pLogHdrRV, /* Returns log header information. */ - FLMBYTE * pLogHdr - ) + IF_FileHdl * pFileHdl, + FILE_HDR * pFileHdrRV, + LOG_HDR * pLogHdrRV, + FLMBYTE * pLogHdr) { - RCODE rc = FERR_OK; - FLMBYTE * pBuf = NULL; - F_FileHdlImp * pCFileHdl; + RCODE rc = FERR_OK; + FLMBYTE * pBuf = NULL; if (RC_BAD( rc = f_alloc( 2048, &pBuf))) { goto Exit; } - if( RC_BAD( rc = pSFileHdl->GetFileHdl( 0, FALSE, &pCFileHdl))) + if( RC_BAD( rc = flmReadAndVerifyHdrInfo( NULL, pFileHdl, pBuf, pFileHdrRV, + pLogHdrRV, pLogHdr))) { goto Exit; } - rc = flmReadAndVerifyHdrInfo( NULL, pCFileHdl, - pBuf, pFileHdrRV, pLogHdrRV, pLogHdr); - Exit: if( pBuf) diff --git a/flaim/src/ffilesys.cpp b/flaim/src/ffilesys.cpp deleted file mode 100644 index 5320eec..0000000 --- a/flaim/src/ffilesys.cpp +++ /dev/null @@ -1,1218 +0,0 @@ -//------------------------------------------------------------------------- -// Desc: File system class. -// Tabs: 3 -// -// Copyright (c) 1998-2003,2005-2006 Novell, Inc. All Rights Reserved. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of version 2 of the GNU General Public -// License as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, contact Novell, Inc. -// -// To contact Novell about this file by physical or electronic mail, -// you may find current contact information at www.novell.com -// -// $Id: ffilesys.cpp 12334 2006-01-23 12:45:35 -0700 (Mon, 23 Jan 2006) dsanders $ -//------------------------------------------------------------------------- - -#include "flaimsys.h" - -/**************************************************************************** -Desc: Convert local time to UTC -Note: This code was basically copied from prtime.c -****************************************************************************/ -FINLINE FLMUINT flmLocalToUTC( - FLMUINT uiSeconds) -{ - return( uiSeconds + f_timeGetLocalOffset()); -} - -/**************************************************************************** -Desc: Create a file, return a file handle to created file. -****************************************************************************/ -RCODE F_FileSystemImp::Create( - const char * pFilePath, - FLMUINT uiIoFlags, - F_FileHdl ** ppFileHdl) -{ - RCODE rc = FERR_OK; - F_FileHdlImp * pFileHdl = NULL; - - if (RC_BAD( rc = getFileHdl( &pFileHdl))) - { - goto Exit; - } - - if (RC_BAD( rc = pFileHdl->Create( pFilePath, uiIoFlags))) - { - pFileHdl->Release(); - pFileHdl = NULL; - goto Exit; - } - -Exit: - - *ppFileHdl = (F_FileHdl *)pFileHdl; - return( rc); -} - -/**************************************************************************** -Desc: Create a block-oriented file, return a file handle to created file. -****************************************************************************/ -RCODE F_FileSystemImp::CreateBlockFile( - const char * pFilePath, - FLMUINT uiIoFlags, - FLMUINT uiBlockSize, - F_FileHdlImp ** ppFileHdl) -{ - RCODE rc = FERR_OK; - F_FileHdlImp * pFileHdl = NULL; - - if (RC_BAD( rc = getFileHdl( &pFileHdl))) - { - goto Exit; - } - -#ifdef FLM_WIN - pFileHdl->SetBlockSize( uiBlockSize); -#else - F_UNREFERENCED_PARM( uiBlockSize); -#endif - - if (RC_BAD( rc = pFileHdl->Create( pFilePath, uiIoFlags))) - { - pFileHdl->Release(); - pFileHdl = NULL; - goto Exit; - } - -Exit: - - *ppFileHdl = pFileHdl; - return( rc); -} - -/**************************************************************************** -Desc: Create a unique file, return a file handle to created file. -****************************************************************************/ -RCODE F_FileSystemImp::CreateUnique( - char * pszDirPath, - const char * pszFileExtension, - FLMUINT uiIoFlags, - F_FileHdl ** ppFileHdl) -{ - RCODE rc = FERR_OK; - F_FileHdlImp * pFileHdl = NULL; - - if( RC_BAD( rc = getFileHdl( &pFileHdl))) - { - goto Exit; - } - - if( RC_BAD( rc = pFileHdl->CreateUnique( - pszDirPath, pszFileExtension, uiIoFlags))) - { - pFileHdl->Release(); - pFileHdl = NULL; - goto Exit; - } - -Exit: - - *ppFileHdl = (F_FileHdl *)pFileHdl; - return( rc); -} - -/**************************************************************************** -Desc: Open a file, return a file handle to opened file. -****************************************************************************/ -RCODE F_FileSystemImp::Open( - const char * pFilePath, - FLMUINT uiIoFlags, - F_FileHdl ** ppFileHdl) -{ - RCODE rc = FERR_OK; - F_FileHdlImp * pFileHdl = NULL; - - if (RC_BAD( rc = getFileHdl( &pFileHdl))) - { - goto Exit; - } - - if (RC_BAD( rc = pFileHdl->Open( pFilePath, uiIoFlags))) - { - pFileHdl->Release(); - pFileHdl = NULL; - goto Exit; - } - -Exit: - - *ppFileHdl = (F_FileHdl *)pFileHdl; - return( rc); -} - -/**************************************************************************** -Desc: Open a block-oriented file, return a file handle to opened file. -****************************************************************************/ -RCODE F_FileSystemImp::OpenBlockFile( - const char * pFilePath, - FLMUINT uiIoFlags, - FLMUINT uiBlockSize, - F_FileHdlImp ** ppFileHdl) -{ - RCODE rc = FERR_OK; - F_FileHdlImp * pFileHdl = NULL; - - if (RC_BAD( rc = getFileHdl( &pFileHdl))) - { - goto Exit; - } - -#ifdef FLM_WIN - pFileHdl->SetBlockSize( uiBlockSize); -#else - F_UNREFERENCED_PARM( uiBlockSize); -#endif - - if (RC_BAD( rc = pFileHdl->Open( pFilePath, uiIoFlags))) - { - pFileHdl->Release(); - pFileHdl = NULL; - goto Exit; - } - -Exit: - - *ppFileHdl = pFileHdl; - return( rc); -} - -/**************************************************************************** -Desc: Open a directory, return a file handle to opened directory. -****************************************************************************/ -RCODE F_FileSystemImp::OpenDir( - const char * pszDirPath, - const char * pszPattern, - F_DirHdl ** ppDirHdl) -{ - RCODE rc = FERR_OK; - F_DirHdl * pDirHdl = NULL; - - if( (pDirHdl = f_new F_DirHdlImp) == NULL) - { - rc = RC_SET( FERR_MEM); - goto Exit; - } - - if( RC_BAD( rc = pDirHdl->OpenDir( pszDirPath, pszPattern))) - { - pDirHdl->Release(); - pDirHdl = NULL; - } - -Exit: - - *ppDirHdl = pDirHdl; - return( rc); -} - -/**************************************************************************** -Desc: Create a directory (and parent directories if necessary). -****************************************************************************/ -RCODE F_FileSystemImp::CreateDir( - const char * pszDirPath) -{ - char * pszParentDir = NULL; - RCODE rc = FERR_OK; - - if( RC_BAD( rc = f_alloc( F_PATH_MAX_SIZE, &pszParentDir))) - { - goto Exit; - } - - // Discover the parent directory of the given one - - if( RC_BAD( rc = f_pathReduce( pszDirPath, pszParentDir, NULL))) - { - goto Exit; - } - - // If f_pathReduce couldn't reduce the path at all, then an invalid - // path was supplied. - - if( f_strcmp( pszDirPath, pszParentDir) == 0) - { - rc = RC_SET( FERR_IO_INVALID_PATH); - goto Exit; - } - - // If a parent directory was found, and it doesn't already exist, create it - - if( *pszParentDir) - { - // If the "parent" is actually a regular file we need to return an error - - if( RC_OK( gv_FlmSysData.pFileSystem->Exists( pszParentDir))) - { - if( !gv_FlmSysData.pFileSystem->IsDir( pszParentDir)) - { - rc = RC_SET( FERR_IO_ACCESS_DENIED); - goto Exit; - } - } - - // Recurse on the parent directory - - else if( RC_BAD( rc = CreateDir( pszParentDir))) - { - goto Exit; - } - } - -#if defined( FLM_WIN) - - if( !CreateDirectory((LPTSTR)pszDirPath, NULL)) - { - rc = MapWinErrorToFlaim( GetLastError(), FERR_CREATING_FILE); - } - -#elif defined( FLM_UNIX) - - // Create a new directory with mode parameter 0777. From the linux - // man (2) mkdir page: - - // mode specifies the permissions to use. It is modified by the - // process's umask in the usual way: the permissions of the created - // file are (mode & ~umask). - - if( mkdir( pszDirPath, 0700) == -1 ) - { - rc = MapErrnoToFlaimErr( errno, FERR_CREATING_FILE); - } - -#elif defined( FLM_NLM) - - rc = _CreateDir( pszDirPath); - -#endif - -Exit: - if (pszParentDir) - { - f_free( &pszParentDir); - } - return (rc); -} - -/**************************************************************************** -Desc: NetWare implementation to create a directory -Input: - pPathToDirectory = fully-qualified path to the directory to be created - Examples: - In this example, the directory 'myDir' would be created: - sys:\system\myDir - - Note that ConvertPathString doesn't support server names. So - it returns an error on paths like: - server-name/volume:\directory_1 - -Return: - FERR_OK = success, otherwise there was an error - Note that the parent directory must exist. If it doesn't, an error will - occur. -****************************************************************************/ -#ifdef FLM_NLM -RCODE F_FileSystemImp::_CreateDir( - const char * pPathToDirectory) -{ - FLMBYTE pucPseudoLNamePath[ F_PATH_MAX_SIZE + 1]; - FLMBYTE pucLNamePath[ F_PATH_MAX_SIZE]; - LONG lVolumeID; - LONG lPathID; - LONG lLNamePathCount; - LONG lNewDirectoryID; - void *pNotUsed; - LONG lErrorCode; - RCODE rc = FERR_OK; - - f_strcpy( (char *)&pucPseudoLNamePath[1], pPathToDirectory); - pucPseudoLNamePath[0] = (FLMBYTE)f_strlen( pPathToDirectory); - - if( (lErrorCode = ConvertPathString( 0, 0, pucPseudoLNamePath, &lVolumeID, - &lPathID, pucLNamePath, &lLNamePathCount)) != 0) - { - goto Exit; - } - - if( (lErrorCode = CreateDirectory( 0, lVolumeID, lPathID, pucLNamePath, - lLNamePathCount, LONGNameSpace, MaximumDirectoryAccessBits, - &lNewDirectoryID, &pNotUsed)) != 0) - { - goto Exit; - } - -Exit: - - if( lErrorCode) - { - rc = MapNWtoFlaimError( lErrorCode, FERR_CREATING_FILE); - } - - return( rc); -} -#endif - -/**************************************************************************** -Desc: Remove a directory. -****************************************************************************/ -RCODE F_FileSystemImp::RemoveDir( - const char * pszDirPath, - FLMBOOL bClear) -{ - RCODE rc = FERR_OK; - F_DirHdl * pDirHdl = NULL; - char szFilePath[ F_PATH_MAX_SIZE]; - - if( bClear) - { - if( RC_BAD( rc = OpenDir( pszDirPath, "*", &pDirHdl))) - { - goto Exit; - } - - // Delete everything in the directory - - for( rc = pDirHdl->Next(); RC_OK( rc) ; rc = pDirHdl->Next()) - { - pDirHdl->CurrentItemPath( szFilePath); - if( !pDirHdl->CurrentItemIsDir()) - { - if( RC_BAD( rc = Delete( szFilePath))) - { - if( rc == FERR_IO_PATH_NOT_FOUND || rc == FERR_IO_INVALID_PATH) - { - rc = FERR_OK; - } - else - { - goto Exit; - } - } - } - else - { - if( RC_BAD( rc = RemoveDir( szFilePath, bClear))) - { - if( rc == FERR_IO_PATH_NOT_FOUND || rc == FERR_IO_INVALID_PATH) - { - rc = FERR_OK; - } - else - { - goto Exit; - } - } - } - } - - // Need to release the directory handle so the - // directory will be closed when we try to delete it - // below. - - pDirHdl->Release(); - pDirHdl = NULL; - } - - if( RC_BAD( rc = RemoveEmptyDir( pszDirPath))) - { - goto Exit; - } - -Exit: - - if( pDirHdl) - { - pDirHdl->Release(); - } - - return( rc); -} - -/**************************************************************************** -Desc: Remove an empty directory -****************************************************************************/ -RCODE F_FileSystemImp::RemoveEmptyDir( - const char * pszDirPath) -{ -#if defined( FLM_WIN) - - if( !RemoveDirectory( (LPTSTR)pszDirPath)) - { - return( MapWinErrorToFlaim( GetLastError(), FERR_DELETING_FILE)); - } - - return( FERR_OK); - -#elif defined( FLM_UNIX) - - if( rmdir( pszDirPath) == -1 ) - { - return( MapErrnoToFlaimErr( errno, FERR_DELETING_FILE)); - } - - return( FERR_OK); - -#elif defined( FLM_NLM) - RCODE rc = FERR_OK; - FLMBYTE pucPseudoLNamePath[ F_PATH_MAX_SIZE + 1]; - FLMBYTE pucLNamePath[ F_PATH_MAX_SIZE]; - LONG lVolumeID; - LONG lPathID; - LONG lLNamePathCount; - LONG lErrorCode; - - f_strcpy( (char *)&pucPseudoLNamePath[1], pszDirPath); - pucPseudoLNamePath[0] = (FLMBYTE)f_strlen( pszDirPath); - - if( (lErrorCode = ConvertPathString( 0, 0, pucPseudoLNamePath, &lVolumeID, - &lPathID, pucLNamePath, &lLNamePathCount)) != 0) - { - goto Exit; - } - - if( (lErrorCode = DeleteDirectory( 0, lVolumeID, lPathID, pucLNamePath, - lLNamePathCount, LONGNameSpace)) != 0) - { - goto Exit; - } - -Exit: - - if( lErrorCode) - { - rc = MapNWtoFlaimError( lErrorCode, FERR_DELETING_FILE); - } - - return( rc); -#endif -} - -/**************************************************************************** -Desc: Determine if a file or directory exists. -****************************************************************************/ -RCODE F_FileSystemImp::Exists( - const char * pPath) -{ -#if defined( FLM_NLM) - return( NWTestIfFileExists( pPath)); -#elif defined( FLM_WIN) - DWORD dwFileAttr = GetFileAttributes( (LPTSTR)pPath); - - if( dwFileAttr == (DWORD)-1) - { - return( RC_SET( FERR_IO_PATH_NOT_FOUND)); - } - - return( FERR_OK); - -#else - - // Check for the file's existence - - if( access( pPath, F_OK) == -1) - { - return( MapErrnoToFlaimErr( errno, FERR_CHECKING_FILE_EXISTENCE)); - } - - return( FERR_OK); -#endif -} - -/**************************************************************************** -Desc: Get the time stamp of the last modification to this file. -****************************************************************************/ -RCODE F_FileSystemImp::GetTimeStamp( - const char * pPath, - FLMUINT * puiTimeStamp) -{ -#if defined( FLM_NLM) - FLMUINT uiTmp; - FLMBYTE ucPseudoLNamePath[ F_PATH_MAX_SIZE + 1]; - FLMBYTE ucLNamePath[ F_PATH_MAX_SIZE]; - LONG lVolumeID; - LONG lPathID; - LONG lLNamePathCount; - LONG lDirectoryID; - LONG lErrorCode; - struct DirectoryStructure * - pFileInfo = NULL; - RCODE rc = FERR_OK; - - flmAssert( puiTimeStamp ); - *puiTimeStamp = 0; - - f_strcpy( (char *)&ucPseudoLNamePath[1], pPath); - ucPseudoLNamePath[ 0] = (FLMBYTE)f_strlen( pPath ); - - if( (lErrorCode = ConvertPathString( 0, 0, ucPseudoLNamePath, &lVolumeID, - &lPathID, ucLNamePath, &lLNamePathCount)) != 0) - { - goto Exit; - } - - if( (lErrorCode = GetEntryFromPathStringBase( 0, lVolumeID, 0, ucLNamePath, - lLNamePathCount, LONGNameSpace, LONGNameSpace, &pFileInfo, - &lDirectoryID)) != 0) - { - goto Exit; - } - - if( pFileInfo) - { - FLMUINT uiTime; - FLMUINT uiDate; - F_TMSTAMP dateTime; - LONG DayMask = 0x001F; - LONG MonthMask = 0x01E0; - LONG YearMask = 0xFE00; - LONG SecMask = 0x001F; - LONG MinMask = 0x07E0; - LONG HourMask = 0xF800; - - //Get the low-order 16 bits - - uiTime = (FLMUINT)pFileInfo->DLastUpdatedDateAndTime; - - //Get the high-order 16 bits - - uiDate = (FLMUINT)(pFileInfo->DLastUpdatedDateAndTime >> 16); - - f_memset( &dateTime, 0, sizeof( dateTime)); - dateTime.second = (FLMBYTE) ((uiTime & SecMask) * 2); - dateTime.minute = (FLMBYTE) ((uiTime & MinMask) >> 5); - dateTime.hour = (FLMBYTE) ((uiTime & HourMask) >> 11); - dateTime.day = (FLMBYTE) (uiDate & DayMask); - dateTime.month = (FLMBYTE) ((uiDate & MonthMask) >> 5)-1; - dateTime.year = (FLMUINT16)(((uiDate & YearMask) >> 9) + 1980); - - f_timeDateToSeconds( &dateTime, &uiTmp); - *puiTimeStamp = uiTmp; - *puiTimeStamp = flmLocalToUTC(*puiTimeStamp); - } - -Exit: - - if( lErrorCode != 0 ) - { - rc = MapNWtoFlaimError(lErrorCode, FERR_PARSING_FILE_NAME); - } - - return( rc); - -#elif defined( FLM_WIN) - - RCODE rc = FERR_OK; - WIN32_FIND_DATA find_data; - FILETIME ftLocalFileTime; - SYSTEMTIME stLastFileWriteTime; - HANDLE hSearch = INVALID_HANDLE_VALUE; - F_TMSTAMP tmstamp; - - hSearch = FindFirstFile( (LPTSTR)pPath, &find_data); - if( hSearch == INVALID_HANDLE_VALUE) - { - rc = MapWinErrorToFlaim( GetLastError(), FERR_OPENING_FILE); - - switch( rc) - { - case FERR_IO_NO_MORE_FILES: - rc = RC_SET( FERR_IO_PATH_NOT_FOUND); - goto Exit; - default: - goto Exit; - } - } - - if( FileTimeToLocalFileTime( &(find_data.ftLastWriteTime), - &ftLocalFileTime) == FALSE) - { - rc = MapWinErrorToFlaim( GetLastError(), FERR_OPENING_FILE); - goto Exit; - } - - if( FileTimeToSystemTime( &ftLocalFileTime, &stLastFileWriteTime) == FALSE) - { - rc = MapWinErrorToFlaim( GetLastError(), FERR_OPENING_FILE); - goto Exit; - } - - f_memset( &tmstamp, 0, sizeof( F_TMSTAMP)); - - tmstamp.hour = (FLMBYTE)stLastFileWriteTime.wHour; - tmstamp.minute = (FLMBYTE)stLastFileWriteTime.wMinute; - tmstamp.second = (FLMBYTE)stLastFileWriteTime.wSecond; - tmstamp.hundredth = (FLMBYTE)stLastFileWriteTime.wMilliseconds; - tmstamp.year = (FLMUINT16)stLastFileWriteTime.wYear; - tmstamp.month = (FLMBYTE)(stLastFileWriteTime.wMonth - 1); - tmstamp.day = (FLMBYTE)stLastFileWriteTime.wDay; - - f_timeDateToSeconds( &tmstamp, puiTimeStamp); - -Exit: - - if( hSearch != INVALID_HANDLE_VALUE) - { - FindClose( hSearch); - } - - if( RC_OK( rc)) - { - *puiTimeStamp = flmLocalToUTC( *puiTimeStamp); - } - - return( rc); - -#else - - struct stat filestatus; - - if( stat( pPath, &filestatus) == -1) - { - return( MapErrnoToFlaimErr( errno, FERR_GETTING_FILE_INFO)); - } - - *puiTimeStamp = (FLMUINT)filestatus.st_mtime; - return( FERR_OK); - -#endif -} - -/**************************************************************************** -Desc: Determine if a path is a directory. -****************************************************************************/ -FLMBOOL F_FileSystemImp::IsDir( - const char * pPath) -{ - FLMBOOL bIsDir = FALSE; - -#if defined( FLM_NLM) - LONG lIsFile; - FLMBYTE ucPseudoLNamePath[ F_PATH_MAX_SIZE + 1]; - FLMBYTE ucLNamePath[ F_PATH_MAX_SIZE]; - LONG lVolumeID; - LONG lPathID; - LONG lLNamePathCount; - LONG lDirectoryID; - - f_strcpy( (char *)&ucPseudoLNamePath[1], pPath); - ucPseudoLNamePath[0] = (FLMBYTE)f_strlen( pPath ); - if( ConvertPathString( 0, 0, ucPseudoLNamePath, &lVolumeID, &lPathID, - ucLNamePath, &lLNamePathCount) == 0) - { - if( MapPathToDirectoryNumber( 0, lVolumeID, 0, ucLNamePath, - lLNamePathCount, LONGNameSpace, &lDirectoryID, &lIsFile) == 0) - { - bIsDir = (FLMBOOL)((lIsFile == 0) ? (FLMBOOL)TRUE : (FLMBOOL)FALSE); - } - } - - return( bIsDir); - -#elif defined( FLM_WIN) - - DWORD FileAttr = GetFileAttributes( (LPTSTR)pPath); - - if( FileAttr == 0xFFFFFFFF) - { - return( bIsDir); - } - - return( FileAttr & FILE_ATTRIBUTE_DIRECTORY) ? TRUE : FALSE; - -#else - - struct stat filestatus; - - if( stat( pPath, &filestatus) == -1) - { - return bIsDir; - } - - return( S_ISDIR( filestatus.st_mode)) ? TRUE : FALSE; -#endif -} - -/**************************************************************************** -Desc: Delete a file or directory -****************************************************************************/ -RCODE F_FileSystemImp::Delete( - const char * pPath) -{ -#if defined( FLM_NLM) - - return( NWDeleteFile( pPath)); - -#elif defined( FLM_WIN) - - if( DeleteFile( (LPTSTR)pPath) == FALSE) - { - return( MapWinErrorToFlaim( GetLastError(), FERR_DELETING_FILE)); - } - - return FERR_OK; - -#else - - struct stat FileStat; - - if( stat( pPath, &FileStat) == -1) - { - return( MapErrnoToFlaimErr( errno, FERR_GETTING_FILE_INFO)); - } - - if( S_ISDIR(FileStat.st_mode)) - { - return( RC_SET( FERR_IO_ACCESS_DENIED)); - } - - if( unlink( pPath) == -1) - { - return( MapErrnoToFlaimErr( errno, FERR_DELETING_FILE)); - } - - return( FERR_OK); -#endif -} - -/**************************************************************************** -Desc: Copy a file. -****************************************************************************/ -RCODE F_FileSystemImp::Copy( - const char * pSrcFilePath, - const char * pDestFilePath, - FLMBOOL bOverwrite, - FLMUINT * puiBytesCopied) -{ - RCODE rc = FERR_OK; - F_FileHdl * pSrcFileHdl = NULL; - F_FileHdl * pDestFileHdl = NULL; - FLMBOOL bCreatedDest = FALSE; - FLMUINT uiSrcSize; - - // See if the destination file exists. If it does, see if it is - // OK to overwrite it. If so, delete it. - - if( Exists( pDestFilePath) == FERR_OK) - { - if( !bOverwrite) - { - rc = RC_SET( FERR_IO_ACCESS_DENIED); - goto Exit; - } - - if( RC_BAD( rc = Delete( pDestFilePath))) - { - goto Exit; - } - } - - // Open the source file - - if( RC_BAD( rc = Open( pSrcFilePath, F_IO_RDONLY | F_IO_SH_DENYNONE, - &pSrcFileHdl))) - { - goto Exit; - } - - if( RC_BAD( rc = pSrcFileHdl->Size( &uiSrcSize))) - { - goto Exit; - } - - // Create the destination file - - if( RC_BAD( rc = Create( pDestFilePath, F_IO_RDWR | F_IO_SH_DENYNONE, - &pDestFileHdl))) - { - goto Exit; - } - - bCreatedDest = TRUE; - - // Do the copy - - if( RC_BAD( rc = flmCopyPartial( pSrcFileHdl, 0, uiSrcSize, - pDestFileHdl, 0, puiBytesCopied))) - { - goto Exit; - } - -Exit: - - if( pSrcFileHdl) - { - pSrcFileHdl->Close(); - pSrcFileHdl->Release(); - } - - if( pDestFileHdl) - { - pDestFileHdl->Close(); - pDestFileHdl->Release(); - } - - if( RC_BAD( rc)) - { - if( bCreatedDest) - { - (void)Delete( pDestFilePath); - } - - *puiBytesCopied = 0; - } - - return( rc); -} - -/**************************************************************************** -Desc: Rename a file. -****************************************************************************/ -RCODE F_FileSystemImp::Rename( - const char * pFilePath, - const char * pNewFilePath) -{ -#if defined( FLM_NLM) - - return( NWRenameFile( pFilePath, pNewFilePath)); - -#elif defined( FLM_WIN) - DWORD error; - RCODE rc = FERR_OK; - FLMUINT uiBytesCopied; - - // Try to move the file by doing a rename first, otherwise copy the file - - if( (MoveFile( (LPTSTR)pFilePath, (LPTSTR)pNewFilePath)) != TRUE) - { - error = GetLastError(); - - switch( error) - { - case ERROR_NOT_SAME_DEVICE: - case ERROR_NO_MORE_FILES: - case NO_ERROR: - { - if( Copy( pFilePath, pNewFilePath, TRUE, &uiBytesCopied)) - { - rc = RC_SET( FERR_IO_COPY_ERR); - } - else - { - rc = F_FileSystemImp::Delete( pFilePath); - } - - break; - } - - default: - { - rc = MapWinErrorToFlaim( error, FERR_RENAMING_FILE); - break; - } - } - } - - return( rc); - -#else - RCODE rc = FERR_OK; - FLMBOOL bSrcIsDir; - FLMUINT uiBytesCopied; - - if( RC_BAD( rc = targetIsDir( (const char *)pFilePath, &bSrcIsDir))) - { - return( rc); - } - - errno = 0; - - if( RC_BAD( renameSafe( pFilePath, pNewFilePath))) - { - switch( errno) - { - case EXDEV: - { - if( bSrcIsDir) - { - return( RC_SET( FERR_IO_PATH_CREATE_FAILURE)); - } - else - { - if( Copy( pFilePath, pNewFilePath, TRUE, &uiBytesCopied)) - { - return( RC_SET( FERR_IO_COPY_ERR)); - } - - F_FileSystemImp::Delete( pFilePath); - return( FERR_OK); - } - } - - default: - { - if( errno == ENOENT) - { - return( RC_SET( FERR_IO_RENAME_FAILURE)); - } - else - { - return( MapErrnoToFlaimErr( errno, FERR_RENAMING_FILE)); - } - } - } - } - - return( FERR_OK); -#endif -} - -/**************************************************************************** -Desc: Get the sector size (not supported on all platforms). -****************************************************************************/ -RCODE F_FileSystemImp::GetSectorSize( - const char * pFileName, - FLMUINT * puiSectorSize) -{ -#ifdef FLM_NLM - - F_UNREFERENCED_PARM( pFileName); - *puiSectorSize = 512; - return( FERR_OK); - -#elif defined( FLM_WIN) - - RCODE rc = FERR_OK; - DWORD udSectorsPerCluster; - DWORD udBytesPerSector; - DWORD udNumberOfFreeClusters; - DWORD udTotalNumberOfClusters; - char szVolume [256]; - char * pszVolume; - FLMUINT uiLen; - - if( !pFileName) - { - pszVolume = NULL; - } - else - { - f_pathParse( pFileName, NULL, szVolume, NULL, NULL); - - if( !szVolume [0]) - { - pszVolume = NULL; - } - else - { - uiLen = f_strlen( szVolume); - - if( szVolume [uiLen - 1] == ':') - { - szVolume [uiLen] = '\\'; - szVolume [uiLen + 1] = 0; - } - pszVolume = &szVolume [0]; - } - } - - if( !GetDiskFreeSpace( (LPCTSTR)pszVolume, &udSectorsPerCluster, - &udBytesPerSector, &udNumberOfFreeClusters, - &udTotalNumberOfClusters)) - { - rc = MapWinErrorToFlaim( GetLastError(), - FERR_INITIALIZING_IO_SYSTEM); - *puiSectorSize = 0; - goto Exit; - } - - *puiSectorSize = (FLMUINT)udBytesPerSector; - -Exit: - - return( rc); - -#else - - F_UNREFERENCED_PARM( pFileName); - *puiSectorSize = 0; - return( FERR_OK); - -#endif -} - -/**************************************************************************** -Desc: Set the Read-Only Attribute (not supported on all platforms). -****************************************************************************/ -RCODE F_FileSystemImp::SetReadOnly( - const char * pszFileName, - FLMBOOL bReadOnly) -{ - RCODE rc = FERR_OK; - -#if defined( FLM_UNIX) - struct stat filestatus; - - if( stat( (char *)pszFileName, &filestatus)) - { - flmAssert( 0); - rc = RC_SET( FERR_FAILURE); - goto Exit; - } - - if ( bReadOnly) - { - filestatus.st_mode &= ~S_IWUSR; - } - else - { - filestatus.st_mode |= S_IWUSR; - } - - if ( chmod( (char *)pszFileName, filestatus.st_mode)) - { - rc = RC_SET( FERR_FAILURE); - goto Exit; - } - -#elif defined( FLM_WIN) - - DWORD dwAttr; - - dwAttr = GetFileAttributes( (LPTSTR)pszFileName); - if( dwAttr == (DWORD)-1) - { - rc = RC_SET( FERR_IO_PATH_NOT_FOUND); - goto Exit; - } - - if ( bReadOnly) - { - dwAttr |= F_IO_FA_RDONLY; - } - else - { - dwAttr &= ~F_IO_FA_RDONLY; - } - - if( !SetFileAttributes( (LPTSTR)pszFileName, dwAttr)) - { - flmAssert( 0); - rc = RC_SET( FERR_FAILURE); - goto Exit; - } -#else - F_UNREFERENCED_PARM( pszFileName); - F_UNREFERENCED_PARM( bReadOnly); - flmAssert( 0); - rc = RC_SET( FERR_NOT_IMPLEMENTED); - goto Exit; -#endif - -Exit: - - return( rc); -} - -/**************************************************************************** -Desc: stat tpath to see if it is a directory -****************************************************************************/ -#if defined( FLM_UNIX) -RCODE F_FileSystemImp::targetIsDir( - const char * pszPath, - FLMBOOL * pbIsDir) -{ - RCODE rc = FERR_OK; - struct stat sbuf; - - *pbIsDir = FALSE; - - if( stat( pszPath, &sbuf) < 0) - { - rc = MapErrnoToFlaimErr( errno, FERR_IO_ACCESS_DENIED); - } - else if( (sbuf.st_mode & S_IFMT) == S_IFDIR) - { - *pbIsDir = TRUE; - } - - return( rc); -} -#endif - -/**************************************************************************** -Desc: Rename an existing file (typically an "X" locked file to an - unlocked file) using a safe (non-race) method. To ensure that - an existing file is not being overwritten by a rename operation, - we will first create a new file with the desired name (using the - CREAT and EXCL options, (ensuring a unique file name)). Then, - the source file will be renamed to new name. -****************************************************************************/ -#if defined( FLM_UNIX) -RCODE F_FileSystemImp::renameSafe( - const char * pszSrcFile, - const char * pszDestFile) -{ - RCODE rc = FERR_OK; - struct stat temp_stat_buf; - - // There appears to be a bug in newer versions of glibc (it was first - // noticed in RedHat 8) where the behavior of the reaname() function has - // changed. According to the man page, rename should allow you to - // overwrite an existing directory (ie: rename( "OldDir", "NewDir") - // should succeed, even if NewDir already exists). In order to - // avoid having #ifdefs for individual Linux distributions, we - // decided not to rely on this behavior, and simply do the - // existence test ourselves. Thus, the race condition that this - // function was supposed to avoid is theoretically possible, but as long - // as this function only gets called while the database is closed, it won't - // be a problem. - - errno = 0; - if( stat( pszDestFile, &temp_stat_buf) != -1) - { - // If we were able to stat it, then the file obviously exists... - - rc = RC_SET( FERR_IO_RENAME_FAILURE); - goto Exit; - } - else - { - if( errno != ENOENT) - { - // ENOENT means the file didn't exist, which is what we were - // hoping for - - rc = MapErrnoToFlaimErr( errno, FERR_IO_RENAME_FAILURE); - goto Exit; - } - } - - errno = 0; - if( rename( pszSrcFile, pszDestFile) != 0) - { - rc = MapErrnoToFlaimErr( errno, FERR_IO_RENAME_FAILURE); - } - -Exit: - - return( rc); -} -#endif diff --git a/flaim/src/ffilesys.h b/flaim/src/ffilesys.h deleted file mode 100644 index ab428fb..0000000 --- a/flaim/src/ffilesys.h +++ /dev/null @@ -1,160 +0,0 @@ -//------------------------------------------------------------------------- -// Desc: File system class - definitions. -// Tabs: 3 -// -// Copyright (c) 1998-2006 Novell, Inc. All Rights Reserved. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of version 2 of the GNU General Public -// License as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, contact Novell, Inc. -// -// To contact Novell about this file by physical or electronic mail, -// you may find current contact information at www.novell.com -// -// $Id: ffilesys.h 12329 2006-01-20 17:49:30 -0700 (Fri, 20 Jan 2006) ahodgkinson $ -//------------------------------------------------------------------------- - -#ifndef FFILESYS_H -#define FFILESYS_H - -#include "fpackon.h" - -// IMPORTANT NOTE: No other include files should follow this one except -// for fpackoff.h - -/**************************************************************************** -Desc: The F_FileSystem class provides a file system abstraction for - interacting with the underlying O/S file system. -****************************************************************************/ -class F_FileSystemImp : public F_FileSystem -{ -public: - - F_FileSystemImp() - { - } - - virtual ~F_FileSystemImp() - { - } - - RCODE Create( // Create a new file handle - const char * pszFilePath, // Name of file to be created - FLMUINT uiIoFlags, // Access amd Mode flags - F_FileHdl ** ppFileHdl); // Returns open file handle object. - - RCODE CreateBlockFile( // Create a new block-oriented file handle - const char * pszFilePath, // Name of file to be created - FLMUINT uiIoFlags, // Access amd Mode flags - FLMUINT uiBlockSize, // Block size - F_FileHdlImp ** ppFileHdl); // Returns open file handle object. - - RCODE CreateUnique( // Create a new file (with a unique - // file name). - char * pszDirPath, // Directory where file is to be created. - const char * pszFileExtension, // Extension to be used on file. - FLMUINT uiIoFlags, // Access and Mode flags. - F_FileHdl ** ppFileHdl); // Returns open file handle object. - - RCODE Open( // Open an existing file. - const char * pszFilePath, // Name of file to be opened. - FLMUINT uiIoFlags, // Access and Mode flags. - F_FileHdl ** ppFileHdl); // Returns open file handle object. - - RCODE OpenBlockFile( // Open an existing block-oriented file. - const char * pszFilePath, // Name of file to be opened. - FLMUINT uiIoFlags, // Access and Mode flags. - FLMUINT uiBlockSize, // Block size. - F_FileHdlImp ** ppFileHdl); // Returns open file handle object. - - RCODE OpenDir( // Open a directory - const char * pszDirPath, // Directory to be opened. - const char * pszPattern, // File name pattern. - F_DirHdl ** ppDirHdl); // Returns open directory handle - // object. - - RCODE CreateDir( // Create a directory - const char * pszDirPath); // Directory to be created. - - RCODE RemoveDir( // Remove a directory - const char * pszDirPath, // Directory to be removed. - FLMBOOL bClear = FALSE); // OK to delete files if dir is not empty? - - RCODE Exists( // See if a file or directory exists. - const char * pszPath); // Name of file or directory to check. - - FLMBOOL IsDir( // See if a path is a directory. - const char * pszPath); // Name of path to check. - - RCODE GetTimeStamp( // Get the date/time when the file - // was last updated. - const char * pszPath, // Path to file - FLMUINT * puiTimeStamp); // Buffer in which time stamp is - // returned. - - RCODE Delete( // Delete a file or directory - const char * pszPath); // Name of file or directory to delete. - - RCODE Copy( // Copy a file. - const char * pszSrcFilePath, // Name of source file to be copied. - const char * pszDestFilePath, // Name of destination file. - FLMBOOL bOverwrite, // Overwrite destination file? - FLMUINT * puiBytesCopied); // Number of bytes copied. - - RCODE Rename( // Rename a file. - const char * pszFilePath, // File to be renamed - const char * pszNewFilePath); // New file name - - // Miscellaneous methos - - RCODE SetReadOnly( - const char * pszFileName, - FLMBOOL bReadOnly); - - RCODE GetSectorSize( // Get the sector size of the volume for - const char * pFileName, // this file. - FLMUINT * puiSectorSize); - -private: - -#ifdef FLM_NLM - RCODE _CreateDir( - const char * pszPathToDirectory); -#endif - - FINLINE RCODE getFileHdl( - F_FileHdlImp ** ppFileHdl) - { - if( (*ppFileHdl = f_new F_FileHdlImp) == NULL) - { - return( RC_SET( FERR_MEM)); - } - - return( FERR_OK); - } - - RCODE RemoveEmptyDir( - const char * pszDirPath); - -#if defined( FLM_UNIX) - RCODE renameSafe( - const char * pszSrcFile, - const char * pszDestFile); - - RCODE targetIsDir( - const char * pszPath, - FLMBOOL * pbIsDir); -#endif -}; - -#include "fpackoff.h" - -#endif diff --git a/flaim/src/fgedcom.cpp b/flaim/src/fgedcom.cpp index 0c40f47..a0a112d 100644 --- a/flaim/src/fgedcom.cpp +++ b/flaim/src/fgedcom.cpp @@ -74,7 +74,7 @@ FSTATIC RCODE impRead( FLMUINT * puiBytesReadRV); FSTATIC RCODE tagValLenType( - POOL * pPool, + F_Pool * pPool, GED_STREAM * x, NODE ** ppNode, F_NameTable * pNameTable); @@ -147,7 +147,7 @@ Exit: Desc: *****************************************************************************/ RCODE GedPutBINARY( - POOL * pPool, + F_Pool * pPool, NODE * pNode, const void * pvData, FLMUINT uiDataLen, @@ -203,8 +203,8 @@ Exit: Desc: *****************************************************************************/ RCODE GedToTree( - POOL * pPool, - F_FileHdl * pFileHdl, + F_Pool * pPool, + IF_FileHdl * pFileHdl, char ** pBuf, FLMUINT uiBufSize, NODE ** ppRoot, @@ -218,7 +218,7 @@ RCODE GedToTree( FLMBYTE nextChar; NODE * nd = NULL; NODE * ndPrior = NULL; - FLMUINT startPos; + FLMUINT64 ui64StartPos; gedStream.pFileHdl = pFileHdl; gedStream.pThis = gedStream.pBuf = *pBuf; @@ -229,10 +229,11 @@ RCODE GedToTree( // Find 1st starting file position - if (RC_OK( pFileHdl->Seek( 0L, F_IO_SEEK_CUR, &gedStream.uiFilePos))) + if (RC_OK( pFileHdl->seek( 0, FLM_IO_SEEK_CUR, + &gedStream.ui64FilePos))) { gedStream.pLast = gedStream.pBuf; - gedReadChar( &gedStream, gedStream.uiFilePos); + gedReadChar( &gedStream, gedStream.ui64FilePos); } else { @@ -242,7 +243,7 @@ RCODE GedToTree( else { gedStream.errorIO = 0; - gedStream.uiFilePos = 0; + gedStream.ui64FilePos = 0; gedStream.pLast = gedStream.pBuf + (uiBufSize - 1); gedStream.thisC = f_toascii( *gedStream.pBuf); } @@ -250,7 +251,7 @@ RCODE GedToTree( for (;;) { gedSkipBlankLines( &gedStream); - startPos = gedStream.uiFilePos; + ui64StartPos = gedStream.ui64FilePos; if (f_isdigit( gedStream.thisC)) { @@ -320,13 +321,13 @@ RCODE GedToTree( successful: ndPrior->next = NULL; - if (pFileHdl == NULL) + if( !pFileHdl) { *pBuf = gedStream.pThis + - (FLMINT32) (startPos - gedStream.uiFilePos); + (FLMINT32) (ui64StartPos - gedStream.ui64FilePos); } - gedStream.uiFilePos = startPos; + gedStream.ui64FilePos = ui64StartPos; rc = FERR_OK; } else @@ -354,7 +355,8 @@ successful: if (pFileHdl) { - pFileHdl->Seek( gedStream.uiFilePos, F_IO_SEEK_SET, &gedStream.uiFilePos); + pFileHdl->seek( gedStream.ui64FilePos, FLM_IO_SEEK_SET, + &gedStream.ui64FilePos); } return (rc); @@ -364,21 +366,21 @@ successful: Desc: *****************************************************************************/ FSTATIC RCODE tagValLenType( - POOL * pPool, + F_Pool * pPool, GED_STREAM * pGedStream, NODE ** newNode, F_NameTable * pNameTable) { - FLMUINT startPos; - RCODE rc = FERR_OK; - NODE * nd; - FLMUINT drn = 0; - FLMUINT uiTagNum; - char tagBuf[ GED_MAXTAGLEN + 1]; + FLMUINT64 ui64StartPos; + RCODE rc = FERR_OK; + NODE * nd; + FLMUINT drn = 0; + FLMUINT uiTagNum; + char tagBuf[ GED_MAXTAGLEN + 1]; gedSkipWhiteSpaces( pGedStream); - startPos = pGedStream->uiFilePos; + ui64StartPos = pGedStream->ui64FilePos; if (pGedStream->thisC == ASCII_AT) { int badDRN; @@ -422,7 +424,7 @@ FSTATIC RCODE tagValLenType( // Determine the Tag Number and Build the NODE - startPos = pGedStream->uiFilePos; + ui64StartPos = pGedStream->ui64FilePos; if (!gedCopyTag( pGedStream, tagBuf)) { @@ -455,7 +457,7 @@ FSTATIC RCODE tagValLenType( gedSkipWhiteSpaces( pGedStream); - startPos = pGedStream->uiFilePos; + ui64StartPos = pGedStream->ui64FilePos; if (pGedStream->thisC == ASCII_AT) { for (drn = 0; gedNextChar( pGedStream) != ASCII_AT;) @@ -485,8 +487,8 @@ FSTATIC RCODE tagValLenType( } else { - FLMINT valLength; - FLMUINT tempPos = pGedStream->uiFilePos; + FLMINT valLength; + FLMUINT64 ui64TempPos = pGedStream->ui64FilePos; if ((valLength = gedCopyValue( pGedStream, NULL)) > 0) { @@ -495,7 +497,7 @@ FSTATIC RCODE tagValLenType( if (vp) { - gedReadChar( pGedStream, tempPos); + gedReadChar( pGedStream, ui64TempPos); gedCopyValue( pGedStream, vp); } else @@ -506,11 +508,11 @@ FSTATIC RCODE tagValLenType( } } - startPos = pGedStream->uiFilePos; + ui64StartPos = pGedStream->ui64FilePos; Exit: - gedReadChar( pGedStream, startPos); + gedReadChar( pGedStream, ui64StartPos); return (rc); } @@ -518,10 +520,10 @@ Exit: Desc: *****************************************************************************/ NODE * GedNodeCopy( - POOL * pPool, + F_Pool * pPool, NODE * pNode, - NODE * childList, - NODE * sibList) + NODE * pChildList, + NODE * pSibList) { NODE * newNd; FLMUINT bias; @@ -557,7 +559,7 @@ NODE * GedNodeCopy( } newNd->prior = NULL; - newNd->next = childList; + newNd->next = pChildList; GedNodeLevelSet( newNd, 0); if ((vp = (FLMBYTE *) GedAllocSpace( pPool, newNd, GedValType( pNode), @@ -577,28 +579,28 @@ NODE * GedNodeCopy( return (NULL); } - if (childList) + if (pChildList) { - childList->prior = newNd; - for (bias = GedNodeLevel( childList) - 1; - childList->next; - GedNodeLevelSub( childList, bias), childList = childList->next); + pChildList->prior = newNd; + for (bias = GedNodeLevel( pChildList) - 1; + pChildList->next; + GedNodeLevelSub( pChildList, bias), pChildList = pChildList->next); - GedNodeLevelSub( childList, bias); - childList->next = sibList; + GedNodeLevelSub( pChildList, bias); + pChildList->next = pSibList; } else { - childList = newNd; + pChildList = newNd; } - if (sibList) + if (pSibList) { - sibList->prior = childList; - childList->next = sibList; - for (bias = GedNodeLevel( sibList); sibList->next; - GedNodeLevelSub( sibList, bias), sibList = sibList->next); - GedNodeLevelSub( sibList, bias); + pSibList->prior = pChildList; + pChildList->next = pSibList; + for (bias = GedNodeLevel( pSibList); pSibList->next; + GedNodeLevelSub( pSibList, bias), pSibList = pSibList->next); + GedNodeLevelSub( pSibList, bias); } return (newNd); @@ -608,7 +610,7 @@ NODE * GedNodeCopy( Desc: *****************************************************************************/ NODE * GedCopy( - POOL * pPool, + F_Pool * pPool, FLMUINT cnt, NODE * tree) { @@ -928,36 +930,37 @@ NODE * GedSibGraft( Desc: *****************************************************************************/ NODE * GedNodeCreate( - POOL * pPool, + F_Pool * pPool, FLMUINT tagNum, FLMUINT id, RCODE * rc) { NODE * nd; - - if ((nd = (NODE *) GedPoolAlloc( pPool, (sizeof(NODE) + - (id ? sizeof(id) : 0)))) == NULL) + + *rc = FERR_OK; + + if( RC_BAD( *rc = pPool->poolAlloc( (sizeof(NODE) + (id ? sizeof(id) : 0)), + (void **)&nd))) { - *rc = RC_SET( FERR_MEM); - } - else - { - f_memset( nd, '\0', sizeof(NODE)); - - GedValTypeSet( nd, FLM_CONTEXT_TYPE); - GedTagNumSet( nd, tagNum); - - if (id) - { - FLMBYTE * ptr; - GedValTypeSetFlag( nd, HAS_REC_ID); - ptr = ((FLMBYTE *) nd) + sizeof(NODE); - *((FLMUINT *) (ptr + NODE_DRN_POS)) = id; - } - - *rc = FERR_OK; + goto Exit; } + f_memset( nd, '\0', sizeof(NODE)); + + GedValTypeSet( nd, FLM_CONTEXT_TYPE); + GedTagNumSet( nd, tagNum); + + if (id) + { + FLMBYTE * ptr; + + GedValTypeSetFlag( nd, HAS_REC_ID); + ptr = ((FLMBYTE *) nd) + sizeof(NODE); + *((FLMUINT *) (ptr + NODE_DRN_POS)) = id; + } + +Exit: + return (nd); } @@ -965,7 +968,7 @@ NODE * GedNodeCreate( Desc: *****************************************************************************/ void * GedAllocSpace( - POOL * pPool, + F_Pool * pPool, NODE * pNode, FLMUINT valType, FLMUINT size, @@ -997,13 +1000,14 @@ void * GedAllocSpace( } else { - if ((pNode->value = rPtr = (FLMBYTE *) GedPoolAlloc( - pPool, uiAllocSize)) == NULL) + if( RC_BAD( pPool->poolAlloc( uiAllocSize, (void **)&rPtr))) { pNode->ui32Length = 0; pNode->value = NULL; return (NULL); } + + pNode->value = rPtr; } if (valType == FLM_TEXT_TYPE) @@ -1041,8 +1045,8 @@ void * GedAllocSpace( { if (uiEncSize > GedEncLen( pNode)) { - if ((pNode->pucEncValue = (FLMBYTE *) GedPoolAlloc( - pPool, uiEncSize)) == NULL) + if( RC_BAD( pPool->poolAlloc( uiEncSize, + (void **)&pNode->pucEncValue))) { pNode->ui32EncLength = 0; pNode->pucEncValue = NULL; @@ -1090,7 +1094,7 @@ void * GedEncPtr( Desc: *****************************************************************************/ RCODE GedPutRecId( - POOL * pPool, + F_Pool * pPool, NODE ** ppNd, FLMUINT uiId) { @@ -1098,8 +1102,8 @@ RCODE GedPutRecId( NODE * pOldNd = *ppNd; FLMBYTE * ptr; - if ((pNewNd = (NODE *) GedPoolAlloc( pPool, - sizeof(NODE) + sizeof(uiId))) == NULL) + if( RC_BAD( pPool->poolAlloc( sizeof(NODE) + sizeof(uiId), + (void **)&pNewNd))) { *ppNd = NULL; return (RC_SET( FERR_MEM)); @@ -1250,7 +1254,7 @@ Exit: Desc: *****************************************************************************/ RCODE GedPutRecPtr( - POOL * pPool, + F_Pool * pPool, NODE * nd, FLMUINT drn, FLMUINT uiEncId, @@ -1422,7 +1426,7 @@ NODE * GedSibPrev( Desc: *****************************************************************************/ RCODE GedPutNATIVE( - POOL * pPool, + F_Pool * pPool, NODE * pNode, const char * nativeString, FLMUINT uiEncId, @@ -1535,7 +1539,7 @@ Exit: Desc: *****************************************************************************/ RCODE GedPutUINT( - POOL * pPool, + F_Pool * pPool, NODE * pNode, FLMUINT uiNum, FLMUINT uiEncId, @@ -1605,7 +1609,7 @@ Exit: Desc: *****************************************************************************/ RCODE GedPutINT( - POOL * pPool, + F_Pool * pPool, NODE * pNode, FLMINT iNum, FLMUINT uiEncId, @@ -2404,7 +2408,7 @@ RCODE GedTextToNum( Desc: *****************************************************************************/ RCODE GedPutUNICODE( - POOL * pPool, + F_Pool * pPool, NODE * pNode, const FLMUNICODE * puzString, FLMUINT uiEncId, @@ -2512,7 +2516,7 @@ Exit: Desc: *****************************************************************************/ RCODE gedCreateSourceNode( - POOL * pPool, + F_Pool * pPool, FLMUINT uiFieldNum, HFDB hDb, FLMUINT uiContainer, @@ -2522,29 +2526,28 @@ RCODE gedCreateSourceNode( NODE * nd; RCODE rc = FERR_OK; - *ppNode = nd = (NODE *) GedPoolCalloc( pPool, (sizeof(NODE) + - sizeof(FLMUINT) + sizeof(FLMUINT) + sizeof(HFDB))); + if( RC_BAD( rc = pPool->poolCalloc( + sizeof(NODE) + sizeof(FLMUINT) + sizeof(FLMUINT) + sizeof(HFDB), + (void **)&nd))) + { + goto Exit; + } + + GedValTypeSet( nd, FLM_CONTEXT_TYPE); + GedTagNumSet( nd, uiFieldNum); + gedSetRecSource( nd, hDb, uiContainer, uiRecId); + *ppNode = nd; - if (nd != NULL) - { - GedValTypeSet( nd, FLM_CONTEXT_TYPE); - GedTagNumSet( nd, uiFieldNum); - gedSetRecSource( nd, hDb, uiContainer, uiRecId); - } - else - { - rc = RC_SET( FERR_MEM); - } +Exit: return (rc); } - /***************************************************************************** Desc: *****************************************************************************/ RCODE expImpInit( - F_FileHdl * pFileHdl, + IF_FileHdl * pFileHdl, FLMUINT uiFlag, EXP_IMP_INFO * pExpImpInfoRV) { @@ -2589,8 +2592,8 @@ RCODE expImpInit( } else if (uiFlag == EXPIMP_IMPORT_DICTIONARY) { - rc = pFileHdl->Seek( (FLMUINT) BINARY_GED_HEADER_LEN, F_IO_SEEK_SET, - &pExpImpInfoRV->uiFilePos); + rc = pFileHdl->seek( (FLMUINT) BINARY_GED_HEADER_LEN, FLM_IO_SEEK_SET, + &pExpImpInfoRV->ui64FilePos); } else { @@ -2632,7 +2635,7 @@ RCODE expFlush( if ((pExpImpInfo->uiBufUsed) && (pExpImpInfo->bBufDirty)) { - if (RC_BAD( rc = pExpImpInfo->pFileHdl->Write( pExpImpInfo->uiFilePos, + if (RC_BAD( rc = pExpImpInfo->pFileHdl->write( pExpImpInfo->ui64FilePos, pExpImpInfo->uiBufUsed, pExpImpInfo->pBuf, &uiBytesWritten))) { goto Exit; @@ -2644,7 +2647,7 @@ RCODE expFlush( goto Exit; } - pExpImpInfo->uiFilePos += uiBytesWritten; + pExpImpInfo->ui64FilePos += uiBytesWritten; pExpImpInfo->uiCurrBuffOffset = pExpImpInfo->uiBufUsed = 0; pExpImpInfo->bBufDirty = FALSE; } @@ -2663,10 +2666,11 @@ RCODE expImpSeek( { RCODE rc = FERR_OK; - if ((uiSeekPos >= pExpImpInfo->uiFilePos) && - (uiSeekPos < pExpImpInfo->uiFilePos + (FLMUINT) pExpImpInfo->uiBufUsed)) + if ((uiSeekPos >= pExpImpInfo->ui64FilePos) && + (uiSeekPos < pExpImpInfo->ui64FilePos + (FLMUINT) pExpImpInfo->uiBufUsed)) { - pExpImpInfo->uiCurrBuffOffset = (FLMUINT) (uiSeekPos - pExpImpInfo->uiFilePos); + pExpImpInfo->uiCurrBuffOffset = + (FLMUINT) (uiSeekPos - pExpImpInfo->ui64FilePos); } else { @@ -2678,7 +2682,7 @@ RCODE expImpSeek( } } - pExpImpInfo->uiFilePos = uiSeekPos; + pExpImpInfo->ui64FilePos = uiSeekPos; pExpImpInfo->uiBufUsed = pExpImpInfo->uiCurrBuffOffset = 0; } @@ -2904,11 +2908,11 @@ FSTATIC RCODE impRead( } else { - pExpImpInfo->uiFilePos += (FLMUINT) pExpImpInfo->uiBufUsed; + pExpImpInfo->ui64FilePos += (FLMUINT) pExpImpInfo->uiBufUsed; pExpImpInfo->uiBufUsed = pExpImpInfo->uiCurrBuffOffset = 0; } - if (RC_BAD( rc = pExpImpInfo->pFileHdl->Read( pExpImpInfo->uiFilePos, + if (RC_BAD( rc = pExpImpInfo->pFileHdl->read( pExpImpInfo->ui64FilePos, pExpImpInfo->uiBufSize, pExpImpInfo->pBuf, &pExpImpInfo->uiBufUsed))) { @@ -3109,12 +3113,11 @@ Exit: Desc: *****************************************************************************/ RCODE impFileIsExpImp( - F_FileHdl * pFileHdl, + IF_FileHdl * pFileHdl, FLMBOOL * pbFileIsBinaryRV) { RCODE rc = FERR_OK; - FLMUINT uiCurrPos; - FLMUINT uiIgnore; + FLMUINT64 ui64CurrPos; FLMBYTE byHeader[ BINARY_GED_HEADER_LEN]; FLMUINT uiBytesRead; @@ -3122,14 +3125,14 @@ RCODE impFileIsExpImp( // Save current position so we can return to it. - if (RC_BAD( rc = pFileHdl->Seek( (FLMUINT) 0, F_IO_SEEK_CUR, &uiCurrPos))) + if (RC_BAD( rc = pFileHdl->seek( 0, FLM_IO_SEEK_CUR, &ui64CurrPos))) { goto Exit; } // Read the file's header information. - if (RC_BAD( rc = pFileHdl->Read( (FLMUINT) 0, BINARY_GED_HEADER_LEN, + if (RC_BAD( rc = pFileHdl->read( (FLMUINT) 0, BINARY_GED_HEADER_LEN, byHeader, &uiBytesRead))) { if (rc == FERR_IO_END_OF_FILE) @@ -3152,7 +3155,7 @@ RCODE impFileIsExpImp( // Reset the file position to where it was before. - rc = pFileHdl->Seek( uiCurrPos, F_IO_SEEK_SET, &uiIgnore); + rc = pFileHdl->seek( ui64CurrPos, FLM_IO_SEEK_SET); Exit: @@ -3164,7 +3167,7 @@ Exit: Desc: This routine adds a field to a GEDCOM tree ****************************************************************************/ RCODE gedAddField( - POOL * pPool, + F_Pool * pPool, NODE * pRecord, FLMUINT uiTagNum, const void * pvData, diff --git a/flaim/src/filesys.h b/flaim/src/filesys.h index bb99f14..6b1feca 100644 --- a/flaim/src/filesys.h +++ b/flaim/src/filesys.h @@ -892,7 +892,7 @@ struct UCUR; RCODE FSReadElement( FDB * pDb, - POOL * pPool, + F_Pool * pPool, LFILE * pLFile, FLMUINT drn, BTSK * pStack, @@ -1493,38 +1493,6 @@ struct UCUR; return( SENNextVal( &pCurElm)); } - /**************************************************************************** - Desc: This routine locks the write lock on a database. - ****************************************************************************/ - inline RCODE dbWriteLock( - FFILE * pFile, - DB_STATS * pDbStats = NULL, - FLMUINT uiTimeout = FLM_NO_TIMEOUT) - { - RCODE rc = FERR_OK; - - if (RC_BAD( rc = pFile->pWriteLockObj->Lock( FALSE, NULL, - (FLMBOOL)(uiTimeout ? TRUE : FALSE), - TRUE, uiTimeout, 0, pDbStats))) - { - goto Exit; - } - - Exit: - - return( rc); - } - - /**************************************************************************** - Desc: This routine unlocks the write lock on a database. - ****************************************************************************/ - inline void dbWriteUnlock( - FFILE * pFile, - DB_STATS * pDbStats = NULL) - { - (void)pFile->pWriteLockObj->Unlock( FALSE, NULL, FALSE, pDbStats); - } - /**************************************************************************** Desc: ****************************************************************************/ diff --git a/flaim/src/flaim.h b/flaim/src/flaim.h index c179cd2..43dac6c 100644 --- a/flaim/src/flaim.h +++ b/flaim/src/flaim.h @@ -28,293 +28,7 @@ #ifndef FLAIM_H #define FLAIM_H - #ifndef FLM_PLATFORM_CONFIGURED - #define FLM_PLATFORM_CONFIGURED - - // Determine the build platform - - #undef FLM_WIN - #undef FLM_NLM - #undef FLM_UNIX - #undef FLM_AIX - #undef FLM_LINUX - #undef FLM_SOLARIS - #undef FLM_SPARC - #undef FLM_HPUX - #undef FLM_OSX - #undef FLM_BIG_ENDIAN - #undef FLM_PPC - #undef FLM_STRICT_ALIGNMENT - #undef FLM_S390 - #undef FLM_IA64 - #undef FLM_GNUC - - #if defined( __GNUC__) - #define FLM_GNUC - #endif - - #if defined( __NETWARE__) || defined( NLM) || defined( N_PLAT_NLM) - #define FLM_NLM - #define FLM_OSTYPE_STR "NetWare" - #if defined( __WATCOMC__) - #define FLM_WATCOM_NLM - #elif defined( __MWERKS__) - #define FLM_MWERKS_NLM - #endif - #elif defined( _WIN64) - #define FLM_WIN - #define FLM_OSTYPE_STR "Windows" - #ifndef FLM_64BIT - #define FLM_64BIT - #endif - #define FLM_STRICT_ALIGNMENT - #elif defined( _WIN32) - #define FLM_WIN - #define FLM_OSTYPE_STR "Windows" - #elif defined( _AIX) - #define FLM_AIX - #define FLM_OSTYPE_STR "AIX" - #define FLM_UNIX - #define FLM_BIG_ENDIAN - #define FLM_STRICT_ALIGNMENT - #elif defined( linux) - #define FLM_LINUX - #define FLM_OSTYPE_STR "Linux" - #define FLM_UNIX - #if defined( __PPC__) || defined( __ppc__) - #define FLM_PPC - #define FLM_BIG_ENDIAN - #define FLM_STRICT_ALIGNMENT - #elif defined( __s390__) - #define FLM_S390 - #define FLM_BIG_ENDIAN - #define FLM_STRICT_ALIGNMENT - #elif defined( __s390x__) - #define FLM_S390 - #ifndef FLM_64BIT - #define FLM_64BIT - #endif - #define FLM_BIG_ENDIAN - #define FLM_STRICT_ALIGNMENT - #elif defined( __ia64__) - #define FLM_IA64 - #ifndef FLM_64BIT - #define FLM_64BIT - #endif - #define FLM_STRICT_ALIGNMENT - #elif defined( sparc) || defined( __sparc) || defined( __sparc__) - #define FLM_SPARC - #define FLM_BIG_ENDIAN - #define FLM_STRICT_ALIGNMENT - #endif - #elif defined( sun) - #define FLM_SOLARIS - #define FLM_OSTYPE_STR "Solaris" - #define FLM_UNIX - #define FLM_STRICT_ALIGNMENT - #if defined( sparc) || defined( __sparc) || defined( __sparc__) - #define FLM_SPARC - #define FLM_BIG_ENDIAN - #endif - #elif defined( __hpux) || defined( hpux) - #define FLM_HPUX - #define FLM_OSTYPE_STR "HPUX" - #define FLM_UNIX - #define FLM_BIG_ENDIAN - #define FLM_STRICT_ALIGNMENT - #elif defined( __APPLE__) - #define FLM_OSX - #define FLM_OSTYPE_STR "OSX" - #define FLM_UNIX - #if (defined( __ppc__) || defined( __ppc64__)) - #define FLM_PPC - #define FLM_BIG_ENDIAN - #define FLM_STRICT_ALIGNMENT - #endif - #else - #error Platform architecture is undefined. - #endif - - #if !defined( FLM_64BIT) && !defined( FLM_32BIT) - #if defined( FLM_UNIX) - #if defined( __x86_64__) || defined( _LP64) || \ - defined( __LP64__) || defined( __sparcv9) - #define FLM_64BIT - #endif - #endif - #endif - - #if !defined( FLM_64BIT) - #define FLM_32BIT - #elif defined( FLM_32BIT) - #error Cannot define both FLM_32BIT and FLM_64BIT - #endif - - // Debug or release build? - - #ifndef FLM_DEBUG - #if defined( DEBUG) || (defined( PRECHECKIN) && PRECHECKIN != 0) - #define FLM_DEBUG - #endif - #endif - - // Alignment - - #if defined( FLM_UNIX) || defined( FLM_64BIT) - #define FLM_ALLOC_ALIGN 0x0007 - #define FLM_ALIGN_SIZE 8 - #elif defined( FLM_WIN) || defined( FLM_NLM) - #define FLM_ALLOC_ALIGN 0x0003 - #define FLM_ALIGN_SIZE 4 - #else - #error Platform not supported - #endif - - // Basic type definitions - - #if defined( FLM_UNIX) - typedef unsigned long FLMUINT; - typedef long FLMINT; - typedef unsigned char FLMBYTE; - typedef unsigned short FLMUNICODE; - - typedef unsigned long long FLMUINT64; - typedef unsigned int FLMUINT32; - typedef unsigned short FLMUINT16; - typedef unsigned char FLMUINT8; - typedef long long FLMINT64; - typedef int FLMINT32; - typedef short FLMINT16; - typedef signed char FLMINT8; - - #if defined( FLM_64BIT) || defined( FLM_OSX) || \ - defined( FLM_S390) || defined( FLM_HPUX) || defined( FLM_AIX) - typedef unsigned long FLMSIZET; - #else - typedef unsigned FLMSIZET; - #endif - #else - - #if defined( FLM_WIN) - - #if defined( FLM_64BIT) - typedef unsigned __int64 FLMUINT; - typedef __int64 FLMINT; - typedef unsigned __int64 FLMSIZET; - typedef unsigned int FLMUINT32; - #elif _MSC_VER >= 1300 - typedef unsigned long __w64 FLMUINT; - typedef long __w64 FLMINT; - typedef unsigned int FLMUINT32; - typedef __w64 unsigned int FLMSIZET; - #else - typedef unsigned long FLMUINT; - typedef long FLMINT; - typedef unsigned int FLMUINT32; - typedef __w64 unsigned int FLMSIZET; - #endif - - #elif defined( FLM_NLM) - - typedef unsigned long int FLMUINT; - typedef long int FLMINT; - typedef unsigned long int FLMUINT32; - typedef unsigned FLMSIZET; - #else - #error Platform not supported - #endif - - typedef unsigned char FLMBYTE; - typedef unsigned short int FLMUNICODE; - - typedef unsigned short int FLMUINT16; - typedef unsigned char FLMUINT8; - typedef signed int FLMINT32; - typedef signed short int FLMINT16; - typedef signed char FLMINT8; - - #if defined( __MWERKS__) - typedef unsigned long long FLMUINT64; - typedef long long FLMINT64; - #else - typedef unsigned __int64 FLMUINT64; - typedef __int64 FLMINT64; - #endif - - #endif - - #if defined( FLM_WIN) || defined( FLM_NLM) - #define FLMATOMIC volatile long - #else - #define FLMATOMIC volatile int - #endif - - /// \addtogroup retcodes - /// @{ - typedef FLMINT RCODE; ///< Return code - /// @} - - typedef FLMINT FLMBOOL; - - #define F_FILENAME_SIZE 256 - #define F_PATH_MAX_SIZE 256 - - #define FLM_MAX_UINT ((FLMUINT)(-1L)) - #define FLM_MAX_INT ((FLMINT)(((FLMUINT)(-1L)) >> 1)) - #define FLM_MIN_INT ((FLMINT)((((FLMUINT)(-1L)) >> 1) + 1)) - #define FLM_MAX_UINT32 ((FLMUINT32)(0xFFFFFFFFL)) - #define FLM_MAX_INT32 ((FLMINT32)(0x7FFFFFFFL)) - #define FLM_MIN_INT32 ((FLMINT32)(0x80000000L)) - #define FLM_MAX_UINT16 ((FLMUINT16)(0xFFFF)) - #define FLM_MAX_INT16 ((FLMINT16)(0x7FFF)) - #define FLM_MIN_INT16 ((FLMINT16)(0x8000)) - #define FLM_MAX_UINT8 ((FLMUINT8)0xFF) - - #if( _MSC_VER >= 1200) && (_MSC_VER < 1300) - #define FLM_MAX_UINT64 ((FLMUINT64)(0xFFFFFFFFFFFFFFFFL)) - #define FLM_MAX_INT64 ((FLMINT64)(0x7FFFFFFFFFFFFFFFL)) - #define FLM_MIN_INT64 ((FLMINT64)(0x8000000000000000L)) - #else - #define FLM_MAX_UINT64 ((FLMUINT64)(0xFFFFFFFFFFFFFFFFLL)) - #define FLM_MAX_INT64 ((FLMINT64)(0x7FFFFFFFFFFFFFFFLL)) - #define FLM_MIN_INT64 ((FLMINT64)(0x8000000000000000LL)) - #endif - - #endif - - #if defined( FLM_WIN) - #if defined( FLM_DLL) - #if defined( FLM_SRC) - #define FLMEXP __declspec(dllexport) - #else - #define FLMEXP __declspec(dllimport) - #endif - #else - #define FLMEXP - #endif - #define FLMAPI __cdecl - #ifdef FLM_DEBUG - #define FINLINE inline - #else - #define FINLINE __forceinline - #endif - #elif defined( FLM_NLM) - #define FLMEXP - #define FLMAPI __cdecl - #define FINLINE inline - #elif defined( FLM_UNIX) - #define FLMEXP - #define FLMAPI - #if defined( FLM_GNUC) - #define FINLINE __attribute__((always_inline)) inline - #else - #define FINLINE inline - #endif - #else - #error Platform not supported - #endif - - /// \defgroup retcodes Return Codes + #include "flaimtk.h" /// \defgroup dbsystem FLAIM System Functions @@ -405,310 +119,263 @@ /// \defgroup memoryalloc Memory Functions /// \ingroup misc - #ifndef NULL - #define NULL 0 - #endif - - #ifndef TRUE - #define TRUE 1 - #endif - - #ifndef FALSE - #define FALSE 0 - #endif - - typedef void * F_MUTEX; - typedef void * F_SEM; - #define F_MUTEX_NULL NULL - #define F_MAXIMUM_FILE_SIZE 0xFFFC0000 - /**************************************************************************** Desc: General errors ****************************************************************************/ /// \addtogroup retcodes /// @{ - #define FERR_OK 0 ///< 0 - Operation succeeded + #define FERR_OK NE_FLM_OK ///< 0 - Operation succeeded - #define FIRST_FLAIM_ERROR 0xC001 ///< 0xC001 - Placeholder - #define FERR_BOF_HIT 0xC001 ///< 0xC001 - Beginning of file or set hit. - #define FERR_EOF_HIT 0xC002 ///< 0xC002 - End of file or set hit. - #define FERR_END 0xC003 ///< 0xC003 - End of GEDCOM file - this is an internal error. - #define FERR_EXISTS 0xC004 ///< 0xC004 - Record already exists. - #define FERR_FAILURE 0xC005 ///< 0xC005 - Internal failure. - #define FERR_NOT_FOUND 0xC006 ///< 0xC006 - A record, key, or key reference was not found. - #define FERR_BAD_DICT_ID 0xC007 ///< 0xC007 - Invalid dictionary record number -- outside unreserved range. - #define FERR_BAD_CONTAINER 0xC008 ///< 0xC008 - Invalid container number. - #define FERR_NO_ROOT_BLOCK 0xC009 ///< 0xC009 - LFILE does not have a root block - always handled internally - never returned to application. - #define FERR_BAD_DRN 0xC00A ///< 0xC00A - Cannot pass a zero DRN into modify or delete or 0xFFFFFFFF into add. - #define FERR_BAD_FIELD_NUM 0xC00B ///< 0xC00B - Bad field number in record being added. - #define FERR_BAD_FIELD_TYPE 0xC00C ///< 0xC00C - Bad field type in record being added. - #define FERR_BAD_HDL 0xC00D ///< 0xC00D - Request contained bad db handle. - #define FERR_BAD_IX 0xC00E ///< 0xC00E - Invalid index number. - #define FERR_BACKUP_ACTIVE 0xC00F ///< 0xC00F - Operation could not be completed - a backup is being performed. - #define FERR_SERIAL_NUM_MISMATCH 0xC010 ///< 0xC010 - Comparison of serial numbers failed. - #define FERR_BAD_RFL_DB_SERIAL_NUM 0xC011 ///< 0xC011 - Bad database serial number in RFL file header. - #define FERR_BTREE_ERROR 0xC012 ///< 0xC012 - A corruption was found in an index or container b-tree. - #define FERR_BTREE_FULL 0xC013 ///< 0xC013 - An index or container b-tree is full. - #define FERR_BAD_RFL_FILE_NUMBER 0xC014 ///< 0xC014 - Bad RFL file number in RFL file header. - #define FERR_CANNOT_DEL_ITEM 0xC015 ///< 0xC015 - Cannot delete field definitions. - #define FERR_CANNOT_MOD_FIELD_TYPE 0xC016 ///< 0xC016 - Cannot modify a field's type. - #define FERR_NOT_USED_C017 0xC017 ///< 0xC017 - Not used - #define FERR_CONV_BAD_DEST_TYPE 0xC018 ///< 0xC018 - Bad destination type specified for conversion. - #define FERR_CONV_BAD_DIGIT 0xC019 ///< 0xC019 - Non-numeric digit found in text to numeric conversion. - #define FERR_CONV_BAD_SRC_TYPE 0xC01A ///< 0xC01A - Bad source type specified for conversion. - #define FERR_RFL_FILE_NOT_FOUND 0xC01B ///< 0xC01B - Could not open an RFL file. - #define FERR_CONV_DEST_OVERFLOW 0xC01C ///< 0xC01C - Destination buffer not large enough to hold converted data. - #define FERR_CONV_ILLEGAL 0xC01D ///< 0xC01D - Illegal conversion -- not supported. - #define FERR_CONV_NULL_SRC 0xC01E ///< 0xC01E - Source cannot be a NULL pointer in conversion. - #define FERR_CONV_NULL_DEST 0xC01F ///< 0xC01F - Destination cannot be a NULL pointer in conversion. - #define FERR_CONV_NUM_OVERFLOW 0xC020 ///< 0xC020 - Numeric overflow (GT upper bound) converting to numeric type. - #define FERR_CONV_NUM_UNDERFLOW 0xC021 ///< 0xC021 - Numeric underflow (LT lower bound) converting to numeric type. - #define FERR_DATA_ERROR 0xC022 ///< 0xC022 - Database corruption found. - #define FERR_NOT_USED_C023 0xC023 ///< 0xC023 - Not used - #define FERR_DD_ERROR 0xC024 ///< 0xC024 - Corruption found in logical file block chain. - #define FERR_INVALID_FILE_SEQUENCE 0xC025 ///< 0xC025 - Incremental backup file number provided during a restore is invalid. - #define FERR_ILLEGAL_OP 0xC026 ///< 0xC026 - Illegal operation for database. - #define FERR_DUPLICATE_DICT_REC 0xC027 ///< 0xC027 - Duplicate dictionary record found. - #define FERR_CANNOT_CONVERT 0xC028 ///< 0xC028 - Condition occurred which prevents database conversion. - #define FERR_UNSUPPORTED_VERSION 0xC029 ///< 0xC029 - Database version is not supported. - #define FERR_FILE_ER 0xC02A ///< 0xC02A - File error in a GEDCOM routine. - #define FERR_BAD_FIELD_LEVEL 0xC02B ///< 0xC02B - Invalid field level. - #define FERR_GED_BAD_RECID 0xC02C ///< 0xC02C - Bad record ID syntax. - #define FERR_GED_BAD_VALUE 0xC02D ///< 0xC02D - Bad or ambiguous/extra value in GEDCOM. - #define FERR_GED_MAXLVLNUM 0xC02E ///< 0xC02E - Exceeded GED_MAXLVLNUM in gedcom routines. - #define FERR_GED_SKIP_LEVEL 0xC02F ///< 0xC02F - Bad GEDCOM tree structure -- level skipped. - #define FERR_ILLEGAL_TRANS 0xC030 ///< 0xC030 - Attempt to start an illegal type of transaction. - #define FERR_ILLEGAL_TRANS_OP 0xC031 ///< 0xC031 - Illegal operation for transaction type. - #define FERR_INCOMPLETE_LOG 0xC032 ///< 0xC032 - Incomplete log record encountered during recovery. - #define FERR_INVALID_BLOCK_LENGTH 0xC033 ///< 0xC033 - Invalid block length. - #define FERR_INVALID_TAG 0xC034 ///< 0xC034 - Invalid tag name. - #define FERR_KEY_NOT_FOUND 0xC035 ///< 0xC035 - A key or reference is not found -- modify/delete error. - #define FERR_VALUE_TOO_LARGE 0xC036 ///< 0xC036 - Value too large. - #define FERR_MEM 0xC037 ///< 0xC037 - Memory allocation error. - #define FERR_BAD_RFL_SERIAL_NUM 0xC038 ///< 0xC038 - Bad serial number in RFL file header. - #define FERR_NOT_USED_C039 0xC039 ///< 0xC039 - Not used - #define FERR_NEWER_FLAIM 0xC03A ///< 0xC03A - Database version newer than this code base will support, must use newer version of code. - #define FERR_CANNOT_MOD_FIELD_STATE 0xC03B ///< 0xC03B - Attempted to change a field state illegally. - #define FERR_NO_MORE_DRNS 0xC03C ///< 0xC03C - The highest DRN number has already been used in an add. - #define FERR_NO_TRANS_ACTIVE 0xC03D ///< 0xC03D - Attempted to updated database outside transaction. - #define FERR_NOT_UNIQUE 0xC03E ///< 0xC03E - Found duplicate key for unique index. - #define FERR_NOT_FLAIM 0xC03F ///< 0xC03F - File is not a FLAIM database. - #define FERR_NULL_RECORD 0xC040 ///< 0xC040 - NULL record cannot be passed to add or modify. - #define FERR_NO_HTTP_STACK 0xC041 ///< 0xC041 - No http stack was loaded. - #define FERR_OLD_VIEW 0xC042 ///< 0xC042 - While reading was unable to get previous version of block or record. - #define FERR_PCODE_ERROR 0xC043 ///< 0xC043 - Corruption found in dictionary. - #define FERR_PERMISSION 0xC044 ///< 0xC044 - Invalid permission for file operation. - #define FERR_SYNTAX 0xC045 ///< 0xC045 - Dictionary record has improper syntax, or syntax error in query criteria. - #define FERR_CALLBACK_FAILURE 0xC046 ///< 0xC046 - Callback failure. - #define FERR_TRANS_ACTIVE 0xC047 ///< 0xC047 - Attempted to close database while transaction was active. - #define FERR_RFL_TRANS_GAP 0xC048 ///< 0xC048 - A gap was found in the transaction sequence in the RFL. - #define FERR_BAD_COLLATED_KEY 0xC049 ///< 0xC049 - Something in collated key is bad. - #define FERR_UNSUPPORTED_FEATURE 0xC04A ///< 0xC04A - Attempting a feature that is not supported for the database version. - #define FERR_MUST_DELETE_INDEXES 0xC04B ///< 0xC04B - Attempting to delete a container that has indexes defined for it -- indexes must be deleted first. - #define FERR_RFL_INCOMPLETE 0xC04C ///< 0xC04C - RFL file is incomplete. - #define FERR_CANNOT_RESTORE_RFL_FILES 0xC04D ///< 0xC04D - Cannot restore RFL files - not using multiple RFL files. - #define FERR_INCONSISTENT_BACKUP 0xC04E ///< 0xC04E - A problem (corruption, etc) was detected in a backup set. - #define FERR_BLOCK_CHECKSUM 0xC04F ///< 0xC04F - Block checksum error. - #define FERR_ABORT_TRANS 0xC050 ///< 0xC050 - Attempted operation after a critical error - should abort transaction. - #define FERR_NOT_RFL 0xC051 ///< 0xC051 - Attempted to open file which was not an RFL file. - #define FERR_BAD_RFL_PACKET 0xC052 ///< 0xC052 - RFL packet was bad. - #define FERR_DATA_PATH_MISMATCH 0xC053 ///< 0xC053 - Bad data path specified to open database. - #define FERR_HTTP_REGISTER_FAILURE 0xC054 ///< 0xC054 - Call to FlmConfig() with FLM_HTTP_REGISTER_URL option failed. - #define FERR_HTTP_DEREG_FAILURE 0xC055 ///< 0xC055 - Call to FlmConfig() with FLM_HTTP_DEREGISTER_URL option failed. - #define FERR_IX_FAILURE 0xC056 ///< 0xC056 - Indexing process failed, non-unique data was found when a unique index was being created. - #define FERR_HTTP_SYMS_EXIST 0xC057 ///< 0xC057 - Tried to import new http related symbols before unimporting the old ones. - #define FERR_NOT_USED_C058 0xC058 ///< 0xC058 - Not used - #define FERR_FILE_EXISTS 0xC059 ///< 0xC059 - Attempt to create a database, but the database already exists. - #define FERR_SYM_RESOLVE_FAIL 0xC05A ///< 0xC05A - Could not resolve a symbol needed to run. - #define FERR_BAD_SERVER_CONNECTION 0xC05B ///< 0xC05B - Connection to FLAIM server is bad. - #define FERR_CLOSING_DATABASE 0xC05C ///< 0xC05C - Database is being closed due to a critical error. - #define FERR_INVALID_CRC 0xC05D ///< 0xC05D - CRC could not be verified. - #define FERR_KEY_OVERFLOW 0xC05E ///< 0xC05E - Key generated by the record causes the maximum key size to be exceeded. - #define FERR_NOT_IMPLEMENTED 0xC05F ///< 0xC05F - Functionality not implemented. - #define FERR_MUTEX_OPERATION_FAILED 0xC060 ///< 0xC060 - Mutex operation failed. - #define FERR_MUTEX_UNABLE_TO_LOCK 0xC061 ///< 0xC061 - Unable to get the mutex lock. - #define FERR_SEM_OPERATION_FAILED 0xC062 ///< 0xC062 - Semaphore operation failed. - #define FERR_SEM_UNABLE_TO_LOCK 0xC063 ///< 0xC063 - Unable to get the semaphore lock. - #define FERR_NOT_USED_C064 0xC064 ///< 0xC064 - Not used - #define FERR_NOT_USED_C065 0xC065 ///< 0xC065 - Not used - #define FERR_NOT_USED_C066 0xC066 ///< 0xC066 - Not used - #define FERR_NOT_USED_C067 0xC067 ///< 0xC067 - Not used - #define FERR_NOT_USED_C068 0xC068 ///< 0xC068 - Not used - #define FERR_BAD_REFERENCE 0xC069 ///< 0xC069 - Bad reference in the dictionary. - #define FERR_NOT_USED_C06A 0xC06A ///< 0xC06A - Not used - #define FERR_NOT_USED_C06B 0xC06B ///< 0xC06B - Not used - #define FERR_NOT_USED_C06C 0xC06C ///< 0xC06C - Not used - #define FERR_NOT_USED_C06D 0xC06D ///< 0xC06D - Not used - #define FERR_NOT_USED_C06E 0xC06E ///< 0xC06E - Not used - #define FERR_NOT_USED_C06F 0xC06F ///< 0xC06F - Not used - #define FERR_UNALLOWED_UPGRADE 0xC070 ///< 0xC070 - FlmDbUpgrade cannot upgrade the database. - #define FERR_NOT_USED_C071 0xC071 ///< 0xC071 - Not used - #define FERR_NOT_USED_C072 0xC072 ///< 0xC072 - Not used - #define FERR_NOT_USED_C073 0xC073 ///< 0xC073 - Not used - #define FERR_ID_RESERVED 0xC074 ///< 0xC074 - Attempted to use a dictionary ID that has been reserved. - #define FERR_CANNOT_RESERVE_ID 0xC075 ///< 0xC075 - Attempted to reserve a dictionary ID that has been used. - #define FERR_DUPLICATE_DICT_NAME 0xC076 ///< 0xC076 - Dictionary record with duplicate name found. - #define FERR_CANNOT_RESERVE_NAME 0xC077 ///< 0xC077 - Attempted to reserve a dictionary name that is in use. - #define FERR_BAD_DICT_DRN 0xC078 ///< 0xC078 - Attempted to add, modify, or delete a dictionary DRN >= FLM_RESERVED_TAG_NUMS. - #define FERR_CANNOT_MOD_DICT_REC_TYPE 0xC079 ///< 0xC079 - Cannot modify a dictionary item into another type of item, must delete then add. - #define FERR_PURGED_FLD_FOUND 0xC07A ///< 0xC07A - Record contained a field whose field definition has been marked as purged. - #define FERR_DUPLICATE_INDEX 0xC07B ///< 0xC07B - Duplicate index. - #define FERR_TOO_MANY_OPEN_DBS 0xC07C ///< 0xC07C - Too many open databases. - #define FERR_ACCESS_DENIED 0xC07D ///< 0xC07D - Cannot access database. - #define FERR_NOT_USED_C07E 0xC07E ///< 0xC07E - Not used - #define FERR_CACHE_ERROR 0xC07F ///< 0xC07F - Cache block is corrupt. - #define FERR_NOT_USED_C080 0xC080 ///< 0xC080 - Not used - #define FERR_BLOB_MISSING_FILE 0xC081 ///< 0xC081 - Missing BLOB file on add/modify. - #define FERR_NO_REC_FOR_KEY 0xC082 ///< 0xC082 - Record pointed to by an index key is missing. - #define FERR_DB_FULL 0xC083 ///< 0xC083 - Database is full, cannot create more blocks. - #define FERR_TIMEOUT 0xC084 ///< 0xC084 - Operation timed out (usually a query operation). - #define FERR_CURSOR_SYNTAX 0xC085 ///< 0xC085 - Query criteria had improper syntax. - #define FERR_THREAD_ERR 0xC086 ///< 0xC086 - Thread error. - #define FERR_UNIMPORT_SYMBOL 0xC087 ///< 0xC087 - Failed to unimport a public symbol. - #define FERR_EMPTY_QUERY 0xC088 ///< 0xC088 - Warning: Query has no results. - #define FERR_INDEX_OFFLINE 0xC089 ///< 0xC089 - Warning: Index is offline and being rebuilt. - #define FERR_TRUNCATED_KEY 0xC08A ///< 0xC08A - Warning: Can't evaluate truncated key against selection criteria. - #define FERR_INVALID_PARM 0xC08B ///< 0xC08B - Invalid parameter. - #define FERR_USER_ABORT 0xC08C ///< 0xC08C - User or application aborted the operation. - #define FERR_RFL_DEVICE_FULL 0xC08D ///< 0xC08D - No space on RFL device for logging. - #define FERR_MUST_WAIT_CHECKPOINT 0xC08E ///< 0xC08E - Must wait for a checkpoint before starting transaction - due to disk problems - usually in RFL volume. - #define FERR_NAMED_SEMAPHORE_ERR 0xC08F ///< 0xC08F - Error occurred while accessing a named semaphore. - #define FERR_LOAD_LIBRARY 0xC090 ///< 0xC090 - Failed to load a shared library module. - #define FERR_UNLOAD_LIBRARY 0xC091 ///< 0xC091 - Failed to unload a shared library module. - #define FERR_IMPORT_SYMBOL 0xC092 ///< 0xC092 - Failed to import a symbol from a shared library module. - #define FERR_BLOCK_FULL 0xC093 ///< 0xC093 - Destination block for insert is full. - #define FERR_BAD_BASE64_ENCODING 0xC094 ///< 0xC094 - Could not perform base 64 encoding. - #define FERR_MISSING_FIELD_TYPE 0xC095 ///< 0xC095 - Field type not specified in field definition record. - #define FERR_BAD_DATA_LENGTH 0xC096 ///< 0xC096 - Invalid field data length. + #define FERR_BOF_HIT NE_FLM_BOF_HIT ///< 0xC001 - Beginning of file or set hit. + #define FERR_EOF_HIT NE_FLM_EOF_HIT ///< 0xC002 - End of file or set hit. + #define FERR_END 0xC003 ///< 0xC003 - End of GEDCOM file - this is an internal error. + #define FERR_EXISTS NE_FLM_EXISTS ///< 0xC004 - Record already exists. + #define FERR_FAILURE NE_FLM_FAILURE ///< 0xC005 - Internal failure. + #define FERR_NOT_FOUND NE_FLM_NOT_FOUND ///< 0xC006 - A record, key, or key reference was not found. + #define FERR_BAD_DICT_ID 0xC007 ///< 0xC007 - Invalid dictionary record number -- outside unreserved range. + #define FERR_BAD_CONTAINER 0xC008 ///< 0xC008 - Invalid container number. + #define FERR_NO_ROOT_BLOCK 0xC009 ///< 0xC009 - LFILE does not have a root block - always handled internally - never returned to application. + #define FERR_BAD_DRN 0xC00A ///< 0xC00A - Cannot pass a zero DRN into modify or delete or 0xFFFFFFFF into add. + #define FERR_BAD_FIELD_NUM 0xC00B ///< 0xC00B - Bad field number in record being added. + #define FERR_BAD_FIELD_TYPE 0xC00C ///< 0xC00C - Bad field type in record being added. + #define FERR_BAD_HDL 0xC00D ///< 0xC00D - Request contained bad db handle. + #define FERR_BAD_IX 0xC00E ///< 0xC00E - Invalid index number. + #define FERR_BACKUP_ACTIVE 0xC00F ///< 0xC00F - Operation could not be completed - a backup is being performed. + #define FERR_SERIAL_NUM_MISMATCH 0xC010 ///< 0xC010 - Comparison of serial numbers failed. + #define FERR_BAD_RFL_DB_SERIAL_NUM 0xC011 ///< 0xC011 - Bad database serial number in RFL file header. + #define FERR_BTREE_ERROR NE_FLM_BTREE_ERROR ///< 0xC012 - A corruption was found in an index or container b-tree. + #define FERR_BTREE_FULL NE_FLM_BTREE_FULL ///< 0xC013 - An index or container b-tree is full. + #define FERR_BAD_RFL_FILE_NUMBER 0xC014 ///< 0xC014 - Bad RFL file number in RFL file header. + #define FERR_CANNOT_DEL_ITEM 0xC015 ///< 0xC015 - Cannot delete field definitions. + #define FERR_CANNOT_MOD_FIELD_TYPE 0xC016 ///< 0xC016 - Cannot modify a field's type. + #define FERR_NOT_USED_C017 0xC017 ///< 0xC017 - Not used + #define FERR_CONV_BAD_DEST_TYPE 0xC018 ///< 0xC018 - Bad destination type specified for conversion. + #define FERR_CONV_BAD_DIGIT 0xC019 ///< 0xC019 - Non-numeric digit found in text to numeric conversion. + #define FERR_CONV_BAD_SRC_TYPE 0xC01A ///< 0xC01A - Bad source type specified for conversion. + #define FERR_RFL_FILE_NOT_FOUND 0xC01B ///< 0xC01B - Could not open an RFL file. + #define FERR_CONV_DEST_OVERFLOW NE_FLM_CONV_DEST_OVERFLOW ///< 0xC01C - Destination buffer not large enough to hold converted data. + #define FERR_CONV_ILLEGAL NE_FLM_CONV_ILLEGAL ///< 0xC01D - Illegal conversion -- not supported. + #define FERR_CONV_NULL_SRC 0xC01E ///< 0xC01E - Source cannot be a NULL pointer in conversion. + #define FERR_CONV_NULL_DEST 0xC01F ///< 0xC01F - Destination cannot be a NULL pointer in conversion. + #define FERR_CONV_NUM_OVERFLOW NE_FLM_CONV_NUM_OVERFLOW ///< 0xC020 - Numeric overflow (GT upper bound) converting to numeric type. + #define FERR_CONV_NUM_UNDERFLOW 0xC021 ///< 0xC021 - Numeric underflow (LT lower bound) converting to numeric type. + #define FERR_DATA_ERROR NE_FLM_DATA_ERROR ///< 0xC022 - Database corruption found. + #define FERR_NOT_USED_C023 0xC023 ///< 0xC023 - Not used + #define FERR_DD_ERROR 0xC024 ///< 0xC024 - Corruption found in logical file block chain. + #define FERR_INVALID_FILE_SEQUENCE 0xC025 ///< 0xC025 - Incremental backup file number provided during a restore is invalid. + #define FERR_ILLEGAL_OP NE_FLM_ILLEGAL_OP ///< 0xC026 - Illegal operation for database. + #define FERR_DUPLICATE_DICT_REC 0xC027 ///< 0xC027 - Duplicate dictionary record found. + #define FERR_CANNOT_CONVERT 0xC028 ///< 0xC028 - Condition occurred which prevents database conversion. + #define FERR_UNSUPPORTED_VERSION 0xC029 ///< 0xC029 - Database version is not supported. + #define FERR_FILE_ER 0xC02A ///< 0xC02A - File error in a GEDCOM routine. + #define FERR_BAD_FIELD_LEVEL 0xC02B ///< 0xC02B - Invalid field level. + #define FERR_GED_BAD_RECID 0xC02C ///< 0xC02C - Bad record ID syntax. + #define FERR_GED_BAD_VALUE 0xC02D ///< 0xC02D - Bad or ambiguous/extra value in GEDCOM. + #define FERR_GED_MAXLVLNUM 0xC02E ///< 0xC02E - Exceeded GED_MAXLVLNUM in gedcom routines. + #define FERR_GED_SKIP_LEVEL 0xC02F ///< 0xC02F - Bad GEDCOM tree structure -- level skipped. + #define FERR_ILLEGAL_TRANS 0xC030 ///< 0xC030 - Attempt to start an illegal type of transaction. + #define FERR_ILLEGAL_TRANS_OP 0xC031 ///< 0xC031 - Illegal operation for transaction type. + #define FERR_INCOMPLETE_LOG 0xC032 ///< 0xC032 - Incomplete log record encountered during recovery. + #define FERR_INVALID_BLOCK_LENGTH 0xC033 ///< 0xC033 - Invalid block length. + #define FERR_INVALID_TAG 0xC034 ///< 0xC034 - Invalid tag name. + #define FERR_KEY_NOT_FOUND 0xC035 ///< 0xC035 - A key or reference is not found -- modify/delete error. + #define FERR_VALUE_TOO_LARGE 0xC036 ///< 0xC036 - Value too large. + #define FERR_MEM NE_FLM_MEM ///< 0xC037 - Memory allocation error. + #define FERR_BAD_RFL_SERIAL_NUM 0xC038 ///< 0xC038 - Bad serial number in RFL file header. + #define FERR_NOT_USED_C039 0xC039 ///< 0xC039 - Not used + #define FERR_NEWER_FLAIM 0xC03A ///< 0xC03A - Database version newer than this code base will support, must use newer version of code. + #define FERR_CANNOT_MOD_FIELD_STATE 0xC03B ///< 0xC03B - Attempted to change a field state illegally. + #define FERR_NO_MORE_DRNS 0xC03C ///< 0xC03C - The highest DRN number has already been used in an add. + #define FERR_NO_TRANS_ACTIVE 0xC03D ///< 0xC03D - Attempted to updated database outside transaction. + #define FERR_NOT_UNIQUE NE_FLM_NOT_UNIQUE ///< 0xC03E - Found duplicate key for unique index. + #define FERR_NOT_FLAIM 0xC03F ///< 0xC03F - File is not a FLAIM database. + #define FERR_NULL_RECORD 0xC040 ///< 0xC040 - NULL record cannot be passed to add or modify. + #define FERR_NO_HTTP_STACK 0xC041 ///< 0xC041 - No http stack was loaded. + #define FERR_OLD_VIEW 0xC042 ///< 0xC042 - While reading was unable to get previous version of block or record. + #define FERR_PCODE_ERROR 0xC043 ///< 0xC043 - Corruption found in dictionary. + #define FERR_PERMISSION 0xC044 ///< 0xC044 - Invalid permission for file operation. + #define FERR_SYNTAX NE_FLM_SYNTAX ///< 0xC045 - Dictionary record has improper syntax, or syntax error in query criteria. + #define FERR_CALLBACK_FAILURE 0xC046 ///< 0xC046 - Callback failure. + #define FERR_TRANS_ACTIVE 0xC047 ///< 0xC047 - Attempted to close database while transaction was active. + #define FERR_RFL_TRANS_GAP 0xC048 ///< 0xC048 - A gap was found in the transaction sequence in the RFL. + #define FERR_BAD_COLLATED_KEY 0xC049 ///< 0xC049 - Something in collated key is bad. + #define FERR_UNSUPPORTED_FEATURE 0xC04A ///< 0xC04A - Attempting a feature that is not supported for the database version. + #define FERR_MUST_DELETE_INDEXES 0xC04B ///< 0xC04B - Attempting to delete a container that has indexes defined for it -- indexes must be deleted first. + #define FERR_RFL_INCOMPLETE 0xC04C ///< 0xC04C - RFL file is incomplete. + #define FERR_CANNOT_RESTORE_RFL_FILES 0xC04D ///< 0xC04D - Cannot restore RFL files - not using multiple RFL files. + #define FERR_INCONSISTENT_BACKUP 0xC04E ///< 0xC04E - A problem (corruption, etc) was detected in a backup set. + #define FERR_BLOCK_CHECKSUM 0xC04F ///< 0xC04F - Block checksum error. + #define FERR_ABORT_TRANS 0xC050 ///< 0xC050 - Attempted operation after a critical error - should abort transaction. + #define FERR_NOT_RFL 0xC051 ///< 0xC051 - Attempted to open file which was not an RFL file. + #define FERR_BAD_RFL_PACKET 0xC052 ///< 0xC052 - RFL packet was bad. + #define FERR_DATA_PATH_MISMATCH 0xC053 ///< 0xC053 - Bad data path specified to open database. + #define FERR_HTTP_REGISTER_FAILURE 0xC054 ///< 0xC054 - Call to FlmConfig() with FLM_HTTP_REGISTER_URL option failed. + #define FERR_HTTP_DEREG_FAILURE 0xC055 ///< 0xC055 - Call to FlmConfig() with FLM_HTTP_DEREGISTER_URL option failed. + #define FERR_IX_FAILURE 0xC056 ///< 0xC056 - Indexing process failed, non-unique data was found when a unique index was being created. + #define FERR_HTTP_SYMS_EXIST 0xC057 ///< 0xC057 - Tried to import new http related symbols before unimporting the old ones. + #define FERR_NOT_USED_C058 0xC058 ///< 0xC058 - Not used + #define FERR_FILE_EXISTS 0xC059 ///< 0xC059 - Attempt to create a database, but the database already exists. + #define FERR_SYM_RESOLVE_FAIL 0xC05A ///< 0xC05A - Could not resolve a symbol needed to run. + #define FERR_BAD_SERVER_CONNECTION 0xC05B ///< 0xC05B - Connection to FLAIM server is bad. + #define FERR_CLOSING_DATABASE 0xC05C ///< 0xC05C - Database is being closed due to a critical error. + #define FERR_INVALID_CRC 0xC05D ///< 0xC05D - CRC could not be verified. + #define FERR_KEY_OVERFLOW 0xC05E ///< 0xC05E - Key generated by the record causes the maximum key size to be exceeded. + #define FERR_NOT_IMPLEMENTED NE_FLM_NOT_IMPLEMENTED ///< 0xC05F - Functionality not implemented. + #define FERR_MUTEX_OPERATION_FAILED 0xC060 ///< 0xC060 - Mutex operation failed. + #define FERR_MUTEX_UNABLE_TO_LOCK 0xC061 ///< 0xC061 - Unable to get the mutex lock. + #define FERR_SEM_OPERATION_FAILED 0xC062 ///< 0xC062 - Semaphore operation failed. + #define FERR_SEM_UNABLE_TO_LOCK 0xC063 ///< 0xC063 - Unable to get the semaphore lock. + #define FERR_NOT_USED_C064 0xC064 ///< 0xC064 - Not used + #define FERR_NOT_USED_C065 0xC065 ///< 0xC065 - Not used + #define FERR_NOT_USED_C066 0xC066 ///< 0xC066 - Not used + #define FERR_NOT_USED_C067 0xC067 ///< 0xC067 - Not used + #define FERR_NOT_USED_C068 0xC068 ///< 0xC068 - Not used + #define FERR_BAD_REFERENCE 0xC069 ///< 0xC069 - Bad reference in the dictionary. + #define FERR_NOT_USED_C06A 0xC06A ///< 0xC06A - Not used + #define FERR_NOT_USED_C06B 0xC06B ///< 0xC06B - Not used + #define FERR_NOT_USED_C06C 0xC06C ///< 0xC06C - Not used + #define FERR_NOT_USED_C06D 0xC06D ///< 0xC06D - Not used + #define FERR_NOT_USED_C06E 0xC06E ///< 0xC06E - Not used + #define FERR_NOT_USED_C06F 0xC06F ///< 0xC06F - Not used + #define FERR_UNALLOWED_UPGRADE 0xC070 ///< 0xC070 - FlmDbUpgrade cannot upgrade the database. + #define FERR_NOT_USED_C071 0xC071 ///< 0xC071 - Not used + #define FERR_NOT_USED_C072 0xC072 ///< 0xC072 - Not used + #define FERR_NOT_USED_C073 0xC073 ///< 0xC073 - Not used + #define FERR_ID_RESERVED 0xC074 ///< 0xC074 - Attempted to use a dictionary ID that has been reserved. + #define FERR_CANNOT_RESERVE_ID 0xC075 ///< 0xC075 - Attempted to reserve a dictionary ID that has been used. + #define FERR_DUPLICATE_DICT_NAME 0xC076 ///< 0xC076 - Dictionary record with duplicate name found. + #define FERR_CANNOT_RESERVE_NAME 0xC077 ///< 0xC077 - Attempted to reserve a dictionary name that is in use. + #define FERR_BAD_DICT_DRN 0xC078 ///< 0xC078 - Attempted to add, modify, or delete a dictionary DRN >= FLM_RESERVED_TAG_NUMS. + #define FERR_CANNOT_MOD_DICT_REC_TYPE 0xC079 ///< 0xC079 - Cannot modify a dictionary item into another type of item, must delete then add. + #define FERR_PURGED_FLD_FOUND 0xC07A ///< 0xC07A - Record contained a field whose field definition has been marked as purged. + #define FERR_DUPLICATE_INDEX 0xC07B ///< 0xC07B - Duplicate index. + #define FERR_TOO_MANY_OPEN_DBS 0xC07C ///< 0xC07C - Too many open databases. + #define FERR_ACCESS_DENIED 0xC07D ///< 0xC07D - Cannot access database. + #define FERR_NOT_USED_C07E 0xC07E ///< 0xC07E - Not used + #define FERR_CACHE_ERROR 0xC07F ///< 0xC07F - Cache block is corrupt. + #define FERR_NOT_USED_C080 0xC080 ///< 0xC080 - Not used + #define FERR_BLOB_MISSING_FILE 0xC081 ///< 0xC081 - Missing BLOB file on add/modify. + #define FERR_NO_REC_FOR_KEY 0xC082 ///< 0xC082 - Record pointed to by an index key is missing. + #define FERR_DB_FULL 0xC083 ///< 0xC083 - Database is full, cannot create more blocks. + #define FERR_TIMEOUT 0xC084 ///< 0xC084 - Operation timed out (usually a query operation). + #define FERR_CURSOR_SYNTAX 0xC085 ///< 0xC085 - Query criteria had improper syntax. + #define FERR_THREAD_ERR 0xC086 ///< 0xC086 - Thread error. + #define FERR_UNIMPORT_SYMBOL 0xC087 ///< 0xC087 - Failed to unimport a public symbol. + #define FERR_EMPTY_QUERY 0xC088 ///< 0xC088 - Warning: Query has no results. + #define FERR_INDEX_OFFLINE 0xC089 ///< 0xC089 - Warning: Index is offline and being rebuilt. + #define FERR_TRUNCATED_KEY 0xC08A ///< 0xC08A - Warning: Can't evaluate truncated key against selection criteria. + #define FERR_INVALID_PARM NE_FLM_INVALID_PARM ///< 0xC08B - Invalid parameter. + #define FERR_USER_ABORT 0xC08C ///< 0xC08C - User or application aborted the operation. + #define FERR_RFL_DEVICE_FULL 0xC08D ///< 0xC08D - No space on RFL device for logging. + #define FERR_MUST_WAIT_CHECKPOINT 0xC08E ///< 0xC08E - Must wait for a checkpoint before starting transaction - due to disk problems - usually in RFL volume. + #define FERR_NAMED_SEMAPHORE_ERR 0xC08F ///< 0xC08F - Error occurred while accessing a named semaphore. + #define FERR_LOAD_LIBRARY 0xC090 ///< 0xC090 - Failed to load a shared library module. + #define FERR_UNLOAD_LIBRARY 0xC091 ///< 0xC091 - Failed to unload a shared library module. + #define FERR_IMPORT_SYMBOL 0xC092 ///< 0xC092 - Failed to import a symbol from a shared library module. + #define FERR_BLOCK_FULL 0xC093 ///< 0xC093 - Destination block for insert is full. + #define FERR_BAD_BASE64_ENCODING 0xC094 ///< 0xC094 - Could not perform base 64 encoding. + #define FERR_MISSING_FIELD_TYPE 0xC095 ///< 0xC095 - Field type not specified in field definition record. + #define FERR_BAD_DATA_LENGTH 0xC096 ///< 0xC096 - Invalid field data length. /**************************************************************************** IO Errors ****************************************************************************/ - #define FERR_IO_ACCESS_DENIED 0xC201 ///< 0xC201 - Access denied. Caller is not allowed access to a file. - #define FERR_IO_BAD_FILE_HANDLE 0xC202 ///< 0xC202 - Bad file handle. - #define FERR_IO_COPY_ERR 0xC203 ///< 0xC203 - Copy error. - #define FERR_IO_DISK_FULL 0xC204 ///< 0xC204 - Disk full. - #define FERR_IO_END_OF_FILE 0xC205 ///< 0xC205 - End of file. - #define FERR_IO_OPEN_ERR 0xC206 ///< 0xC206 - Error opening file. - #define FERR_IO_SEEK_ERR 0xC207 ///< 0xC207 - File seek error. - #define FERR_IO_MODIFY_ERR 0xC208 ///< 0xC208 - File modify error. - #define FERR_IO_PATH_NOT_FOUND 0xC209 ///< 0xC209 - Path not found. - #define FERR_IO_TOO_MANY_OPEN_FILES 0xC20A ///< 0xC20A - Too many files open. - #define FERR_IO_PATH_TOO_LONG 0xC20B ///< 0xC20B - Path too long. - #define FERR_IO_NO_MORE_FILES 0xC20C ///< 0xC20C - No more files in directory. - #define FERR_DELETING_FILE 0xC20D ///< 0xC20D - Had error deleting a file. - #define FERR_IO_FILE_LOCK_ERR 0xC20E ///< 0xC20E - File lock error. - #define FERR_IO_FILE_UNLOCK_ERR 0xC20F ///< 0xC20F - File unlock error. - #define FERR_IO_PATH_CREATE_FAILURE 0xC210 ///< 0xC210 - Path create failed. - #define FERR_IO_RENAME_FAILURE 0xC211 ///< 0xC211 - File rename failed. - #define FERR_IO_INVALID_PASSWORD 0xC212 ///< 0xC212 - Invalid file password. - #define FERR_SETTING_UP_FOR_READ 0xC213 ///< 0xC213 - Had error setting up to do a read. - #define FERR_SETTING_UP_FOR_WRITE 0xC214 ///< 0xC214 - Had error setting up to do a write. - #define FERR_IO_AT_PATH_ROOT 0xC215 ///< 0xC215 - Currently positioned at the path root level. - #define FERR_INITIALIZING_IO_SYSTEM 0xC216 ///< 0xC216 - Had error initializing the file system. - #define FERR_FLUSHING_FILE 0xC217 ///< 0xC217 - Had error flushing a file. - #define FERR_IO_INVALID_PATH 0xC218 ///< 0xC218 - Invalid path. - #define FERR_IO_CONNECT_ERROR 0xC219 ///< 0xC219 - Failed to connect to a remote network resource. - #define FERR_OPENING_FILE 0xC21A ///< 0xC21A - Had error opening a file. - #define FERR_DIRECT_OPENING_FILE 0xC21B ///< 0xC21B - Had error opening a file for direct I/O. - #define FERR_CREATING_FILE 0xC21C ///< 0xC21C - Had error creating a file. - #define FERR_DIRECT_CREATING_FILE 0xC21D ///< 0xC21D - Had error creating a file for direct I/O. - #define FERR_READING_FILE 0xC21E ///< 0xC21E - Had error reading a file. - #define FERR_DIRECT_READING_FILE 0xC21F ///< 0xC21F - Had error reading a file using direct I/O. - #define FERR_WRITING_FILE 0xC220 ///< 0xC220 - Had error writing to a file. - #define FERR_DIRECT_WRITING_FILE 0xC221 ///< 0xC221 - Had error writing to a file using direct I/O. - #define FERR_POSITIONING_IN_FILE 0xC222 ///< 0xC222 - Had error positioning within a file. - #define FERR_GETTING_FILE_SIZE 0xC223 ///< 0xC223 - Had error getting file size. - #define FERR_TRUNCATING_FILE 0xC224 ///< 0xC224 - Had error truncating a file. - #define FERR_PARSING_FILE_NAME 0xC225 ///< 0xC225 - Had error parsing a file name. - #define FERR_CLOSING_FILE 0xC226 ///< 0xC226 - Had error closing a file. - #define FERR_GETTING_FILE_INFO 0xC227 ///< 0xC227 - Had error getting file information. - #define FERR_EXPANDING_FILE 0xC228 ///< 0xC228 - Had error expanding a file (using direct I/O). - #define FERR_GETTING_FREE_BLOCKS 0xC229 ///< 0xC229 - Had error getting free blocks from file system. - #define FERR_CHECKING_FILE_EXISTENCE 0xC22A ///< 0xC22A - Had error checking if a file exists. - #define FERR_RENAMING_FILE 0xC22B ///< 0xC22B - Had error renaming a file. - #define FERR_SETTING_FILE_INFO 0xC22C ///< 0xC22C - Had error setting file information. + #define FERR_IO_ACCESS_DENIED NE_FLM_IO_ACCESS_DENIED ///< 0xC201 - Access denied. Caller is not allowed access to a file. + #define FERR_IO_BAD_FILE_HANDLE NE_FLM_IO_BAD_FILE_HANDLE ///< 0xC202 - Bad file handle. + #define FERR_IO_COPY_ERR NE_FLM_IO_COPY_ERR ///< 0xC203 - Copy error. + #define FERR_IO_DISK_FULL NE_FLM_IO_DISK_FULL ///< 0xC204 - Disk full. + #define FERR_IO_END_OF_FILE NE_FLM_IO_END_OF_FILE ///< 0xC205 - End of file. + #define FERR_IO_OPEN_ERR NE_FLM_IO_OPEN_ERR ///< 0xC206 - Error opening file. + #define FERR_IO_SEEK_ERR NE_FLM_IO_SEEK_ERR ///< 0xC207 - File seek error. + #define FERR_IO_DIRECTORY_ERR NE_FLM_IO_DIRECTORY_ERR ///< 0xC208 - Error occurred while accessing or deleting a directory. + #define FERR_IO_PATH_NOT_FOUND NE_FLM_IO_PATH_NOT_FOUND ///< 0xC209 - Path not found. + #define FERR_IO_TOO_MANY_OPEN_FILES NE_FLM_IO_TOO_MANY_OPEN_FILES ///< 0xC20A - Too many files open. + #define FERR_IO_PATH_TOO_LONG NE_FLM_IO_PATH_TOO_LONG ///< 0xC20B - Path too long. + #define FERR_IO_NO_MORE_FILES NE_FLM_IO_NO_MORE_FILES ///< 0xC20C - No more files in directory. + #define FERR_DELETING_FILE NE_FLM_IO_DELETING_FILE ///< 0xC20D - Had error deleting a file. + #define FERR_IO_FILE_LOCK_ERR NE_FLM_IO_FILE_LOCK_ERR ///< 0xC20E - File lock error. + #define FERR_IO_FILE_UNLOCK_ERR NE_FLM_IO_FILE_UNLOCK_ERR ///< 0xC20F - File unlock error. + #define FERR_IO_PATH_CREATE_FAILURE NE_FLM_IO_PATH_CREATE_FAILURE ///< 0xC210 - Path create failed. + #define FERR_IO_RENAME_FAILURE NE_FLM_IO_RENAME_FAILURE ///< 0xC211 - File rename failed. + #define FERR_IO_INVALID_PASSWORD NE_FLM_IO_INVALID_PASSWORD ///< 0xC212 - Invalid file password. + #define FERR_SETTING_UP_FOR_READ NE_FLM_SETTING_UP_FOR_READ ///< 0xC213 - Had error setting up to do a read. + #define FERR_SETTING_UP_FOR_WRITE NE_FLM_SETTING_UP_FOR_WRITE ///< 0xC214 - Had error setting up to do a write. + #define FERR_IO_AT_PATH_ROOT NE_FLM_IO_CANNOT_REDUCE_PATH ///< 0xC215 - Currently positioned at the path root level. + #define FERR_INITIALIZING_IO_SYSTEM NE_FLM_INITIALIZING_IO_SYSTEM ///< 0xC216 - Had error initializing the file system. + #define FERR_FLUSHING_FILE NE_FLM_FLUSHING_FILE ///< 0xC217 - Had error flushing a file. + #define FERR_IO_INVALID_PATH NE_FLM_IO_INVALID_FILENAME ///< 0xC218 - Invalid path. + #define FERR_IO_CONNECT_ERROR NE_FLM_IO_CONNECT_ERROR ///< 0xC219 - Failed to connect to a remote network resource. + #define FERR_OPENING_FILE NE_FLM_OPENING_FILE ///< 0xC21A - Had error opening a file. + #define FERR_DIRECT_OPENING_FILE NE_FLM_DIRECT_OPENING_FILE ///< 0xC21B - Had error opening a file for direct I/O. + #define FERR_CREATING_FILE NE_FLM_CREATING_FILE ///< 0xC21C - Had error creating a file. + #define FERR_DIRECT_CREATING_FILE NE_FLM_DIRECT_CREATING_FILE ///< 0xC21D - Had error creating a file for direct I/O. + #define FERR_READING_FILE NE_FLM_READING_FILE ///< 0xC21E - Had error reading a file. + #define FERR_DIRECT_READING_FILE NE_FLM_DIRECT_READING_FILE ///< 0xC21F - Had error reading a file using direct I/O. + #define FERR_WRITING_FILE NE_FLM_WRITING_FILE ///< 0xC220 - Had error writing to a file. + #define FERR_DIRECT_WRITING_FILE NE_FLM_DIRECT_WRITING_FILE ///< 0xC221 - Had error writing to a file using direct I/O. + #define FERR_POSITIONING_IN_FILE NE_FLM_POSITIONING_IN_FILE ///< 0xC222 - Had error positioning within a file. + #define FERR_GETTING_FILE_SIZE NE_FLM_GETTING_FILE_SIZE ///< 0xC223 - Had error getting file size. + #define FERR_TRUNCATING_FILE NE_FLM_TRUNCATING_FILE ///< 0xC224 - Had error truncating a file. + #define FERR_PARSING_FILE_NAME NE_FLM_PARSING_FILE_NAME ///< 0xC225 - Had error parsing a file name. + #define FERR_CLOSING_FILE NE_FLM_CLOSING_FILE ///< 0xC226 - Had error closing a file. + #define FERR_GETTING_FILE_INFO NE_FLM_GETTING_FILE_INFO ///< 0xC227 - Had error getting file information. + #define FERR_EXPANDING_FILE NE_FLM_EXPANDING_FILE ///< 0xC228 - Had error expanding a file (using direct I/O). + #define FERR_GETTING_FREE_BLOCKS NE_FLM_GETTING_FREE_BLOCKS ///< 0xC229 - Had error getting free blocks from file system. + #define FERR_CHECKING_FILE_EXISTENCE NE_FLM_CHECKING_FILE_EXISTENCE ///< 0xC22A - Had error checking if a file exists. + #define FERR_RENAMING_FILE NE_FLM_RENAMING_FILE ///< 0xC22B - Had error renaming a file. + #define FERR_SETTING_FILE_INFO NE_FLM_SETTING_FILE_INFO ///< 0xC22C - Had error setting file information. /**************************************************************************** Encryption / Decryption Errors ****************************************************************************/ - #define FERR_NICI_CONTEXT 0xC301 ///< 0xC301 - Failed to obtain a NICI context. - #define FERR_NICI_FIND_INIT 0xC302 ///< 0xC302 - CCS_FindInit failed. - #define FERR_NICI_FIND_OBJECT 0xC303 ///< 0xC303 - CCS_FindObject failed. - #define FERR_NICI_WRAPKEY_NOT_FOUND 0xC304 ///< 0xC304 - Could not locate a wrapping key. - #define FERR_NICI_ATTRIBUTE_VALUE 0xC305 ///< 0xC305 - CCS_AttributeValue failed. - #define FERR_NICI_BAD_ATTRIBUTE 0xC306 ///< 0xC306 - Invalid attribute. - #define FERR_NICI_BAD_RANDOM 0xC307 ///< 0xC307 - CCS_GetRandom failed. - #define FERR_NOT_USED_C308 0xC308 ///< 0xC308 - Not used - #define FERR_NICI_WRAPKEY_FAILED 0xC309 ///< 0xC309 - CCS_WrapKey failed. - #define FERR_NICI_GENKEY_FAILED 0xC30A ///< 0xC30A - CCS_GenerateKey failed. - #define FERR_REQUIRE_PASSWD 0xC30B ///< 0xC30B - Password required to unwrap key. - #define FERR_NICI_SHROUDKEY_FAILED 0xC30C ///< 0xC30C - CCS_pbeShroudPrivateKey failed. - #define FERR_NICI_UNSHROUDKEY_FAILED 0xC30D ///< 0xC30D - CCS_pbdUnshroudPrivateKey failed. - #define FERR_NICI_UNWRAPKEY_FAILED 0xC30E ///< 0xC30E - CCS_UnrapKey failed. - #define FERR_NICI_ENC_INIT_FAILED 0xC30F ///< 0xC30F - CCS_DataEncryptInit failed. - #define FERR_NICI_ENCRYPT_FAILED 0xC310 ///< 0xC310 - CCS_DataEncrypt failed. - #define FERR_NICI_DECRYPT_INIT_FAILED 0xC311 ///< 0xC311 - CCS_DataDecryptInit failed. - #define FERR_NICI_DECRYPT_FAILED 0xC312 ///< 0xC312 - CCS_DataDecrypt failed. - #define FERR_NICI_INIT_FAILED 0xC313 ///< 0xC313 - CCS_Init failed. - #define FERR_NICI_KEY_NOT_FOUND 0xC314 ///< 0xC314 - Could not locate encryption/decryption key. - #define FERR_NICI_INVALID_ALGORITHM 0xC315 ///< 0xC315 - Unsupported NICI ecncryption algorithm. - #define FERR_FLD_NOT_ENCRYPTED 0xC316 ///< 0xC316 - Field is not encrypted. - #define FERR_CANNOT_SET_KEY 0xC317 ///< 0xC317 - Attempted to set an encryption key for new encryption definition record. - #define FERR_MISSING_ENC_TYPE 0xC318 ///< 0xC318 - Encryption type not specified in encryption definition record. - #define FERR_CANNOT_MOD_ENC_TYPE 0xC319 ///< 0xC319 - Attempting to change the encryption type in encryption definition record. - #define FERR_MISSING_ENC_KEY 0xC31A ///< 0xC31A - Encryption key must be present in modified encryption definition record. - #define FERR_CANNOT_CHANGE_KEY 0xC31B ///< 0xC31B - Attempt to modify the encryption key in an encryption definition record. - #define FERR_BAD_ENC_KEY 0xC31C ///< 0xC31C - Bad encryption key. - #define FERR_CANNOT_MOD_ENC_STATE 0xC31D ///< 0xC31D - Illegal state change for an encryption definition record. - #define FERR_DATA_SIZE_MISMATCH 0xC31E ///< 0xC31E - Calculated encrypted data length does not match the length returned from encryption/decryption routines. - #define FERR_ENCRYPTION_UNAVAILABLE 0xC31F ///< 0xC31F - Encryption capabilities are not available for encrypting/decrypting data in database. - #define FERR_PURGED_ENCDEF_FOUND 0xC320 ///< 0xC320 - Cannot use encryption ID for encryption of data - encryption definition record is marked as purged. - #define FERR_FLD_NOT_DECRYPTED 0xC321 ///< 0xC321 - Attempting to access data from a field that is encrypted, field could not be decrypted for some reason - probably because encryption/decryption capabilities are not available. - #define FERR_BAD_ENCDEF_ID 0xC322 ///< 0xC322 - Encryption ID is invalid - not defined in dictionary. - #define FERR_PBE_ENCRYPT_FAILED 0xC323 ///< 0xC323 - Call to NICI function CCS_pbeEncrypt failed. - #define FERR_DIGEST_FAILED 0xC324 ///< 0xC324 - Call to NICI function CCS_Digest failed. - #define FERR_DIGEST_INIT_FAILED 0xC325 ///< 0xC325 - Call to NICI function CCS_DigestInit failed. - #define FERR_EXTRACT_KEY_FAILED 0xC326 ///< 0xC326 - Call to NICI function CCS_ExtractKey failed. - #define FERR_INJECT_KEY_FAILED 0xC327 ///< 0xC327 - Call to NICI function CCS_InjectKey failed. - #define FERR_PBE_DECRYPT_FAILED 0xC328 ///< 0xC328 - Call to NICI function CCS_pbeDecrypt failed. - #define FERR_PASSWD_INVALID 0xC329 ///< 0xC329 - Invalid password passed, database could not be opened. - + #define FERR_NICI_CONTEXT 0xC301 ///< 0xC301 - Failed to obtain a NICI context. + #define FERR_NICI_FIND_INIT 0xC302 ///< 0xC302 - CCS_FindInit failed. + #define FERR_NICI_FIND_OBJECT 0xC303 ///< 0xC303 - CCS_FindObject failed. + #define FERR_NICI_WRAPKEY_NOT_FOUND 0xC304 ///< 0xC304 - Could not locate a wrapping key. + #define FERR_NICI_ATTRIBUTE_VALUE 0xC305 ///< 0xC305 - CCS_AttributeValue failed. + #define FERR_NICI_BAD_ATTRIBUTE 0xC306 ///< 0xC306 - Invalid attribute. + #define FERR_NICI_BAD_RANDOM 0xC307 ///< 0xC307 - CCS_GetRandom failed. + #define FERR_NOT_USED_C308 0xC308 ///< 0xC308 - Not used + #define FERR_NICI_WRAPKEY_FAILED 0xC309 ///< 0xC309 - CCS_WrapKey failed. + #define FERR_NICI_GENKEY_FAILED 0xC30A ///< 0xC30A - CCS_GenerateKey failed. + #define FERR_REQUIRE_PASSWD 0xC30B ///< 0xC30B - Password required to unwrap key. + #define FERR_NICI_SHROUDKEY_FAILED 0xC30C ///< 0xC30C - CCS_pbeShroudPrivateKey failed. + #define FERR_NICI_UNSHROUDKEY_FAILED 0xC30D ///< 0xC30D - CCS_pbdUnshroudPrivateKey failed. + #define FERR_NICI_UNWRAPKEY_FAILED 0xC30E ///< 0xC30E - CCS_UnrapKey failed. + #define FERR_NICI_ENC_INIT_FAILED 0xC30F ///< 0xC30F - CCS_DataEncryptInit failed. + #define FERR_NICI_ENCRYPT_FAILED 0xC310 ///< 0xC310 - CCS_DataEncrypt failed. + #define FERR_NICI_DECRYPT_INIT_FAILED 0xC311 ///< 0xC311 - CCS_DataDecryptInit failed. + #define FERR_NICI_DECRYPT_FAILED 0xC312 ///< 0xC312 - CCS_DataDecrypt failed. + #define FERR_NICI_INIT_FAILED 0xC313 ///< 0xC313 - CCS_Init failed. + #define FERR_NICI_KEY_NOT_FOUND 0xC314 ///< 0xC314 - Could not locate encryption/decryption key. + #define FERR_NICI_INVALID_ALGORITHM 0xC315 ///< 0xC315 - Unsupported NICI ecncryption algorithm. + #define FERR_FLD_NOT_ENCRYPTED 0xC316 ///< 0xC316 - Field is not encrypted. + #define FERR_CANNOT_SET_KEY 0xC317 ///< 0xC317 - Attempted to set an encryption key for new encryption definition record. + #define FERR_MISSING_ENC_TYPE 0xC318 ///< 0xC318 - Encryption type not specified in encryption definition record. + #define FERR_CANNOT_MOD_ENC_TYPE 0xC319 ///< 0xC319 - Attempting to change the encryption type in encryption definition record. + #define FERR_MISSING_ENC_KEY 0xC31A ///< 0xC31A - Encryption key must be present in modified encryption definition record. + #define FERR_CANNOT_CHANGE_KEY 0xC31B ///< 0xC31B - Attempt to modify the encryption key in an encryption definition record. + #define FERR_BAD_ENC_KEY 0xC31C ///< 0xC31C - Bad encryption key. + #define FERR_CANNOT_MOD_ENC_STATE 0xC31D ///< 0xC31D - Illegal state change for an encryption definition record. + #define FERR_DATA_SIZE_MISMATCH 0xC31E ///< 0xC31E - Calculated encrypted data length does not match the length returned from encryption/decryption routines. + #define FERR_ENCRYPTION_UNAVAILABLE 0xC31F ///< 0xC31F - Encryption capabilities are not available for encrypting/decrypting data in database. + #define FERR_PURGED_ENCDEF_FOUND 0xC320 ///< 0xC320 - Cannot use encryption ID for encryption of data - encryption definition record is marked as purged. + #define FERR_FLD_NOT_DECRYPTED 0xC321 ///< 0xC321 - Attempting to access data from a field that is encrypted, field could not be decrypted for some reason - probably because encryption/decryption capabilities are not available. + #define FERR_BAD_ENCDEF_ID 0xC322 ///< 0xC322 - Encryption ID is invalid - not defined in dictionary. + #define FERR_PBE_ENCRYPT_FAILED 0xC323 ///< 0xC323 - Call to NICI function CCS_pbeEncrypt failed. + #define FERR_DIGEST_FAILED 0xC324 ///< 0xC324 - Call to NICI function CCS_Digest failed. + #define FERR_DIGEST_INIT_FAILED 0xC325 ///< 0xC325 - Call to NICI function CCS_DigestInit failed. + #define FERR_EXTRACT_KEY_FAILED 0xC326 ///< 0xC326 - Call to NICI function CCS_ExtractKey failed. + #define FERR_INJECT_KEY_FAILED 0xC327 ///< 0xC327 - Call to NICI function CCS_InjectKey failed. + #define FERR_PBE_DECRYPT_FAILED 0xC328 ///< 0xC328 - Call to NICI function CCS_pbeDecrypt failed. + #define FERR_PASSWD_INVALID 0xC329 ///< 0xC329 - Invalid password passed, database could not be opened. - /************************************************************************* - Server TCP/IP Errors - *************************************************************************/ - - #define FERR_SVR_NOIP_ADDR 0xC900 ///< 0xC900 - IP address not found. - #define FERR_SVR_SOCK_FAIL 0xC901 ///< 0xC901 - IP socket failure. - #define FERR_SVR_CONNECT_FAIL 0xC902 ///< 0xC902 - TCP/IP connection failure. - #define FERR_SVR_BIND_FAIL 0xC903 ///< 0xC903 - The TCP/IP services on your system may not be configured or installed. - #define FERR_SVR_LISTEN_FAIL 0xC904 ///< 0xC904 - TCP/IP listen failed. - #define FERR_SVR_ACCEPT_FAIL 0xC905 ///< 0xC905 - TCP/IP accept failed. - #define FERR_SVR_SELECT_ERR 0xC906 ///< 0xC906 - TCP/IP select failed. - #define FERR_SVR_SOCKOPT_FAIL 0xC907 ///< 0xC907 - TCP/IP socket operation failed. - #define FERR_SVR_DISCONNECT 0xC908 ///< 0xC908 - TCP/IP disconnected. - #define FERR_SVR_READ_FAIL 0xC909 ///< 0xC909 - TCP/IP read failed. - #define FERR_SVR_WRT_FAIL 0xC90A ///< 0xC90A - TCP/IP write failed. - #define FERR_SVR_READ_TIMEOUT 0xC90B ///< 0xC90B - TCP/IP read timeout. - #define FERR_SVR_WRT_TIMEOUT 0xC90C ///< 0xC90C - TCP/IP write timeout. - #define FERR_SVR_ALREADY_CLOSED 0xC90D ///< 0xC90D - Connection already closed. - - #define LAST_FLAIM_ERROR 0xC90D ///< 0xC90D - Place holder - #define FERR_BT_END_OF_DATA 0xFFFF ///< 0xFFFF - Used internally + #define FERR_BT_END_OF_DATA 0xFFFF ///< 0xFFFF - Used internally /// @} - #ifndef RC_OK - #define RC_OK( rc) ((rc) == FERR_OK) - #endif - - #ifndef RC_BAD - #define RC_BAD( rc) ((rc) != FERR_OK) - #endif - /*************************************************************************** Forward Declarations ***************************************************************************/ @@ -716,9 +383,6 @@ class FlmRecord; class FlmRecordSet; class F_LogMessage; - class F_FileHdl; - class F_ListItem; - class F_ListMgr; class F_Restore; /*************************************************************************** @@ -726,86 +390,14 @@ ***************************************************************************/ typedef void * HFDB; ///< Database handle. - #define HFDB_NULL NULL typedef void * HFCURSOR; ///< Query object handle. - #define HFCURSOR_NULL NULL typedef void * HFBLOB; ///< BLOB handle. - #define HFBLOB_NULL NULL typedef void * HFBACKUP; ///< Backup object handle. - #define HFBACKUP_NULL NULL - - /// Header for blocks in a memory pool. This structure is at the head of each block that belongs to a pool of - /// memory. - typedef struct MBLK - { - MBLK * pPrevBlk; ///< Points to the previous memory block in the memory pool. - FLMUINT uiBlkSize; ///< Total size of the memory block. - FLMUINT uiFreeOfs; ///< Offset in block where next allocation should be made. - FLMUINT uiFreeSize; ///< Amount of free memory left in block - from uiFreeOfs. - } MBLK; - - - /// Pool statistics. This structure is used to track statistics on - /// smart pools. - typedef struct - { - FLMUINT uiAllocBytes; ///< Total number of bytes requested from - ///< GedPoolAlloc and GedPoolCalloc calls - FLMUINT uiCount; ///< Number of frees and resets performed on - ///< the pool - } POOL_STATS; - - /// Pool memory manager. This structure is used to keep track of a pool - /// of memory blocks that are used for pool memory allocation. - typedef struct - { - MBLK * lblk; ///< Pointer to last memory block in the pool. - FLMUINT uiBlkSize; ///< Default size to use when allocating new memory blocks. - FLMUINT uiBytesAllocated; ///< Total bytes allocated in the memory pool. - POOL_STATS * pPoolStats; ///< Pool statistics - may be NULL. - } POOL; - - /// Initialize memory pool. - /// \ingroup pool - FLMEXP void FLMAPI GedPoolInit( - POOL * pPool, ///< Pool memory manager object that is to be initialized. - FLMUINT uiBlkSize ///< Default block size for the memory pool. - ); - - /// Free all memory blocks in a memory pool. - /// \ingroup pool - FLMEXP RCODE FLMAPI GedPoolFree( - POOL * pPool ///< Pool memory manager object whose memory is to be freed. - ); - - /// Allocate memory from a memory pool.\ Returns pointer to allocated memory. - /// \ingroup pool - FLMEXP void * FLMAPI GedPoolAlloc( - POOL * pPool, ///< Pool memory manager object where memory is to be allocated from. - FLMUINT uiSize ///< Requested allocation size (in bytes). - ); - - /// Allocate memory from a memory pool and initialize memory to zeroes.\ Returns pointer to allocated memory. - /// \ingroup pool - FLMEXP void * FLMAPI GedPoolCalloc( - POOL * pPool, ///< Pool memory manager object where memory is to be allocated from. - FLMUINT uiSize ///< Requested allocation size (in bytes). - ); - - /// Obtain a mark in a memory pool.\ Returned mark remembers a location in the - /// pool which can later be passed to GedPoolReset() to free all memory that was - /// allocated after the mark. - /// \ingroup pool - FLMEXP void * FLMAPI GedPoolMark( - POOL * pPool ///< Pool memory manager object. - ); - - /// Reset a memory pool back to a mark.\ Free all memory blocks allocated after the mark. - /// \ingroup pool - FLMEXP RCODE FLMAPI GedPoolReset( - POOL * pPool, ///< Pool memory manager object. - void * pvMark ///< Mark that was obtained from GedPoolMark(). - ); + + #define HFDB_NULL NULL + #define HFCURSOR_NULL NULL + #define HFBLOB_NULL NULL + #define HFBACKUP_NULL NULL /// Database create options.\ This structure is passed to FlmDbCreate() /// to specify create options for a new database. @@ -832,7 +424,7 @@ FLMUINT uiMinRflFileSize; ///< Minimum bytes per RFL file. #define DEFAULT_MIN_RFL_FILE_SIZE ((FLMUINT)100 * (FLMUINT)1024 * (FLMUINT)1024) FLMUINT uiMaxRflFileSize; ///< Maximum bytes per RFL file. - #define DEFAULT_MAX_RFL_FILE_SIZE F_MAXIMUM_FILE_SIZE + #define DEFAULT_MAX_RFL_FILE_SIZE FLM_MAXIMUM_FILE_SIZE FLMBOOL bKeepRflFiles; ///< Keep RFL files? #define DEFAULT_KEEP_RFL_FILES_FLAG FALSE FLMBOOL bLogAbortedTransToRfl; ///< Log aborted transactions to RFL? @@ -843,122 +435,6 @@ FLMUINT uiAppMinorVer; ///< The application's minor version number } CREATE_OPTS; - /// This is a pure virtual base class that other FLAIM classes inherit from.\ It - /// provides methods for reference counting (AddRef, Release), as well as - /// methods for overloading new and delete operators. - class FLMEXP F_Base - { - public: - - F_Base() - { - m_refCnt = 1; - } - - virtual ~F_Base() - { - } - - /// Increment the reference count for this object. - /// The reference count is the number of pointers that are referencing this object. - /// Return value is the incremented reference count. - FINLINE FLMINT AddRef( void) - { - return( (FLMINT)(++m_refCnt)); - } - - /// Decrement the reference count for this object. - /// The reference count is the number of pointers that are referencing this object. - /// Return value is the decremented reference count. If the reference count goes to - /// zero, the object will be deleted. - FLMINT Release( void); - - /// Return the current reference count on the object. - FINLINE FLMINT getRefCount( void) - { - return( (FLMINT)(m_refCnt)); - } - - /// Overloaded new operator for objects of this class. - void * operator new( - FLMSIZET uiSize) ///< Number of bytes to allocate - should be sizeof( ThisClass). - #if !defined( FLM_NLM) - throw() - #endif - ; - - /// Overloaded new operator for objects of this class (with source file and line number). - /// This new operator passes in the current file and line number. This information is - /// useful in tracking memory allocations to determine where memory leaks are coming from. - void * operator new( - FLMSIZET uiSize, ///< Number of bytes to allocate - should be sizeof( ThisClass). - const char * pszFile, ///< Name of source file where this allocation is made. - int iLine) ///< Line number in source file where this allocation request is made. - #if !defined( FLM_NLM) - throw() - #endif - ; - - /// Overloaded new operator (array) for objects of this class. - /// This method is called when an array of objects of this class is allocated. - void * operator new[]( - FLMSIZET uiSize) ///< Number of bytes to allocate - should be a multiple of sizeof( ThisClass). - #if !defined( FLM_NLM) - throw() - #endif - ; - - /// Overloaded new operator (array) for objects of this class (with source file and line number). - /// This new operator is called when an array of objects of this class are allocated. - /// This new operator passes in the current file and line number. This information is - /// useful in tracking memory allocations to determine where memory leaks are coming from. - void * operator new[]( - FLMSIZET uiSize, ///< Number of bytes to allocate - should be a multiple of sizeof( ThisClass). - const char * pszFile, ///< Name of source file where this allocation is made. - int iLine) ///< Line number in source file where this allocation request is made. - #if !defined( FLM_NLM) - throw() - #endif - ; - - /// Overloaded delete operator for objects of this class. - void operator delete( - void * ptr); ///< Pointer to object being freed. - - /// Overloaded delete operator (array) for objects of this class. - /// This method is called when an array of objects of this class is freed. - void operator delete[]( - void * ptr); ///< Pointer to array of objects being freed. - - #if defined( FLM_DEBUG) && !defined( __WATCOMC__) - /// Overloaded delete operator for objects of this class (with source file and line number). - /// This delete operator passes in the current file and line number. This information is - /// useful in tracking memory allocations to determine where memory leaks are coming from. - void operator delete( - void * ptr, ///< Pointer to object being freed. - const char * pszFile, ///< Name of source file where this delete occurs. - int iLine); ///< Line number in source file where this delete occurs. - #endif - - #if defined( FLM_DEBUG) && !defined( __WATCOMC__) - /// Overloaded delete operator (array) for objects of this class (with source file and line number). - /// This delete operator is called when an array of objects of this class is freed. - /// This delete operator passes in the current file and line number. This information is - /// useful in tracking memory allocations to determine where memory leaks are coming from. - void operator delete[]( - void * ptr, ///< Pointer to array of objects being freed. - const char * pszFile, ///< Name of source file where this delete occurs. - int iLine); ///< Line number in source file where this delete occurs. - #endif - - protected: - - FLMATOMIC m_refCnt; - - friend class F_FileHdlPage; - friend class F_FileHdlMgrPage; - }; - /**************************************************************************** Name Table Function Structures ****************************************************************************/ @@ -977,7 +453,7 @@ /// index name, or container name.\ It also allows an application to /// to get a field name, index name, or field name using the dictionary /// number. - class FLMEXP F_NameTable : public F_Base + class FLMEXP F_NameTable : public F_Object { public: @@ -1142,7 +618,7 @@ FLMUINT uiTagTypeAndNameTblInsertPos, FLMUINT uiTagNumTblInsertPos); - POOL m_pool; + F_Pool m_pool; FLM_TAG_INFO ** m_ppSortedByTagName; FLM_TAG_INFO ** m_ppSortedByTagNum; FLM_TAG_INFO ** m_ppSortedByTagTypeAndName; @@ -1194,27 +670,18 @@ /// Structure that holds cache usage statistics. The statistics will be for either block cache or record cache. typedef struct { - FLMUINT uiMaxBytes; ///< Maximum bytes allowed in cache. - FLMUINT uiTotalBytesAllocated; ///< Total bytes currently allocated in cache. - FLMUINT uiCount; ///< Number of items cached (blocks or records). - FLMUINT uiOldVerCount; ///< Number of items cached that are prior versions. - FLMUINT uiOldVerBytes; ///< Total bytes in prior versions. - FLMUINT uiCacheHits; ///< Total number of times an item was found in cache. - FLMUINT uiCacheHitLooks; ///< Total number of items traversed to find items in cache. - FLMUINT uiCacheFaults; ///< Total number of times an item was not found in cache. - FLMUINT uiCacheFaultLooks; ///< Total number of items traversed to determine that an item was not in cache. + FLMUINT uiMaxBytes; ///< Maximum bytes allowed in cache. + FLMUINT uiTotalBytesAllocated; ///< Total bytes currently allocated in cache. + FLMUINT uiCount; ///< Number of items cached (blocks or records). + FLMUINT uiOldVerCount; ///< Number of items cached that are prior versions. + FLMUINT uiOldVerBytes; ///< Total bytes in prior versions. + FLMUINT uiCacheHits; ///< Total number of times an item was found in cache. + FLMUINT uiCacheHitLooks; ///< Total number of items traversed to find items in cache. + FLMUINT uiCacheFaults; ///< Total number of times an item was not found in cache. + FLMUINT uiCacheFaultLooks; ///< Total number of items traversed to determine that an item was not in cache. + FLM_SLAB_USAGE SlabUsage; ///< Slab usage statistics } FLM_CACHE_USAGE; - /// Structure that holds extended cache usage statistics. - typedef struct - { - FLMUINT64 ui64TotalExtendedMemory; ///< Total bytes of extended memory. - FLMUINT64 ui64RemainingExtendedMemory; ///< Total bytes of extended memory that are available for use. - FLMUINT64 ui64TotalBytesAllocated; ///< Total bytes of extended memory currently allocated. - FLMUINT64 ui64CacheHits; ///< Total number of times an item was found in extended memory. - FLMUINT64 ui64CacheFaults; ///< Total number of times an item was not found in extended memory. - } FLM_ECACHE_USAGE; - /// Structure returned from FlmGetMemoryInfo(). typedef struct { @@ -1239,20 +706,8 @@ FLMUINT uiReplaceableBytes; ///< Total number of bytes in the replaceable blocks. FLM_CACHE_USAGE RecordCache; ///< Record cache usage statistics. FLM_CACHE_USAGE BlockCache; ///< Block cache usage statistics. - FLM_ECACHE_USAGE ECache; ///< Extended cache usage statistics. } FLM_MEM_INFO; - /// Structure returned from FlmGetThreadInfo() - contains information about a thread. - typedef struct - { - FLMUINT uiThreadId; ///< Operating system thread ID. - FLMUINT uiThreadGroup; ///< Thread group this thread belongs to. - FLMUINT uiAppId; ///< Application ID that was assigned to the thread when it was started. - FLMUINT uiStartTime; ///< Time the thread was started. - char * pszThreadName; ///< Name of the thread. - char * pszThreadStatus; ///< String indicating the last action the thread reported it was performing. - } F_THREAD_INFO; - /// Structure returned to an event handler function whenever transaction events occur.\ Specifically, this structure is /// returned for transaction begin, commit, and abort events. typedef struct @@ -1311,16 +766,6 @@ ///< If zero, the checkpoint thread is not currently waiting to truncate the rollback log. } CHECKPOINT_INFO; - /// Structure that gives information on threads that are either waiting to obtain a database lock or have obtained a - /// database lock.\ Returned from FlmDbGetConfig() when eDbGetConfigType::FDB_GET_LOCK_HOLDER or - /// eDbGetConfigType::FDB_GET_LOCK_WAITERS is passed in as the option. - typedef struct - { - FLMUINT uiThreadId; ///< Thread id of thread that is waiting to obtain a lock or holds a lock. - FLMUINT uiTime; ///< For lock holder, this is the time the lock was obtained. - ///< For the lock waiter, this is the time he started waiting for the lock. - } LOCK_USER; - /// Structure that reports information on the progress of FlmDbSweep(). The FlmDbSweep() status callback /// function is called and passed a pointer to this structure. typedef struct @@ -1469,26 +914,6 @@ char szDstFileName[ F_PATH_MAX_SIZE]; ///< Name the file is to be renamed to. } DB_RENAME_INFO; - /// Types of locks that may be requested using FlmDbLock(). - typedef enum - { - FLM_LOCK_NONE, ///< No lock.\ NOTE: This is not a valid option for FlmDbLock(), but it may be returned by - ///< FlmDbGetLockType(). - FLM_LOCK_EXCLUSIVE, ///< Exclusive lock. - FLM_LOCK_SHARED ///< Shared lock. - } FLOCK_TYPE; - - /// Structure returned from FlmDbGetLockInfo(). - typedef struct - { - FLOCK_TYPE eCurrLockType; ///< Current lock type. - FLMUINT uiThreadId; ///< Thread ID of thread that has the lock, if lock is an exclusive lock. - FLMUINT uiNumExclQueued; ///< Number of threads waiting to obtain an exclusive lock. - FLMUINT uiNumSharedQueued; ///< Number of threads waiting to obtain a shared lock. - FLMUINT uiPriorityCount; ///< Number of threads waiting to obtain a lock (shared or exclusive) whose - ///< priority is >= the priority value that was passed into FlmDbGetLockInfo(). - } FLOCK_INFO; - /// Structure for nodes used in GEDCOM functions.\ Nodes are the basic components of GEDCOM trees. typedef struct NODE { @@ -1528,18 +953,6 @@ FLMBYTE * pucEncValue; ///< The encrypted value. } NODE; - /// Convert a language string to the appropriate language code. - /// \ingroup language - FLMEXP FLMUINT FLMAPI FlmLanguage( - char * pszLanguageCode ///< Language string that is to be converted to a code. - ); - - /// Get the language string from a language code - /// \ingroup language - FLMEXP void FLMAPI FlmGetLanguage( - FLMUINT uiLangNum, - char * pszLanguageCode); - /// Compare two strings using database comparison rules. Zero is returned if two strings are equal. /// Negative number is returned if puzStr1 < puzStr2. Positive number is returned if puzStr1 > puzStr2. /// \ingroup stringcompare @@ -1559,7 +972,7 @@ ); /// This class allows an application to keep a set of ::FlmRecord objects. - class FLMEXP FlmRecordSet : public F_Base + class FLMEXP FlmRecordSet : public F_Object { public: @@ -1638,7 +1051,7 @@ /// This is an abstract base class which defines the interface that an application /// must implement to embed its own predicate in a query. - class FLMEXP FlmUserPredicate : public F_Base + class FLMEXP FlmUserPredicate : public F_Object { public: @@ -2057,18 +1470,6 @@ ///< space into a single space character ); - // Predefined values for text comparison modes - - #define FLM_WILD 0x02 - #define FLM_NOCASE 0x04 - - // Predefined values for text conversions - - #define FLM_NO_SPACE 0x1000 - #define FLM_NO_DASH 0x2000 - #define FLM_NO_UNDERSCORE 0x4000 - #define FLM_MIN_SPACES 0x8000 - // Predefined value for no time limit #define FLM_NO_LIMIT 0xFFFF @@ -2314,12 +1715,6 @@ /// Output: pvValue is (FLMUINT *), percent. FLM_BLOCK_CACHE_PERCENTAGE, - /// FlmConfig().\ Enable/disable out-of-memory simulation.\ \n - /// Input: pvValue1 is (FLMUINT), 0=disable,other=enable.\ \n - /// FlmGetConfig().\ Get out-of-memory simulation state.\ \n - /// Output: pvValue is (FLMBOOL *), FALSE=disabled,TRUE=enabled. - FLM_OUT_OF_MEM_SIMULATION, - /// FlmConfig().\ Enable/disable cache checking.\ \n /// Input: pvValue1 is (FLMUINT), 0=disable,other=enable.\ \n /// FlmGetConfig().\ Get cache checking state.\ \n @@ -2335,12 +1730,6 @@ /// NULL means disable logging. FLM_LOGGER, - /// FlmConfig().\ Enable/disable use of extended memory.\ \n - /// Input: pvValue1 is (FLMUINT), 0=disable,other=enable.\ \n - /// FlmGetConfig().\ Get extended memory usage state.\ \n - /// Output: pvValue is (FLMBOOL *), FALSE=disabled,TRUE=enabled. - FLM_USE_ESM, - /// FlmConfig().\ Set function pointers for HTTP server.\ \n /// Input: pvValue1 is (HTTPCONFIGPARAMS *), pointer to structure /// containing HTTP handling functions. @@ -2475,7 +1864,7 @@ /// Get information on background threads in the FLAIM database system. /// \ingroup systemconfiguration FLMEXP RCODE FLMAPI FlmGetThreadInfo( - POOL * pPool, ///< Memory pool for allocating memory.\ This pool is used to allocate the structures + F_Pool * pPool, ///< Memory pool for allocating memory.\ This pool is used to allocate the structures ///< and other buffers that will contain the thread information.\ To free all of the ///< information, the application only needs to call GedPoolFree(). F_THREAD_INFO ** ppThreadInfo, ///< Pointer to array of thread information structures is returned here.\ The memory @@ -2496,39 +1885,32 @@ Statistics ****************************************************************************/ - /// Structure used in gathering statistics to hold an operation count and an elapsed time. - typedef struct - { - FLMUINT64 ui64Count; ///< Number of times operation was performed - FLMUINT64 ui64ElapMilli; ///< Total elapsed time (milliseconds) for the operations. - } COUNT_TIME_STAT; - /// Structure used in gathering statistics to hold a operation count, a byte count, and an elapsed time. This /// is typically used for I/O operations where it is useful to know the number of bytes that were read or /// written by the operation. typedef struct { - FLMUINT64 ui64Count; ///< Number of times operation was performed. - FLMUINT64 ui64TotalBytes; ///< Total number of bytes involved in the operations.\ This usually represents - ///< bytes read from or written to disk. - FLMUINT64 ui64ElapMilli; ///< Total elapsed time (milliseconds) for the operations. + FLMUINT64 ui64Count; ///< Number of times operation was performed. + FLMUINT64 ui64TotalBytes; ///< Total number of bytes involved in the operations.\ This usually represents + ///< bytes read from or written to disk. + FLMUINT64 ui64ElapMilli; ///< Total elapsed time (milliseconds) for the operations. } DISKIO_STAT; /// Statistics for read transactions. typedef struct { - COUNT_TIME_STAT CommittedTrans; ///< Statistics for read transactions committed. - COUNT_TIME_STAT AbortedTrans; ///< Statistics for read transactions aborted. - COUNT_TIME_STAT InvisibleTrans; ///< Statistics for invisible read transactions. + F_COUNT_TIME_STAT CommittedTrans; ///< Statistics for read transactions committed. + F_COUNT_TIME_STAT AbortedTrans; ///< Statistics for read transactions aborted. + F_COUNT_TIME_STAT InvisibleTrans; ///< Statistics for invisible read transactions. } RTRANS_STATS; /// Statistics for update transactions. typedef struct { - COUNT_TIME_STAT CommittedTrans; ///< Statistics for update transactions committed. - COUNT_TIME_STAT GroupCompletes; ///< Statistics for number of times multiple transactions were committed together. - FLMUINT64 ui64GroupFinished;///< Total update transactions that were committed in a group. - COUNT_TIME_STAT AbortedTrans; ///< Statistics for update transactions aborted. + F_COUNT_TIME_STAT CommittedTrans; ///< Statistics for update transactions committed. + F_COUNT_TIME_STAT GroupCompletes; ///< Statistics for number of times multiple transactions were committed together. + FLMUINT64 ui64GroupFinished; ///< Total update transactions that were committed in a group. + F_COUNT_TIME_STAT AbortedTrans; ///< Statistics for update transactions aborted. } UTRANS_STATS; /// Statistics for block reads and writes. @@ -2543,8 +1925,8 @@ ///< was read in - either checksum errors or other problems ///< validating data in the block.\ This statistic is for ///< older versions of a block as opposed to the current version. - FLMUINT uiOldViewErrors; // Number of times we had an old view error when reading blocks. - DISKIO_STAT BlockWrites; // Statistics on Block writes. + FLMUINT uiOldViewErrors; ///< Number of times we had an old view error when reading blocks. + DISKIO_STAT BlockWrites; ///< Statistics on block writes. } BLOCKIO_STATS; /// Statistics gathered for a particular logical file (index or container). @@ -2585,11 +1967,11 @@ FLMUINT64 ui64NumCursorReads; ///< Number of query operations that have been performed on this database.\ This ///< includes counts for FlmCursorFirst(), FlmCursorLast(), FlmCursorNext(), ///< FlmCursorPrev(), and FlmCursorCurrent(). - COUNT_TIME_STAT RecordAdds; ///< Number of record add operations (FlmRecordAdd()) that have been performed on + F_COUNT_TIME_STAT RecordAdds; ///< Number of record add operations (FlmRecordAdd()) that have been performed on ///< this database. - COUNT_TIME_STAT RecordDeletes; ///< Number of record delete operations (FlmRecordDelete()) that have been performed + F_COUNT_TIME_STAT RecordDeletes; ///< Number of record delete operations (FlmRecordDelete()) that have been performed ///< on this database. - COUNT_TIME_STAT RecordModifies; ///< Number of record modify operations (FlmRecordModify()) that have been performed + F_COUNT_TIME_STAT RecordModifies; ///< Number of record modify operations (FlmRecordModify()) that have been performed ///< on this database. FLMUINT64 ui64NumRecordReads; ///< Number of record read operations (FlmRecordRetrieve()) that have been performed ///< on this database. @@ -2615,10 +1997,8 @@ FLMUINT uiWriteErrors; ///< Number of times we got write errors. // Lock statistics - - COUNT_TIME_STAT NoLocks; ///< Statistics on times when nobody was holding a lock on the database. - COUNT_TIME_STAT WaitingForLock; ///< Statistics on times threads were waiting to obtain a database lock. - COUNT_TIME_STAT HeldLock; ///< Statistics on times when a thread was holding a lock on the database. + + F_LOCK_STATS LockStats; ///< Database lock statistics } DB_STATS; @@ -2884,8 +2264,6 @@ ///< between events. } eDbConfigType; -#define F_SERIAL_NUM_SIZE 16 - /// Options for FlmDbGetConfig(). typedef enum { @@ -2899,11 +2277,11 @@ ///< update transaction ID if this database handle has the database locked.\ Otherwise it will return zero. FDB_GET_CHECKPOINT_INFO, ///< Get the current state of the checkpoint thread.\ pvValue1 is a pointer to a ::CHECKPOINT_INFO ///< structure where the checkpoint information is to be returned. - FDB_GET_LOCK_HOLDER, ///< Get the current lock holder for the database.\ pvValue1 is a pointer to a ::LOCK_USER structure + FDB_GET_LOCK_HOLDER, ///< Get the current lock holder for the database.\ pvValue1 is a pointer to a ::F_LOCK_USER structure ///< where the lock information is to be returned. FDB_GET_LOCK_WAITERS, ///< Get the entire list of threads that are either holding the lock on the database or are waiting - ///< to obtain the lock on the database.\ pvValue1 is a ::LOCK_USER **.\ This option will allocate - ///< an array of ::LOCK_USER structures and return a pointer to them.\ The zeroeth element of the + ///< to obtain the lock on the database.\ pvValue1 is a ::F_LOCK_USER **.\ This option will allocate + ///< an array of ::F_LOCK_USER structures and return a pointer to them.\ The zeroeth element of the ///< array contains the lock holder.\ All other elements contain lock waiters.\ The last element ///< in the array will be zeroed out.\ NOTE: The memory allocated by this function should be freed ///< by calling FlmFreeMem(). @@ -3092,36 +2470,6 @@ ///< FlmSetStatusHook() function when the status callback function was set. ); - /// Abstract base class to get lock information for a database. The application must implement - /// this class. A pointer to an object of this class is passed into FlmDbGetConfig() when it is - /// called with the eDbGetConfigType::FDB_GET_LOCK_WAITERS_EX option. - class FLMEXP FlmLockInfo : public F_Base - { - public: - - /// Return the lock count on the database. This method is called by FLAIM to tell the - /// application how many lock holders plus lock waiters there are. This gives the - /// application an opportunity to allocate memory to hold the information that will - /// be returned via the FlmLockInfo::addLockInfo() method. The application should - /// return TRUE from this method in order to tell FLAIM to continue, FALSE if it wants - /// FLAIM to stop and return from the FlmDbGetConfig() function. - virtual FLMBOOL setLockCount( - FLMUINT uiTotalLocks ///< Total number of lock holders plus lock waiters. - ) = 0; - - /// Return lock information for a lock holder or waiter. This method is called by FLAIM - /// for each thread that is either holding the database lock or waiting to obtain the lock. - /// The application should return TRUE from this method in order to tell FLAIM to continue, - /// FALSE if it wants FLAIM to stop and return from the FlmDbGetConfig() function. - virtual FLMBOOL addLockInfo( - FLMUINT uiLockNum, ///< Position in queue (0 = lock holder, 1..n = lock waiter). - FLMUINT uiThreadID, ///< Thread ID of the lock holder/waiter. - FLMUINT uiTime ///< For the lock holder, this is the amount of time the lock has been - ///< held.\ For a lock waiter, this is the amount of time the thread - ///< has been waiting to obtain the lock.\ Both times are milliseconds. - ) = 0; - }; - /// Retrieve status of an index. /// \ingroup indexing FLMEXP RCODE FLMAPI FlmIndexStatus( @@ -3287,7 +2635,7 @@ /// \ingroup trans FLMEXP RCODE FLMAPI FlmDbLock( HFDB hDb, ///< Database handle. - FLOCK_TYPE eLockType, ///< Type of lock being requested. + eLockType lockType, ///< Type of lock being requested. FLMINT iPriority, ///< Priority of lock being requested. FLMUINT uiTimeout ///< Specifies the maximum number of seconds to wait to obtain the lock.\ NOTE: A ///< value of FLM_NO_TIMEOUT specifies that it should wait forever - until the @@ -3304,7 +2652,7 @@ /// \ingroup trans FLMEXP RCODE FLMAPI FlmDbGetLockType( HFDB hDb, ///< Database handle. - FLOCK_TYPE * peLockType, ///< Type of lock currently held returned here. + eLockType * pLockType, ///< Type of lock currently held returned here. FLMBOOL * pbImplicit ///< Flag indicating if the lock is an implicit lock.\ An implicit lock is one that ///< FLAIM obtained automatically when it started an update transaction.\ An ///< implicit lock will be released automatically when the transaction commits or @@ -3312,15 +2660,6 @@ ///< explicit lock is released when the application calls FlmDbUnlock(). ); - /// Get lock information for a database. - /// \ingroup trans - FLMEXP RCODE FLMAPI FlmDbGetLockInfo( - HFDB hDb, ///< Database handle. - FLMINT iPriority, ///< A count of all locks with a priority >= this value will be returned in - ///< pLockInfo (FLOCK_INFO::uiPriorityCount). - FLOCK_INFO * pLockInfo ///< Lock information is returned here. - ); - /// Perform a checkpoint on the database. /// \ingroup trans FLMEXP RCODE FLMAPI FlmDbCheckpoint( @@ -3614,7 +2953,7 @@ /// This is an abstract base class that allows an application to read "unknown" data from the /// RFL or to write "unknown" data to the RFL. /// The application must implement this class. - class FLMEXP F_UnknownStream : public F_Base + class FLMEXP F_UnknownStream : public F_Object { public: @@ -3692,7 +3031,7 @@ RESTORE_WRAP_KEY, ///< Restoring a FlmDbWrapKey() operation.\ pvValue1 is a FLMUINT that contains the length of the database key. RESTORE_ENABLE_ENCRYPTION, ///< Restoring a FlmEnableEncryption() operation.\ pvValue1 is a FLMUINT that contains the length of ///< the database key. - RESTORE_CONFIG_SIZE_EVENT ///< Restoring a FlmSetSizeEventThreshold() operation.\ pvValue1 is a FLMUINT .... // here + RESTORE_CONFIG_SIZE_EVENT ///< Restoring a FlmSetSizeEventThreshold() operation.\ pvValue1 is a FLMUINT .... } eRestoreStatusType; /// Actions that an application may want to tell FlmDbRestore() to take during a restore operation. @@ -3715,7 +3054,7 @@ /// function of FlmDbBackup() (see its fnWrite parameter) allow an application to have complete /// control over writing and reading of backup data. Backup data could be streamed directly to /// a tape device, or any other media the application chooses. - class FLMEXP F_Restore : public F_Base + class FLMEXP F_Restore : public F_Object { public: @@ -3819,7 +3158,7 @@ /// This class provides an interface for handling binary large objects. Currently, FLAIM only /// supports referencing of external files. BLOB data is not actually stored "in" the database. - class FLMEXP FlmBlob : public F_Base + class FLMEXP FlmBlob : public F_Object { public: @@ -3879,34 +3218,12 @@ FLM_DEBUG_MESSAGE ///< Debug message. } FlmLogMessageSeverity; - typedef enum - { - FLM_BLACK = 0, - FLM_BLUE, - FLM_GREEN, - FLM_CYAN, - FLM_RED, - FLM_PURPLE, - FLM_BROWN, - FLM_LIGHTGRAY, - FLM_DARKGRAY, - FLM_LIGHTBLUE, - FLM_LIGHTGREEN, - FLM_LIGHTCYAN, - FLM_LIGHTRED, - FLM_LIGHTPURPLE, - FLM_YELLOW, - FLM_WHITE, - FLM_NUM_COLORS, - FLM_CURRENT_COLOR - } FlmColorType; - /// This is an abstract base class that allows an application to catch messages logged by FLAIM. The /// application must create an implementation for this class and then pass that object into /// the FlmConfig() function using the eFlmConfigTypes::FLM_LOGGER option. Doing so allows the /// application to catch messages logged by FLAIM. The application can do whatever it wants with /// the messages - write them to a log file, display them to a console, save them to a database, etc. - class FLMEXP F_Logger : public F_Base + class FLMEXP F_Logger : public F_Object { public: @@ -3990,7 +3307,8 @@ /// class when the F_Logger::beginMessage() method is called by FLAIM. Doing so allows the /// application to catch messages logged by FLAIM. The application can do whatever it wants with /// the messages - write them to a log file, display them to a console, save them to a database, etc. - class FLMEXP F_LogMessage : public F_Base + + class FLMEXP F_LogMessage : public F_Object { public: @@ -3998,8 +3316,8 @@ { m_uiBackColors = 0; m_uiForeColors = 0; - m_eCurrentForeColor = FLM_LIGHTGRAY; - m_eCurrentBackColor = FLM_BLACK; + m_currentForeColor = FLM_LIGHTGRAY; + m_currentBackColor = FLM_BLACK; } virtual ~F_LogMessage() @@ -4012,8 +3330,8 @@ /// set the colors for text that is appended after this call (see F_LogMessage::appendString()). /// The colors may be changed at any time - thus allowing a message to have multiple different colors. virtual void changeColor( - FlmColorType eForeColor, ///< Foreground color. - FlmColorType eBackColor ///< Background color. + eColorType foreColor, ///< Foreground color. + eColorType backColor ///< Background color. ) = 0; /// Append a string to the message. FLAIM calls this to add text to a message. It may be called @@ -4045,29 +3363,29 @@ void popBackgroundColor( void); - FlmColorType getForegroundColor() + eColorType getForegroundColor() { - return( m_eCurrentForeColor); + return( m_currentForeColor); } - FlmColorType getBackgroundColor() + eColorType getBackgroundColor() { - return( m_eCurrentBackColor); + return( m_currentBackColor); } void setColor( - FlmColorType eForeColor, - FlmColorType eBackColor); + eColorType foreColor, + eColorType backColor); private: #define F_MAX_COLOR_STACK_SIZE 8 - FlmColorType m_eBackColors[ F_MAX_COLOR_STACK_SIZE]; - FlmColorType m_eForeColors[ F_MAX_COLOR_STACK_SIZE]; + eColorType m_backColors[ F_MAX_COLOR_STACK_SIZE]; + eColorType m_foreColors[ F_MAX_COLOR_STACK_SIZE]; FLMUINT m_uiBackColors; FLMUINT m_uiForeColors; - FlmColorType m_eCurrentBackColor; - FlmColorType m_eCurrentForeColor; + eColorType m_currentBackColor; + eColorType m_currentForeColor; }; #define F_MAX_NUM_BUF 12 @@ -4626,7 +3944,7 @@ access and manipulate all records. ****************************************************************************/ /// Class for creating and modifying database records. - class FLMEXP FlmRecord : public F_Base + class FLMEXP FlmRecord : public F_Object { public: @@ -4645,11 +3963,8 @@ /// Overloaded new operator for ::FlmRecord objects. void * operator new( - FLMSIZET uiSize) ///< Number of bytes to allocate - should be sizeof( ::FlmRecord). - #if !defined( FLM_NLM) - throw() - #endif - ; + FLMSIZET uiSize ///< Number of bytes to allocate - should be sizeof( ::FlmRecord). + ); /// Overloaded new operator for ::FlmRecord objects (with source file and line number). /// This new operator passes in the current file and line number. This information is @@ -4657,20 +3972,14 @@ void * operator new( FLMSIZET uiSize, ///< Number of bytes to allocate - should be sizeof( ::FlmRecord). const char * pszFile, ///< Name of source file where this allocation is made. - int iLine) ///< Line number in source file where this allocation request is made. - #if !defined( FLM_NLM) - throw() - #endif - ; + int iLine ///< Line number in source file where this allocation request is made. + ); /// Overloaded new operator (array) for ::FlmRecord objects. /// This method is called when an array of ::FlmRecord objects is allocated. void * operator new[]( - FLMSIZET uiSize) ///< Number of bytes to allocate - should be a multiple of sizeof( ::FlmRecord). - #if !defined( FLM_NLM) - throw() - #endif - ; + FLMSIZET uiSize ///< Number of bytes to allocate - should be a multiple of sizeof( ::FlmRecord). + ); /// Overloaded new operator (array) for ::FlmRecord objects (with source file and line number). /// This new operator is called when an array of ::FlmRecord objects is allocated. @@ -4679,11 +3988,8 @@ void * operator new[]( FLMSIZET uiSize, ///< Number of bytes to allocate - should be a multiple of sizeof( ::FlmRecord). const char * pszFile, ///< Name of source file where this allocation is made. - int iLine) ///< Line number in source file where this allocation request is made. - #if !defined( FLM_NLM) - throw() - #endif - ; + int iLine ///< Line number in source file where this allocation request is made. + ); /// Overloaded delete operator for ::FlmRecord objects. void operator delete( @@ -4718,16 +4024,13 @@ /// Increment the reference count for this ::FlmRecord object. /// The reference count is the number of pointers that are referencing this ::FlmRecord object. /// Return value is the incremented reference count. - FINLINE FLMINT AddRef( void) - { - return( AddRef( FALSE)); - } + FLMINT FLMAPI AddRef( void); /// Decrement the reference count for this ::FlmRecord object. /// The reference count is the number of pointers that are referencing this ::FlmRecord object. /// Return value is the decremented reference count. If the reference count goes to /// zero, the ::FlmRecord object will be deleted. - FINLINE FLMINT Release( void) + FINLINE FLMINT FLMAPI Release( void) { return( Release( FALSE)); } @@ -5315,7 +4618,7 @@ /// Import a record from a file. The record in the file should be formatted according /// to the specification for GEDCOM. RCODE importRecord( - F_FileHdl * pFileHdl, ///< Open file handle where the data for the record is to be read from. + IF_FileHdl * pFileHdl, ///< Open file handle where the data for the record is to be read from. F_NameTable * pNameTable ///< Name table object that is to be used to translate field names to ///< field numbers. ); @@ -5337,7 +4640,7 @@ /// Export a record to a Gedcom ::NODE tree. RCODE exportRecord( HFDB hDb, ///< Database handle.\ The root node of the Gedcom tree will be associated with this handle. - POOL * pPool, ///< Memory pool for allocating ::NODE structures and space for field data. + F_Pool * pPool, ///< Memory pool for allocating ::NODE structures and space for field data. NODE ** ppNode ///< Root of the Gedcom ::NODE tree will be returned here. ); @@ -5487,9 +4790,6 @@ private: - FLMINT AddRef( - FLMBOOL bMutexLocked); - FLMINT Release( FLMBOOL bMutexLocked); @@ -5720,6 +5020,8 @@ FLMBYTE * m_pucFieldIdTable; friend struct FlmRecordExt; + friend class F_RecRelocator; + friend class F_RecBufferRelocator; friend class F_Rfl; }; @@ -5987,31 +5289,31 @@ /// Structure containing statistics collected during FlmDbCheck() for a particular category of blocks in the database. typedef struct { - FLMUINT uiBlockCount; ///< Total blocks found in the database that were in the in the block category. - FLMUINT64 ui64BytesUsed; ///< Total bytes used in the blocks. - FLMUINT64 ui64ElementCount; ///< Total elements in the blocks.\ NOTE: This only applies to b-tree blocks. - FLMUINT64 ui64ContElementCount; ///< Total continuation elements in the blocks.\ NOTE: This only applies to b-tree blocks. - FLMUINT64 ui64ContElmBytes; ///< Total bytes in continuation elements.\ NOTE: This only applies to b-tree blocks. - eCorruptionType eCorruption; ///< First corruption error found in blocks in this block category. - FLMUINT uiNumErrors; ///< Total corruption errors found in blocks in this block category. + FLMUINT uiBlockCount; ///< Total blocks found in the database that were in the in the block category. + FLMUINT64 ui64BytesUsed; ///< Total bytes used in the blocks. + FLMUINT64 ui64ElementCount; ///< Total elements in the blocks.\ NOTE: This only applies to b-tree blocks. + FLMUINT64 ui64ContElementCount; ///< Total continuation elements in the blocks.\ NOTE: This only applies to b-tree blocks. + FLMUINT64 ui64ContElmBytes; ///< Total bytes in continuation elements.\ NOTE: This only applies to b-tree blocks. + eCorruptionType eCorruption; ///< First corruption error found in blocks in this block category. + FLMUINT uiNumErrors; ///< Total corruption errors found in blocks in this block category. } BLOCK_INFO; /// Locations of corruptions in the database. typedef enum { LOCALE_NONE = 0, - LOCALE_LFH_LIST, ///< Corruption was found in the list of logical file blocks. - LOCALE_AVAIL_LIST = 3, ///< Corruption was found in the list of available blocks. - LOCALE_B_TREE, ///< Corruption was found in an index or container b-tree block. - LOCALE_IXD_TBL, ///< Corruption was found in index table. - LOCALE_INDEX ///< Corruption was logical index corruption. + LOCALE_LFH_LIST, ///< Corruption was found in the list of logical file blocks. + LOCALE_AVAIL_LIST = 3, ///< Corruption was found in the list of available blocks. + LOCALE_B_TREE, ///< Corruption was found in an index or container b-tree block. + LOCALE_IXD_TBL, ///< Corruption was found in index table. + LOCALE_INDEX ///< Corruption was logical index corruption. } eCorruptionLocale; /// Structure used to create a linked list of index keys from a record. typedef struct REC_KEY { - FlmRecord * pKey; ///< Pointer to index key that was generated from a record. - REC_KEY * pNextKey; ///< Pointer to next key in the record. + FlmRecord * pKey; ///< Pointer to index key that was generated from a record. + REC_KEY * pNextKey; ///< Pointer to next key in the record. } REC_KEY; /// Structure containing information about a specific corruption that is being reported by FlmDbCheck(). @@ -6046,13 +5348,13 @@ // Index corruption information - FlmRecord * pErrIxKey; ///< If non-NULL, this will contain a pointer to the key from an index for an index + FlmRecord * pErrIxKey; ///< If non-NULL, this will contain a pointer to the key from an index for an index ///< logical corruption.\ NOTE: This will only be set when eErrLocale is ///< eCorruptionLocale::LOCALE_INDEX. - FlmRecord * pErrRecord; ///< If non-NULL, this will contain a pointer to the record involved in an index + FlmRecord * pErrRecord; ///< If non-NULL, this will contain a pointer to the record involved in an index ///< logical corruption.\ NOTE: This will only be set when eErrLocale is ///< eCorruptionLocale::LOCALE_INDEX. - REC_KEY * pErrRecordKeyList; ///< If non-NULL, this will contain a pointer to a linked list of keys from the record that + REC_KEY * pErrRecordKeyList; ///< If non-NULL, this will contain a pointer to a linked list of keys from the record that ///< was involved in an index logical corruption.\ NOTE: This will only be set when ///< eErrLocale is eCorruptionLocale::LOCALE_INDEX. @@ -6192,7 +5494,7 @@ ///< in the index are in the referenced records and that all keys generated from records ///< are in the index ///< - FLM_CHK_FIELDS - Check fields in records - POOL * pPool, ///< Memory pool for allocating memory to hold various statistics in the pDbStats parameter. + F_Pool * pPool, ///< Memory pool for allocating memory to hold various statistics in the pDbStats parameter. DB_CHECK_PROGRESS * pDbStats, ///< Statistics collected about the database during the check. STATUS_HOOK fnStatusHook, ///< Callback status function. void * pvAppArg ///< Pointer to application data.\ This pointer is passed into fnStatusHook whenever it @@ -6384,539 +5686,4 @@ ///< that password must be supplied to FlmDbOpen() when opening the database. ); - FLMEXP void FLMAPI f_pathParse( - const char * pszPath, - char * pszServer, - char * pszVolume, - char * pszDirPath, - char * pszFileName); - - FLMEXP RCODE FLMAPI f_pathReduce( - const char * pszSourcePath, - char * pszDestPath, - char * pszString); - - FLMEXP RCODE FLMAPI f_pathAppend( - char * pszPath, - const char * pszPathComponent); - - FLMEXP RCODE FLMAPI f_pathToStorageString( - const char * pszPath, - char * pszString); - - FLMEXP void FLMAPI f_pathCreateUniqueName( - FLMUINT * puiTime, - char * pszFileName, - const char * pszFileExt, - char * pszHighChars, - FLMBOOL bModext); - - FLMEXP FLMBOOL FLMAPI f_doesFileMatch( - const char * pszFileName, - const char * pszTemplate); - - /**************************************************************************** - Desc: Directory handle - ****************************************************************************/ - class FLMEXP F_DirHdl : public F_Base - { - public: - - virtual ~F_DirHdl() - { - } - - virtual RCODE OpenDir( - const char * pszDirPath, - const char * pszPattern) = 0; - - virtual RCODE Next( void) = 0; - - virtual const char * CurrentItemName( void) = 0; - - virtual FLMUINT CurrentItemSize( void) = 0; - - virtual FLMBOOL CurrentItemIsDir( void) = 0; - - virtual void CurrentItemPath( - char * pszPath) = 0; - }; - - FLMEXP RCODE FLMAPI FlmAllocDirHdl( - F_DirHdl ** ppDirHdl); - - typedef struct - { - F_ListItem * pPrevItem; // Prev ListItem - F_ListItem * pNextItem; // Next ListItem - FLMUINT uiListCount; // Number of items within a list. This - // element is not used when found within - // a ListItem (only used in ListMgr) - } F_ListNode; - - /**************************************************************************** - Desc: - ****************************************************************************/ - class FLMEXP F_ListItem : public F_Base - { - protected: - - F_ListMgr * m_pListMgr; // List that this item is linked into. - FLMUINT m_uiLNodeCnt; // Number of LNODEs - F_ListNode * m_pLNodes; // List of LNODES that this item is apart of. - // Call F_List::GetListCount to determine how - // many LNODEs this item has. - FLMBOOL m_bInList; - - F_ListItem() - { - m_pListMgr = NULL; - m_pLNodes = NULL; - m_uiLNodeCnt = 0; - m_bInList = FALSE; - } - - virtual ~F_ListItem(); - - RCODE Setup( // Finish setup operation on this ListItem - F_ListMgr * pList, // List manager to use - F_ListNode * pLNodes, // Array of LNODEs to be used - FLMUINT uiLNodeCnt); // Number of F_ListNodes supplied. - - RCODE RemoveFromList( // Remove this list item from all lists. - FLMUINT uiList = 0); // Which list to remove item from - // To remove item from all lists pass in - // FLM_ALL_LISTS define. - - // List Traversal Methods - - FINLINE F_ListItem * GetNextListItem( - FLMUINT uiList = 0) - { - return( m_pLNodes[ uiList].pNextItem); - } - - FINLINE F_ListItem * GetPrevListItem( - FLMUINT uiList = 0) - { - return( m_pLNodes[ uiList].pPrevItem); - } - - // List Modification Methods - - FINLINE F_ListItem * SetNextListItem( - FLMUINT uiList, - F_ListItem * pNewNext) - { - F_ListNode * pLNode; - - pLNode = &m_pLNodes[ uiList]; - pLNode->pNextItem = pNewNext; - - return pNewNext; - } - - FINLINE F_ListItem * SetPrevListItem( - FLMUINT uiList, - F_ListItem * pNewPrev) - { - F_ListNode * pLNode; - - pLNode = &m_pLNodes[ uiList]; - pLNode->pPrevItem = pNewPrev; - - return pNewPrev; - } - - friend class F_ListMgr; - friend class F_FileHdlPage; - friend class F_FileHdlMgr; - friend class F_ObjRefTracker; - }; - - /**************************************************************************** - Desc: - ****************************************************************************/ - class FLMEXP F_FileHdl : public F_ListItem - { - public: - - virtual ~F_FileHdl() - { - } - - virtual RCODE Close( void) = 0; // Close a file - The destructor will call this - // This is used to obtain an error code. - - virtual RCODE Create( // Create a new file. - const char * pszIoPath, // File to be created - FLMUINT uiIoFlags) = 0; // Access and Mode Flags - - virtual RCODE CreateUnique( // Create a new file (with a unique file name). - char * pszIoPath, // Directory where the file is to be created - const char * pszFileExtension, // Extension to be used on the new file. - FLMUINT uiIoFlags) = 0; // Access and Mode Flags - - virtual RCODE Open( // Initiates access to an existing file. - const char * pszIoPath, // File to be opened - FLMUINT uiIoFlags) = 0; // Access and Mode Flags - - virtual RCODE Flush( void) = 0; // Flushes a file's buffers to disk - - virtual RCODE Read( // Reads a buffer of data from a file - FLMUINT uiOffset, // Offset to being reading at. - FLMUINT uiLength, // Number of bytes to read - void * pvBuffer, // Buffer to place read bytes into - FLMUINT * puiBytesRead) = 0; // [out] number of bytes read - - virtual RCODE Seek( // Moves the current position in the file - FLMUINT uiOffset, // Offset to seek to - FLMINT iWhence, // Location to apply sdwOffset to. - FLMUINT * puiNewOffset) = 0; // [out] new file offset - - virtual RCODE Size( // Returns to size of the open file. - FLMUINT * puiSize) = 0; // [out] size of the file - - virtual RCODE Tell( // Returns to current position of the file - // pointer in the open file. - FLMUINT * puiOffset) = 0; // [out] current file position - - virtual RCODE Truncate( // Decreases the size of a file. - FLMUINT uiSize) = 0; // Size to truncate the file to. - - virtual RCODE Write( // Writes a buffer of data to a file. - FLMUINT uiOffset, // Offset to seek to. - FLMUINT uiLength, // Number of bytes to write. - const void * pvBuffer, // Buffer that contains bytes to be written - FLMUINT * puiBytesWritten) = 0; // Number of bytes written. - }; - - FLMEXP RCODE FLMAPI FlmAllocFileHandle( - F_FileHdl ** ppFileHandle); - - // File flags - - #define F_IO_CURRENT_POS 0xFFFFFFFF - #define F_IO_RDONLY 0x0001 - #define F_IO_RDWR 0x0002 - #define F_IO_TRUNC 0x0004 - #define F_IO_EXCL 0x0008 - #define F_IO_CREATE_DIR 0x0010 - #define F_IO_SH_DENYRW 0x0020 - #define F_IO_SH_DENYWR 0x0040 - #define F_IO_SH_DENYNONE 0x0080 - #define F_IO_DIRECT 0x0100 - #define F_IO_DELETE_ON_CLOSE 0x0200 - - // File Positioning Definitions - - #define F_IO_SEEK_SET 0 // Beginning of File - #define F_IO_SEEK_CUR 1 // Current File Pointer Position - #define F_IO_SEEK_END 2 // End of File - - /**************************************************************************** - Desc: - ****************************************************************************/ - class FLMEXP F_FileSystem : public F_Base - { - public: - - virtual ~F_FileSystem() - { - } - - virtual RCODE Open( - const char * pszFilePath, // Name of file to be opened. - FLMUINT uiIoFlags, // Access and Mode flags. - F_FileHdl ** ppFileHdl) = 0; // Returns open file handle object. - - virtual RCODE Create( // Create a new file handle - const char * pszFilePath, // Name of file to be created - FLMUINT uiIoFlags, // Access amd Mode flags - F_FileHdl ** ppFileHdl) = 0; // Returns open file handle object. - - virtual RCODE OpenDir( // Open a directory - const char * pszDirPath, // Directory to be opened. - const char * pszPattern, // File name pattern. - F_DirHdl ** ppDirHdl) = 0; // Returns open directory handle - // object. - - virtual RCODE CreateDir( // Create a directory - const char * pszDirPath) = 0; // Directory to be created. - - virtual RCODE RemoveDir( // Remove a directory - const char * pszDirPath, // Directory to be removed. - FLMBOOL bClear = FALSE) = 0; // OK to delete files if dir is not empty? - - virtual RCODE Exists( // See if a file or directory exists. - const char * pszPath) = 0; // Name of file or directory to check. - - virtual FLMBOOL IsDir( // See if a path is a directory. - const char * pszPath) = 0; // Name of path to check. - - virtual RCODE GetTimeStamp( // Get the date/time when the file - // was last updated. - const char * pszPath, // Path to file - FLMUINT * puiTimeStamp) = 0; // Buffer in which time stamp is - // returned. - - virtual RCODE Delete( // Delete a file or directory - const char * pszPath) = 0; // Name of file or directory to delete. - - virtual RCODE Rename( // Rename a file. - const char * pszFilePath, // File to be renamed - const char * pszNewFilePath) = 0; // New file name - - virtual RCODE Copy( // Copy a file. - const char * pszSrcFilePath, // Name of source file to be copied. - const char * pszDestFilePath, // Name of destination file. - FLMBOOL bOverwrite, // Overwrite destination file? - FLMUINT * puiBytesCopied) = 0; // Number of bytes copied. - - virtual RCODE SetReadOnly( - const char * pszFileName, - FLMBOOL bReadOnly) = 0; - - virtual RCODE GetSectorSize( // Get the sector size of the volume for - const char * pFileName, // this file. - FLMUINT * puiSectorSize) = 0; - - }; - - FLMEXP RCODE FLMAPI FlmAllocFileSystem( - F_FileSystem ** ppFileSystem); - - FLMEXP FLMINT FLMAPI f_sprintf( - char * pszDestStr, - const char * pszFormat, - ...); - - #define f_min(a, b) \ - ((a) < (b) ? (a) : (b)) - - #define f_max(a, b) \ - ((a) < (b) ? (b) : (a)) - - #define f_swap( a, b, tmp) \ - ((tmp) = (a), (a) = (b), (b) = (tmp)) - - FLMEXP char * FLMAPI f_wtoa( - FLMINT16 i16Value, - char * ptr); - - FLMEXP char * FLMAPI f_dtoa( - FLMINT iValue, - char * ptr); - - FLMEXP char * FLMAPI f_uwtoa( - FLMUINT16 ui16Value, - char * ptr); - - FLMEXP char * FLMAPI f_udtoa( - FLMUINT uiValue, - char * ptr); - - FLMEXP FLMINT FLMAPI f_atoi( - const char * ptr); - - FLMEXP FLMINT FLMAPI f_atol( - const char * ptr); - - FLMEXP FLMINT FLMAPI f_atod( - const char * ptr); - - FLMEXP FLMUINT FLMAPI f_atoud( - const char * ptr); - - FLMEXP FLMINT FLMAPI f_unicmp( - const FLMUNICODE * puzStr1, - const FLMUNICODE * puzStr2); - - FLMEXP FLMUINT FLMAPI f_unilen( - const FLMUNICODE * puzStr); - - FLMEXP FLMUNICODE * FLMAPI f_uniindex( - const FLMUNICODE * puzStr, - const FLMUNICODE * puzSearch); - - FLMEXP FLMINT FLMAPI f_unincmp( - const FLMUNICODE * puzStr1, - const FLMUNICODE * puzStr2, - FLMUINT uiLen); - - FLMEXP FLMINT FLMAPI f_uninativecmp( - const FLMUNICODE * puzStr1, - const char * pszStr2); - - FLMEXP FLMINT FLMAPI f_uninativencmp( - const FLMUNICODE * puzStr1, - const char * pszStr2, - FLMUINT uiCount); - - FLMEXP FLMUNICODE * FLMAPI f_unicpy( - FLMUNICODE * puzDestStr, - const FLMUNICODE * puzSrcStr); - - FLMEXP void FLMAPI f_nativetounistrcpy( - FLMUNICODE * puzDestBuf, - const char * pszSrcBuf); - - FLMEXP FLMBOOL FLMAPI tokenIsNum( - const char * pszToken, - FLMUINT * puiNum); - - FINLINE void f_align32( - FLMBYTE * pucStart, - FLMBYTE ** pucCur) - { - FLMBYTE * pucTmp = *pucCur; - FLMUINT uiSize; - - uiSize = sizeof( FLMUINT32) - (pucTmp - pucStart) % sizeof( FLMUINT32); - - if( uiSize != sizeof( FLMUINT32)) - { - *pucCur = pucTmp + uiSize; - } - } - - /**************************************************************************** - Random Generation Functions - ****************************************************************************/ - - #define MAX_RANDOM 2147483646L - - typedef struct - { - FLMINT32 i32Seed; - } f_randomGenerator; - - // Call f_randomSetSeed to initialize your random-number generator. Then - // call f_randomLong, f_randomChoice, or f_randomTruth to access the series - // of random values. - // - // Initialize your generator with f_randomSetSeed( &r, SOME_CONSTANT) to - // get a reproducible sequence of pseudo-random numbers. Using different - // constant seeds will give you independent sequences. The constant can - // be any number between 1 and MAX_RANDOM, inclusive. - // - // Call f_randomLong to get a number randomly distributed between 1 and - // MAX_RANDOM. This is the basic call, but is usually not as convenient as - // the subsequent functions, all of which call f_randomLong and process the - // result into a more useable form. - // - // 1 <= f_randomLong(&r) <= MAX_RANDOM - // - // Call f_randomChoice to get a number uniformly distributed across a - // specified range of integer values. - // - // lo <= f_randomChoice(&r, lo, hi) <= hi - // - // Call f_randomTruth(&r, n) to get a boolean value which is true n percent - // of the time (0 <= n <= 100). - // - // 0 <= f_randomTrue(&r, n) <= 1 - - FLMEXP void FLMAPI f_randomize( - f_randomGenerator * pRand); - - FLMEXP void FLMAPI f_randomSetSeed( - f_randomGenerator * pRand, - FLMINT32 i32seed); - - FLMEXP FLMINT32 FLMAPI f_randomLong( - f_randomGenerator * pRand); - - FLMEXP FLMINT32 FLMAPI f_randomChoice( - f_randomGenerator * pRand, - FLMINT32 lo, - FLMINT32 hi); - - FLMEXP FLMINT FLMAPI f_randomTruth( - f_randomGenerator * pRand, - FLMINT iPercentageTrue); - - /**************************************************************************** - Time, date, timestamp functions - ****************************************************************************/ - typedef struct - { - FLMUINT16 year; - FLMBYTE month; - FLMBYTE day; - } F_DATE, * F_DATE_p; - - typedef struct - { - FLMBYTE hour; - FLMBYTE minute; - FLMBYTE second; - FLMBYTE hundredth; - } F_TIME, * F_TIME_p; - - typedef struct - { - FLMUINT16 year; - FLMBYTE month; - FLMBYTE day; - FLMBYTE hour; - FLMBYTE minute; - FLMBYTE second; - FLMBYTE hundredth; - } F_TMSTAMP, * F_TMSTAMP_p; - - FLMEXP void FLMAPI f_timeGetSeconds( - FLMUINT * puiSeconds); - - FLMEXP void FLMAPI f_timeGetTimeStamp( - F_TMSTAMP * pTimeStamp); - - FLMEXP FLMINT FLMAPI f_timeGetLocalOffset( void); - - FLMEXP void FLMAPI f_timeSecondsToDate( - FLMUINT uiSeconds, - F_TMSTAMP * pTimeStamp); - - FLMEXP void FLMAPI f_timeDateToSeconds( - F_TMSTAMP * pTimeStamp, - FLMUINT * puiSeconds); - - FLMEXP FLMINT FLMAPI f_timeCompareTimeStamps( - F_TMSTAMP * pTimeStamp1, - F_TMSTAMP * pTimeStamp2, - FLMUINT uiCompareFlag); - - #define COMPARE_DATE_AND_TIME 0 - #define COMPARE_DATE_ONLY 1 - #define COMPARE_TIME_ONLY 2 - - #if defined( FLM_UNIX) - FLMEXP FLMUINT FLMAPI f_timeGetMilliTime(); - #endif - - // Get the current time as platform-dependent timer units. - FLMEXP FLMUINT FLMAPI f_getCurrTimeAsTimerUnits( void); - - // Convert seconds to platform-dependent timer units. - FLMEXP FLMUINT FLMAPI f_secondsToTimerUnits( - FLMUINT uiSeconds); - - // Convert platform-dependent timer units to seconds. - FLMEXP FLMUINT FLMAPI f_timerUnitsToSeconds( - FLMUINT uiTimerUnits); - - // Convert milliseconds to platform-dependent timer units. - FLMEXP FLMUINT FLMAPI f_milliSecondsToTimerUnits( - FLMUINT uiMilliSeconds); - - // Convert platform-dependent timer units to milli-seconds. - FLMEXP FLMUINT FLMAPI f_timerUnitsToMilliSeconds( - FLMUINT uiTimerUnits); - - // Return elapsed time (as platform-dependent timer units). Input - // parameters must be passed in as platform-dependent timer units. - FLMEXP FLMUINT FLMAPI f_elapsedTimeTimerUnits( - FLMUINT uiEarlierTimeTimerUnits, - FLMUINT uiLaterTimeTimerUnits); - #endif diff --git a/flaim/src/flaim.vcproj b/flaim/src/flaim.vcproj deleted file mode 100644 index f67e5e9..0000000 --- a/flaim/src/flaim.vcproj +++ /dev/null @@ -1,1162 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/flaim/src/flaim_static.vcproj b/flaim/src/flaim_static.vcproj deleted file mode 100644 index b70bfb3..0000000 --- a/flaim/src/flaim_static.vcproj +++ /dev/null @@ -1,1134 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/flaim/src/flaimsys.h b/flaim/src/flaimsys.h index de57b18..c0d6a4b 100644 --- a/flaim/src/flaimsys.h +++ b/flaim/src/flaimsys.h @@ -28,160 +28,58 @@ #include "flaim.h" -#if defined( FLM_DEBUG) && !defined( FLM_HPUX) - #define f_new new( __FILE__, __LINE__) -#else - #define f_new new +#if defined( FLM_WIN) + // Conversion from XXX to YYY, possible loss of data + #pragma warning( disable : 4244) + + // Local variable XXX may be used without having been initialized + #pragma warning( disable : 4701) + + // Function XXX not inlined + #pragma warning( disable : 4710) +#endif + +#if defined( FLM_WATCOM_NLM) + + // Disable "Warning! W549: col(XX) 'sizeof' operand contains + // compiler generated information" + + #pragma warning 549 9 #endif -FLMUINT flmStrHashBucket( - const char * pszStr, - struct FBUCKET * pHashTbl, - FLMUINT uiNumBuckets); - -class FResultSet; -class F_Thread; class HRequest; class F_Session; class F_SessionMgr; -class F_XMLImport; -class F_XMLExport; class F_HashTable; -class F_FileHdlMgr; -class F_FileSystemImp; -class ServerLockManager; -class F_ThreadMgr; class FCS_ISTM; class FCS_OSTM; class FCS_DIS; class FCS_DOS; class F_Rfl; -class F_FileIdList; -class F_IOBufferMgr; -class F_IOBuffer; -class ServerLockObject; class F_SuperFileHdl; -class FlmECache; -class F_FileHdlImp; class FlmBlobImp; -class F_SlabManager; -class F_FixedAlloc; -class F_BufferAlloc; class F_CCS; -#include "ftk.h" -#include "ftkmem.h" -#include "ftknsem.h" -#include "ftksem.h" -#include "ftkthrd.h" #include "fstructs.h" #include "fdict.h" -#include "flist.h" -#include "fmutxref.h" -#include "ffilehdl.h" #include "flmstat.h" -#include "fbuff.h" #include "rfl.h" -#include "fsrvlock.h" #include "filesys.h" #include "fquery.h" #include "fscursor.h" #include "flog.h" -#include "frset.h" #include "flmimon.h" -#include "fdir.h" -#include "ffilesys.h" #include "flmstat.h" #include "fcs.h" #include "fsv.h" -#include "fxml.h" #include "furl.h" -#include "ecache.h" #include "fsuperfl.h" -#include "f64bitfh.h" -#include "fdynsset.h" -#include "fobjtrck.h" -#include "ftrace.h" -#include "flfixed.h" #include "f_nici.h" #include "fpackon.h" // IMPORTANT NOTE: No other include files should follow this one except // for fpackoff.h -#if defined( FLM_NLM) && !defined( __MWERKS__) - // Turn off "Warning! W007: col(80) "&array" may not produce intended result - #pragma warning 007 9 - #pragma warning 731 9 -#endif - -#if defined( FLM_NLM) - - #define os_malloc(size) \ - Alloc( (size), gv_lAllocRTag) - - void * nlm_realloc( - void * pMemory, - size_t newSize); - - #define os_realloc nlm_realloc - - #define os_free Free - -#else - - #define os_malloc malloc - #define os_realloc realloc - #define os_free free - -#endif - -// Language definitions - -#define US_LANG 0 // English, United States -#define AF_LANG 1 // Afrikaans -#define AR_LANG 2 // Arabic -#define CA_LANG 3 // Catalan -#define HR_LANG 4 // Croatian -#define CZ_LANG 5 // Czech -#define DK_LANG 6 // Danish -#define _NL_LANG 7 // Dutch -#define OZ_LANG 8 // English, Australia -#define CE_LANG 9 // English, Canada -#define UK_LANG 10 // English, United Kingdom -#define FA_LANG 11 // Farsi -#define SU_LANG 12 // Finnish -#define CF_LANG 13 // French, Canada -#define FR_LANG 14 // French, France -#define GA_LANG 15 // Galician -#define DE_LANG 16 // German, Germany -#define SD_LANG 17 // German, Switzerland -#define GR_LANG 18 // Greek -#define HE_LANG 19 // Hebrew -#define HU_LANG 20 // Hungarian -#define IS_LANG 21 // Icelandic -#define IT_LANG 22 // Italian -#define NO_LANG 23 // Norwegian -#define PL_LANG 24 // Polish -#define BR_LANG 25 // Portuguese, Brazil -#define PO_LANG 26 // Portuguese, Portugal -#define RU_LANG 27 // Russian -#define SL_LANG 28 // Slovak -#define ES_LANG 29 // Spanish -#define SV_LANG 30 // Swedish -#define YK_LANG 31 // Ukrainian -#define UR_LANG 32 // Urdu -#define TK_LANG 33 // Turkey -#define JP_LANG 34 // Japanese -#define KO_LANG 35 // Korean -#define CT_LANG 36 // Chinese-Traditional -#define CS_LANG 37 // Chinese-Simplified -#define LA_LANG 38 // another asian language - -#define LAST_LANG (LA_LANG + 1) -#define FIRST_DBCS_LANG (JP_LANG) -#define LAST_DBCS_LANG (LA_LANG) - // Character code high byte values for character sets #define CHSASCI 0 // ASCII @@ -375,18 +273,6 @@ FLMUINT flmUnicodeToWP( This first section contains general FLAIM defines and macros ****************************************************************************/ -RCODE f_netwareStartup( void); - -void f_netwareShutdown( void); - -void f_memoryInit( void); - -void f_memoryCleanup( void); - -RCODE nssInitialize( void); - -void nssUninitialize( void); - #define MIN_BLOCK_SIZE 4096 #define MAX_BLOCK_SIZE 8192 @@ -436,10 +322,6 @@ This section contains prototypes, defines, ... that are used within FLAIM's GEDCOM code. ****************************************************************************/ -void GedSmartPoolInit( - POOL * pPool, - POOL_STATS * pPoolStats); - // Defines for 'nth' parmeter, GedSibGraft(), GedChildGraft() #define GED_LAST 32767 // last sib/child #define GED_FIRST (-GED_LAST) // first sib/child @@ -451,15 +333,15 @@ void GedSmartPoolInit( #define GED_MAXTAGLEN 127 // maximum significant tag length RCODE GedToTree( - POOL * pPool, - F_FileHdl * pFileHdl, + F_Pool * pPool, + IF_FileHdl * pFileHdl, char ** pBuf, FLMUINT uiBufSize, NODE ** root, F_NameTable * pNameTable); void * GedAllocSpace( - POOL * pPool, + F_Pool * pPool, NODE * nd, FLMUINT uiValType, FLMUINT uiLen, @@ -473,7 +355,7 @@ RCODE GedBinToText( FLMUINT * lenRV); NODE * GedNodeCopy( - POOL * pPool, + F_Pool * pPool, NODE * node, NODE * childList, NODE * sibList ); @@ -501,7 +383,7 @@ void gedSetRecSource( FLMUINT uiDrn); RCODE gedCreateSourceNode( - POOL * pPool, + F_Pool * pPool, FLMUINT uiFieldNum, HFDB hDb, FLMUINT uiContainer, @@ -521,7 +403,7 @@ NODE * GedClip( NODE * self); NODE * GedCopy( - POOL * pPool, + F_Pool * pPool, FLMUINT uiTreeCount, NODE * oldTree); @@ -586,7 +468,7 @@ NODE * GedParent( NODE * self); RCODE GedPutBINARY( - POOL * pPool, + F_Pool * pPool, NODE * node, const void * pvData, FLMUINT uiLength, @@ -594,33 +476,33 @@ RCODE GedPutBINARY( FLMUINT uiEncSize = 0); RCODE GedPutRecId( - POOL * pPool, + F_Pool * pPool, NODE ** ppNd, FLMUINT uiRecId); RCODE GedPutRecPtr( - POOL * pPool, + F_Pool * pPool, NODE * node, FLMUINT uiDRN, FLMUINT uiEncId = 0, FLMUINT uiEncSize = 0); RCODE GedPutNATIVE( - POOL * pPool, + F_Pool * pPool, NODE * node, const char * pszNativeStr, FLMUINT uiEncId = 0, FLMUINT uiEncSize = 0); RCODE GedPutINT( - POOL * pPool, + F_Pool * pPool, NODE * nd, FLMINT iNumber, FLMUINT uiEncId = 0, FLMUINT uiEncSize = 0); RCODE GedPutUINT( - POOL * pPool, + F_Pool * pPool, NODE * nd, FLMUINT uiNumber, FLMUINT uiEncId = 0, @@ -632,7 +514,7 @@ RCODE GedGetUNICODE( FLMUINT * puiBufferLen); RCODE GedPutUNICODE( - POOL * pPool, + F_Pool * pPool, NODE * node, const FLMUNICODE * pUnicode, FLMUINT uiEncId = 0, @@ -667,7 +549,7 @@ RCODE GedWalk( void * xyz); NODE * GedNodeCreate( - POOL * pPool, + F_Pool * pPool, FLMUINT uiTagNum, FLMUINT uiId, RCODE * rcRV); @@ -743,7 +625,7 @@ FLMINT gedNextChar( FLMINT gedReadChar( GED_STREAM * pStream, - FLMUINT uiFilePos); + FLMUINT64 ui64FilePos); FLMUINT gedCopyTag( GED_STREAM * pStream, @@ -783,14 +665,14 @@ RCODE flmEncryptField( FlmRecord * pRecord, void * pvField, FLMUINT uiEncId, - POOL * pPool); + F_Pool * pPool); RCODE flmDecryptField( FDICT * pDict, FlmRecord * pRecord, void * pvField, FLMUINT uiEncId, - POOL * pPool); + F_Pool * pPool); FLMBOOL flmCheckIfdPath( IFD * pIfd, @@ -1022,7 +904,7 @@ RCODE fdbInit( void fdbExit( FDB * pDb); -#if defined( FLM_DEBUG) && (defined( FLM_WIN) || defined( FLM_NLM)) +#if defined( FLM_DEBUG) void fdbUseCheck( FDB * pDb); @@ -1062,8 +944,8 @@ void flmLogError( void flmLogMessage( FlmLogMessageSeverity eMsgSeverity, - FlmColorType eForground, - FlmColorType eBackground, + eColorType eForground, + eColorType eBackground, const char * pszFormat, ...); @@ -1181,22 +1063,6 @@ RCODE BlkCheckSum( FLMUINT uiBlkAddress, FLMUINT uiBlkSize); -#if defined( FLM_NLM) || defined( FLM_WIN) - void FastBlockCheckSum( - void * pBlk, - FLMUINT * puiChecksum, - FLMUINT * puiXORData, - FLMUINT uiNumberOfBytes); - - void InitFastBlockCheckSum( void); -#endif - -#ifdef FLM_WIN - RCODE MapWinErrorToFlaim( - DWORD udErrCode, - RCODE defaultRc); -#endif - #define CHECKSUM_SET 0 #define CHECKSUM_CHECK 1 @@ -1225,12 +1091,6 @@ F_BKGND_IX * flmBackgroundIndexGet( FLMBOOL bMutexLocked, FLMUINT * puiThreadId = NULL); -FLMUINT flmBinHashBucket( - void * pBuf, - FLMUINT uiBufLen, - FBUCKET * pHashTbl, - FLMUINT uiNumBuckets); - RCODE flmWaitNotifyReq( F_MUTEX hMutex, FNOTIFY ** ppNotifyListRV, @@ -1367,7 +1227,7 @@ RCODE flmDecrField( FLMUINT uiTagNum); RCODE gedAddField( - POOL * pPool, + F_Pool * pPool, NODE * pRecord, FLMUINT uiTagNum, const void * pvData, @@ -1387,7 +1247,7 @@ RCODE flmOpenFile( FLMUINT uiOpenFlags, FLMBOOL bInternalOpen, F_Restore * pRestoreObj, - F_FileHdlImp * pLockFileHdl, + IF_FileHdl * pLockFileHdl, const char * pszPassword, FDB ** ppDb); @@ -1425,7 +1285,7 @@ RCODE flmVerifyFileUse( RCODE flmCreateLckFile( const char * pszFilePath, - F_FileHdlImp ** ppLockFileHdlRV); + IF_FileHdl ** ppLockFileHdlRV); RCODE flmGetExclAccess( const char * pszFilePath, @@ -1463,7 +1323,7 @@ RCODE flmMaintFreeBlockChain( FLMUINT64 * pui64BlocksFreed); RCODE flmGetHdrInfo( - F_SuperFileHdl * pSFileHdl, + IF_FileHdl * pFileHdl, FILE_HDR * pFileHdrRV, LOG_HDR * pLogHdrRV, FLMBYTE * pLogHdr); @@ -1497,7 +1357,7 @@ RCODE flmGetFileHdrInfo( RCODE flmReadAndVerifyHdrInfo( DB_STATS * pDbStats, - F_FileHdl * pFileHdl, + IF_FileHdl * pFileHdl, FLMBYTE * pReadBuf, FILE_HDR * pFileHdrRV, LOG_HDR * pLogHdrRV, @@ -1573,7 +1433,7 @@ RCODE flmIndexSetOfRecords( void * IxCallbackData, FINDEX_STATUS * pIndexStatus, FLMBOOL * pbHitEnd, - F_Thread * pThread = NULL, + IF_Thread * pThread = NULL, FlmRecord * pReusableRec = NULL); RCODE flmRemoveContainerKeys( @@ -1620,7 +1480,7 @@ RCODE tokenGetUnicode( FLMUINT * puiValBufSize); RCODE expImpInit( - F_FileHdl * pFileHdl, + IF_FileHdl * pFileHdl, FLMUINT uiFlag, EXP_IMP_INFO * pExpImpInfoRV); @@ -1648,7 +1508,7 @@ RCODE impReadRec( FlmRecord ** ppRecordRV); RCODE impFileIsExpImp( - F_FileHdl * pFileHdl, + IF_FileHdl * pFileHdl, FLMBOOL * pbFileIsExpImpRV); #ifdef FLM_DBG_LOG @@ -1726,8 +1586,8 @@ FINLINE FLMUINT getIxContainerPartLen( { IFD * pLastIfd = &pIxd->pFirstIfd [pIxd->uiNumFlds]; - return( (pIxd->uiLanguage < FIRST_DBCS_LANG || - pIxd->uiLanguage > LAST_DBCS_LANG || + return( (pIxd->uiLanguage < FLM_FIRST_DBCS_LANG || + pIxd->uiLanguage > FLM_LAST_DBCS_LANG || IFD_GET_FIELD_TYPE( pLastIfd) != FLM_TEXT_TYPE || (pLastIfd->uiFlags & IFD_CONTEXT)) ? 3 @@ -1930,7 +1790,7 @@ FINLINE RCODE KYFlushKeys( { if (RC_OK( rc = KYKeysCommit( pDb, FALSE))) { - pDb->KrefCntrl.pReset = GedPoolMark( pDb->KrefCntrl.pPool); + pDb->KrefCntrl.pReset = pDb->KrefCntrl.pPool->poolMark(); } } return( rc); @@ -2208,10 +2068,10 @@ Desc: ****************************************************************************/ typedef struct IX_CHK_INFO { - POOL pool; + F_Pool pool; FLMUINT uiIxCount; FLMUINT * puiIxArray; - void * pRSet; + IF_ResultSet * pRSet; FLMBOOL bGetNextRSKey; RS_IX_KEY IxKey1; RS_IX_KEY IxKey2; @@ -2414,7 +2274,7 @@ RCODE flmGetRecKeys( FlmRecord * pRecord, FLMUINT uiContainerNum, FLMBOOL bRemoveDups, - POOL * pPool, + F_Pool * pPool, REC_KEY ** ppKeysRV); #ifdef FLM_UNIX @@ -2534,7 +2394,7 @@ private: FLMBYTE * m_pHeaderBuf; FLMUINT m_uiHeaderLen; HFDB m_hDb; - F_FileHdlImp * m_pFileHdl; + IF_FileHdl * m_pFileHdl; FLMUINT m_uiStorageType; #define BLOB_REFERENCE_TYPE 0x04 #define BLOB_OWNED_TYPE 0x10 @@ -2712,8 +2572,8 @@ public: private: - F_FileHdlImp * m_pFileHdl; - F_64BitFileHandle * m_pFileHdl64; + IF_FileHdl * m_pFileHdl; + IF_MultiFileHdl * m_pMultiFileHdl; FLMUINT64 m_ui64Offset; FLMUINT m_uiDbVersion; char m_szDbPath[ F_PATH_MAX_SIZE]; diff --git a/flaim/src/ftksem.h b/flaim/src/flaimtk.h similarity index 75% rename from flaim/src/ftksem.h rename to flaim/src/flaimtk.h index 3091c25..484b066 100644 --- a/flaim/src/ftksem.h +++ b/flaim/src/flaimtk.h @@ -1,8 +1,10 @@ -//------------------------------------------------------------------------- -// Desc: Cross platform toolkit for mutexes and semaphores - definitions. +//------------------------------------------------------------------------------ +// Desc: Placeholder for FLAIM's cross-platform toolkit public definitions +// and interfaces +// // Tabs: 3 // -// Copyright (c) 2000-2006 Novell, Inc. All Rights Reserved. +// Copyright (c) 2006 Novell, Inc. All Rights Reserved. // // This program is free software; you can redistribute it and/or // modify it under the terms of version 2 of the GNU General Public @@ -19,10 +21,7 @@ // To contact Novell about this file by physical or electronic mail, // you may find current contact information at www.novell.com // -// $Id: ftksem.h 12329 2006-01-20 17:49:30 -0700 (Fri, 20 Jan 2006) ahodgkinson $ -//------------------------------------------------------------------------- +// $Id$ +//------------------------------------------------------------------------------ -#ifndef FTKSEM_H -#define FTKSEM_H - -#endif +#include "ftk.h" diff --git a/flaim/src/flalloc.cpp b/flaim/src/flalloc.cpp deleted file mode 100644 index 8be7b51..0000000 --- a/flaim/src/flalloc.cpp +++ /dev/null @@ -1,1464 +0,0 @@ -//------------------------------------------------------------------------- -// Desc: Memory allocation routines. -// Tabs: 3 -// -// Copyright (c) 1991,1993,1995-2006 Novell, Inc. All Rights Reserved. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of version 2 of the GNU General Public -// License as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, contact Novell, Inc. -// -// To contact Novell about this file by physical or electronic mail, -// you may find current contact information at www.novell.com -// -// $Id: flalloc.cpp 12329 2006-01-20 17:49:30 -0700 (Fri, 20 Jan 2006) ahodgkinson $ -//------------------------------------------------------------------------- - -#include "flaimsys.h" - -#undef f_free -#undef f_alloc -#undef f_calloc -#undef f_realloc -#undef f_recalloc - -#ifdef FLM_NLM - extern "C" - { - extern LONG gv_lAllocRTag; - } -#endif - -#ifdef FLM_UNIX - #ifdef HAVE_CONFIG_H - #include "config.h" - #endif - - #ifdef HAVE_DLADDR - #include - #endif - #include - -#endif - -#define F_GET_ALLOC_PTR( pDataPtr) \ - (FLMBYTE *)((FLMBYTE *)(pDataPtr) - sizeof( F_MEM_HDR)) - -#define F_GET_DATA_PTR( pAllocPtr) \ - (FLMBYTE *)((FLMBYTE *)(pAllocPtr) + sizeof( F_MEM_HDR)) - -#define F_GET_MEM_DATA_SIZE( pDataPtr) \ - (((F_MEM_HDR *)(F_GET_ALLOC_PTR( pDataPtr)))->uiDataSize) - -// Picket fence - -#define F_PICKET_FENCE "FFFFFFFF" - -#if defined( FLM_DEBUG) - #define F_PICKET_FENCE_SIZE 8 -#else - #define F_PICKET_FENCE_SIZE 0 -#endif - -#define MEM_PTR_INIT_ARRAY_SIZE 512 -#define MEM_MAX_STACK_WALK_DEPTH 32 - -// If stack tracking is on, leak checking also -// needs to be on. - -#ifndef FLM_DEBUG - #ifdef DEBUG_SIM_OUT_OF_MEM - #undef DEBUG_SIM_OUT_OF_MEM - #endif -#endif - -#ifdef FLM_DEBUG - -// Local function prototypes - -FSTATIC FLMBOOL initMemTracking( - void); - -FSTATIC void saveMemTrackingInfo( - F_MEM_HDR * pHdr); - -FSTATIC void updateMemTrackingInfo( - F_MEM_HDR * pHdr); - -FSTATIC void freeMemTrackingInfo( - FLMBOOL bMutexAlreadyLocked, - FLMUINT uiId, - FLMUINT * puiStack); - -#ifdef DEBUG_SIM_OUT_OF_MEM - -//one of every OUT_OF_MEM_FREQUENCY calls will fail - -#define OUT_OF_MEM_FREQUENCY 40000 - -//OUT_OF_MEM_SEQUENCE_LENGTH calls in a row will fail - -#define OUT_OF_MEM_SEQUENCE_LENGTH 10 - -FLMBOOL SimulateOutOfMemory() -{ - if ( - //is the flag turned on - (gv_FlmSysData.uiOutOfMemSimEnabledFlag == - (FLMUINT)OUT_OF_MEM_SIM_ENABLED_FLAG) && - - //continuing a sequence of failures - ((gv_FlmSysData.uiSimOutOfMemFailSequence > 0) || - - //failing randomly for the first time, and starting a new sequence - (f_randomChoice( &gv_FlmSysData.memSimRandomGen, 0, OUT_OF_MEM_FREQUENCY) == 0))) - { - gv_FlmSysData.uiSimOutOfMemFailTotal++; - gv_FlmSysData.uiSimOutOfMemFailSequence++; - //if reached the end of failure sequence, reset back to 0 so the - //sequence will cease - if ( gv_FlmSysData.uiSimOutOfMemFailSequence >= OUT_OF_MEM_SEQUENCE_LENGTH) - { - gv_FlmSysData.uiSimOutOfMemFailSequence = 0; - } - return TRUE; - } - else - { - return FALSE; - } -} - -#endif //#ifdef DEBUG_SIM_OUT_OF_MEM - -#if defined( FLM_NLM) - - void * memGetEBP(void); - -#ifdef __MWERKS__ - - void * memGetEBP(void) - { - __asm - { - mov eax,[ebp] - } - } - -#else - - #pragma aux memGetEBP = "mov eax,ebp"; - -#endif - -void * memValueAtStackOffset( - void * pos, - int offset); - -#ifdef __MWERKS__ - - void * memValueAtStackOffset( void *, int) - { - __asm - { - mov eax,[ebp+0x8] - mov ebx,[ebp+0xC] - mov eax,ss:[eax+ebx] - } - } - -#else - - #pragma aux memValueAtStackOffset = "mov eax,ss:[eax+ebx]" parm [eax] [ebx]; - -#endif - -/**************************************************************************** -Desc: -****************************************************************************/ -FLMUINT * memWalkStack( void) -{ - FLMUINT uiLoop; - FLMUINT uiRtnAddr; - FLMUINT uiEbp = (FLMUINT) memGetEBP(); - FLMUINT uiAddresses [MEM_MAX_STACK_WALK_DEPTH + 1]; - FLMUINT * puiAddresses; - - uiEbp = (FLMUINT) memValueAtStackOffset( (void *)uiEbp, 0); - uiRtnAddr = (FLMUINT) memValueAtStackOffset( (void *)uiEbp, 4); - - for( uiLoop = 0; uiLoop < MEM_MAX_STACK_WALK_DEPTH; uiLoop++) - { - FLMUINT uiOldEbp; - - uiAddresses [uiLoop] = uiRtnAddr; - - if( !uiEbp) - { - break; - } - - uiOldEbp = uiEbp; - uiEbp = (FLMUINT) memValueAtStackOffset( (void *)uiEbp, 0); - - if (!uiEbp || uiEbp <= uiOldEbp || uiEbp > uiOldEbp + 5000) - { - break; - } - - uiRtnAddr = (FLMUINT) memValueAtStackOffset( (void *) uiEbp, 4); - } - - uiAddresses[ uiLoop] = 0; - - if( (puiAddresses = (FLMUINT *)os_malloc( - sizeof( FLMUINT) * (uiLoop+1))) != NULL) - { - f_memcpy( puiAddresses, &uiAddresses [0], - sizeof( FLMUINT) * (uiLoop + 1)); - } - - return( puiAddresses); -} - -#elif defined( FLM_WIN) - -/******************************************************************** -Desc: Reads NSIZE bytes of memory from LPBASEADDRESS -*********************************************************************/ -static BOOL CALLBACK ReadProcMemory( - HANDLE, - DWORD64 lpBaseAddress, - PVOID lpBuffer, - DWORD nSize, - LPDWORD lpNumberOfBytesRead) -{ - static HANDLE hRealProcess = GetCurrentProcess(); - SIZE_T bytesRead = 0; - BOOL rv = ReadProcessMemory(hRealProcess, - (const void *)((FLMUINT)lpBaseAddress & 0xFFFFFFFF), - lpBuffer, SIZE_T(nSize), &bytesRead); - - if (lpNumberOfBytesRead) - { - *lpNumberOfBytesRead = DWORD(bytesRead & 0xFFFFFFFF); - } - - return( rv); -} - -/******************************************************************** -Desc: Walk the call stack. -*********************************************************************/ -FLMUINT * memWalkStack() -{ - STACKFRAME64 stackFrame; - DWORD machineType; - FLMUINT uiLoop; - FLMUINT uiAddresses [MEM_MAX_STACK_WALK_DEPTH + 1]; - FLMUINT * puiAddresses; - HANDLE hProcess = GetCurrentProcess(); - FLMUINT uiAddrCount; - const void * pc; - const void * fp; - - __asm - { - call $ + 5 - pop eax - mov [pc], eax - mov [fp], ebp - } - -#ifdef FLM_64BIT - machineType = IMAGE_FILE_MACHINE_IA64; -#else - machineType = IMAGE_FILE_MACHINE_I386; -#endif - - f_memset( &stackFrame, 0, sizeof( stackFrame)); - - stackFrame.AddrPC.Offset = DWORD((FLMUINT)pc); - stackFrame.AddrPC.Mode = AddrModeFlat; - stackFrame.AddrFrame.Offset = DWORD((FLMUINT)fp); - stackFrame.AddrFrame.Mode = AddrModeFlat; - - f_mutexLock( gv_FlmSysData.hMemTrackingMutex); - - // We have already processed the address inside memWalkStack - - uiAddrCount = 1; - uiLoop = 0; - for (;;) - { - if( !StackWalk64( machineType, hProcess, 0, &stackFrame, - 0, ReadProcMemory, SymFunctionTableAccess64, SymGetModuleBase64, 0)) - { - break; - } - - if( !stackFrame.AddrFrame.Offset) - { - break; - } - - // Skip the first two addresses. These represent the following: - // 1) memWalkStack - // 2) saveMemTrackingInfo or updateMemTrackingInfo - // We don't need to see them in the stack trace. - - uiAddrCount++; - if (uiAddrCount > 2) - { - uiAddresses [uiLoop] = (FLMUINT)stackFrame.AddrReturn.Offset; - uiLoop++; - if (uiLoop == MEM_MAX_STACK_WALK_DEPTH) - { - break; - } - } - } - - f_mutexUnlock( gv_FlmSysData.hMemTrackingMutex); - - uiAddresses [uiLoop] = 0; - if ((puiAddresses = (FLMUINT *)os_malloc( - sizeof( FLMUINT) * (uiLoop+1))) != NULL) - { - f_memcpy( puiAddresses, &uiAddresses [0], sizeof( FLMUINT) * (uiLoop + 1)); - } - return( puiAddresses); -} -#else -FLMUINT * memWalkStack() -{ - return( NULL); -} -#endif - -/******************************************************************** -Desc: Initialize memory tracking -*********************************************************************/ -FSTATIC FLMBOOL initMemTracking( void) -{ - RCODE rc; - F_MUTEX memMutex; - - if (!gv_FlmSysData.bMemTrackingInitialized && !gv_FlmSysData.uiInitThreadId) - { - gv_FlmSysData.uiInitThreadId = f_threadId(); - rc = f_mutexCreate( &memMutex); - f_sleep( 50); - - // Only set to initialized if we were the last thread - // to set gv_FlmSysData.uiInitThreadId - - if (f_threadId() == gv_FlmSysData.uiInitThreadId) - { - if (RC_OK( rc)) - { - gv_FlmSysData.hMemTrackingMutex = memMutex; - } - else - { - gv_FlmSysData.hMemTrackingMutex = F_MUTEX_NULL; - } -#ifdef FLM_WIN - SymSetOptions( SYMOPT_UNDNAME | SYMOPT_DEFERRED_LOADS); - gv_FlmSysData.hMemProcess = GetCurrentProcess(); - SymInitialize( gv_FlmSysData.hMemProcess, NULL, TRUE); -#endif - gv_FlmSysData.bMemTrackingInitialized = TRUE; - } - else - { - if (RC_OK( rc)) - { - f_mutexDestroy( &memMutex); - } - } - } - - // Go into a loop until we see initialized flag set to TRUE - // Could be another thread that is doing it. - - while (!gv_FlmSysData.bMemTrackingInitialized) - { - f_sleep( 10); - } - return( (gv_FlmSysData.hMemTrackingMutex != F_MUTEX_NULL) ? TRUE : FALSE); -} - -/******************************************************************** -Desc: Save memory tracking information - called on alloc or realloc. -*********************************************************************/ -FSTATIC void saveMemTrackingInfo( - F_MEM_HDR * pHdr) -{ - FLMUINT uiNewCnt; - FLMUINT uiId; - void ** pNew; - - if (gv_FlmSysData.bTrackLeaks && initMemTracking()) - { - f_mutexLock( gv_FlmSysData.hMemTrackingMutex); - - // See if there is enough room in the array - - if (gv_FlmSysData.uiMemNumPtrs == gv_FlmSysData.uiMemTrackingPtrArraySize) - { - - // If array is not initialized, use initial count. Otherwise - // double the size. - - uiNewCnt = (FLMUINT)((!gv_FlmSysData.uiMemTrackingPtrArraySize) - ? MEM_PTR_INIT_ARRAY_SIZE - : gv_FlmSysData.uiMemTrackingPtrArraySize * 2); - if ((pNew = (void **)os_malloc( sizeof( void *) * uiNewCnt)) != NULL) - { - - // Copy the pointers from the old array, if any, - // into the newly allocated array. - - if (gv_FlmSysData.uiMemTrackingPtrArraySize) - { - f_memcpy( pNew, gv_FlmSysData.ppvMemTrackingPtrs, - sizeof( void *) * gv_FlmSysData.uiMemTrackingPtrArraySize); - os_free( gv_FlmSysData.ppvMemTrackingPtrs); - } - f_memset( &pNew [gv_FlmSysData.uiMemTrackingPtrArraySize], 0, - sizeof( void *) * (uiNewCnt - gv_FlmSysData.uiMemTrackingPtrArraySize)); - gv_FlmSysData.ppvMemTrackingPtrs = pNew; - gv_FlmSysData.uiMemTrackingPtrArraySize = uiNewCnt; - } - } - - // If we are still full, we were not able to reallocate memory, so we - // do nothing. - - if (gv_FlmSysData.uiMemNumPtrs == gv_FlmSysData.uiMemTrackingPtrArraySize) - { - pHdr->uiAllocationId = 0; - } - else - { - // Find an empty slot - there has to be one! - - uiId = gv_FlmSysData.uiMemNextPtrSlotToUse; - while (gv_FlmSysData.ppvMemTrackingPtrs [uiId]) - { - if (++uiId == gv_FlmSysData.uiMemTrackingPtrArraySize) - { - uiId = 0; - } - } - - // Allocation ID in the header is offset by one to avoid - // using a value of zero. - - pHdr->uiAllocationId = uiId + 1; - gv_FlmSysData.ppvMemTrackingPtrs [uiId] = pHdr; - gv_FlmSysData.uiMemNumPtrs++; - if ((gv_FlmSysData.uiMemNextPtrSlotToUse = uiId + 1) == - gv_FlmSysData.uiMemTrackingPtrArraySize) - { - gv_FlmSysData.uiMemNextPtrSlotToUse = 0; - } - } - pHdr->uiAllocCnt = ++gv_FlmSysData.uiAllocCnt; - f_mutexUnlock( gv_FlmSysData.hMemTrackingMutex); - } - else - { - pHdr->uiAllocationId = 0; - pHdr->uiAllocCnt = 0; - } - - // Follow the stack. - - if (gv_FlmSysData.bTrackLeaks && gv_FlmSysData.bStackWalk) - { - pHdr->puiStack = memWalkStack(); - } - else - { - pHdr->puiStack = NULL; - } -} - -/******************************************************************** -Desc: Update memory tracking information - called after realloc -*********************************************************************/ -FSTATIC void updateMemTrackingInfo( - F_MEM_HDR * pHdr) -{ - if (pHdr->puiStack) - { - os_free( pHdr->puiStack); - pHdr->puiStack = NULL; - } - if (gv_FlmSysData.bTrackLeaks && gv_FlmSysData.bStackWalk) - { - pHdr->puiStack = memWalkStack(); - } -} - -/******************************************************************** -Desc: Free memory tracking information - called on free. -*********************************************************************/ -FSTATIC void freeMemTrackingInfo( - FLMBOOL bMutexAlreadyLocked, - FLMUINT uiId, - FLMUINT * puiStack - ) -{ - if (uiId) - { - // NOTE: If uiId is non-zero, it means we had to have - // successfully initialized, so we are guaranteed to - // have a mutex. - - if ( !bMutexAlreadyLocked) - { - f_mutexLock( gv_FlmSysData.hMemTrackingMutex); - } - - // Allocation ID in the header is offset by one so that it - // is never zero - a value of zero means that the allocation - // does not have a slot for tracking it in the array. - - gv_FlmSysData.ppvMemTrackingPtrs [uiId - 1] = NULL; - flmAssert( gv_FlmSysData.uiMemNumPtrs); - gv_FlmSysData.uiMemNumPtrs--; - - if ( !bMutexAlreadyLocked) - { - f_mutexUnlock( gv_FlmSysData.hMemTrackingMutex); - } - } - - // Free the stack information, if any. - - if (puiStack) - { - os_free( puiStack); - } -} - -/******************************************************************** -Desc: Log memory leaks. -*********************************************************************/ -void logMemLeak( - F_MEM_HDR * pHdr) -{ - char szMessageBuffer [1024]; - char * pszTmp = &szMessageBuffer [0]; - F_FileHdl * pFileHdl = NULL; - FLMBOOL bOldTrackLeaks = gv_FlmSysData.bTrackLeaks; - - gv_FlmSysData.bTrackLeaks = FALSE; // This ensures that any future - // allocations (for instance, - // allocating the file handle for the - // memtest.ert file) will not try to - // lock the mem tracking mutex. - - - - // Format message to be logged. - - f_strcpy( pszTmp, "Abort=Debug, Retry=Continue, Ignore=Don't Show\r\n"); - while (*pszTmp) - { - pszTmp++; - } -#if defined( FLM_64BIT) - f_sprintf( pszTmp, "Unfreed Pointer: 0x%016I64x\r\n", (FLMUINT)(&pHdr [1])); -#else - f_sprintf( pszTmp, "Unfreed Pointer: 0x%08x\r\n", - (unsigned)((FLMUINT)(&pHdr [1]))); -#endif - while (*pszTmp) - { - pszTmp++; - } - - if (pHdr->pszFileName) - { - f_sprintf( pszTmp, "Source: %s, Line#: %u\r\n", pHdr->pszFileName, - (unsigned)pHdr->iLineNumber); - while (*pszTmp) - { - pszTmp++; - } - } - - if (pHdr->uiAllocCnt) - { - f_sprintf( pszTmp, "Malloc #: %u\r\n", (unsigned)pHdr->uiAllocCnt); - while (*pszTmp) - { - pszTmp++; - } - } - f_sprintf( pszTmp, "Size: %u bytes\r\n", (unsigned)pHdr->uiDataSize); - while (*pszTmp) - { - pszTmp++; - } - - if (pHdr->puiStack) - { - FLMUINT * puiStack = pHdr->puiStack; - FLMUINT uiLen = pszTmp - szMessageBuffer; - char szFuncName [200]; - char * pszFuncName; -#ifdef FLM_WIN - IMAGEHLP_SYMBOL * pImgHlpSymbol; - - pImgHlpSymbol = (IMAGEHLP_SYMBOL *)os_malloc( - sizeof( IMAGEHLP_SYMBOL) + 100); -#endif - - while (*puiStack) - { - szFuncName [0] = 0; -#if defined( FLM_WIN) - if (pImgHlpSymbol) - { -#ifdef FLM_64BIT - DWORD64 udDisplacement; -#else - DWORD udDisplacement; -#endif - - pImgHlpSymbol->SizeOfStruct = sizeof(IMAGEHLP_SYMBOL); - pImgHlpSymbol->Address = *puiStack; - pImgHlpSymbol->MaxNameLength = 100; - - if (SymGetSymFromAddr( gv_FlmSysData.hMemProcess, *puiStack, - &udDisplacement, pImgHlpSymbol)) - { - f_sprintf( szFuncName, "\t%s + %X\r\n", - (&pImgHlpSymbol->Name [0]), - udDisplacement); - } - } -#elif defined( FLM_NLM) - { - szFuncName [0] = '\t'; - GetClosestSymbol( (BYTE *)(&szFuncName[1]), (LONG)(*puiStack)); - } -#else - -#ifdef HAVE_DLADDR - { - Dl_info dlip; - - if (dladdr( (void *)(*puiStack), &dlip) != 0 && dlip.dli_sname) - { - const char * pszFileName; - if (dlip.dli_saddr != (void *)(*puiStack)) - { - pszFileName = strrchr(dlip.dli_fname, '/'); - if (!pszFileName) - { - pszFileName = dlip.dli_fname; - } - else - { - pszFileName++; // skip over slash - } - f_sprintf( szFuncName, "\t0x%08x (%s)\r\n", - (unsigned)(*puiStack), pszFileName); - } - else - { - f_sprintf( szFuncName, "\t%s\r\n", dlip.dli_sname); - } - } - } -#endif - -#endif - - // If szFuncName [0] is zero, we didn't find a name, so we - // just output the address in HEX. - - if (!szFuncName [0]) - { - f_sprintf( szFuncName, "\t0x%08X\r\n", (unsigned)*puiStack ); - } - - // Output whatever portion of the name will fit into the - // message buffer. - - pszFuncName = &szFuncName [0]; - while (*pszFuncName && uiLen < sizeof( szMessageBuffer) - 1) - { - *pszTmp++ = *pszFuncName++; - uiLen++; - } - - // Process next address in the stack. - - puiStack++; - } - *pszTmp = 0; -#ifdef FLM_WIN - if (pImgHlpSymbol) - { - os_free( pImgHlpSymbol); - } -#endif - } - -#ifdef FLM_WIN - FLMINT iRet; - - iRet = MessageBox( NULL, (LPCTSTR)szMessageBuffer, "WIN Memory Testing", - MB_ABORTRETRYIGNORE | MB_ICONINFORMATION | MB_TASKMODAL - | MB_SETFOREGROUND | MB_DEFBUTTON2); - if (iRet == IDIGNORE) - { - gv_FlmSysData.bLogLeaks = TRUE; - } - else if (iRet == IDABORT) - { - flmAssert( 0); - } -#else - gv_FlmSysData.bLogLeaks = TRUE; -#endif - - if (gv_FlmSysData.bLogLeaks) - { - F_FileSystemImp FileSystem; - RCODE rc; - FLMUINT uiDummy; -#ifdef FLM_NLM - const char * pszErrPath = "sys:\\memtest.ert"; -#else - const char * pszErrPath = "memtest.ert"; -#endif - - if (RC_BAD( rc = FileSystem.Open( pszErrPath, - F_IO_RDWR | F_IO_SH_DENYNONE, &pFileHdl))) - { - if (rc == FERR_IO_PATH_NOT_FOUND) - { - rc = FileSystem.Create( pszErrPath, - F_IO_RDWR | F_IO_SH_DENYNONE, &pFileHdl); - } - } - else - { - FLMUINT uiOffset; - - // Position to append to file. - - rc = pFileHdl->Seek( 0, F_IO_SEEK_END, &uiOffset); - } - - // If we successfully opened the file, write to it. - - if (RC_OK( rc)) - { - if (RC_OK( pFileHdl->Write( F_IO_CURRENT_POS, - (FLMUINT)(pszTmp - &szMessageBuffer [0]), - szMessageBuffer, &uiDummy))) - { - (void)pFileHdl->Flush(); - } - pFileHdl->Close(); - } - } -//Exit: - - gv_FlmSysData.bTrackLeaks = bOldTrackLeaks; - - if (pFileHdl) - { - pFileHdl->Release(); - } -} -#endif - -/******************************************************************** -Desc: Initialize memory - if not already done. -*********************************************************************/ -void f_memoryInit( void) -{ -#ifdef FLM_DEBUG - (void)initMemTracking(); -#endif -} - -/******************************************************************** -Desc: Clean up memory and check for unfreed memory. -*********************************************************************/ -void f_memoryCleanup( void) -{ - -#ifdef FLM_DEBUG - if (initMemTracking()) - { - FLMUINT uiId; - F_MEM_HDR * pHdr; - - f_mutexLock( gv_FlmSysData.hMemTrackingMutex); - for (uiId = 0; uiId < gv_FlmSysData.uiMemTrackingPtrArraySize; uiId++) - { - if ((pHdr = (F_MEM_HDR *)gv_FlmSysData.ppvMemTrackingPtrs [uiId]) != NULL) - { - logMemLeak( pHdr); - freeMemTrackingInfo( TRUE, uiId + 1, pHdr->puiStack); - } - } - - // Free the memory pointer array. - - os_free( gv_FlmSysData.ppvMemTrackingPtrs); - gv_FlmSysData.ppvMemTrackingPtrs = NULL; - gv_FlmSysData.uiMemTrackingPtrArraySize = 0; - gv_FlmSysData.uiMemNumPtrs = 0; - - f_mutexUnlock( gv_FlmSysData.hMemTrackingMutex); - - // Free up the mutex. - - f_mutexDestroy( &gv_FlmSysData.hMemTrackingMutex); - - // Reset to unitialized state. - - gv_FlmSysData.uiInitThreadId = 0; - gv_FlmSysData.hMemTrackingMutex = F_MUTEX_NULL; - gv_FlmSysData.bMemTrackingInitialized = FALSE; -#ifdef FLM_WIN - SymCleanup( gv_FlmSysData.hMemProcess); -#endif - } -#endif -} - -/******************************************************************** -Desc: Allocate Memory. -*********************************************************************/ -RCODE f_alloc( - FLMUINT uiSize, - void ** ppvPtr, - const char * pszFileName, - int iLineNumber) -{ - RCODE rc = FERR_OK; - F_MEM_HDR * pHdr; - -#ifndef FLM_DEBUG - F_UNREFERENCED_PARM( pszFileName); - F_UNREFERENCED_PARM( iLineNumber); -#endif - -#ifdef DEBUG_SIM_OUT_OF_MEM - if ( SimulateOutOfMemory()) - { - *ppvPtr = NULL; - rc = RC_SET( FERR_MEM); - goto Exit; - } -#endif - - if ((pHdr = (F_MEM_HDR *)os_malloc( uiSize + - sizeof( F_MEM_HDR) + - F_PICKET_FENCE_SIZE)) == NULL) - { - rc = RC_SET( FERR_MEM); - goto Exit; - } - - pHdr->uiDataSize = uiSize; - *ppvPtr = (void *)(&pHdr [1]); - -#ifdef FLM_DEBUG - pHdr->iLineNumber = iLineNumber; - pHdr->pszFileName = pszFileName; - saveMemTrackingInfo( pHdr); - - #if F_PICKET_FENCE_SIZE - - f_memcpy( ((FLMBYTE *)(*ppvPtr)) + uiSize, - F_PICKET_FENCE, F_PICKET_FENCE_SIZE); - - #endif -#endif - -Exit: - - return( rc); -} - -/******************************************************************** -Desc: Allocate and initialize memory. -*********************************************************************/ -RCODE f_calloc( - FLMUINT uiSize, - void ** ppvPtr, - const char * pszFileName, - int iLineNumber) -{ - RCODE rc = FERR_OK; - F_MEM_HDR * pHdr; - -#ifndef FLM_DEBUG - F_UNREFERENCED_PARM( pszFileName); - F_UNREFERENCED_PARM( iLineNumber); -#endif - -#ifdef DEBUG_SIM_OUT_OF_MEM - if ( SimulateOutOfMemory()) - { - *ppvPtr = NULL; - rc = RC_SET( FERR_MEM); - goto Exit; - } -#endif - - if ((pHdr = (F_MEM_HDR *)os_malloc( uiSize + - sizeof( F_MEM_HDR) + - F_PICKET_FENCE_SIZE)) == NULL) - { - rc = RC_SET( FERR_MEM); - goto Exit; - } - - pHdr->uiDataSize = uiSize; - *ppvPtr = (void *)(&pHdr [1]); - f_memset( *ppvPtr, 0, uiSize); -#ifdef FLM_DEBUG - pHdr->iLineNumber = iLineNumber; - pHdr->pszFileName = pszFileName; - saveMemTrackingInfo( pHdr); - - #if F_PICKET_FENCE_SIZE - - f_memcpy( ((FLMBYTE *)(*ppvPtr)) + uiSize, - F_PICKET_FENCE, F_PICKET_FENCE_SIZE); - - #endif - -#endif -Exit: - return( rc); -} - -/******************************************************************** -Desc: Reallocate memory. -*********************************************************************/ -RCODE f_realloc( - FLMUINT uiSize, - void ** ppvPtr, - const char * pszFileName, - int iLineNumber) -{ - RCODE rc = FERR_OK; - F_MEM_HDR * pNewHdr; -#ifdef FLM_DEBUG - F_MEM_HDR * pOldHdr; - FLMUINT uiOldAllocationId; - FLMUINT * puiOldStack; -#endif - -#ifdef DEBUG_SIM_OUT_OF_MEM - if ( SimulateOutOfMemory()) - { - *ppvPtr = NULL; - rc = RC_SET( FERR_MEM); - goto Exit; - } -#endif - - if (!(*ppvPtr)) - { - rc = f_alloc( uiSize, ppvPtr, pszFileName, iLineNumber); - goto Exit; - } - -#ifdef FLM_DEBUG - pOldHdr = (F_MEM_HDR *)F_GET_ALLOC_PTR( *ppvPtr); - - #if F_PICKET_FENCE_SIZE - - // Verify the old picket fence - - if (f_memcmp( ((FLMBYTE *)(*ppvPtr)) + pOldHdr->uiDataSize, - F_PICKET_FENCE, F_PICKET_FENCE_SIZE) != 0) - { - flmAssert( 0); - } - - #endif - - uiOldAllocationId = pOldHdr->uiAllocationId; - puiOldStack = pOldHdr->puiStack; -#endif - - if ((pNewHdr = (F_MEM_HDR *)os_realloc( F_GET_ALLOC_PTR( *ppvPtr), - uiSize + sizeof( F_MEM_HDR) + - F_PICKET_FENCE_SIZE)) == NULL) - { - rc = RC_SET( FERR_MEM); - goto Exit; - } - - pNewHdr->uiDataSize = uiSize; - *ppvPtr = (void *)(&pNewHdr [1]); -#ifdef FLM_DEBUG - pNewHdr->iLineNumber = iLineNumber; - pNewHdr->pszFileName = pszFileName; - if (pNewHdr != pOldHdr) - { - freeMemTrackingInfo( FALSE, uiOldAllocationId, puiOldStack); - saveMemTrackingInfo( pNewHdr); - } - else - { - updateMemTrackingInfo( pNewHdr); - } - - #if F_PICKET_FENCE_SIZE - - f_memcpy( ((FLMBYTE *)(*ppvPtr)) + uiSize, - F_PICKET_FENCE, F_PICKET_FENCE_SIZE); - - #endif - -#endif - -Exit: - return( rc); -} - -/******************************************************************** -Desc: Reallocate memory, and initialize the new part. -*********************************************************************/ -RCODE f_recalloc( - FLMUINT uiSize, - void ** ppvPtr, - const char * pszFileName, - int iLineNumber) -{ - RCODE rc = FERR_OK; - F_MEM_HDR * pNewHdr; - FLMUINT uiOldSize; -#ifdef FLM_DEBUG - F_MEM_HDR * pOldHdr; - FLMUINT uiOldAllocationId; - FLMUINT * puiOldStack; -#endif - -#ifdef DEBUG_SIM_OUT_OF_MEM - if ( SimulateOutOfMemory()) - { - *ppvPtr = NULL; - rc = RC_SET( FERR_MEM); - goto Exit; - } -#endif - - if (!(*ppvPtr)) - { - rc = f_calloc( uiSize, ppvPtr, pszFileName, iLineNumber); - goto Exit; - } - -#ifdef FLM_DEBUG - pOldHdr = (F_MEM_HDR *)F_GET_ALLOC_PTR( *ppvPtr); - - #if F_PICKET_FENCE_SIZE - - // Verify the old picket fence - - if (f_memcmp( ((FLMBYTE *)(*ppvPtr)) + pOldHdr->uiDataSize, - F_PICKET_FENCE, F_PICKET_FENCE_SIZE) != 0) - { - flmAssert( 0); - } - - #endif - - uiOldAllocationId = pOldHdr->uiAllocationId; - puiOldStack = pOldHdr->puiStack; - -#endif - - uiOldSize = F_GET_MEM_DATA_SIZE( *ppvPtr); - - if ((pNewHdr = (F_MEM_HDR *)os_realloc( F_GET_ALLOC_PTR( *ppvPtr), - uiSize + sizeof( F_MEM_HDR) + - F_PICKET_FENCE_SIZE)) == NULL) - { - rc = RC_SET( FERR_MEM); - goto Exit; - } - - pNewHdr->uiDataSize = uiSize; - *ppvPtr = (void *)(&pNewHdr [1]); - if (uiOldSize < uiSize) - { - f_memset( ((FLMBYTE *)(*ppvPtr)) + uiOldSize, 0, - uiSize - uiOldSize); - } -#ifdef FLM_DEBUG - pNewHdr->iLineNumber = iLineNumber; - pNewHdr->pszFileName = pszFileName; - if (pNewHdr != pOldHdr) - { - freeMemTrackingInfo( FALSE, uiOldAllocationId, puiOldStack); - saveMemTrackingInfo( pNewHdr); - } - else - { - updateMemTrackingInfo( pNewHdr); - } - - #if F_PICKET_FENCE_SIZE - - f_memcpy( ((FLMBYTE *)(*ppvPtr)) + uiSize, - F_PICKET_FENCE, F_PICKET_FENCE_SIZE); - - #endif - -#endif -Exit: - return( rc); -} - -/******************************************************************** -Desc: Free previously allocated memory. -*********************************************************************/ -void f_free( - void ** ppvPtr) -{ - if (*ppvPtr) - { - -#ifdef FLM_DEBUG - F_MEM_HDR * pHdr = (F_MEM_HDR *)F_GET_ALLOC_PTR( *ppvPtr); - - #if F_PICKET_FENCE_SIZE - - // Check the picket fence - - if (f_memcmp( ((FLMBYTE *)(*ppvPtr)) + pHdr->uiDataSize, - F_PICKET_FENCE, F_PICKET_FENCE_SIZE) != 0) - { - flmAssert( 0); - } - - #endif - - freeMemTrackingInfo( FALSE, pHdr->uiAllocationId, pHdr->puiStack); -#endif - - os_free( F_GET_ALLOC_PTR( *ppvPtr)); - *ppvPtr = NULL; - } -} - -/**************************************************************************** -Desc: -****************************************************************************/ -#ifdef FLM_NLM -void * nlm_realloc( - void * pMemory, - size_t newSize) -{ - void * pNewMemory; - LONG lSize; - - if( !pMemory) - { - pNewMemory = Alloc( newSize, gv_lAllocRTag); - goto Exit; - } - - lSize = SizeOfAllocBlock( pMemory); - - pNewMemory = os_malloc( newSize); - if( !pNewMemory) - { - goto Exit; - } - - if( lSize > newSize) - { - lSize = newSize; - } - - f_memcpy( pNewMemory, pMemory, lSize); - - if( pMemory) - { - Free( pMemory); - } - -Exit: - - return( pNewMemory); -} -#endif - -#undef new -#undef delete -#define FLM_NEW_MEMORY_SIGNATURE 0xABCDABCD - -/**************************************************************************** -Desc: -****************************************************************************/ -void * F_Base::operator new( - FLMSIZET uiSize) -#ifndef FLM_NLM - throw() -#endif -{ - void * pvReturnPtr = NULL; - - uiSize += FLM_ALIGN_SIZE; - f_alloc( uiSize, &pvReturnPtr, "unknown", 0); - - if( pvReturnPtr) - { - *((FLMUINT *)pvReturnPtr) = FLM_NEW_MEMORY_SIGNATURE; - pvReturnPtr = (void *)(((FLMBYTE *)pvReturnPtr) + FLM_ALIGN_SIZE); - } - - return( pvReturnPtr); -} - -/**************************************************************************** -Desc: -****************************************************************************/ -void * F_Base::operator new[]( - FLMSIZET uiSize) -#ifndef FLM_NLM - throw() -#endif -{ - void * pvReturnPtr = NULL; - - uiSize += FLM_ALIGN_SIZE; - f_alloc( uiSize, &pvReturnPtr, "unknown", 0); - - if( pvReturnPtr) - { - *((FLMUINT *)pvReturnPtr) = FLM_NEW_MEMORY_SIGNATURE; - pvReturnPtr = (void *)(((FLMBYTE *)pvReturnPtr) + FLM_ALIGN_SIZE); - } - - return( pvReturnPtr); -} - -/**************************************************************************** -Desc: -****************************************************************************/ -#ifdef FLM_DEBUG -void * F_Base::operator new( - FLMSIZET uiSize, - const char * pszFile, - int iLine) -#ifndef FLM_NLM - throw() -#endif -{ - void * pvReturnPtr = NULL; - - uiSize += FLM_ALIGN_SIZE; - f_alloc( uiSize, &pvReturnPtr, pszFile, iLine); - - if( pvReturnPtr) - { - *((FLMUINT *)pvReturnPtr) = FLM_NEW_MEMORY_SIGNATURE; - pvReturnPtr = (void *)(((FLMBYTE *)pvReturnPtr) + FLM_ALIGN_SIZE); - } - - return( pvReturnPtr); -} -#endif - -/**************************************************************************** -Desc: -****************************************************************************/ -#ifdef FLM_DEBUG -void * F_Base::operator new[]( - FLMSIZET uiSize, - const char * pszFile, - int iLine) -#ifndef FLM_NLM - throw() -#endif -{ - void * pvReturnPtr = NULL; - - uiSize += FLM_ALIGN_SIZE; - f_alloc( uiSize, &pvReturnPtr, pszFile, iLine); - - if( pvReturnPtr) - { - *((FLMUINT *)pvReturnPtr) = FLM_NEW_MEMORY_SIGNATURE; - pvReturnPtr = (void *)(((FLMBYTE *)pvReturnPtr) + FLM_ALIGN_SIZE); - } - - return( pvReturnPtr); -} -#endif - -/**************************************************************************** -Desc: -****************************************************************************/ -void F_Base::operator delete( - void * ptr) -{ - if( !ptr) - { - return; - } - - ptr = (void *)(((FLMBYTE *)ptr) - FLM_ALIGN_SIZE); - if( *((FLMUINT *)ptr) != FLM_NEW_MEMORY_SIGNATURE) - { - // Something is wrong with the allocation ... don't - // try to free it. - - flmAssert( 0); - return; - } - - f_free( &ptr); -} - -/**************************************************************************** -Desc: -****************************************************************************/ -void F_Base::operator delete[]( - void * ptr) -{ - if( !ptr) - { - return; - } - - ptr = (void *)(((FLMBYTE *)ptr) - FLM_ALIGN_SIZE); - if( *((FLMUINT *)ptr) != FLM_NEW_MEMORY_SIGNATURE) - { - // Something is wrong with the allocation ... don't - // try to free it. - - flmAssert( 0); - return; - } - - f_free( &ptr); -} - -/**************************************************************************** -Desc: -****************************************************************************/ -#if defined( FLM_DEBUG) && !defined( __WATCOMC__) -void F_Base::operator delete( - void * ptr, - const char *, // file - int) // line -{ - if( !ptr) - { - return; - } - - ptr = (void *)(((FLMBYTE *)ptr) - FLM_ALIGN_SIZE); - if( *((FLMUINT *)ptr) != FLM_NEW_MEMORY_SIGNATURE) - { - // Something is wrong with the allocation ... don't - // try to free it. - - flmAssert( 0); - return; - } - - f_free( &ptr); -} -#endif - -/**************************************************************************** -Desc: -****************************************************************************/ -#if defined( FLM_DEBUG) && !defined( __WATCOMC__) -void F_Base::operator delete[]( - void * ptr, - const char *, // file - int // line - ) -{ - if( !ptr) - { - return; - } - - ptr = (void *)(((FLMBYTE *)ptr) - FLM_ALIGN_SIZE); - if( *((FLMUINT *)ptr) != FLM_NEW_MEMORY_SIGNATURE) - { - // Something is wrong with the allocation ... don't - // try to free it. - - flmAssert( 0); - return; - } - - f_free( &ptr); -} -#endif - -/**************************************************************************** -Desc: -****************************************************************************/ -FLMINT F_Base::Release( void) -{ - FLMINT iRefCnt = --m_refCnt; - - if( !iRefCnt) - { - delete this; - } - - return( iRefCnt); -} - -/**************************************************************************** -Desc: -****************************************************************************/ -FLMEXP void FLMAPI FlmFreeMem( - void * pMem) -{ - f_free( &pMem); -} - -/**************************************************************************** -Desc: -****************************************************************************/ -FLMUINT f_msize( - void * pvPtr) -{ - #if defined( FLM_UNIX) - return( pvPtr ? F_GET_MEM_DATA_SIZE( (pvPtr)) : 0); - #elif defined( FLM_NLM) - return( pvPtr ? (unsigned)SizeOfAllocBlock( - (F_GET_ALLOC_PTR( (pvPtr)))) : 0); - #else - return( pvPtr ? _msize( (F_GET_ALLOC_PTR( (pvPtr)))) : 0); - #endif -} diff --git a/flaim/src/flbackup.cpp b/flaim/src/flbackup.cpp index a188837..52060f2 100644 --- a/flaim/src/flbackup.cpp +++ b/flaim/src/flbackup.cpp @@ -27,7 +27,7 @@ typedef struct { char szPath[ F_PATH_MAX_SIZE]; - F_64BitFileHandle * pFileHdl64; + IF_MultiFileHdl * pMultiFileHdl; FLMUINT64 ui64Offset; void * pvAppData; RCODE rc; @@ -71,8 +71,10 @@ FSTATIC RCODE flmDefaultBackerWriteHook( FSTATIC RCODE flmRestoreFile( F_Restore * pRestoreObj, + const char * pszDbPath, + const char * pszDataDir, const char * pszPassword, - F_SuperFileHdl * pSFile, + F_SuperFileHdl ** ppSFile, FLMBOOL bIncremental, FLMUINT * puiDbVersion, FLMUINT * puiNextIncSeqNum, @@ -86,7 +88,7 @@ FSTATIC RCODE flmRestoreFile( /******************************************************************************* Desc: *******************************************************************************/ -class F_BackerStream : public F_Base +class F_BackerStream : public F_Object { public: @@ -139,10 +141,10 @@ private: RCODE _setup( void); static RCODE readThread( - F_Thread * pThread); + IF_Thread * pThread); static RCODE writeThread( - F_Thread * pThread); + IF_Thread * pThread); FLMBOOL m_bSetup; FLMBOOL m_bFirstRead; @@ -151,7 +153,7 @@ private: F_Restore * m_pRestoreObj; F_SEM m_hDataSem; F_SEM m_hIdleSem; - F_Thread * m_pThread; + IF_Thread * m_pThread; RCODE m_rc; FLMBYTE * m_pucInBuf; FLMUINT * m_puiInOffset; @@ -962,10 +964,9 @@ Exit: (void *)&backupInfo, NULL, pvAppData); } - if( hookState.pFileHdl64) + if( hookState.pMultiFileHdl) { - hookState.pFileHdl64->Close(); - hookState.pFileHdl64->Release(); + hookState.pMultiFileHdl->Release(); } if( pucBlkBuf) @@ -1179,8 +1180,8 @@ FLMEXP RCODE FLMAPI FlmDbRestore( { RCODE rc = FERR_OK; HFDB hDb = HFDB_NULL; - F_FileHdl * pFileHdl = NULL; - F_FileHdlImp * pLockFileHdl = NULL; + IF_FileHdl * pFileHdl = NULL; + IF_FileHdl * pLockFileHdl = NULL; F_SuperFileHdl * pSFile = NULL; char szBasePath[ F_PATH_MAX_SIZE]; char szTmpPath[ F_PATH_MAX_SIZE]; @@ -1282,24 +1283,10 @@ FLMEXP RCODE FLMAPI FlmDbRestore( goto Exit; } - // Create the control file and set up the super file object + // Create the control file - if( RC_BAD( rc = gv_FlmSysData.pFileSystem->Create( - pszDbPath, F_IO_RDWR, &pFileHdl))) - { - goto Exit; - } - - // Allocate a super file object - - if( (pSFile = f_new F_SuperFileHdl) == NULL) - { - rc = RC_SET( FERR_MEM); - goto Exit; - } - - if( RC_BAD( rc = pSFile->Setup( pFile->pFileIdList, pszDbPath, - pszDataDir))) + if( RC_BAD( rc = gv_FlmSysData.pFileSystem->createFile( + pszDbPath, FLM_IO_RDWR, &pFileHdl))) { goto Exit; } @@ -1327,9 +1314,9 @@ FLMEXP RCODE FLMAPI FlmDbRestore( // Restore the data in the backup set - if( RC_BAD( rc = flmRestoreFile( pRestoreObj, pszTempPassword, - pSFile, FALSE, &uiDbVersion, &uiNextIncNum, &bRflPreserved, - &eRestoreAction, NULL, &pucDbKey, NULL, &uiKeyLen))) + if( RC_BAD( rc = flmRestoreFile( pRestoreObj, pszDbPath, pszDataDir, + pszTempPassword, &pSFile, FALSE, &uiDbVersion, &uiNextIncNum, + &bRflPreserved, &eRestoreAction, NULL, &pucDbKey, NULL, &uiKeyLen))) { goto Exit; } @@ -1373,9 +1360,10 @@ FLMEXP RCODE FLMAPI FlmDbRestore( } else { - if( RC_BAD( rc = flmRestoreFile( pRestoreObj, pszTempPassword, - pSFile, TRUE, &uiDbVersion, &uiNextIncNum, &bRflPreserved, - &eRestoreAction, &bOKToRetry, NULL, pucDbKey, &uiKeyLen))) + if( RC_BAD( rc = flmRestoreFile( pRestoreObj, pszDbPath, pszDataDir, + pszTempPassword, &pSFile, TRUE, &uiDbVersion, &uiNextIncNum, + &bRflPreserved, &eRestoreAction, &bOKToRetry, NULL, + pucDbKey, &uiKeyLen))) { RCODE tmpRc; @@ -1438,7 +1426,7 @@ FLMEXP RCODE FLMAPI FlmDbRestore( // Force everything out to disk - if( RC_BAD( rc = pSFile->Flush())) + if( RC_BAD( rc = pSFile->flush())) { goto Exit; } @@ -1468,10 +1456,10 @@ FLMEXP RCODE FLMAPI FlmDbRestore( // should be identical without having differences in the // tracker container due to background indexing. - rc = flmOpenFile( pFile, - pszDbPath, pszDataDir, + rc = flmOpenFile( pFile, pszDbPath, pszDataDir, pszRflDir, FO_DONT_RESUME_BACKGROUND_THREADS, TRUE, pRestoreObj, pLockFileHdl, NULL, (FDB **)&hDb); + pLockFileHdl = NULL; pFile = NULL; @@ -1566,8 +1554,10 @@ Desc : Restores a full or incremental backup ****************************************************************************/ FSTATIC RCODE flmRestoreFile( F_Restore * pRestoreObj, + const char * pszDbPath, + const char * pszDataDir, const char * pszPassword, - F_SuperFileHdl * pSFile, + F_SuperFileHdl ** ppSFile, FLMBOOL bIncremental, FLMUINT * puiDbVersion, FLMUINT * puiNextIncSeqNum, @@ -1578,6 +1568,7 @@ FSTATIC RCODE flmRestoreFile( FLMBYTE * pucKeyToUse, FLMUINT * puiKeyLen) { + RCODE rc = FERR_OK; FLMUINT uiBytesWritten; FLMUINT uiLogicalEOF; FLMUINT uiBlkAddr; @@ -1594,15 +1585,14 @@ FSTATIC RCODE flmRestoreFile( FLMBYTE ucNextIncSerialNum[ F_SERIAL_NUM_SIZE]; FLMUINT uiIncSeqNum; FLMBYTE * pucBlkBuf = NULL; - char szPath[ F_PATH_MAX_SIZE]; FLMBYTE ucLowChecksumByte; FLMUINT uiBlkBufSize; FLMUINT uiPriorBlkAddr = 0; BYTE_PROGRESS byteProgress; FBackupType eBackupType; F_BackerStream * pBackerStream = NULL; - RCODE rc = FERR_OK; F_CCS * pTmpCCS = NULL; + F_SuperFileHdl * pSFile = NULL; #ifndef FLM_USE_NICI F_UNREFERENCED_PARM( pszPassword); @@ -1615,18 +1605,6 @@ FSTATIC RCODE flmRestoreFile( *pbOKToRetry = TRUE; } -#ifdef FLM_WIN - - // Don't want to do extra file extensions or flush when file - // is extended. Setting the extend size to ~0 has the effect - // of not updating the directory entry (a time-consuming operation) - // on Windows platforms. On all other platforms, we will just - // go with the default behavior. - - pSFile->setExtendSize( (FLMUINT)(~0)); - -#endif - // Initialize the progress struct f_memset( &byteProgress, 0, sizeof( BYTE_PROGRESS)); @@ -1643,18 +1621,11 @@ FSTATIC RCODE flmRestoreFile( { goto Exit; } - - // Get the path of the .DB file (file 0). - - if( RC_BAD( rc = pSFile->GetFilePath( 0, szPath))) - { - goto Exit; - } - + // Get the sector size - if( RC_BAD( rc = gv_FlmSysData.pFileSystem->GetSectorSize( - szPath, &uiSectorSize))) + if( RC_BAD( rc = gv_FlmSysData.pFileSystem->getSectorSize( + pszDbPath, &uiSectorSize))) { goto Exit; } @@ -1667,20 +1638,11 @@ FSTATIC RCODE flmRestoreFile( { uiBlkBufSize = (((uiBlkBufSize / uiSectorSize) + 1) * uiSectorSize); } - -#ifdef FLM_WIN - if ((pucBlkBuf = (FLMBYTE *)VirtualAlloc( NULL, - (DWORD)uiBlkBufSize, MEM_COMMIT, PAGE_READWRITE)) == NULL) - { - rc = MapWinErrorToFlaim( GetLastError(), FERR_MEM); - goto Exit; - } -#else - if (RC_BAD( rc = f_alloc( uiBlkBufSize, &pucBlkBuf))) + + if( RC_BAD( rc = f_allocAlignedBuffer( uiBlkBufSize, (void **)&pucBlkBuf))) { goto Exit; } -#endif // Read and verify the backup header @@ -1801,18 +1763,6 @@ FSTATIC RCODE flmRestoreFile( } uiMaxFileSize = flmGetMaxFileSize( uiDbVersion, pLogHdr); - // Set the database version number and block size into the - // super file handle. We only do this if the file being restored - // is the full backup. It will always be first in the restore sequence, - // and thus we only need to set these values into the super file handle - // at that time. - - if( !bIncremental) - { - pSFile->SetDbVersion( uiDbVersion); - pSFile->SetBlockSize( uiBlockSize); - } - // Make sure the maximum block file size matches what was read from the // backup header. @@ -1822,6 +1772,38 @@ FSTATIC RCODE flmRestoreFile( goto Exit; } + // Allocate a super file object + + if( (pSFile = *ppSFile) != NULL) + { + pSFile->AddRef(); + } + else + { + flmAssert( !bIncremental); + + if( (pSFile = f_new F_SuperFileHdl) == NULL) + { + rc = RC_SET( FERR_MEM); + goto Exit; + } + + if( RC_BAD( rc = pSFile->setup( pszDbPath, pszDataDir, uiDbVersion))) + { + goto Exit; + } + + // Don't want to do extra file extensions or flush when file + // is extended. Setting the extend size to ~0 has the effect + // of not updating the directory entry (a time-consuming operation) + // on Windows platforms. On all other platforms, we will just + // go with the default behavior. + + pSFile->setExtendSize( (FLMUINT)(~0)); + *ppSFile = pSFile; + (*ppSFile)->AddRef(); + } + // Unshroud the database key (stored in the log header) using the // password the user gave us. (Note: this only re-writes the data // in the log header. It's up to the database open call to actually @@ -1937,7 +1919,7 @@ FSTATIC RCODE flmRestoreFile( // Compare the incremental backup sequence number to the value in the // database's log header. - if( RC_BAD( rc = pSFile->ReadHeader( + if( RC_BAD( rc = pSFile->readHeader( DB_LOG_HEADER_START + LOG_INC_BACKUP_SEQ_NUM, 4, ucTmpSeqNum, &uiTmp))) { @@ -1953,7 +1935,7 @@ FSTATIC RCODE flmRestoreFile( // Compare the incremental backup serial number to the value in the // database's log header. - if( RC_BAD( rc = pSFile->ReadHeader( + if( RC_BAD( rc = pSFile->readHeader( DB_LOG_HEADER_START + LOG_INC_BACKUP_SERIAL_NUM, F_SERIAL_NUM_SIZE, ucTmpSerialNum, &uiTmp))) { @@ -2008,7 +1990,7 @@ FSTATIC RCODE flmRestoreFile( // Write the database header - if( RC_BAD( rc = pSFile->WriteHeader( 0, + if( RC_BAD( rc = pSFile->writeHeader( 0, uiBlockSize, pucBlkBuf, &uiBytesWritten))) { goto Exit; @@ -2094,9 +2076,7 @@ FSTATIC RCODE flmRestoreFile( pucBlkBuf[ BH_CHECKSUM_LOW] = ucLowChecksumByte; // Write the block to the database - -#ifdef FLM_UNIX - + // // Unix systems can have sector sizes that are larger than our // typical 4K database blocks. The Unix implementation of SectorWrite // (called by WriteBlock) will write the passed-in block and clobber any @@ -2105,14 +2085,9 @@ FSTATIC RCODE flmRestoreFile( // block buffer is less than a full sector, the Unix SectorWrite will only // write out the amount requested, not a full sector. - if( RC_BAD( rc = pSFile->WriteBlock( uiBlkAddr, + if( RC_BAD( rc = pSFile->writeBlock( uiBlkAddr, uiBlockSize, pucBlkBuf, uiBlockSize, NULL, &uiBytesWritten))) -#else - if( RC_BAD( rc = pSFile->WriteBlock( uiBlkAddr, - uiBlockSize, pucBlkBuf, uiBlkBufSize, - NULL, &uiBytesWritten))) -#endif { if( rc == FERR_IO_PATH_NOT_FOUND || rc == FERR_IO_INVALID_PATH) @@ -2125,21 +2100,15 @@ FSTATIC RCODE flmRestoreFile( goto Exit; } - if( RC_BAD( rc = pSFile->CreateFile( + if( RC_BAD( rc = pSFile->createFile( FSGetFileNumber( uiBlkAddr)))) { goto Exit; } -#ifdef FLM_UNIX - if( RC_BAD( rc = pSFile->WriteBlock( uiBlkAddr, + if( RC_BAD( rc = pSFile->writeBlock( uiBlkAddr, uiBlockSize, pucBlkBuf, uiBlockSize, NULL, &uiBytesWritten))) -#else - if( RC_BAD( rc = pSFile->WriteBlock( uiBlkAddr, - uiBlockSize, pucBlkBuf, uiBlkBufSize, - NULL, &uiBytesWritten))) -#endif { goto Exit; } @@ -2191,11 +2160,7 @@ Exit: if( pucBlkBuf) { -#ifdef FLM_WIN - (void)VirtualFree( pucBlkBuf, 0, MEM_RELEASE); -#else - f_free( &pucBlkBuf); -#endif + f_freeAlignedBuffer( (void **)&pucBlkBuf); } if( pBackerStream) @@ -2203,10 +2168,15 @@ Exit: pBackerStream->Release(); } - if (pTmpCCS) + if( pTmpCCS) { pTmpCCS->Release(); } + + if( pSFile) + { + pSFile->Release(); + } return( rc); } @@ -2228,34 +2198,33 @@ FSTATIC RCODE flmDefaultBackerWriteHook( goto Exit; } - if( !pState->pFileHdl64) + if( !pState->pMultiFileHdl) { // Remove any existing backup files - if( (pState->pFileHdl64 = f_new F_64BitFileHandle) == NULL) + if( RC_BAD( rc = FlmAllocMultiFileHdl( &pState->pMultiFileHdl))) { - rc = RC_SET( FERR_MEM); goto Exit; } - - if( RC_BAD( rc = pState->pFileHdl64->Delete( pState->szPath)) && - rc != FERR_IO_PATH_NOT_FOUND && + + if( RC_BAD( rc = pState->pMultiFileHdl->deleteMultiFile( + pState->szPath)) && rc != FERR_IO_PATH_NOT_FOUND && rc != FERR_IO_INVALID_PATH) { - pState->pFileHdl64->Release(); - pState->pFileHdl64 = NULL; + pState->pMultiFileHdl->Release(); + pState->pMultiFileHdl = NULL; goto Exit; } - if( RC_BAD( rc = pState->pFileHdl64->Create( pState->szPath))) + if( RC_BAD( rc = pState->pMultiFileHdl->create( pState->szPath))) { - pState->pFileHdl64->Release(); - pState->pFileHdl64 = NULL; + pState->pMultiFileHdl->Release(); + pState->pMultiFileHdl = NULL; goto Exit; } } - rc = pState->pFileHdl64->Write( pState->ui64Offset, + rc = pState->pMultiFileHdl->write( pState->ui64Offset, uiBytesToWrite, pvBuffer, &uiBytesWritten); pState->ui64Offset += uiBytesWritten; @@ -2264,10 +2233,10 @@ Exit: if( RC_BAD( rc)) { pState->rc = rc; - if( pState->pFileHdl64) + if( pState->pMultiFileHdl) { - pState->pFileHdl64->Release(); - pState->pFileHdl64 = NULL; + pState->pMultiFileHdl->Release(); + pState->pMultiFileHdl = NULL; } } @@ -2373,7 +2342,7 @@ RCODE F_BackerStream::startThreads( void) { if( RC_BAD( rc = f_threadCreate( &m_pThread, F_BackerStream::writeThread, "backup", - FLM_DEFAULT_THREAD_GROUP, 0, (void *)this))) + 0, 0, (void *)this))) { goto Exit; } @@ -2382,7 +2351,7 @@ RCODE F_BackerStream::startThreads( void) { if( RC_BAD( rc = f_threadCreate( &m_pThread, F_BackerStream::readThread, "restore", - FLM_DEFAULT_THREAD_GROUP, 0, (void *)this))) + 0, 0, (void *)this))) { goto Exit; } @@ -2808,7 +2777,7 @@ Exit: Desc: This thread reads data in the background ****************************************************************************/ RCODE F_BackerStream::readThread( - F_Thread * pThread) + IF_Thread * pThread) { F_BackerStream * pBackerStream = (F_BackerStream *)pThread->getParm1(); RCODE rc = FERR_OK; @@ -2852,10 +2821,10 @@ Exit: Desc: This thread writes data in the background ****************************************************************************/ RCODE F_BackerStream::writeThread( - F_Thread * pThread) + IF_Thread * pThread) { - F_BackerStream * pBackerStream = (F_BackerStream *)pThread->getParm1(); RCODE rc = FERR_OK; + F_BackerStream * pBackerStream = (F_BackerStream *)pThread->getParm1(); for( ;;) { @@ -2908,7 +2877,7 @@ Desc: F_FSRestore::F_FSRestore() { m_pFileHdl = NULL; - m_pFileHdl64 = NULL; + m_pMultiFileHdl = NULL; m_ui64Offset = 0; m_bSetupCalled = FALSE; m_szDbPath[ 0] = 0; @@ -2962,18 +2931,17 @@ RCODE F_FSRestore::openBackupSet( void) RCODE rc = FERR_OK; flmAssert( m_bSetupCalled); - flmAssert( !m_pFileHdl64); + flmAssert( !m_pMultiFileHdl); - if( (m_pFileHdl64 = f_new F_64BitFileHandle) == NULL) + if( RC_BAD( rc = FlmAllocMultiFileHdl( &m_pMultiFileHdl))) { - rc = RC_SET( FERR_MEM); goto Exit; } - - if( RC_BAD( rc = m_pFileHdl64->Open( m_szBackupSetPath))) + + if( RC_BAD( rc = m_pMultiFileHdl->open( m_szBackupSetPath))) { - m_pFileHdl64->Release(); - m_pFileHdl64 = NULL; + m_pMultiFileHdl->Release(); + m_pMultiFileHdl = NULL; goto Exit; } @@ -2998,7 +2966,7 @@ RCODE F_FSRestore::openRflFile( FLMBYTE * pBuf = NULL; FILE_HDR fileHdr; LOG_HDR logHdr; - F_FileHdl * pFileHdl = NULL; + IF_FileHdl * pFileHdl = NULL; flmAssert( m_bSetupCalled); flmAssert( uiFileNum); @@ -3013,8 +2981,8 @@ RCODE F_FSRestore::openRflFile( goto Exit; } - if( RC_BAD( rc = gv_FlmSysData.pFileSystem->Open( - m_szDbPath, F_IO_RDWR | F_IO_SH_DENYNONE, &pFileHdl))) + if( RC_BAD( rc = gv_FlmSysData.pFileSystem->openFile( + m_szDbPath, FLM_IO_RDWR | FLM_IO_SH_DENYNONE, &pFileHdl))) { goto Exit; } @@ -3025,16 +2993,13 @@ RCODE F_FSRestore::openRflFile( goto Exit; } - pFileHdl->Close(); pFileHdl->Release(); pFileHdl = NULL; m_uiDbVersion = fileHdr.uiVersionNum; } - /* - Generate the log file name. - */ + // Generate the log file name. if( RC_BAD( rc = rflGetDirAndPrefix( m_uiDbVersion, m_szDbPath, m_szRflDir, szRflPath, szDbPrefix))) @@ -3043,15 +3008,13 @@ RCODE F_FSRestore::openRflFile( } rflGetBaseFileName( m_uiDbVersion, szDbPrefix, uiFileNum, szBaseName); - f_pathAppend( szRflPath, szBaseName); + gv_FlmSysData.pFileSystem->pathAppend( szRflPath, szBaseName); - /* - Open the file. - */ + // Open the file. - if( RC_BAD( rc = gv_FlmSysData.pFileSystem->OpenBlockFile( - szRflPath, F_IO_RDWR | F_IO_SH_DENYNONE | F_IO_DIRECT, - 512, &m_pFileHdl))) + if( RC_BAD( rc = gv_FlmSysData.pFileSystem->openFile( + szRflPath, FLM_IO_RDWR | FLM_IO_SH_DENYNONE | FLM_IO_DIRECT, + &m_pFileHdl))) { goto Exit; } @@ -3085,7 +3048,7 @@ RCODE F_FSRestore::openIncFile( char szIncFile[ F_FILENAME_SIZE]; flmAssert( m_bSetupCalled); - flmAssert( !m_pFileHdl64); + flmAssert( !m_pMultiFileHdl); /* Since this is a non-interactive restore, we will "guess" @@ -3095,25 +3058,24 @@ RCODE F_FSRestore::openIncFile( where X is a hex digit. */ - if( RC_BAD( rc = f_pathReduce( m_szBackupSetPath, + if( RC_BAD( rc = gv_FlmSysData.pFileSystem->pathReduce( m_szBackupSetPath, szIncPath, NULL))) { goto Exit; } f_sprintf( szIncFile, "%08X.INC", (unsigned)uiFileNum); - f_pathAppend( szIncPath, szIncFile); + gv_FlmSysData.pFileSystem->pathAppend( szIncPath, szIncFile); - if( (m_pFileHdl64 = f_new F_64BitFileHandle) == NULL) + if( RC_BAD( rc = FlmAllocMultiFileHdl( &m_pMultiFileHdl))) { - rc = RC_SET( FERR_MEM); goto Exit; } - if( RC_BAD( rc = m_pFileHdl64->Open( szIncPath))) + if( RC_BAD( rc = m_pMultiFileHdl->open( szIncPath))) { - m_pFileHdl64->Release(); - m_pFileHdl64 = NULL; + m_pMultiFileHdl->Release(); + m_pMultiFileHdl = NULL; goto Exit; } @@ -3137,11 +3099,11 @@ RCODE F_FSRestore::read( RCODE rc = FERR_OK; flmAssert( m_bSetupCalled); - flmAssert( m_pFileHdl || m_pFileHdl64); + flmAssert( m_pFileHdl || m_pMultiFileHdl); - if( m_pFileHdl64) + if( m_pMultiFileHdl) { - if( RC_BAD( rc = m_pFileHdl64->Read( m_ui64Offset, + if( RC_BAD( rc = m_pMultiFileHdl->read( m_ui64Offset, uiLength, pvBuffer, &uiBytesRead))) { goto Exit; @@ -3149,7 +3111,7 @@ RCODE F_FSRestore::read( } else { - if( RC_BAD( rc = m_pFileHdl->Read( (FLMUINT)m_ui64Offset, + if( RC_BAD( rc = m_pFileHdl->read( (FLMUINT)m_ui64Offset, uiLength, pvBuffer, &uiBytesRead))) { goto Exit; @@ -3175,10 +3137,10 @@ RCODE F_FSRestore::close( void) { flmAssert( m_bSetupCalled); - if( m_pFileHdl64) + if( m_pMultiFileHdl) { - m_pFileHdl64->Release(); - m_pFileHdl64 = NULL; + m_pMultiFileHdl->Release(); + m_pMultiFileHdl = NULL; } if( m_pFileHdl) diff --git a/flaim/src/flchkdb.cpp b/flaim/src/flchkdb.cpp index d35d2ca..b2afe66 100644 --- a/flaim/src/flchkdb.cpp +++ b/flaim/src/flchkdb.cpp @@ -118,7 +118,7 @@ FSTATIC RCODE chkResolveIXMissingKey( FSTATIC RCODE chkRSInit( const char * pszIoPath, - void ** pRSetRV); + IF_ResultSet ** ppRSet); FSTATIC RCODE chkRSFinalize( IX_CHK_INFO * pIxChkInfo, @@ -144,7 +144,7 @@ FSTATIC RCODE chkBlkRead( FSTATIC RCODE chkVerifyBTrees( DB_INFO * pDbInfo, - POOL * pPool, + F_Pool * pPool, FLMBOOL * pbStartOverRV); FSTATIC RCODE chkReportError( @@ -180,9 +180,6 @@ FSTATIC RCODE chkEndUpdate( STATE_INFO * pStateInfo, IX_CHK_INFO * pIxChkInfo); -FSTATIC FLMINT chkRSCallbackFunc( - RSET_CB_INFO * pCBInfo); - FSTATIC RCODE chkCompareIxRSEntries( void * vpData1, FLMUINT uiLength1, @@ -204,7 +201,7 @@ FSTATIC RCODE chkVerifyElmFields( STATE_INFO * pStateInfo, DB_INFO * pDbInfo, IX_CHK_INFO * pIxChkInfo, - POOL * pTmpPool, + F_Pool * pTmpPool, FLMUINT * puiErrElmRecOffsetRV, eCorruptionType * peElmErrCorruptCode); @@ -214,14 +211,14 @@ FSTATIC RCODE chkVerifySubTree( STATE_INFO * ParentState, STATE_INFO * pStateInfo, FLMUINT uiBlkAddress, - POOL * pTmpPool, + F_Pool * pTmpPool, FLMBYTE * pucResetKey, FLMUINT uiResetKeyLen, FLMUINT uiResetDrn); FSTATIC RCODE chkGetLfInfo( DB_INFO * pDbInfo, - POOL * pPool, + F_Pool * pPool, LF_STATS * pLfStats, LFILE * pLFile, LF_STATS * pCurrLfStats, @@ -229,7 +226,7 @@ FSTATIC RCODE chkGetLfInfo( FSTATIC RCODE chkSetupLfTable( DB_INFO * pDbInfo, - POOL * pPool); + F_Pool * pPool); FSTATIC RCODE chkSetupIxInfo( DB_INFO * pDbInfo, @@ -241,6 +238,42 @@ FSTATIC RCODE chkOutputIndexKeys( IXD * pIxd, REC_KEY * pKeyList); +/**************************************************************************** +Desc: +****************************************************************************/ +class F_ChkResultSetCompare : public IF_ResultSetCompare +{ +public: + + RCODE FLMAPI compare( + const void * pvData1, + FLMUINT uiLength1, + const void * pvData2, + FLMUINT uiLength2, + FLMINT * piCompare) + { + FLMBYTE * pucData1 = (FLMBYTE *) pvData1; + FLMBYTE * pucData2 = (FLMBYTE *) pvData2; + FLMUINT uiIxNum1; + FLMUINT uiIxNum2; + FLMUINT uiDrn1; + FLMUINT uiDrn2; + + uiIxNum1 = (FLMUINT) FB2UW( &(pucData1[RS_IX_OFFSET])); + uiIxNum2 = (FLMUINT) FB2UW( &(pucData2[RS_IX_OFFSET])); + uiDrn1 = (FLMUINT) FB2UD( &(pucData1[RS_REF_OFFSET])); + uiDrn2 = (FLMUINT) FB2UD( &(pucData2[RS_REF_OFFSET])); + + *piCompare = chkCompareKeySet( + uiIxNum1, &(pucData1[RS_KEY_OFFSET]), + uiLength1 - RS_KEY_OVERHEAD, uiDrn1, uiIxNum2, + &(pucData2[RS_KEY_OFFSET]), + uiLength2 - RS_KEY_OVERHEAD, uiDrn2); + + return( FERR_OK); + } +}; + /**************************************************************************** Desc: ****************************************************************************/ @@ -260,58 +293,46 @@ FINLINE RCODE chkCallProgFunc( /**************************************************************************** Desc: ****************************************************************************/ -FINLINE RCODE chkRSGetNext( - void * pRSet, - FLMBYTE * pBuffer, - FLMUINT uiBufferLength, - FLMUINT * puiReturnLength) +class F_ChkSortStatus : public IF_ResultSetSortStatus { - FLMUINT uiReturnLen; - RCODE rc; +public: - rc = ((FResultSet *) pRSet)->GetNext( (void *) pBuffer, uiBufferLength, - &uiReturnLen); - *puiReturnLength = (rc == FERR_OK) ? uiReturnLen : 0; - - return (rc); -} - -/**************************************************************************** -Desc: -****************************************************************************/ -FINLINE RCODE chkKeyToTree( - IXD * pIxd, - FLMBYTE * pucKey, - FLMUINT uiKeyLen, - FlmRecord ** ppKeyRV) -{ - return (flmIxKeyOutput( pIxd, pucKey, uiKeyLen, ppKeyRV, FALSE)); -} - -/**************************************************************************** -Desc: Frees memory allocated to a result set and deletes any temporary - files that may have been created. -****************************************************************************/ -FINLINE void chkRSFree(void ** ppRSetRV) -{ - FResultSet * pRSet; - - pRSet = *((FResultSet **) ppRSetRV); - pRSet->Release(); - *ppRSetRV = (void *) 0; -} - -/**************************************************************************** -Desc: Adds a variable-length entry to a result set. -****************************************************************************/ -FINLINE RCODE chkRSAddEntry( - void * pRSet, - FLMBYTE * pEntry, - FLMUINT uiEntryLength) -{ - return (((FResultSet *) pRSet)->AddEntry( pEntry, uiEntryLength)); -} + F_ChkSortStatus( IX_CHK_INFO * pIxChkInfo) + { + m_pIxChkInfo = pIxChkInfo; + } + + RCODE FLMAPI reportSortStatus( + FLMUINT64 ui64EstTotalUnits, + FLMUINT64 ui64UnitsDone) + { + FLMINT iRetVal = 0; + DB_CHECK_PROGRESS * pProgress = m_pIxChkInfo->pDbInfo->pProgress; + + // Set the status values. + + pProgress->ui64NumRSUnits = ui64EstTotalUnits; + pProgress->ui64NumRSUnitsDone = ui64UnitsDone; + + // Call the progress callback. + + if (RC_BAD( chkCallProgFunc( m_pIxChkInfo->pDbInfo))) + { + iRetVal = -1; + goto Exit; + } + + Exit: + + pProgress->bStartFlag = FALSE; + return( iRetVal); + } + +private: + IX_CHK_INFO * m_pIxChkInfo; +}; + /**************************************************************************** Desc: This routine counts the number of fields in an object table. ****************************************************************************/ @@ -341,8 +362,10 @@ Desc: Frees memory allocated to an IX_CHK_INFO structure FINLINE RCODE chkFreeIxInfo( IX_CHK_INFO * pIxInfoRV) { - GedPoolFree( &(pIxInfoRV->pool)); - chkRSFree( &(pIxInfoRV->pRSet)); + pIxInfoRV->pool.poolFree(); + pIxInfoRV->pRSet->Release(); + pIxInfoRV->pRSet = NULL; + f_free( &(pIxInfoRV->puiIxArray)); f_memset( pIxInfoRV, 0, sizeof(IX_CHK_INFO)); @@ -364,7 +387,7 @@ FLMEXP RCODE FLMAPI FlmDbCheck( const char * pszDataDir, const char * pRflDir, FLMUINT uiCheckFlags, - POOL * pPool, + F_Pool * pPool, DB_CHECK_PROGRESS * pCheckProgress, STATUS_HOOK fnStatusFunc, void * AppArg) @@ -379,11 +402,11 @@ FLMEXP RCODE FLMAPI FlmDbCheck( FDB * pDb = (FDB *) hDb; FLMBOOL bIgnore; FLMUINT uiLoop; - FLMUINT uiTmpSize; + FLMUINT64 ui64TmpSize; FLMBOOL bStartOver; FLMBOOL bOkToCloseTrans = FALSE; DB_INFO * pDbInfo; - POOL localPool; + F_Pool localPool; void * pvDbInfoMark; if (hDb != HFDB_NULL && IsInCSMode( hDb)) @@ -392,16 +415,19 @@ FLMEXP RCODE FLMAPI FlmDbCheck( goto ExitCS; } - GedPoolInit( &localPool, 512); + localPool.poolInit( 512); if (!pPool) { pPool = &localPool; } - pDbInfo = (DB_INFO *) GedPoolCalloc( pPool, sizeof(DB_INFO)); + if( RC_BAD( rc = pPool->poolCalloc( sizeof( DB_INFO), (void **)&pDbInfo))) + { + goto Exit; + } - pvDbInfoMark = GedPoolMark( pPool); + pvDbInfoMark = pPool->poolMark(); if (hDb == HFDB_NULL) { @@ -490,7 +516,7 @@ Begin_Check: rc = FERR_OK; bStartOver = FALSE; - GedPoolReset( pPool, pvDbInfoMark); + pPool->poolReset( pvDbInfoMark); pDbInfo->pProgress->bPhysicalCorrupt = FALSE; pDbInfo->pProgress->bLogicalIndexCorrupt = FALSE; pDbInfo->pProgress->ui64DatabaseSize = 0; @@ -521,12 +547,12 @@ Begin_Check: uiLoop <= MAX_DATA_BLOCK_FILE_NUMBER( pDb->pFile->FileHdr.uiVersionNum); uiLoop++) { - if (RC_BAD( pSFileHdl->GetFileSize( uiLoop, &uiTmpSize))) + if (RC_BAD( pSFileHdl->getFileSize( uiLoop, &ui64TmpSize))) { break; } - Progress.ui64DatabaseSize += (FLMUINT64) uiTmpSize; + Progress.ui64DatabaseSize += ui64TmpSize; } // See if we have a valid end of file @@ -632,8 +658,6 @@ Exit: (void) FlmDbClose( &hDb); } - GedPoolFree( &localPool); - ExitCS: return (rc); @@ -1294,8 +1318,8 @@ RCODE chkGetNextRSKey( // Get the next key - if (RC_BAD( rc = chkRSGetNext( pIxChkInfo->pRSet, pCurrRSKey->pucRSKeyBuf, - MAX_KEY_SIZ + RS_KEY_OVERHEAD, &(pCurrRSKey->uiRSKeyLen)))) + if (RC_BAD( rc = pIxChkInfo->pRSet->getNext( pCurrRSKey->pucRSKeyBuf, + MAX_KEY_SIZ + RS_KEY_OVERHEAD, &pCurrRSKey->uiRSKeyLen))) { goto Exit; } @@ -1603,7 +1627,7 @@ RCODE chkResolveNonUniqueKey( // Mark the temporary pool. - pvMark = GedPoolMark( &(pDb->TempPool)); + pvMark = pDb->TempPool.poolMark(); // Call the internal delete function, passing boolean flags // indicating that missing keys should not prevent the record @@ -1626,8 +1650,8 @@ RCODE chkResolveNonUniqueKey( // Reset the temporary pool. The flmDeleteRecord call // allocates space for the record that is being deleted. - - GedPoolReset( &(pDb->TempPool), pvMark); + + pDb->TempPool.poolReset( pvMark); if (RC_BAD( rc)) { @@ -1803,13 +1827,13 @@ FSTATIC RCODE chkGetKeySource( // Initialize variables - pIxPoolMark = GedPoolMark( &(pIxChkInfo->pool)); + pIxPoolMark = pIxChkInfo->pool.poolMark(); // Need to mark the DB's temporary pool. The index code allocates // memory for new CDL entries from the DB pool. If the pool is not // reset, it grows during the check and becomes VERY large. - pDbPoolMark = GedPoolMark( &(pDb->TempPool)); + pDbPoolMark = pDb->TempPool.poolMark(); // Set up the KRef so that flmGetRecKeys will work @@ -1955,12 +1979,11 @@ Exit: // Reset the DB's temporary pool - GedPoolReset( &(pDb->TempPool), pDbPoolMark); + pDb->TempPool.poolReset( pDbPoolMark); // Reset the index check pool - GedPoolReset( &(pIxChkInfo->pool), pIxPoolMark); - + pIxChkInfo->pool.poolReset( pIxPoolMark); return (rc); } @@ -2047,19 +2070,19 @@ FLMINT chkCompareKeySet( FLMUINT uiLength2, FLMUINT uiDrn2) { - FLMINT iCmpVal = RS_EQUALS; - FLMUINT uiMinLen; + FLMINT iCmpVal = 0; + FLMUINT uiMinLen; // Compare index numbers if (uiIxNum1 > uiIxNum2) { - iCmpVal = RS_GREATER_THAN; + iCmpVal = 1; goto Exit; } else if (uiIxNum1 < uiIxNum2) { - iCmpVal = RS_LESS_THAN; + iCmpVal = -1; goto Exit; } @@ -2080,32 +2103,30 @@ FLMINT chkCompareKeySet( if (uiDrn1 > uiDrn2) { - iCmpVal = RS_LESS_THAN; + iCmpVal = -1; } else if (uiDrn1 < uiDrn2) { - iCmpVal = RS_GREATER_THAN; + iCmpVal = 1; } else { - iCmpVal = RS_EQUALS; + iCmpVal = 0; goto Exit; } } else if (uiLength1 > uiLength2) { - iCmpVal = RS_GREATER_THAN; + iCmpVal = 1; } else { - iCmpVal = RS_LESS_THAN; + iCmpVal = -1; } } else { - iCmpVal = (FLMINT) ((iCmpVal > 0) - ? (FLMINT) RS_GREATER_THAN - : (FLMINT) RS_LESS_THAN); + iCmpVal = (FLMINT) ((iCmpVal > 0) ? (FLMINT) 1 : (FLMINT) -1); } Exit: @@ -2230,7 +2251,7 @@ FSTATIC RCODE chkReportIxError( { RCODE rc = FERR_OK; FDB * pDb = pStateInfo->pDb; - POOL * pTmpPool; + F_Pool * pTmpPool; IXD * pIxd; LFILE * pLFile; void * pIxPoolMark; @@ -2243,14 +2264,14 @@ FSTATIC RCODE chkReportIxError( // Mark the index check pool - pIxPoolMark = GedPoolMark( &(pIxChkInfo->pool)); + pIxPoolMark = pIxChkInfo->pool.poolMark(); pTmpPool = &(pIxChkInfo->pool); // Need to mark the DB's temporary pool. The index code allocates // memory for new CDL entries from the DB pool. If the pool is not // reset, it grows during the check and becomes VERY large. - pDbPoolMark = GedPoolMark( &(pDb->TempPool)); + pDbPoolMark = pDb->TempPool.poolMark(); // Set up the KRef so that flmGetRecKeys will work @@ -2276,9 +2297,9 @@ FSTATIC RCODE chkReportIxError( } // Generate the key tree using the key that caused the error - - if (RC_BAD( rc = chkKeyToTree( pIxd, pucErrKey, uiErrKeyLen, - &(CorruptInfo.pErrIxKey)))) + + if (RC_BAD( rc = flmIxKeyOutput( pIxd, pucErrKey, uiErrKeyLen, + &(CorruptInfo.pErrIxKey), FALSE))) { goto Exit; } @@ -2391,12 +2412,12 @@ Exit: } // Reset the DB's temporary pool - - GedPoolReset( &(pDb->TempPool), pDbPoolMark); + + pDb->TempPool.poolReset( pDbPoolMark); // Reset the index check pool - GedPoolReset( &(pIxChkInfo->pool), pIxPoolMark); + pIxChkInfo->pool.poolReset( pIxPoolMark); return (rc); } @@ -2433,7 +2454,7 @@ FSTATIC RCODE chkVerifyKeyNotUnique( // Generate the key tree from the collation key. - if (RC_BAD( rc = chkKeyToTree( pIxd, pucKey, uiKeyLen, &pKeyTree))) + if (RC_BAD( rc = flmIxKeyOutput( pIxd, pucKey, uiKeyLen, &pKeyTree, FALSE))) { goto Exit; } @@ -2441,8 +2462,8 @@ FSTATIC RCODE chkVerifyKeyNotUnique( // Count up to the first two references for the key. if (RC_BAD( rc = FlmKeyRetrieve( (HFDB) pDb, uiIndex, - pKeyTree->getContainerID(), pKeyTree, 0, FO_EXACT, NULL, &uiRefDrn - ))) + pKeyTree->getContainerID(), pKeyTree, 0, FO_EXACT, + NULL, &uiRefDrn))) { // If the key is NOT found, the problem no longer exists. @@ -2601,28 +2622,45 @@ Exit: Desc: Initializes a result set for use by the logical check code ****************************************************************************/ RCODE chkRSInit( - const char * pIoPath, - void ** ppvRSetRV) + const char * pIoPath, + IF_ResultSet ** ppRSet) { - RCODE rc = FERR_OK; - FResultSet * pRSet; + RCODE rc = FERR_OK; + IF_ResultSet * pRSet = NULL; + F_ChkResultSetCompare * pCompare = NULL; - if ((pRSet = f_new FResultSet) == NULL) + if( RC_BAD( rc = FlmAllocResultSet( &pRSet))) + { + goto Exit; + } + + if( (pCompare = f_new F_ChkResultSetCompare) == NULL) { rc = RC_SET( FERR_MEM); goto Exit; } - if (RC_BAD( rc = pRSet->Setup( pIoPath, chkCompareIxRSEntries, 0, 0, TRUE, - FALSE))) + if( RC_BAD( rc = pRSet->setupResultSet( pIoPath, + pCompare, 0, FALSE, FALSE, NULL))) { goto Exit; } - *ppvRSetRV = (void *) pRSet; + *ppRSet = pRSet; + pRSet = NULL; Exit: + if( pRSet) + { + pRSet->Release(); + } + + if( pCompare) + { + pCompare->Release(); + } + return (rc); } @@ -2634,9 +2672,9 @@ RCODE chkRSFinalize( FLMUINT64 * pui64TotalEntries) { RCODE rc = FERR_OK; - FResultSet * pRSet = (FResultSet *) (pIxChkInfo->pRSet); DB_CHECK_PROGRESS * pProgress = pIxChkInfo->pDbInfo->pProgress; DB_CHECK_PROGRESS saveInfo; + F_ChkSortStatus chkSortStatus( pIxChkInfo); // Save the current check phase information. @@ -2649,88 +2687,20 @@ RCODE chkRSFinalize( pProgress->ui64NumRSUnits = 0; pProgress->ui64NumRSUnitsDone = 0; - pRSet->SetCallback( chkRSCallbackFunc, (void *) pIxChkInfo); - - if (RC_BAD( rc = pRSet->Finalize( pui64TotalEntries))) + if (RC_BAD( rc = pIxChkInfo->pRSet->finalizeResultSet( + &chkSortStatus, pui64TotalEntries))) { goto Exit; } Exit: - (void) pRSet->SetCallback( NULL, 0); - - // Reset the pProgress information. - - f_memcpy( pProgress, &saveInfo, sizeof(DB_CHECK_PROGRESS)); + f_memcpy( pProgress, &saveInfo, sizeof( DB_CHECK_PROGRESS)); pProgress->bStartFlag = TRUE; return (rc); } -/**************************************************************************** -Desc: Compares result set entries during the finalization stage to allow - the result set to be sorted and to remove duplicates. -****************************************************************************/ -RCODE chkCompareIxRSEntries( - void * vpData1, - FLMUINT uiLength1, - void * vpData2, - FLMUINT uiLength2, - void * UserValue, - FLMINT * piCompare) -{ - FLMBYTE * pucData1 = (FLMBYTE *) vpData1; - FLMBYTE * pucData2 = (FLMBYTE *) vpData2; - FLMUINT uiIxNum1; - FLMUINT uiIxNum2; - FLMUINT uiDrn1; - FLMUINT uiDrn2; - - F_UNREFERENCED_PARM( UserValue); - - uiIxNum1 = (FLMUINT) FB2UW( &(pucData1[RS_IX_OFFSET])); - uiIxNum2 = (FLMUINT) FB2UW( &(pucData2[RS_IX_OFFSET])); - uiDrn1 = (FLMUINT) FB2UD( &(pucData1[RS_REF_OFFSET])); - uiDrn2 = (FLMUINT) FB2UD( &(pucData2[RS_REF_OFFSET])); - - *piCompare = chkCompareKeySet( uiIxNum1, &(pucData1[RS_KEY_OFFSET]), - uiLength1 - RS_KEY_OVERHEAD, uiDrn1, uiIxNum2, - &(pucData2[RS_KEY_OFFSET]), - uiLength2 - RS_KEY_OVERHEAD, uiDrn2); - - return (FERR_OK); -} - -/**************************************************************************** -Desc: Callback for result set sort progress. -****************************************************************************/ -FLMINT chkRSCallbackFunc( - RSET_CB_INFO * pCBInfo) -{ - IX_CHK_INFO * pIxChkInfo = (IX_CHK_INFO *) pCBInfo->UserValue; - DB_CHECK_PROGRESS * pProgress = pIxChkInfo->pDbInfo->pProgress; - FLMINT iRetVal = 0; - - // Set the status values. - - pProgress->ui64NumRSUnits = pCBInfo->ui64EstTotalUnits; - pProgress->ui64NumRSUnitsDone = pCBInfo->ui64UnitsDone; - - // Call the progress callback. - - if (RC_BAD( chkCallProgFunc( pIxChkInfo->pDbInfo))) - { - iRetVal = -1; - goto Exit; - } - -Exit: - - pProgress->bStartFlag = FALSE; - return (iRetVal); -} - /**************************************************************************** Desc: ****************************************************************************/ @@ -2894,7 +2864,7 @@ FSTATIC RCODE chkReadBlkFromDisk( FLMUINT uiBytesRead; FLMUINT uiBlkLen = pFileHdr->uiBlockSize; - if (RC_BAD( rc = pSFileHdl->ReadBlock( uiFilePos, uiBlkLen, pBlk, + if (RC_BAD( rc = pSFileHdl->readBlock( uiFilePos, uiBlkLen, pBlk, &uiBytesRead))) { if (rc == FERR_IO_END_OF_FILE) @@ -2942,7 +2912,7 @@ FSTATIC RCODE chkVerifyElmFields( STATE_INFO * pStateInfo, DB_INFO * pDbInfo, IX_CHK_INFO * pIxChkInfo, - POOL * pTmpPool, + F_Pool * pTmpPool, FLMUINT * puiErrElmRecOffsetRV, eCorruptionType * peElmCorruptCode) { @@ -3152,15 +3122,13 @@ FSTATIC RCODE chkVerifyElmFields( if (!pStateInfo->pDb->pFile->bInLimitedMode) { if (RC_BAD( rc = flmDecryptField( pStateInfo->pDb->pDict, - pRecord, pvField, pStateInfo->uiEncId, pTmpPool - ))) + pRecord, pvField, pStateInfo->uiEncId, pTmpPool))) { goto Exit; } *peElmCorruptCode = flmVerifyField( pData, - pStateInfo->uiFieldLen, - pStateInfo->uiFieldType); + pStateInfo->uiFieldLen, pStateInfo->uiFieldType); } else { @@ -3203,7 +3171,7 @@ FSTATIC RCODE chkVerifyElmFields( // If the pool is not reset, it grows during the check and // becomes VERY large. - pDbPoolMark = GedPoolMark( &(pDbInfo->pDb->TempPool)); + pDbPoolMark = pDbInfo->pDb->TempPool.poolMark(); bResetDbPool = TRUE; // Set up the KRef table so that flmGetRecKeys will work @@ -3237,7 +3205,7 @@ FSTATIC RCODE chkVerifyElmFields( // Mark the field pool so that it can be reset after // the record keys have been generated and output. - pKeyMark = GedPoolMark( pTmpPool); + pKeyMark = pTmpPool->poolMark(); // Build the record keys for the current index. Do // not remove duplicate keys. The result set will @@ -3274,7 +3242,7 @@ FSTATIC RCODE chkVerifyElmFields( // Reset the field pool - GedPoolReset( pTmpPool, pKeyMark); + pTmpPool->poolReset( pKeyMark); } } @@ -3286,7 +3254,7 @@ FSTATIC RCODE chkVerifyElmFields( // Reset the DB's temporary pool - (void) GedPoolReset( &(pDbInfo->pDb->TempPool), pDbPoolMark); + pDbInfo->pDb->TempPool.poolReset( pDbPoolMark); bResetDbPool = FALSE; } } @@ -3297,7 +3265,7 @@ FSTATIC RCODE chkVerifyElmFields( } pValue = pTempValue = NULL; - GedPoolReset( pTmpPool, NULL); + pTmpPool->poolReset( NULL); } if (*peElmCorruptCode != FLM_NO_CORRUPTION) @@ -3334,13 +3302,13 @@ Exit: if (bResetDbPool) { - (void) GedPoolReset( &(pDbInfo->pDb->TempPool), pDbPoolMark); + pDbInfo->pDb->TempPool.poolReset( pDbPoolMark); } if (*peElmCorruptCode != FLM_NO_CORRUPTION || RC_BAD( rc)) { pValue = pTempValue = NULL; - GedPoolReset( pTmpPool, NULL); + pTmpPool->poolReset( NULL); if (pRecord) { pRecord->clear(); @@ -3371,7 +3339,7 @@ FSTATIC RCODE chkVerifySubTree( STATE_INFO * pParentState, STATE_INFO * pStateInfo, FLMUINT uiBlkAddress, - POOL * pTmpPool, + F_Pool * pTmpPool, FLMBYTE * pucResetKey, FLMUINT uiResetKeyLen, FLMUINT uiResetDrn) @@ -3837,7 +3805,7 @@ Desc: This routine reads the LFH areas from disk to make sure they are up ****************************************************************************/ FSTATIC RCODE chkGetLfInfo( DB_INFO * pDbInfo, - POOL * pPool, + F_Pool * pPool, LF_STATS * pLfStats, LFILE * pLFile, LF_STATS * pCurrLfStats, @@ -3920,8 +3888,9 @@ FSTATIC RCODE chkGetLfInfo( { if (pLfStats->uiNumLevels > uiSaveLevel) { - if ((pLfStats->pLevelInfo = (LEVEL_INFO *) GedPoolCalloc( pPool, - (FLMUINT) (sizeof(LEVEL_INFO) * pLfStats->uiNumLevels))) == NULL) + if( RC_BAD( rc = pPool->poolCalloc( + (FLMUINT) (sizeof(LEVEL_INFO) * pLfStats->uiNumLevels), + (void **)&pLfStats->pLevelInfo))) { rc = RC_SET( FERR_MEM); goto Exit; @@ -3954,7 +3923,7 @@ Desc: This routine allocates and initializes the LF table (array of ****************************************************************************/ FSTATIC RCODE chkSetupLfTable( DB_INFO * pDbInfo, - POOL * pPool) + F_Pool * pPool) { RCODE rc = FERR_OK; FLMUINT uiCnt; @@ -4024,16 +3993,17 @@ FSTATIC RCODE chkSetupLfTable( } else { - if ((pDbInfo->pLogicalFiles = (LF_HDR *) GedPoolCalloc( pPool, (FLMUINT) - (sizeof(LF_HDR) * pDbInfo->pProgress->uiNumLogicalFiles))) == NULL) + if( RC_BAD( rc = pPool->poolCalloc( + (FLMUINT)(sizeof(LF_HDR) * pDbInfo->pProgress->uiNumLogicalFiles), + (void **)&pDbInfo->pLogicalFiles))) { rc = RC_SET( FERR_MEM); goto Exit; } - - if ((pDbInfo->pProgress->pLfStats = (LF_STATS *) GedPoolCalloc( pPool, - (FLMUINT)(sizeof(LF_STATS) * - pDbInfo->pProgress->uiNumLogicalFiles))) == NULL) + + if( RC_BAD( rc = pPool->poolCalloc( + (FLMUINT)(sizeof(LF_STATS) * pDbInfo->pProgress->uiNumLogicalFiles), + (void **)&pDbInfo->pProgress->pLfStats))) { rc = RC_SET( FERR_MEM); goto Exit; @@ -4101,13 +4071,13 @@ FSTATIC RCODE chkSetupLfTable( // Copy the LFILE information - so we can return the information // even after the database has been closed. - - if ((pLogicalFile->pLFile = pLFile = (LFILE *) GedPoolAlloc( pPool, - (FLMUINT) sizeof(LFILE))) == NULL) + + if( RC_BAD( rc = pPool->poolAlloc( sizeof( LFILE), (void **)&pLFile))) { - rc = RC_SET( FERR_MEM); goto Exit; } + + pLogicalFile->pLFile = pLFile; // Copy the LFILE structure so we can get enough information to // read them from disk, then read them from disk so we have a @@ -4159,11 +4129,11 @@ FSTATIC RCODE chkSetupLfTable( // Copy the IXD and IFD information - so we can return the // information even after the database has been closed. - - if ((pLogicalFile->pIxd = (IXD *) GedPoolAlloc( pPool, (FLMUINT) - (sizeof(IXD) + sizeof(IFD) * pTmpIxd->uiNumFlds))) == NULL) + + if( RC_BAD( rc = pPool->poolAlloc( + (FLMUINT)(sizeof(IXD) + sizeof(IFD) * pTmpIxd->uiNumFlds), + (void **)&pLogicalFile->pIxd))) { - rc = RC_SET( FERR_MEM); goto Exit; } @@ -4197,7 +4167,7 @@ Desc: This routine checks all of the B-TREES in the database -- all ****************************************************************************/ RCODE chkVerifyBTrees( DB_INFO * pDbInfo, - POOL * pPool, + F_Pool * pPool, FLMBOOL * pbStartOverRV) { RCODE rc = FERR_OK; @@ -4218,7 +4188,7 @@ RCODE chkVerifyBTrees( FLMUINT uiSaveDictSeq; FLMUINT uiTmpLf; LF_STATS * pTmpLfStats; - POOL tmpPool; + F_Pool tmpPool; FLMBOOL bRSFinalized = FALSE; DB_CHECK_PROGRESS * pProgress = pDbInfo->pProgress; IX_CHK_INFO IxChkInfo; @@ -4236,7 +4206,7 @@ RCODE chkVerifyBTrees( goto Exit; } - pvPoolMark = GedPoolMark( pPool); + pvPoolMark = pPool->poolMark(); uiSaveDictSeq = pDb->pDict->uiDictSeq; if (RC_BAD( rc = chkSetupLfTable( pDbInfo, pPool))) @@ -4401,14 +4371,14 @@ RCODE chkVerifyBTrees( // Call chkVerifySubTree to check the B-TREE starting at the root // block. - GedPoolInit( &tmpPool, 512); + tmpPool.poolInit( 512); pDbInfo->bReposition = FALSE; rc = chkVerifySubTree( pDbInfo, pIxChkInfo, NULL, &State[pLfStats->uiNumLevels - 1], pLFile->uiRootBlk, &tmpPool, pucResetKey, uiResetKeyLen, uiResetDrn); - GedPoolFree( &tmpPool); + tmpPool.poolFree(); if (rc == FERR_OLD_VIEW) { @@ -4691,12 +4661,12 @@ FSTATIC RCODE chkSetupIxInfo( FLMUINT uiIxNum = 0; IXD * pIxd; LFILE * pLFile; - char szTmpIoPath[F_PATH_MAX_SIZE]; - char szBaseName[F_FILENAME_SIZE]; + char szTmpIoPath[ F_PATH_MAX_SIZE]; + char szBaseName[ F_FILENAME_SIZE]; FDB * pDb = pDbInfo->pDb; f_memset( pIxInfoRV, 0, sizeof(IX_CHK_INFO)); - GedPoolInit( &(pIxInfoRV->pool), 512); + pIxInfoRV->pool.poolInit( 512); pIxInfoRV->pDbInfo = pDbInfo; // Set up the result set path @@ -4705,8 +4675,8 @@ FSTATIC RCODE chkSetupIxInfo( { if (rc == FERR_IO_PATH_NOT_FOUND || rc == FERR_IO_INVALID_PATH) { - if (RC_BAD( rc = f_pathReduce( pDb->pFile->pszDbPath, szTmpIoPath, - szBaseName))) + if (RC_BAD( rc = gv_FlmSysData.pFileSystem->pathReduce( + pDb->pFile->pszDbPath, szTmpIoPath, szBaseName))) { goto Exit; } @@ -4720,7 +4690,7 @@ FSTATIC RCODE chkSetupIxInfo( // Initialize the result set. The result set will be used to build an // ordered list of keys for comparision to the database's indexes. - if (RC_BAD( rc = chkRSInit( szTmpIoPath, &(pIxInfoRV->pRSet)))) + if (RC_BAD( rc = chkRSInit( szTmpIoPath, &pIxInfoRV->pRSet))) { goto Exit; } @@ -4772,7 +4742,7 @@ Exit: if (RC_BAD( rc)) { - GedPoolFree( &(pIxInfoRV->pool)); + pIxInfoRV->pool.poolFree(); if (pIxInfoRV->puiIxArray) { f_free( &(pIxInfoRV->puiIxArray)); @@ -4816,7 +4786,7 @@ FSTATIC RCODE chkOutputIndexKeys( // Add the composite key (index, ref, key) to the result set - if (RC_BAD( rc = chkRSAddEntry( pIxChkInfo->pRSet, ucBuf, + if (RC_BAD( rc = pIxChkInfo->pRSet->addEntry( ucBuf, uiKeyLen + RS_KEY_OVERHEAD))) { goto Exit; diff --git a/flaim/src/flclose.cpp b/flaim/src/flclose.cpp index 621ffec..60cdaaf 100644 --- a/flaim/src/flclose.cpp +++ b/flaim/src/flclose.cpp @@ -28,10 +28,10 @@ Desc : Closes a FLAIM database. ****************************************************************************/ RCODE flmDbClose( - HFDB * phDbRV, - FLMBOOL bMutexLocked) + HFDB * phDbRV, + FLMBOOL bMutexLocked) { - FDB * pDb; + FDB * pDb; if ((!phDbRV) || ((pDb = (FDB *)*phDbRV) == NULL)) @@ -114,10 +114,10 @@ Finish_Close: f_mutexUnlock( gv_FlmSysData.hShareMutex); } - // Free the temporary pool + // Free the temporary pools - GedPoolFree( &pDb->TempPool); - GedPoolFree( &pDb->tmpKrefPool); + pDb->TempPool.poolFree(); + pDb->tmpKrefPool.poolFree(); // Free up statistics. @@ -128,13 +128,20 @@ Finish_Close: // Get rid of mutex -#if defined( FLM_DEBUG) && (defined( FLM_WIN) || defined( FLM_NLM)) +#if defined( FLM_DEBUG) if (pDb->hMutex != F_MUTEX_NULL) { f_mutexDestroy( &pDb->hMutex); } #endif + // Free the semaphore + + if( pDb->hWaitSem != F_SEM_NULL) + { + f_semDestroy( &pDb->hWaitSem); + } + // Free the FDB. f_free( phDbRV); diff --git a/flaim/src/flconvrt.cpp b/flaim/src/flconvrt.cpp index 399e14b..7a3cc11 100644 --- a/flaim/src/flconvrt.cpp +++ b/flaim/src/flconvrt.cpp @@ -501,7 +501,7 @@ FLMEXP RCODE FLMAPI FlmDbUpgrade( if (RC_OK( rc = rflGetFileName( uiOldVersion, pFile->pszDbPath, NULL, uiRflFileNum, szTmpName))) { - gv_FlmSysData.pFileSystem->Delete( szTmpName); + gv_FlmSysData.pFileSystem->deleteFile( szTmpName); } } diff --git a/flaim/src/flcreate.cpp b/flaim/src/flcreate.cpp index 2c03155..03ee893 100644 --- a/flaim/src/flcreate.cpp +++ b/flaim/src/flcreate.cpp @@ -183,32 +183,28 @@ RCODE flmCreateNewFile( } bNewFile = TRUE; + if (pCreateOpts != NULL) + { + pFile->FileHdr.uiBlockSize = flmAdjustBlkSize( pCreateOpts->uiBlockSize); + pFile->FileHdr.uiVersionNum = pCreateOpts->uiVersionNum; + } + else + { + pFile->FileHdr.uiBlockSize = DEFAULT_BLKSIZ; + pFile->FileHdr.uiVersionNum = FLM_CUR_FILE_FORMAT_VER_NUM; + } + // Link the FDB to the file. rc = flmLinkFdbToFile( pDb, pFile); f_mutexUnlock( gv_FlmSysData.hShareMutex); bMutexLocked = FALSE; + if (RC_BAD( rc)) { goto Exit; } - // If the file has not already been created, do so now. - - // Determine what to set file block size to. - - if (pCreateOpts != NULL) - { - pDb->pSFileHdl->SetBlockSize( - flmAdjustBlkSize( pCreateOpts->uiBlockSize)); - pDb->pSFileHdl->SetDbVersion( pCreateOpts->uiVersionNum); - } - else - { - pDb->pSFileHdl->SetBlockSize( DEFAULT_BLKSIZ); - pDb->pSFileHdl->SetDbVersion( FLM_CUR_FILE_FORMAT_VER_NUM); - } - #ifdef FLM_USE_NICI // Create a new F_CCS object for the database wrapping key if the new @@ -253,15 +249,33 @@ RCODE flmCreateNewFile( } #endif - if (RC_OK( gv_FlmSysData.pFileSystem->Exists( pszFilePath))) + if (RC_OK( gv_FlmSysData.pFileSystem->doesFileExist( pszFilePath))) { rc = RC_SET( FERR_FILE_EXISTS); goto Exit; } + // Allocate the super file object + + flmAssert( !pDb->pSFileHdl); + + if( (pDb->pSFileHdl = f_new F_SuperFileHdl) == NULL) + { + rc = RC_SET( FERR_MEM); + goto Exit; + } + + flmAssert( pFile->FileHdr.uiVersionNum); + + if( RC_BAD( rc = pDb->pSFileHdl->setup( + pFile->pszDbPath, pFile->pszDataDir, pFile->FileHdr.uiVersionNum))) + { + goto Exit; + } + // Create the .db file. - if( RC_BAD( rc = pDb->pSFileHdl->CreateFile( 0))) + if( RC_BAD( rc = pDb->pSFileHdl->createFile( 0))) { goto Exit; } @@ -316,7 +330,7 @@ Exit: { if( bFileCreated) { - (void)gv_FlmSysData.pFileSystem->Delete( pszFilePath); + (void)gv_FlmSysData.pFileSystem->deleteFile( pszFilePath); } } else if( ppDb) @@ -394,34 +408,6 @@ FSTATIC RCODE flmInitNewFile( goto Exit; } - // Setup the FFILE's ECache object - - flmAssert( pFile->pECacheMgr == NULL); - if( gv_FlmSysData.bOkToUseESM) - { - if( (pFile->pECacheMgr = f_new FlmECache) == NULL) - { - rc = RC_SET( FERR_MEM); - goto Exit; - } - - if( !pFile->pECacheMgr->setupECache( - pFile->FileHdr.uiBlockSize, pFile->uiMaxFileSize)) - { - pFile->pECacheMgr->Release(); - pFile->pECacheMgr = NULL; - } - else - { - // Normally the ECacheMgr is set in flmLinkFdbToFile but - // we have to handle this special case here. When this - // FDB was linked there was no ECacheMgr. - - flmAssert( pDb->pSFileHdl != NULL); - pDb->pSFileHdl->setECacheMgr( pFile->pECacheMgr); - } - } - // The following code starts an update transaction on the new DB so // we can get it built. @@ -502,7 +488,7 @@ FSTATIC RCODE flmInitFileHdrs( flmSetFilePrefix( pInitBuf, 0, 0); } - if (RC_BAD( rc = pDb->pSFileHdl->WriteHeader( 0L, uiBlkSize, + if (RC_BAD( rc = pDb->pSFileHdl->writeHeader( 0L, uiBlkSize, pInitBuf, &uiWriteBytes))) { goto Exit; @@ -636,7 +622,7 @@ FSTATIC RCODE flmInitFileHdrs( // Create the first block file. - if (RC_BAD( rc = pDb->pSFileHdl->CreateFile( 1))) + if (RC_BAD( rc = pDb->pSFileHdl->createFile( 1))) { goto Exit; } @@ -712,7 +698,7 @@ FSTATIC RCODE flmInitFileHdrs( uiBlkSize); pDb->pSFileHdl->setMaxAutoExtendSize( pFile->uiMaxFileSize); pDb->pSFileHdl->setExtendSize( pFile->uiFileExtendSize); - if (RC_BAD( rc = pDb->pSFileHdl->WriteBlock( + if (RC_BAD( rc = pDb->pSFileHdl->writeBlock( pFile->FileHdr.uiFirstLFHBlkAddr, uiBlkSize, pInitBuf, uiBufSize, NULL, &uiWriteBytes))) @@ -738,7 +724,7 @@ FSTATIC RCODE flmInitFileHdrs( BlkCheckSum( pInitBuf, CHECKSUM_SET, uiPcodeAddr, uiBlkSize); pDb->pSFileHdl->setMaxAutoExtendSize( pFile->uiMaxFileSize); pDb->pSFileHdl->setExtendSize( pFile->uiFileExtendSize); - if (RC_BAD( rc = pDb->pSFileHdl->WriteBlock( uiPcodeAddr, + if (RC_BAD( rc = pDb->pSFileHdl->writeBlock( uiPcodeAddr, uiBlkSize, pInitBuf, uiBufSize, NULL, &uiWriteBytes))) { @@ -748,7 +734,7 @@ FSTATIC RCODE flmInitFileHdrs( // Force things to disk. - if (RC_BAD( rc = pDb->pSFileHdl->Flush())) + if (RC_BAD( rc = pDb->pSFileHdl->flush())) { goto Exit; } diff --git a/flaim/src/flerror.cpp b/flaim/src/flerror.cpp index a1ed1a4..75f5d21 100644 --- a/flaim/src/flerror.cpp +++ b/flaim/src/flerror.cpp @@ -217,7 +217,7 @@ RCODE flmMakeErr( Desc : Returns a pointer to the string representation of a corruption error code. ****************************************************************************/ -const char * FlmVerifyErrToStr( +const char * FLMAPI FlmVerifyErrToStr( eCorruptionType eCorruption) { return( FlmCorruptStrings [eCorruption]); @@ -394,7 +394,7 @@ const char * flmErrorString( CASE_RET( FERR_IO_END_OF_FILE); CASE_RET( FERR_IO_OPEN_ERR); CASE_RET( FERR_IO_SEEK_ERR); - CASE_RET( FERR_IO_MODIFY_ERR); + CASE_RET( FERR_IO_DIRECTORY_ERR); CASE_RET( FERR_IO_PATH_NOT_FOUND); CASE_RET( FERR_IO_TOO_MANY_OPEN_FILES); CASE_RET( FERR_IO_PATH_TOO_LONG); @@ -471,20 +471,6 @@ const char * flmErrorString( CASE_RET( FERR_INJECT_KEY_FAILED); CASE_RET( FERR_PBE_DECRYPT_FAILED); CASE_RET( FERR_PASSWD_INVALID); - CASE_RET( FERR_SVR_NOIP_ADDR); - CASE_RET( FERR_SVR_SOCK_FAIL); - CASE_RET( FERR_SVR_CONNECT_FAIL); - CASE_RET( FERR_SVR_BIND_FAIL); - CASE_RET( FERR_SVR_LISTEN_FAIL); - CASE_RET( FERR_SVR_ACCEPT_FAIL); - CASE_RET( FERR_SVR_SELECT_ERR); - CASE_RET( FERR_SVR_SOCKOPT_FAIL); - CASE_RET( FERR_SVR_DISCONNECT); - CASE_RET( FERR_SVR_READ_FAIL); - CASE_RET( FERR_SVR_WRT_FAIL); - CASE_RET( FERR_SVR_READ_TIMEOUT); - CASE_RET( FERR_SVR_WRT_TIMEOUT); - CASE_RET( FERR_SVR_ALREADY_CLOSED); default: return( NULL); } diff --git a/flaim/src/flfixed.cpp b/flaim/src/flfixed.cpp deleted file mode 100644 index a5d787a..0000000 --- a/flaim/src/flfixed.cpp +++ /dev/null @@ -1,2128 +0,0 @@ -//------------------------------------------------------------------------- -// Desc: Memory management using fixed-size allocators - for dealing with -// memory fragmentation issues. -// Tabs: 3 -// -// Copyright (c) 2004-2006 Novell, Inc. All Rights Reserved. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of version 2 of the GNU General Public -// License as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, contact Novell, Inc. -// -// To contact Novell about this file by physical or electronic mail, -// you may find current contact information at www.novell.com -// -// $Id: flfixed.cpp 12334 2006-01-23 12:45:35 -0700 (Mon, 23 Jan 2006) dsanders $ -//------------------------------------------------------------------------- - -#include "flaimsys.h" - -#ifdef FLM_NLM - extern "C" - { - extern LONG gv_lAllocRTag; - } -#endif - -/**************************************************************************** -Desc: -****************************************************************************/ -F_SlabManager::F_SlabManager() -{ - m_hMutex = F_MUTEX_NULL; - m_pFirstInSlabList = NULL; - m_pLastInSlabList = NULL; - m_uiTotalSlabs = 0; - m_uiAvailSlabs = 0; - m_uiInUseSlabs = 0; - m_pLowPrealloc = NULL; - m_pHighPrealloc = NULL; -} - -/**************************************************************************** -Desc: -****************************************************************************/ -F_SlabManager::~F_SlabManager() -{ - - flmAssert( !m_uiInUseSlabs); - flmAssert( m_uiAvailSlabs == m_uiTotalSlabs); - - freeAllSlabs(); - - if( m_hMutex != F_MUTEX_NULL) - { - f_mutexDestroy( &m_hMutex); - } -} - -/**************************************************************************** -Desc: -****************************************************************************/ -RCODE F_SlabManager::setup( - FLMUINT uiPreallocSize, - FLMUINT uiMinSlabSize) -{ - RCODE rc = FERR_OK; - FLMUINT uiSysSlabSize = 0; - FLMUINT uiSlabSize = uiMinSlabSize; - - if( RC_BAD( rc = f_mutexCreate( &m_hMutex))) - { - goto Exit; - } - - // Determine the slab size - -#ifdef FLM_WIN - { - SYSTEM_INFO sysInfo; - - GetSystemInfo( &sysInfo); - uiSysSlabSize = sysInfo.dwAllocationGranularity; - } -#endif - - if( !uiSysSlabSize) - { - uiSysSlabSize = uiSlabSize; - } - - // Round the given slab size up to the closest operating - // system slab size so we don't waste any memory. - - if( uiSlabSize % uiSysSlabSize) - { - m_uiSlabSize = ((uiSlabSize / uiSysSlabSize) + 1) * uiSysSlabSize; - } - else - { - m_uiSlabSize = uiSlabSize; - } - - // Pre-allocate the requested amount of memory from the system - - if( uiPreallocSize) - { - if( RC_BAD( rc = resize( uiPreallocSize))) - { - goto Exit; - } - } - -Exit: - - return( rc); -} - -/**************************************************************************** -Desc: -****************************************************************************/ -RCODE F_SlabManager::resize( - FLMUINT uiNumBytes, - FLMUINT * puiActualSize) -{ - RCODE rc = FERR_OK; - FLMUINT uiSlabsNeeded; - void * pSlab; - - f_mutexLock( m_hMutex); - - if( puiActualSize) - { - *puiActualSize = 0; - } - - uiSlabsNeeded = (uiNumBytes / m_uiSlabSize) + - ((uiNumBytes % m_uiSlabSize) ? 1 : 0); - - if( !uiSlabsNeeded && !m_uiInUseSlabs) - { - freeAllSlabs(); - } - else if( m_uiTotalSlabs > uiSlabsNeeded) - { - // Do the best we can to free slabs. We can only get rid of - // slabs that aren't in use. - - if( RC_BAD( rc = sortSlabList())) - { - goto Exit; - } - - while( m_pLastInSlabList && m_uiTotalSlabs > uiSlabsNeeded) - { - pSlab = m_pLastInSlabList; - if( (m_pLastInSlabList = ((SLABHEADER *)pSlab)->pPrev) != NULL) - { - ((SLABHEADER *)m_pLastInSlabList)->pNext = NULL; - } - else - { - m_pFirstInSlabList = NULL; - } - - releaseSlabToSystem( pSlab); - - flmAssert( m_uiTotalSlabs); - flmAssert( m_uiInUseSlabs); - - m_uiAvailSlabs--; - m_uiTotalSlabs--; - } - - if( !m_uiTotalSlabs) - { - flmAssert( !m_pFirstInSlabList); - flmAssert( !m_pLastInSlabList); - - m_pLowPrealloc = NULL; - m_pHighPrealloc = NULL; - } - else if( !uiNumBytes) - { - // Set the low and high pre-allocation pointers to NULL so that - // slabs will be released back to the system when they are returned - // to the slab manager. - - m_pLowPrealloc = NULL; - m_pHighPrealloc = NULL; - } - else - { - if( m_pFirstInSlabList < m_pLowPrealloc) - { - m_pLowPrealloc = m_pFirstInSlabList; - } - - if( m_pLastInSlabList > m_pHighPrealloc) - { - m_pHighPrealloc = m_pLastInSlabList; - } - } - } - else - { - // Allocate the required number of slabs - - while( m_uiTotalSlabs < uiSlabsNeeded) - { - if( (pSlab = allocSlabFromSystem()) == NULL) - { - rc = RC_SET( FERR_MEM); - goto Exit; - } - - if( !m_pLowPrealloc || pSlab < m_pLowPrealloc) - { - m_pLowPrealloc = pSlab; - } - - if( pSlab > m_pHighPrealloc) - { - m_pHighPrealloc = pSlab; - } - - // Touch every byte in the slab so that the operating system is - // forced to immediately assign physical memory. - - f_memset( pSlab, 0, m_uiSlabSize); - - // Link the slab into the avail list - - if( m_pFirstInSlabList) - { - ((SLABHEADER *)m_pFirstInSlabList)->pPrev = pSlab; - } - - ((SLABHEADER *)pSlab)->pNext = m_pFirstInSlabList; - m_pFirstInSlabList = pSlab; - - if( !m_pLastInSlabList) - { - m_pLastInSlabList = pSlab; - } - - m_uiTotalSlabs++; - m_uiAvailSlabs++; - } - } - - if( puiActualSize) - { - *puiActualSize = m_uiTotalSlabs * m_uiSlabSize; - } - -Exit: - - if( RC_BAD( rc)) - { - freeAllSlabs(); - } - - f_mutexUnlock( m_hMutex); - return( rc); -} - -/**************************************************************************** -Desc: -****************************************************************************/ -RCODE F_SlabManager::allocSlab( - void ** ppSlab) -{ - RCODE rc = FERR_OK; - - f_mutexLock( m_hMutex); - - if( m_pFirstInSlabList) - { - *ppSlab = m_pFirstInSlabList; - if( (m_pFirstInSlabList = - ((SLABHEADER *)m_pFirstInSlabList)->pNext) != NULL) - { - ((SLABHEADER *)m_pFirstInSlabList)->pPrev = NULL; - } - else - { - m_pLastInSlabList = NULL; - } - - ((SLABHEADER *)*ppSlab)->pNext = NULL; - - flmAssert( m_uiAvailSlabs); - m_uiAvailSlabs--; - m_uiInUseSlabs++; - } - else - { - flmAssert( !m_uiAvailSlabs); - - if( (*ppSlab = allocSlabFromSystem()) == NULL) - { - rc = RC_SET( FERR_MEM); - goto Exit; - } - - m_uiTotalSlabs++; - m_uiInUseSlabs++; - } - -Exit: - - f_mutexUnlock( m_hMutex); - return( rc); -} - -/**************************************************************************** -Desc: -****************************************************************************/ -void F_SlabManager::freeSlab( - void ** ppSlab) -{ - flmAssert( ppSlab && *ppSlab); - - f_mutexLock( m_hMutex); - - // There's no guarantee that out-of-band allocations will - // fall outside of the preallocated address space, but - // this is the best we can do. The FLAIM cache system - // is generally well-behaved. Thus, even if an out-of-band - // allocation falls within the prealloc range, we won't - // exceed our allocation limits by too much. It is better - // to hold onto a little extra memory than to fail an allocation - // request. - - if( m_pLowPrealloc && *ppSlab >= m_pLowPrealloc && *ppSlab <= m_pHighPrealloc) - { - ((SLABHEADER *)*ppSlab)->pPrev = NULL; - if( (((SLABHEADER *)*ppSlab)->pNext = m_pFirstInSlabList) != NULL) - { - ((SLABHEADER *)m_pFirstInSlabList)->pPrev = *ppSlab; - } - else - { - m_pLastInSlabList = *ppSlab; - } - - m_pFirstInSlabList = *ppSlab; - *ppSlab = NULL; - - flmAssert( m_uiInUseSlabs); - m_uiInUseSlabs--; - m_uiAvailSlabs++; - } - else - { - releaseSlabToSystem( *ppSlab); - *ppSlab = NULL; - - flmAssert( m_uiTotalSlabs); - flmAssert( m_uiInUseSlabs); - - m_uiTotalSlabs--; - m_uiInUseSlabs--; - } - - f_mutexUnlock( m_hMutex); -} - -/**************************************************************************** -Desc: -****************************************************************************/ -void F_SlabManager::freeAllSlabs( void) -{ - void * pNextSlab; - SLABHEADER * pSlabHeader; - - while( m_pFirstInSlabList) - { - pSlabHeader = (SLABHEADER *)m_pFirstInSlabList; - pNextSlab = pSlabHeader->pNext; - releaseSlabToSystem( m_pFirstInSlabList); - m_pFirstInSlabList = pNextSlab; - } - - m_uiTotalSlabs = 0; - m_uiAvailSlabs = 0; - m_pLowPrealloc = NULL; - m_pHighPrealloc = NULL; - m_pLastInSlabList = NULL; -} - -/**************************************************************************** -Desc: -****************************************************************************/ -void * F_SlabManager::allocSlabFromSystem( void) -{ - void * pSlab; - -#if defined( FLM_OSX) && !defined( MAP_ANONYMOUS) - #define MAP_ANONYMOUS MAP_ANON -#endif - -#ifdef FLM_WIN - pSlab = VirtualAlloc( NULL, - (DWORD)m_uiSlabSize, MEM_COMMIT, PAGE_READWRITE); -#elif defined( FLM_UNIX) && !defined( FLM_SOLARIS) - if( (pSlab = mmap( 0, m_uiSlabSize, - PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0)) == MAP_FAILED) - { - return( NULL); - } - - // We don't use mmap on Solaris because of the amount of address - // space it consumes for red-zones and rounding. The following is from - // the Solaris mmap man page: - // - // The mmap() function aligns based on the length of the map- - // ping. When determining the amount of space to add to the - // address space, mmap() includes two 8-Kbyte pages, one at - // each end of the mapping that are not mapped and are there- - // fore used as "red-zone" pages. Attempts to reference these - // pages result in access violations. - // - // The size requested is incremented by the 16 Kbytes for these - // pages and is then subject to rounding constraints. The con- - // straints are: - // - // o For 32-bit processes: - // - // If length > 4 Mbytes - // round to 4-Mbyte multiple - // elseif length > 512 Kbytes - // round to 512-Kbyte multiple - // else - // round to 64-Kbyte multiple - // - // o For 64-bit processes: - // - // If length > 4 Mbytes - // round to 4-Mbyte multiple - // else - // round to 1-Mbyte multiple - // - // The net result is that for a 32-bit process: - // - // o If an mmap() request is made for 4 Mbytes, it results - // in 4 Mbytes + 16 Kbytes and is rounded up to 8 Mbytes. - // - // o If an mmap() request is made for 512 Kbytes, it results - // in 512 Kbytes + 16 Kbytes and is rounded up to 1 Mbyte. - // - // o If an mmap() request is made for 1 Mbyte, it results in - // 1 Mbyte + 16 Kbytes and is rounded up to 1.5 Mbytes. - // - // o Each 8-Kbyte mmap request "consumes" 64 Kbytes of vir- - // tual address space. - -#else - if( RC_BAD( f_alloc( m_uiSlabSize, &pSlab))) - { - return( NULL); - } -#endif - - return( pSlab); -} - -/**************************************************************************** -Desc: -****************************************************************************/ -void F_SlabManager::releaseSlabToSystem( - void * pSlab) -{ - flmAssert( pSlab); - -#ifdef FLM_WIN - VirtualFree( pSlab, 0, MEM_RELEASE); -#elif defined( FLM_UNIX) && !defined( FLM_SOLARIS) - munmap( pSlab, m_uiSlabSize); -#else - f_free( &pSlab); -#endif -} - -/**************************************************************************** -Desc: -****************************************************************************/ -FLMINT F_SlabManager::slabAddrCompareFunc( - void * pvBuffer, - FLMUINT uiPos1, - FLMUINT uiPos2) -{ - void * pSlab1 = (((void **)pvBuffer)[ uiPos1]); - void * pSlab2 = (((void **)pvBuffer)[ uiPos2]); - - flmAssert( pSlab1 != pSlab2); - - if( pSlab1 < pSlab2) - { - return( -1); - } - - return( 1); -} - -/**************************************************************************** -Desc: -****************************************************************************/ -void F_SlabManager::slabAddrSwapFunc( - void * pvBuffer, - FLMUINT uiPos1, - FLMUINT uiPos2) -{ - void ** ppSlab1 = &(((void **)pvBuffer)[ uiPos1]); - void ** ppSlab2 = &(((void **)pvBuffer)[ uiPos2]); - void * pTmp; - - pTmp = *ppSlab1; - *ppSlab1 = *ppSlab2; - *ppSlab2 = pTmp; -} - -/**************************************************************************** -Desc: -****************************************************************************/ -RCODE F_SlabManager::sortSlabList( void) -{ - RCODE rc = FERR_OK; - FLMUINT uiLoop; - void ** pSortBuf = NULL; - FLMUINT uiMaxSortEntries; - FLMUINT uiSortEntries = 0; -#define SMALL_SORT_BUF_SIZE 256 - void * smallSortBuf[ SMALL_SORT_BUF_SIZE]; - void * pCurSlab; - void * pPrevSib; - - if( m_uiAvailSlabs <= 1) - { - goto Exit; - } - - uiMaxSortEntries = m_uiAvailSlabs; - - // Sort the avail list according to the starting memory addresses of the - // slabs - - if( uiMaxSortEntries <= SMALL_SORT_BUF_SIZE) - { - pSortBuf = smallSortBuf; - } - else - { - if( RC_BAD( rc = f_alloc( uiMaxSortEntries * sizeof( void *), &pSortBuf))) - { - goto Exit; - } - } - - pCurSlab = m_pFirstInSlabList; - - while( pCurSlab) - { - flmAssert( uiSortEntries != uiMaxSortEntries); - pSortBuf[ uiSortEntries++] = pCurSlab; - pCurSlab = ((SLABHEADER *)pCurSlab)->pNext; - } - - flmAssert( uiSortEntries == uiMaxSortEntries); - - // Quick sort - - flmAssert( uiSortEntries); - - f_qsort( (FLMBYTE *)pSortBuf, 0, uiSortEntries - 1, - F_SlabManager::slabAddrCompareFunc, - F_SlabManager::slabAddrSwapFunc); - - // Re-link the items in the list according to the new - // sort order - - m_pFirstInSlabList = NULL; - m_pLastInSlabList = NULL; - - pCurSlab = NULL; - pPrevSib = NULL; - - for( uiLoop = 0; uiLoop < uiSortEntries; uiLoop++) - { - pCurSlab = pSortBuf[ uiLoop]; - ((SLABHEADER *)pCurSlab)->pNext = NULL; - ((SLABHEADER *)pCurSlab)->pPrev = NULL; - - if( pPrevSib) - { - ((SLABHEADER *)pCurSlab)->pPrev = pPrevSib; - ((SLABHEADER *)pPrevSib)->pNext = pCurSlab; - } - else - { - m_pFirstInSlabList = pCurSlab; - } - - pPrevSib = pCurSlab; - } - - m_pLastInSlabList = pCurSlab; - -Exit: - - if( pSortBuf && pSortBuf != smallSortBuf) - { - f_free( &pSortBuf); - } - - return( rc); -} - -/**************************************************************************** -Desc: -****************************************************************************/ -F_FixedAlloc::F_FixedAlloc() -{ - m_pSlabManager = NULL; - m_pFirstBlock = NULL; - m_pLastBlock = NULL; - m_pFirstBlockWithAvailCells = NULL; - m_pLastBlockWithAvailCells = NULL; - m_uiBlocksWithAvailCells = 0; - m_bAvailListSorted = TRUE; - m_uiTotalFreeCells = 0; - m_fnCanRelocate = NULL; - m_fnRelocate = NULL; - m_puiTotalBytesAllocated = NULL; - m_uiSlabSize = 0; - - m_hLocalMutex = F_MUTEX_NULL; - m_phMutex = NULL; - - m_uiAllocatedSlabs = 0; - m_uiAllocatedCells = 0; - m_uiAllocatedCellWatermark = 0; - m_uiEverFreedCells = 0; -} - -/**************************************************************************** -Desc: Destructor for F_FixedAlloc. checks for memory leaks, and - frees all memory in use. -****************************************************************************/ -F_FixedAlloc::~F_FixedAlloc() -{ -#ifdef FLM_DEBUG - testForLeaks(); -#endif - - freeAll(); - - if( m_pSlabManager) - { - m_pSlabManager->Release(); - } - - if( m_hLocalMutex != F_MUTEX_NULL) - { - f_mutexDestroy( &m_hLocalMutex); - } -} - -/**************************************************************************** -Desc: Setup method for any setup that can fail -****************************************************************************/ -RCODE F_FixedAlloc::setup( - F_SlabManager * pSlabManager, - FLMBOOL bUseMutex, - FLMUINT uiCellSize, - FLMUINT * puiTotalBytesAllocated) -{ - RCODE rc = FERR_OK; - - flmAssert( pSlabManager); - flmAssert( uiCellSize); - - m_pSlabManager = pSlabManager; - m_pSlabManager->AddRef(); - - m_uiCellSize = uiCellSize; - m_puiTotalBytesAllocated = puiTotalBytesAllocated; - m_uiSlabSize = m_pSlabManager->getSlabSize(); - - // Get the alloc-aligned versions of all the sizes - - m_uiBlockHeaderSize = getAllocAlignedSize( sizeof( BLOCK)); - m_uiCellHeaderSize = getAllocAlignedSize( sizeof( CELLHEADER)); - m_uiCellSize = getAllocAlignedSize( m_uiCellSize); - - // Ensure that there's enough space for our overhead - - flmAssert( m_uiCellSize >= sizeof( CELLAVAILNEXT)); - - m_uiSizeOfCellAndHeader = m_uiCellHeaderSize + m_uiCellSize; - - m_uiCellsPerBlock = - (m_uiSlabSize - m_uiBlockHeaderSize) / - m_uiSizeOfCellAndHeader; - - flmAssert( m_uiCellsPerBlock); - flmAssert( (m_uiCellsPerBlock * m_uiCellSize) < m_uiSlabSize); - - if( bUseMutex) - { - if( RC_BAD( rc = f_mutexCreate( &m_hLocalMutex))) - { - goto Exit; - } - - m_phMutex = &m_hLocalMutex; - } - -Exit: - - return( rc); -} - -/**************************************************************************** -Desc: Setup method for any setup that can fail -****************************************************************************/ -RCODE F_FixedAlloc::setup( - F_SlabManager * pSlabManager, - F_MUTEX * phMutex, - FLMUINT uiCellSize, - FLMUINT * puiTotalBytesAllocated) -{ - RCODE rc = FERR_OK; - - if( RC_BAD( rc = setup( pSlabManager, (FLMBOOL)FALSE, - uiCellSize, puiTotalBytesAllocated))) - { - goto Exit; - } - - if( phMutex) - { - m_phMutex = phMutex; - } - -Exit: - - return( rc); -} - -/**************************************************************************** -Desc: Private, internal method to fetch a cell -****************************************************************************/ -void * F_FixedAlloc::getCell( void) -{ - BLOCK * pBlock = NULL; - FLMBYTE * pCell = NULL; - CELLHEADER * pHeader; - - // If there's a block that has an avail cell, that one gets priority - - if( (pBlock = m_pFirstBlockWithAvailCells) != NULL) - { - flmAssert( pBlock->ui32AvailCellCount <= m_uiTotalFreeCells); - flmAssert( m_uiTotalFreeCells); - flmAssert( pBlock->ui32AllocatedCells < m_uiCellsPerBlock); - - pCell = m_pFirstBlockWithAvailCells->pLocalAvailCellListHead; - flmAssert( pCell); - - pHeader = (CELLHEADER *)((FLMBYTE *)pCell - m_uiCellHeaderSize); - - pBlock->ui32AllocatedCells++; - pBlock->ui32AvailCellCount--; - m_uiTotalFreeCells--; - - // An avail cell holds as its contents the next pointer in the avail chain. - // Avail chains do not span blocks. - - pBlock->pLocalAvailCellListHead = ((CELLAVAILNEXT *)pCell)->pNextInList; - - // If there are no other avail cells in this block at this point, - // then we need to unlink the block from the - // blocks-with-avail-cells list, headed by m_pFirstBlockWithAvailCells - - if( !pBlock->pLocalAvailCellListHead) - { - // Save a copy of the block we're going to unlink - - BLOCK * pBlockToUnlink = pBlock; - - // Need to keep the NULLNESS of the content of the cell consistent - // with the block's ui32AvailCellCount being equal to 0 - - flmAssert( !pBlockToUnlink->ui32AvailCellCount); - - // There can't be a pPrevBlockWithAvailCells since - // we're positioned to the first one - - flmAssert( !pBlockToUnlink->pPrevBlockWithAvailCells); - - // Update m_pFirstBlockWithAvailCells to point to the next one - - if( (m_pFirstBlockWithAvailCells = - pBlockToUnlink->pNextBlockWithAvailCells) == NULL) - { - flmAssert( m_pLastBlockWithAvailCells == pBlockToUnlink); - m_pLastBlockWithAvailCells = NULL; - } - - // Unlink from blocks-with-avail-cells list - - if( pBlockToUnlink->pNextBlockWithAvailCells) - { - pBlockToUnlink-> - pNextBlockWithAvailCells->pPrevBlockWithAvailCells = - pBlockToUnlink->pPrevBlockWithAvailCells; - pBlockToUnlink->pNextBlockWithAvailCells = NULL; - - flmAssert( !pBlockToUnlink->pPrevBlockWithAvailCells); - } - - // Decrement the block count - - flmAssert( m_uiBlocksWithAvailCells); - m_uiBlocksWithAvailCells--; - } - } - else - { - // If our m_pFirstBlock is completely full, or there is no - // m_pFirstBlock, it is time to allocate a new block - - if( !m_pFirstBlock || - (m_pFirstBlock->ui32NextNeverUsedCell == m_uiCellsPerBlock)) - { - BLOCK * pNewBlock; - - if( (pNewBlock = getAnotherBlock()) == NULL) - { - goto Exit; - } - - if( m_pFirstBlock) - { - pNewBlock->pNext = m_pFirstBlock; - m_pFirstBlock->pPrev = pNewBlock; - } - else - { - m_pLastBlock = pNewBlock; - } - - m_pFirstBlock = pNewBlock; - } - - pBlock = m_pFirstBlock; - pBlock->ui32AllocatedCells++; - flmAssert( pBlock->ui32AllocatedCells <= m_uiCellsPerBlock); - - pHeader = (CELLHEADER *) - ((FLMBYTE *)pBlock + m_uiBlockHeaderSize + - (m_uiSizeOfCellAndHeader * m_pFirstBlock->ui32NextNeverUsedCell)); - - pCell = ((FLMBYTE *)pHeader + m_uiCellHeaderSize); - m_pFirstBlock->ui32NextNeverUsedCell++; - } - - pHeader->pContainingBlock = pBlock; - -#ifdef FLM_DEBUG - if (gv_FlmSysData.bTrackLeaks && gv_FlmSysData.bStackWalk) - { - pHeader->puiStack = memWalkStack(); - } - else - { - pHeader->puiStack = NULL; - } -#endif - - m_uiAllocatedCells++; - m_uiAllocatedCellWatermark = - f_max( m_uiAllocatedCells, m_uiAllocatedCellWatermark); - -Exit: - - return( pCell); -} - -/**************************************************************************** -Desc: Public method to free a cell of memory back to the system. -****************************************************************************/ -void F_FixedAlloc::freeCell( - void * pCell, - FLMBOOL bMutexLocked, - FLMBOOL bFreeIfEmpty, - FLMBOOL * pbFreedBlock) -{ - CELLAVAILNEXT * pCellContents; - CELLHEADER * pHeader; - BLOCK * pBlock; - FLMBOOL bUnlockMutex = FALSE; - - if( pbFreedBlock) - { - *pbFreedBlock = FALSE; - } - - if( !pCell) - { - return; - } - - if( !bMutexLocked && m_phMutex) - { - f_mutexLock( *m_phMutex); - bUnlockMutex = TRUE; - } - - pCellContents = (CELLAVAILNEXT *)pCell; - pHeader = (CELLHEADER *)(((FLMBYTE *)pCell) - m_uiCellHeaderSize); - pBlock = pHeader->pContainingBlock; - - flmAssert( pBlock); - flmAssert( pBlock->pvAllocator == (void *)this); - - pHeader->pContainingBlock = NULL; - -#ifdef FLM_DEBUG - if( pHeader->puiStack) - { - os_free( pHeader->puiStack); - pHeader->puiStack = NULL; - } -#endif - - // Should always be set on a free - - flmAssert( m_pFirstBlock); - - // Add the cell to the pBlock's free list - - pCellContents->pNextInList = pBlock->pLocalAvailCellListHead; - -#ifdef FLM_DEBUG - // Write out a string that's easy to see in memory when debugging - - f_strcpy( pCellContents->szDebugPattern, "FREECELL"); -#endif - - flmAssert( pCell); - pBlock->pLocalAvailCellListHead = (FLMBYTE *)pCell; - pBlock->ui32AvailCellCount++; - - flmAssert( pBlock->ui32AllocatedCells); - pBlock->ui32AllocatedCells--; - - // If there's no chain, make this one the first - - if( !m_pFirstBlockWithAvailCells) - { - m_pFirstBlockWithAvailCells = pBlock; - m_pLastBlockWithAvailCells = pBlock; - flmAssert( !pBlock->pNextBlockWithAvailCells); - flmAssert( !pBlock->pPrevBlockWithAvailCells); - m_uiBlocksWithAvailCells++; - m_bAvailListSorted = TRUE; - } - else if( pBlock->ui32AvailCellCount == 1) - { - // This item is not linked in to the chain, so link it in - - if( m_bAvailListSorted && pBlock > m_pFirstBlockWithAvailCells) - { - m_bAvailListSorted = FALSE; - } - - pBlock->pNextBlockWithAvailCells = m_pFirstBlockWithAvailCells; - pBlock->pPrevBlockWithAvailCells = NULL; - m_pFirstBlockWithAvailCells->pPrevBlockWithAvailCells = pBlock; - m_pFirstBlockWithAvailCells = pBlock; - m_uiBlocksWithAvailCells++; - } - - // Adjust counter, because the cell is now considered free - - m_uiTotalFreeCells++; - - // If this block is now totally avail - - if( pBlock->ui32AvailCellCount == m_uiCellsPerBlock) - { - flmAssert( !pBlock->ui32AllocatedCells); - - // If we have met our threshold for being able to free a block - - if( m_uiTotalFreeCells >= m_uiCellsPerBlock || bFreeIfEmpty) - { - freeBlock( pBlock); - if( pbFreedBlock) - { - *pbFreedBlock = TRUE; - } - } - else if( pBlock != m_pFirstBlockWithAvailCells) - { - // Link the block to the front of the avail list so that - // it can be freed quickly at some point in the future - - if( pBlock->pPrevBlockWithAvailCells) - { - pBlock->pPrevBlockWithAvailCells->pNextBlockWithAvailCells = - pBlock->pNextBlockWithAvailCells; - } - - if( pBlock->pNextBlockWithAvailCells) - { - pBlock->pNextBlockWithAvailCells->pPrevBlockWithAvailCells = - pBlock->pPrevBlockWithAvailCells; - } - else - { - flmAssert( m_pLastBlockWithAvailCells == pBlock); - m_pLastBlockWithAvailCells = pBlock->pPrevBlockWithAvailCells; - } - - if( m_pFirstBlockWithAvailCells) - { - m_pFirstBlockWithAvailCells->pPrevBlockWithAvailCells = pBlock; - } - - pBlock->pPrevBlockWithAvailCells = NULL; - pBlock->pNextBlockWithAvailCells = m_pFirstBlockWithAvailCells; - m_pFirstBlockWithAvailCells = pBlock; - } - } - - m_uiAllocatedCells--; - m_uiEverFreedCells++; - - if( bUnlockMutex) - { - f_mutexUnlock( *m_phMutex); - } -} - -/**************************************************************************** -Desc: Grabs another slab of memory from the operating system -****************************************************************************/ -F_FixedAlloc::BLOCK * F_FixedAlloc::getAnotherBlock( void) -{ - BLOCK * pBlock = NULL; - - if( RC_BAD( m_pSlabManager->allocSlab( (void **)&pBlock))) - { - goto Exit; - } - - if (m_puiTotalBytesAllocated) - { - (*m_puiTotalBytesAllocated) += m_uiSlabSize; - } - - // Initialize the block header fields - - f_memset( pBlock, 0, sizeof( BLOCK)); - pBlock->pvAllocator = (void *)this; - m_uiAllocatedSlabs++; - -Exit: - - return( pBlock); -} - -/**************************************************************************** -Desc: Private internal method to free an unused empty block back to the OS. -****************************************************************************/ -void F_FixedAlloc::freeBlock( - BLOCK * pBlock) -{ - flmAssert( pBlock); - flmAssert( !pBlock->ui32AllocatedCells); - flmAssert( pBlock->pvAllocator == this); - - // Unlink from all-blocks-list - - if( pBlock->pNext) - { - pBlock->pNext->pPrev = pBlock->pPrev; - } - else - { - m_pLastBlock = pBlock->pPrev; - } - - if( pBlock->pPrev) - { - pBlock->pPrev->pNext = pBlock->pNext; - } - else - { - m_pFirstBlock = pBlock->pNext; - } - - // Unlink from blocks-with-avail-cells list - - if( pBlock->pNextBlockWithAvailCells) - { - pBlock->pNextBlockWithAvailCells->pPrevBlockWithAvailCells = - pBlock->pPrevBlockWithAvailCells; - } - else - { - m_pLastBlockWithAvailCells = pBlock->pPrevBlockWithAvailCells; - } - - if( pBlock->pPrevBlockWithAvailCells) - { - pBlock->pPrevBlockWithAvailCells->pNextBlockWithAvailCells = - pBlock->pNextBlockWithAvailCells; - } - else - { - m_pFirstBlockWithAvailCells = pBlock->pNextBlockWithAvailCells; - } - - flmAssert( m_uiBlocksWithAvailCells); - m_uiBlocksWithAvailCells--; - flmAssert( m_uiTotalFreeCells >= pBlock->ui32AvailCellCount); - m_uiTotalFreeCells -= pBlock->ui32AvailCellCount; - m_uiAllocatedSlabs--; - - if (m_puiTotalBytesAllocated) - { - flmAssert( *m_puiTotalBytesAllocated >= m_uiSlabSize); - (*m_puiTotalBytesAllocated) -= m_uiSlabSize; - } - - m_pSlabManager->freeSlab( (void **)&pBlock); -} - -/**************************************************************************** -Desc: Public method to free all the memory in the system. -****************************************************************************/ -void F_FixedAlloc::freeAll( void) -{ - BLOCK * pFreeMe; - - if( m_phMutex) - { - f_mutexLock( *m_phMutex); - } - - while( m_pFirstBlock) - { - pFreeMe = m_pFirstBlock; - m_pFirstBlock = m_pFirstBlock->pNext; - freeBlock( pFreeMe); - } - - flmAssert( !m_uiTotalFreeCells); - - m_pFirstBlock = NULL; - m_pLastBlock = NULL; - m_pFirstBlockWithAvailCells = NULL; - m_pLastBlockWithAvailCells = NULL; - m_uiBlocksWithAvailCells = 0; - m_bAvailListSorted = TRUE; - m_uiTotalFreeCells = 0; - m_uiAllocatedSlabs = 0; - m_uiAllocatedCells = 0; - - if( m_phMutex) - { - f_mutexUnlock( *m_phMutex); - } -} - -/**************************************************************************** -Desc: -****************************************************************************/ -void F_FixedAlloc::getStats( - FLM_ALLOC_USAGE * pUsage) -{ - f_memset( pUsage, 0, sizeof( FLM_ALLOC_USAGE)); - - if( m_phMutex) - { - f_mutexLock( *m_phMutex); - } - - pUsage->ui64Slabs = m_uiAllocatedSlabs; - pUsage->ui64SlabBytes = m_uiAllocatedSlabs * m_uiSlabSize; - pUsage->ui64AllocatedCells = m_uiAllocatedCells; - pUsage->ui64FreeCells = m_uiTotalFreeCells; - - if( m_phMutex) - { - f_mutexUnlock( *m_phMutex); - } -} - -/**************************************************************************** -Desc: If a relocation callback function has been registered, and memory - can be compressed, the avail list will be compressed -****************************************************************************/ -void F_FixedAlloc::defragmentMemory( void) -{ - BLOCK * pCurBlock; - BLOCK * pPrevSib; - CELLHEADER * pCellHeader; - FLMBOOL bBlockFreed; - FLMBYTE * pucOriginal; - FLMBYTE * pucReloc = NULL; - FLMUINT uiLoop; - BLOCK ** pSortBuf = NULL; - FLMUINT uiMaxSortEntries; - FLMUINT uiSortEntries = 0; -#define SMALL_SORT_BUF_SIZE 256 - BLOCK * smallSortBuf[ SMALL_SORT_BUF_SIZE]; - - if( m_phMutex) - { - f_mutexLock( *m_phMutex); - } - - if( !m_fnRelocate || m_uiTotalFreeCells < m_uiCellsPerBlock) - { - goto Exit; - } - - uiMaxSortEntries = m_uiBlocksWithAvailCells; - - // Re-sort the blocks in the avail list according to - // their memory addresses to help reduce logical fragmentation - - if( !m_bAvailListSorted && uiMaxSortEntries > 1) - { - if( uiMaxSortEntries <= SMALL_SORT_BUF_SIZE) - { - pSortBuf = smallSortBuf; - } - else - { - if( RC_BAD( f_alloc( uiMaxSortEntries * sizeof( BLOCK *), &pSortBuf))) - { - goto Exit; - } - } - - pCurBlock = m_pFirstBlockWithAvailCells; - - while( pCurBlock) - { - flmAssert( uiSortEntries != uiMaxSortEntries); - pSortBuf[ uiSortEntries++] = pCurBlock; - pCurBlock = pCurBlock->pNextBlockWithAvailCells; - } - - // Quick sort - - flmAssert( uiSortEntries); - - f_qsort( (FLMBYTE *)pSortBuf, 0, uiSortEntries - 1, - F_FixedAlloc::blockAddrCompareFunc, - F_FixedAlloc::blockAddrSwapFunc); - - // Re-link the items in the list according to the new - // sort order - - m_pFirstBlockWithAvailCells = NULL; - m_pLastBlockWithAvailCells = NULL; - - pCurBlock = NULL; - pPrevSib = NULL; - - for( uiLoop = 0; uiLoop < uiSortEntries; uiLoop++) - { - pCurBlock = pSortBuf[ uiLoop]; - pCurBlock->pNextBlockWithAvailCells = NULL; - pCurBlock->pPrevBlockWithAvailCells = NULL; - - if( pPrevSib) - { - pCurBlock->pPrevBlockWithAvailCells = pPrevSib; - pPrevSib->pNextBlockWithAvailCells = pCurBlock; - } - else - { - m_pFirstBlockWithAvailCells = pCurBlock; - } - - pPrevSib = pCurBlock; - } - - m_pLastBlockWithAvailCells = pCurBlock; - m_bAvailListSorted = TRUE; - } - - // Process the avail list (which should be sorted unless - // we are too low on memory) - - pCurBlock = m_pLastBlockWithAvailCells; - - while( pCurBlock) - { - if( m_uiTotalFreeCells < m_uiCellsPerBlock) - { - // No need to continue ... we aren't above the - // free cell threshold - - goto Exit; - } - - pPrevSib = pCurBlock->pPrevBlockWithAvailCells; - - if( pCurBlock == m_pFirstBlockWithAvailCells || - !pCurBlock->ui32AvailCellCount) - { - // We've either hit the beginning of the avail list or - // the block that we are now positioned on has been - // removed from the avail list. In either case, - // we are done. - - break; - } - - if( pCurBlock->ui32AvailCellCount == m_uiCellsPerBlock || - pCurBlock->ui32NextNeverUsedCell == pCurBlock->ui32AvailCellCount) - { - freeBlock( pCurBlock); - pCurBlock = pPrevSib; - continue; - } - - for( uiLoop = 0; uiLoop < pCurBlock->ui32NextNeverUsedCell && - pCurBlock != m_pFirstBlockWithAvailCells && - m_uiTotalFreeCells >= m_uiCellsPerBlock; uiLoop++) - { - pCellHeader = (CELLHEADER *) - ((FLMBYTE *)pCurBlock + m_uiBlockHeaderSize + - (uiLoop * m_uiSizeOfCellAndHeader)); - - if( pCellHeader->pContainingBlock) - { - // If pContainingBlock is non-NULL, the cell is currently allocated - - flmAssert( pCellHeader->pContainingBlock == pCurBlock); - - pucOriginal = ((FLMBYTE *)pCellHeader + m_uiCellHeaderSize); - - if( !m_fnCanRelocate || m_fnCanRelocate( pucOriginal)) - { - if( (pucReloc = (FLMBYTE *)getCell()) == NULL) - { - goto Exit; - } - - f_memcpy( pucReloc, pucOriginal, m_uiCellSize); - m_fnRelocate( pucOriginal, pucReloc); - freeCell( pucOriginal, TRUE, TRUE, &bBlockFreed); - - if( bBlockFreed) - { - break; - } - } - } - } - - pCurBlock = pPrevSib; - } - -Exit: - - if( m_phMutex) - { - f_mutexUnlock( *m_phMutex); - } - - if( pSortBuf && pSortBuf != smallSortBuf) - { - f_free( &pSortBuf); - } -} - -/**************************************************************************** -Desc: -****************************************************************************/ -void F_FixedAlloc::incrementTotalBytesAllocated( - FLMUINT uiCount) -{ - if( m_puiTotalBytesAllocated) - { - if( m_phMutex) - { - f_mutexLock( *m_phMutex); - } - - *m_puiTotalBytesAllocated += uiCount; - - if( m_phMutex) - { - f_mutexUnlock( *m_phMutex); - } - } -} - -/**************************************************************************** -Desc: -****************************************************************************/ -FLMUINT F_FixedAlloc::getTotalBytesAllocated( void) -{ - FLMUINT uiTotal = 0; - - if( m_puiTotalBytesAllocated) - { - if( m_phMutex) - { - f_mutexLock( *m_phMutex); - } - - uiTotal = *m_puiTotalBytesAllocated; - - if( m_phMutex) - { - f_mutexUnlock( *m_phMutex); - } - } - - return( uiTotal); -} - -/**************************************************************************** -Desc: -****************************************************************************/ -void F_FixedAlloc::decrementTotalBytesAllocated( - FLMUINT uiCount) -{ - if( m_puiTotalBytesAllocated) - { - if( m_phMutex) - { - f_mutexLock( *m_phMutex); - } - - flmAssert( *m_puiTotalBytesAllocated >= uiCount); - *m_puiTotalBytesAllocated -= uiCount; - - if( m_phMutex) - { - f_mutexUnlock( *m_phMutex); - } - } -} - -/**************************************************************************** -Desc: -****************************************************************************/ -void F_FixedAlloc::freeUnused( void) -{ - BLOCK * pBlock; - - if( m_phMutex) - { - f_mutexLock( *m_phMutex); - } - - if( (pBlock = m_pFirstBlockWithAvailCells) != NULL && - !pBlock->ui32AllocatedCells) - { - freeBlock( pBlock); - } - - if( (pBlock = m_pFirstBlock) != NULL && - !pBlock->ui32AllocatedCells) - { - freeBlock( pBlock); - } - - if( m_phMutex) - { - f_mutexUnlock( *m_phMutex); - } -} - -/**************************************************************************** -Desc: Debug method to do mem leak testing. Any cells allocated via - allocCell but not freed via freeCell() will be triggered here. -****************************************************************************/ -#ifdef FLM_DEBUG -void F_FixedAlloc::testForLeaks( void) -{ - BLOCK * pBlockRover = m_pFirstBlock; - CELLHEADER * pHeader; - FLMUINT uiLoop; - F_MEM_HDR memHeader; - - // Test for leaks - - while( pBlockRover) - { - for( uiLoop = 0; uiLoop < pBlockRover->ui32NextNeverUsedCell; uiLoop++) - { - pHeader = (CELLHEADER*) - ((FLMBYTE*)pBlockRover + m_uiBlockHeaderSize + - (uiLoop * m_uiSizeOfCellAndHeader)); - - // Nonzero here means we have a leak - - if( pHeader->pContainingBlock) - { - // We have a leak, so let's call logMemLeak with the - // appropriate header passed in - - f_memset( &memHeader, 0, sizeof( F_MEM_HDR)); - memHeader.uiDataSize = m_uiCellSize; - memHeader.puiStack = pHeader->puiStack; - logMemLeak( &memHeader); - } - } - - pBlockRover = pBlockRover->pNext; - } -} -#endif - -/**************************************************************************** -Desc: -****************************************************************************/ -F_BufferAlloc::~F_BufferAlloc() -{ - FLMUINT uiLoop; - - if( m_phMutex) - { - f_mutexLock( *m_phMutex); - } - - for (uiLoop = 0; uiLoop < NUM_BUF_ALLOCATORS; uiLoop++) - { - if( m_ppAllocators[ uiLoop]) - { - m_ppAllocators[ uiLoop]->Release(); - m_ppAllocators[ uiLoop] = NULL; - } - } - - if( m_pSlabManager) - { - m_pSlabManager->Release(); - } - - if( m_phMutex) - { - f_mutexUnlock( *m_phMutex); - } -} - -/**************************************************************************** -Desc: -****************************************************************************/ -RCODE F_BufferAlloc::setup( - F_SlabManager * pSlabManager, - F_MUTEX * phMutex, - FLMUINT * puiTotalBytesAllocated) -{ - RCODE rc = FERR_OK; - FLMUINT uiLoop; - FLMUINT uiSize; - - flmAssert( pSlabManager); - m_pSlabManager = pSlabManager; - m_pSlabManager->AddRef(); - - m_puiTotalBytesAllocated = puiTotalBytesAllocated; - for( uiLoop = 0; uiLoop < NUM_BUF_ALLOCATORS; uiLoop++) - { - if( (m_ppAllocators[ uiLoop] = f_new F_FixedAlloc) == NULL) - { - rc = RC_SET( FERR_MEM); - goto Exit; - } - - switch (uiLoop) - { - case 0: - uiSize = CELL_SIZE_0; - break; - case 1: - uiSize = CELL_SIZE_1; - break; - case 2: - uiSize = CELL_SIZE_2; - break; - case 3: - uiSize = CELL_SIZE_3; - break; - case 4: - uiSize = CELL_SIZE_4; - break; - case 5: - uiSize = CELL_SIZE_5; - break; - case 6: - uiSize = CELL_SIZE_6; - break; - case 7: - uiSize = CELL_SIZE_7; - break; - case 8: - uiSize = CELL_SIZE_8; - break; - case 9: - uiSize = CELL_SIZE_9; - break; - case 10: - uiSize = CELL_SIZE_10; - break; - case 11: - uiSize = CELL_SIZE_11; - break; - case 12: - uiSize = CELL_SIZE_12; - break; - case 13: - uiSize = CELL_SIZE_13; - break; - case 14: - uiSize = CELL_SIZE_14; - break; - case 15: - uiSize = CELL_SIZE_15; - break; - case 16: - uiSize = CELL_SIZE_16; - break; - case 17: - uiSize = CELL_SIZE_17; - break; - case 18: - uiSize = CELL_SIZE_18; - break; - case 19: - uiSize = CELL_SIZE_19; - break; - case 20: - uiSize = CELL_SIZE_20; - break; - case 21: - uiSize = CELL_SIZE_21; - break; - default: - uiSize = 0; - flmAssert( 0); - break; - } - - if (RC_BAD( rc = m_ppAllocators[ uiLoop]->setup( - pSlabManager, (FLMBOOL)FALSE, uiSize, puiTotalBytesAllocated))) - { - goto Exit; - } - } - - m_phMutex = phMutex; - -Exit: - - return( rc); -} - -/**************************************************************************** -Desc: -****************************************************************************/ -void F_BufferAlloc::setRelocationFuncs( - FLM_CAN_RELOC_FUNC fnCanRelocate, - FLM_RELOC_FUNC fnRelocate) -{ - FLMUINT uiLoop; - - flmAssert( fnCanRelocate); - flmAssert( fnRelocate); - - if( m_phMutex) - { - f_mutexLock( *m_phMutex); - } - - for( uiLoop = 0; uiLoop < NUM_BUF_ALLOCATORS; uiLoop++) - { - if( m_ppAllocators[ uiLoop]) - { - m_ppAllocators[ uiLoop]->setRelocationFuncs( - fnCanRelocate, fnRelocate); - } - - uiLoop++; - } - - if( m_phMutex) - { - f_mutexUnlock( *m_phMutex); - } -} - -/**************************************************************************** -Desc: -****************************************************************************/ -RCODE F_BufferAlloc::allocBuf( - FLMUINT uiSize, - void * pvInitialData, - FLMUINT uiDataSize, - FLMBYTE ** ppucBuffer, - FLMBOOL * pbAllocatedOnHeap) -{ - RCODE rc = FERR_OK; - F_FixedAlloc * pAllocator = getAllocator( uiSize); - - if( m_phMutex) - { - f_mutexLock( *m_phMutex); - } - - if( pbAllocatedOnHeap) - { - *pbAllocatedOnHeap = FALSE; - } - - if( pAllocator) - { - flmAssert( pAllocator->getCellSize() >= uiSize); - - if( (*ppucBuffer = (FLMBYTE *)pAllocator->allocCell( - pvInitialData, uiDataSize)) == NULL) - { - rc = RC_SET( FERR_MEM); - goto Exit; - } - } - else - { - if( RC_BAD( rc = f_alloc( uiSize, ppucBuffer))) - { - goto Exit; - } - - if( m_puiTotalBytesAllocated) - { - (*m_puiTotalBytesAllocated) += f_msize( *ppucBuffer); - } - - if( pvInitialData) - { - f_memcpy( *ppucBuffer, pvInitialData, uiDataSize); - } - - if( pbAllocatedOnHeap) - { - *pbAllocatedOnHeap = TRUE; - } - } - -Exit: - - if( m_phMutex) - { - f_mutexUnlock( *m_phMutex); - } - - return( rc); -} - -/**************************************************************************** -Desc: -****************************************************************************/ -RCODE F_BufferAlloc::reallocBuf( - FLMUINT uiOldSize, - FLMUINT uiNewSize, - void * pvInitialData, - FLMUINT uiDataSize, - FLMBYTE ** ppucBuffer, - FLMBOOL * pbAllocatedOnHeap) -{ - RCODE rc = FERR_OK; - FLMBYTE * pucTmp; - F_FixedAlloc * pOldAllocator; - F_FixedAlloc * pNewAllocator; - FLMBOOL bMutexLocked = FALSE; - - flmAssert( uiNewSize); - - if( !uiOldSize) - { - rc = allocBuf( uiNewSize, pvInitialData, uiDataSize, - ppucBuffer, pbAllocatedOnHeap); - goto Exit; - } - - if( m_phMutex) - { - f_mutexLock( *m_phMutex); - bMutexLocked = TRUE; - } - - if( pbAllocatedOnHeap) - { - *pbAllocatedOnHeap = FALSE; - } - - pOldAllocator = getAllocator( uiOldSize); - pNewAllocator = getAllocator( uiNewSize); - - if( pOldAllocator) - { - if( pNewAllocator) - { - if( pOldAllocator == pNewAllocator) - { - // The allocation will still fit in the same cell - - goto Exit; - } - - if( (pucTmp = (FLMBYTE *)pNewAllocator->allocCell()) == NULL) - { - rc = RC_SET( FERR_MEM); - goto Exit; - } - } - else - { - if( RC_BAD( rc = f_alloc( uiNewSize, &pucTmp))) - { - goto Exit; - } - - if( m_puiTotalBytesAllocated) - { - (*m_puiTotalBytesAllocated) += f_msize( pucTmp); - } - - if( pbAllocatedOnHeap) - { - *pbAllocatedOnHeap = TRUE; - } - } - - f_memcpy( pucTmp, *ppucBuffer, f_min( uiOldSize, uiNewSize)); - pOldAllocator->freeCell( *ppucBuffer); - *ppucBuffer = pucTmp; - } - else - { - if( pNewAllocator) - { - if( m_puiTotalBytesAllocated) - { - FLMUINT uiAllocSize = f_msize( *ppucBuffer); - - flmAssert( *m_puiTotalBytesAllocated >= uiAllocSize); - (*m_puiTotalBytesAllocated) -= uiAllocSize; - } - - if( (pucTmp = (FLMBYTE *)pNewAllocator->allocCell( - *ppucBuffer, f_min( uiOldSize, uiNewSize))) == NULL) - { - rc = RC_SET( FERR_MEM); - goto Exit; - } - - f_free( ppucBuffer); - *ppucBuffer = pucTmp; - } - else - { - FLMUINT uiAllocSize = f_msize( *ppucBuffer); - - flmAssert( uiOldSize > m_ppAllocators[ NUM_BUF_ALLOCATORS - 1]->getCellSize()); - flmAssert( uiNewSize > m_ppAllocators[ NUM_BUF_ALLOCATORS - 1]->getCellSize()); - - if( RC_BAD( rc = f_realloc( uiNewSize, ppucBuffer))) - { - goto Exit; - } - - if( m_puiTotalBytesAllocated) - { - flmAssert( *m_puiTotalBytesAllocated >= uiAllocSize); - (*m_puiTotalBytesAllocated) -= uiAllocSize; - (*m_puiTotalBytesAllocated) += f_msize( *ppucBuffer); - } - - if( pbAllocatedOnHeap) - { - *pbAllocatedOnHeap = TRUE; - } - } - } - -Exit: - - if( bMutexLocked) - { - f_mutexUnlock( *m_phMutex); - } - - return( rc); -} - -/**************************************************************************** -Desc: -****************************************************************************/ -void F_BufferAlloc::freeBuf( - FLMUINT uiSize, - FLMBYTE ** ppucBuffer) -{ - F_FixedAlloc * pAllocator = getAllocator( uiSize); - - if( m_phMutex) - { - f_mutexLock( *m_phMutex); - } - - if( pAllocator) - { - pAllocator->freeCell( *ppucBuffer, FALSE, TRUE, NULL); - *ppucBuffer = NULL; - } - else - { - if( m_puiTotalBytesAllocated) - { - FLMUINT uiAllocSize = f_msize( *ppucBuffer); - - flmAssert( *m_puiTotalBytesAllocated >= uiAllocSize); - (*m_puiTotalBytesAllocated) -= uiAllocSize; - } - - f_free( ppucBuffer); - } - - if( m_phMutex) - { - f_mutexUnlock( *m_phMutex); - } -} - -/**************************************************************************** -Desc: -****************************************************************************/ -void F_BufferAlloc::defragmentMemory( void) -{ - FLMUINT uiLoop; - - if( m_phMutex) - { - f_mutexLock( *m_phMutex); - } - - for( uiLoop = 0; uiLoop < NUM_BUF_ALLOCATORS; uiLoop++) - { - if( m_ppAllocators[ uiLoop]) - { - m_ppAllocators[ uiLoop]->defragmentMemory(); - m_ppAllocators[ uiLoop]->freeUnused(); - } - - uiLoop++; - } - - if( m_phMutex) - { - f_mutexUnlock( *m_phMutex); - } -} - -/**************************************************************************** -Desc: -****************************************************************************/ -FLMUINT F_BufferAlloc::getTrueSize( - FLMUINT uiSize, - FLMBYTE * pucBuffer) -{ - FLMUINT uiTrueSize; - F_FixedAlloc * pAllocator; - - if( !uiSize) - { - uiTrueSize = 0; - } - else if( (pAllocator = getAllocator( uiSize)) != NULL) - { - uiTrueSize = pAllocator->getCellSize(); - } - else - { - uiTrueSize = f_msize( pucBuffer); - } - - return( uiTrueSize); -} - -/**************************************************************************** -Desc: -****************************************************************************/ -F_FixedAlloc * F_BufferAlloc::getAllocator( - FLMUINT uiSize) -{ - F_FixedAlloc * pAllocator; - - flmAssert( uiSize); - - if( uiSize <= CELL_SIZE_10) - { - if( uiSize <= CELL_SIZE_4) - { - if( uiSize <= CELL_SIZE_2) - { - if( uiSize <= CELL_SIZE_0) - { - pAllocator = (F_FixedAlloc *)m_ppAllocators [0]; - } - else - { - pAllocator = (F_FixedAlloc *)(uiSize <= CELL_SIZE_1 - ? m_ppAllocators [1] - : m_ppAllocators [2]); - } - } - else - { - pAllocator = (F_FixedAlloc *)(uiSize <= CELL_SIZE_3 - ? m_ppAllocators [3] - : m_ppAllocators [4]); - } - } - else if( uiSize <= CELL_SIZE_7) - { - if( uiSize <= CELL_SIZE_5) - { - pAllocator = (F_FixedAlloc *)m_ppAllocators [5]; - } - else - { - pAllocator = (F_FixedAlloc *)(uiSize <= CELL_SIZE_6 - ? m_ppAllocators [6] - : m_ppAllocators [7]); - } - } - else - { - if( uiSize <= CELL_SIZE_8) - { - pAllocator = (F_FixedAlloc *)m_ppAllocators [8]; - } - else - { - pAllocator = (F_FixedAlloc *)(uiSize <= CELL_SIZE_9 - ? m_ppAllocators [9] - : m_ppAllocators [10]); - } - } - } - else if( uiSize <= CELL_SIZE_16) - { - if( uiSize <= CELL_SIZE_13) - { - if( uiSize <= CELL_SIZE_11) - { - pAllocator = (F_FixedAlloc *)m_ppAllocators [11]; - } - else - { - pAllocator = (F_FixedAlloc *)(uiSize <= CELL_SIZE_12 - ? m_ppAllocators [12] - : m_ppAllocators [13]); - } - } - else - { - if( uiSize <= CELL_SIZE_14) - { - pAllocator = (F_FixedAlloc *)m_ppAllocators [14]; - } - else - { - pAllocator = (F_FixedAlloc *)(uiSize <= CELL_SIZE_15 - ? m_ppAllocators [15] - : m_ppAllocators [16]); - } - } - } - else if( uiSize <= CELL_SIZE_19) - { - if( uiSize <= CELL_SIZE_17) - { - pAllocator = (F_FixedAlloc *)m_ppAllocators [17]; - } - else - { - pAllocator = (F_FixedAlloc *)(uiSize <= CELL_SIZE_18 - ? m_ppAllocators [18] - : m_ppAllocators [19]); - } - } - else if( uiSize <= CELL_SIZE_21) - { - pAllocator = (F_FixedAlloc *)(uiSize <= CELL_SIZE_20 - ? m_ppAllocators [20] - : m_ppAllocators [21]); - } - else - { - pAllocator = NULL; - } - - return( pAllocator); -} diff --git a/flaim/src/flfixed.h b/flaim/src/flfixed.h deleted file mode 100644 index e282915..0000000 --- a/flaim/src/flfixed.h +++ /dev/null @@ -1,445 +0,0 @@ -//------------------------------------------------------------------------- -// Desc: Memory management using fixed-size allocators - for dealing with -// memory fragmentation issues - definitions. -// Tabs: 3 -// -// Copyright (c) 2004-2006 Novell, Inc. All Rights Reserved. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of version 2 of the GNU General Public -// License as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, contact Novell, Inc. -// -// To contact Novell about this file by physical or electronic mail, -// you may find current contact information at www.novell.com -// -// $Id: flfixed.h 12334 2006-01-23 12:45:35 -0700 (Mon, 23 Jan 2006) dsanders $ -//------------------------------------------------------------------------- - -#ifndef FLFIXED_H -#define FLFIXED_H - -#include "fpackon.h" - -/**************************************************************************** -Desc: -****************************************************************************/ -class F_SlabManager : public F_Base -{ -public: - - F_SlabManager(); - - virtual ~F_SlabManager(); - - RCODE setup( - FLMUINT uiPreallocSize, - FLMUINT uiMinSlabSize = 64 * 1024); - - RCODE allocSlab( - void ** ppSlab); - - void freeSlab( - void ** ppSlab); - - FINLINE FLMUINT getSlabSize( void) - { - return( m_uiSlabSize); - } - - RCODE resize( - FLMUINT uiNumBytes, - FLMUINT * puiActualSize = NULL); - -private: - - void freeAllSlabs( void); - - void * allocSlabFromSystem( void); - - void releaseSlabToSystem( - void * pSlab); - - RCODE sortSlabList( void); - - typedef struct SLABHEADER - { - void * pPrev; - void * pNext; - } SLABHEADER; - - static FLMINT slabAddrCompareFunc( - void * pvBuffer, - FLMUINT uiPos1, - FLMUINT uiPos2); - - static void slabAddrSwapFunc( - void * pvBuffer, - FLMUINT uiPos1, - FLMUINT uiPos2); - - F_MUTEX m_hMutex; - void * m_pFirstInSlabList; - void * m_pLastInSlabList; - FLMUINT m_uiSlabSize; - FLMUINT m_uiTotalSlabs; - FLMUINT m_uiAvailSlabs; - FLMUINT m_uiInUseSlabs; - void * m_pLowPrealloc; - void * m_pHighPrealloc; -}; - -// Cell sizes for buffer allocator - -#define CELL_SIZE_0 64 -#define CELL_SIZE_1 128 -#define CELL_SIZE_2 192 -#define CELL_SIZE_3 320 -#define CELL_SIZE_4 512 -#define CELL_SIZE_5 672 -#define CELL_SIZE_6 832 -#define CELL_SIZE_7 1088 -#define CELL_SIZE_8 1344 -#define CELL_SIZE_9 1760 -#define CELL_SIZE_10 2176 -#define CELL_SIZE_11 2848 -#define CELL_SIZE_12 3520 -#define CELL_SIZE_13 4608 -#define CELL_SIZE_14 5152 -#define CELL_SIZE_15 5696 -#define CELL_SIZE_16 8164 -#define CELL_SIZE_17 13068 -#define CELL_SIZE_18 16340 -#define CELL_SIZE_19 21796 -#define CELL_SIZE_20 32700 -#define CELL_SIZE_21 65420 - -#define NUM_BUF_ALLOCATORS 22 - -typedef struct FLM_ALLOC_USAGE -{ - FLMUINT64 ui64Slabs; - FLMUINT64 ui64SlabBytes; - FLMUINT64 ui64AllocatedCells; - FLMUINT64 ui64FreeCells; -} FLM_ALLOC_USAGE; - -typedef void (* FLM_RELOC_FUNC)( - void * pvOldAlloc, - void * pvNewAlloc); - -typedef FLMBOOL (* FLM_CAN_RELOC_FUNC)( - void * pvOldAlloc); - -typedef void (* FLM_ALLOC_INIT_FUNC)( - void * pvAlloc); - -/**************************************************************************** -Desc: Class to provide an efficient means of providing many allocations - of a fixed size. -****************************************************************************/ -class F_FixedAlloc : public F_Base -{ -public: - - F_FixedAlloc(); - - virtual ~F_FixedAlloc(); - - RCODE setup( - F_SlabManager * pSlabManager, - FLMBOOL bUseMutex, - FLMUINT uiCellSize, - FLMUINT * puiTotalBytesAllocated); - - RCODE setup( - F_SlabManager * pSlabManager, - F_MUTEX * phMutex, - FLMUINT uiCellSize, - FLMUINT * puiTotalBytesAllocated); - - FINLINE void setRelocationFuncs( - FLM_CAN_RELOC_FUNC fnCanRelocate, - FLM_RELOC_FUNC fnRelocate) - { - flmAssert( fnCanRelocate); - flmAssert( fnRelocate); - - m_fnCanRelocate = fnCanRelocate; - m_fnRelocate = fnRelocate; - } - - FINLINE void * allocCell( - void * pvInitialData = NULL, - FLMUINT uiDataSize = 0) - { - void * pvCell; - - if( m_phMutex) - { - f_mutexLock( *m_phMutex); - } - - pvCell = getCell(); - - if( pvCell && pvInitialData) - { - f_memcpy( pvCell, pvInitialData, uiDataSize); - } - - if( m_phMutex) - { - f_mutexUnlock( *m_phMutex); - } - - return( pvCell); - } - - FINLINE void * allocCell( - FLM_ALLOC_INIT_FUNC fnAllocInit) - { - void * pvCell; - - if( m_phMutex) - { - f_mutexLock( *m_phMutex); - } - - pvCell = getCell(); - - if( pvCell && fnAllocInit) - { - fnAllocInit( pvCell); - } - - if( m_phMutex) - { - f_mutexUnlock( *m_phMutex); - } - - return( pvCell); - } - - FINLINE void freeCell( - void * ptr) - { - freeCell( ptr, FALSE, FALSE, NULL); - } - - void freeUnused( void); - - void freeAll( void); - - void getStats( - FLM_ALLOC_USAGE * pUsage); - - FINLINE FLMUINT getCellSize( void) - { - return( m_uiCellSize); - } - - void defragmentMemory( void); - - void incrementTotalBytesAllocated( - FLMUINT uiCount); - - void decrementTotalBytesAllocated( - FLMUINT uiCount); - - FLMUINT getTotalBytesAllocated( void); - - F_MUTEX * getMutex( void) - { - return( m_phMutex); - } - - typedef struct BLOCK - { - void * pvAllocator; - BLOCK * pNext; - BLOCK * pPrev; - BLOCK * pNextBlockWithAvailCells; - BLOCK * pPrevBlockWithAvailCells; - FLMBYTE * pLocalAvailCellListHead; - FLMUINT32 ui32NextNeverUsedCell; - FLMUINT32 ui32AvailCellCount; - FLMUINT32 ui32AllocatedCells; - } BLOCK; - - typedef struct CELLHEADER - { - BLOCK * pContainingBlock; -#ifdef FLM_DEBUG - FLMUINT * puiStack; -#endif - } CELLHEADER; - - typedef struct CELLAVAILNEXT - { - FLMBYTE * pNextInList; -#ifdef FLM_DEBUG - char szDebugPattern[ 8]; -#endif - } CELLAVAILNEXT; - -private: - - void * getCell( void); - - BLOCK * getAnotherBlock( void); - - static FINLINE FLMUINT getAllocAlignedSize( - FLMUINT uiAskedForSize) - { - return( (uiAskedForSize + FLM_ALLOC_ALIGN) & (~FLM_ALLOC_ALIGN)); - } - - void freeBlock( - BLOCK * pBlock); - - void freeCell( - void * pCell, - FLMBOOL bMutexLocked, - FLMBOOL bFreeIfEmpty, - FLMBOOL * pbFreedBlock); - -#ifdef FLM_DEBUG - void testForLeaks( void); -#endif - - FINLINE static FLMINT blockAddrCompareFunc( - void * pvBuffer, - FLMUINT uiPos1, - FLMUINT uiPos2) - { - BLOCK * pBlock1 = (((BLOCK **)pvBuffer)[ uiPos1]); - BLOCK * pBlock2 = (((BLOCK **)pvBuffer)[ uiPos2]); - - flmAssert( pBlock1 != pBlock2); - - if( pBlock1 < pBlock2) - { - return( -1); - } - - return( 1); - } - - FINLINE static void blockAddrSwapFunc( - void * pvBuffer, - FLMUINT uiPos1, - FLMUINT uiPos2) - { - BLOCK ** ppBlock1 = &(((BLOCK **)pvBuffer)[ uiPos1]); - BLOCK ** ppBlock2 = &(((BLOCK **)pvBuffer)[ uiPos2]); - BLOCK * pTmp; - - pTmp = *ppBlock1; - *ppBlock1 = *ppBlock2; - *ppBlock2 = pTmp; - } - - F_SlabManager * m_pSlabManager; - BLOCK * m_pFirstBlock; - BLOCK * m_pLastBlock; - BLOCK * m_pFirstBlockWithAvailCells; - BLOCK * m_pLastBlockWithAvailCells; - FLMBOOL m_bAvailListSorted; - FLMUINT m_uiBlocksWithAvailCells; - FLMUINT m_uiBlockHeaderSize; - FLMUINT m_uiCellHeaderSize; - FLMUINT m_uiCellSize; - FLMUINT m_uiSizeOfCellAndHeader; - FLMUINT m_uiTotalFreeCells; - FLMUINT m_uiCellsPerBlock; - - F_MUTEX m_hLocalMutex; - F_MUTEX * m_phMutex; - - FLM_CAN_RELOC_FUNC m_fnCanRelocate; - FLM_RELOC_FUNC m_fnRelocate; - FLMUINT * m_puiTotalBytesAllocated; - FLMUINT m_uiSlabSize; - - // Members specifically for stats - - FLMUINT m_uiAllocatedSlabs; - FLMUINT m_uiAllocatedCells; - FLMUINT m_uiAllocatedCellWatermark; - FLMUINT m_uiEverFreedCells; - -friend class F_BufferAlloc; -}; - -/**************************************************************************** -Desc: -****************************************************************************/ -class F_BufferAlloc : public F_Base -{ -public: - - F_BufferAlloc() - { - f_memset( m_ppAllocators, 0, sizeof( m_ppAllocators)); - m_pSlabManager = NULL; - m_puiTotalBytesAllocated = NULL; - m_phMutex = NULL; - } - - virtual ~F_BufferAlloc(); - - RCODE setup( - F_SlabManager * pSlabManager, - F_MUTEX * phMutex, - FLMUINT * puiTotalBytesAllocated); - - void setRelocationFuncs( - FLM_CAN_RELOC_FUNC fnCanRelocate, - FLM_RELOC_FUNC fnRelocate); - - RCODE allocBuf( - FLMUINT uiSize, - void * pvInitialData, - FLMUINT uiDataSize, - FLMBYTE ** ppucBuffer, - FLMBOOL * pbAllocatedOnHeap); - - RCODE reallocBuf( - FLMUINT uiOldSize, - FLMUINT uiNewSize, - void * pvInitialData, - FLMUINT uiDataSize, - FLMBYTE ** ppucBuffer, - FLMBOOL * pbAllocatedOnHeap); - - void freeBuf( - FLMUINT uiSize, - FLMBYTE ** ppucBuffer); - - FLMUINT getTrueSize( - FLMUINT uiSize, - FLMBYTE * pucBuffer); - - void defragmentMemory( void); - -private: - - F_FixedAlloc * getAllocator( - FLMUINT uiSize); - - F_SlabManager * m_pSlabManager; - F_FixedAlloc * m_ppAllocators[ NUM_BUF_ALLOCATORS]; - FLMUINT * m_puiTotalBytesAllocated; - F_MUTEX * m_phMutex; -}; - -#include "fpackoff.h" - -#endif // FLFIXED_H diff --git a/flaim/src/flindex.cpp b/flaim/src/flindex.cpp index e997024..25c238f 100644 --- a/flaim/src/flindex.cpp +++ b/flaim/src/flindex.cpp @@ -25,7 +25,7 @@ #include "flaimsys.h" FSTATIC RCODE flmBackgroundIndexBuildThrd( - F_Thread * pThread); + IF_Thread * pThread); FSTATIC void stopBackgroundIndexThread( FDB * pDb, @@ -917,8 +917,9 @@ FSTATIC void stopBackgroundIndexThread( // The thread may be waiting to start a transaction. - gv_FlmSysData.pServerLockMgr->SignalLockWaiter( uiThreadId); - + pDb->pFile->pFileLockObj->timeoutLockWaiter( uiThreadId); + pDb->pFile->pWriteLockObj->timeoutLockWaiter( uiThreadId); + if( !bWait) { break; @@ -1053,8 +1054,8 @@ RCODE flmStartIndexBuild( // Generate the thread name - if (RC_BAD( rc = f_pathReduce( pDb->pFile->pszDbPath, - szThreadName, szBaseName))) + if (RC_BAD( rc = gv_FlmSysData.pFileSystem->pathReduce( + pDb->pFile->pszDbPath, szThreadName, szBaseName))) { goto Exit; } @@ -1067,7 +1068,7 @@ RCODE flmStartIndexBuild( if( RC_BAD( rc = f_threadCreate( NULL, flmBackgroundIndexBuildThrd, szThreadName, - FLM_BACKGROUND_INDEXING_THREAD_GROUP, uiIndexNum, + gv_uiBackIxThrdGroup, uiIndexNum, (void *)pBackgroundIx, NULL, 24000))) { goto Exit; @@ -1089,7 +1090,7 @@ Desc: Thread that will build an index in the background. freed at the conclusion of the routine. ****************************************************************************/ FSTATIC RCODE flmBackgroundIndexBuildThrd( - F_Thread * pThread) + IF_Thread * pThread) { RCODE rc = FERR_OK; IXD * pIxd; @@ -1155,6 +1156,8 @@ Loop_Again: goto Exit; } + flmAssert( pDb->pSFileHdl); + bDbInitialized = TRUE; if (RC_BAD( rc = fdbInit( pDb, FLM_NO_TRANS, 0, 0, &bStartedTrans))) { @@ -1181,9 +1184,9 @@ Loop_Again: // Obtain the file lock flmAssert( !(pDb->uiFlags & FDB_HAS_FILE_LOCK)); - if( RC_BAD( rc = pDb->pFile->pFileLockObj->Lock( TRUE, pDb, FALSE, + if( RC_BAD( rc = pDb->pFile->pFileLockObj->lock( pDb->hWaitSem, TRUE, FLM_NO_TIMEOUT, FLM_BACKGROUND_LOCK_PRIORITY, - pDb->pDbStats))) + pDb->pDbStats ? &pDb->pDbStats->LockStats : NULL))) { if( rc == FERR_IO_FILE_LOCK_ERR) { @@ -1214,7 +1217,7 @@ Loop_Again: pDb->pFile->pFileLockObj->haveHigherPriorityWaiter( FLM_BACKGROUND_LOCK_PRIORITY)) { - if (RC_BAD( rc = pDb->pFile->pFileLockObj->Unlock( TRUE, pDb))) + if (RC_BAD( rc = pDb->pFile->pFileLockObj->unlock())) { iErrorLine = (FLMINT)__LINE__; goto Exit; @@ -1421,7 +1424,7 @@ Exit: if( pDb && pDb->uiFlags & FDB_HAS_FILE_LOCK) { - (void)pDb->pFile->pFileLockObj->Unlock( TRUE, pDb); + (void)pDb->pFile->pFileLockObj->unlock(); pDb->uiFlags &= ~(FDB_HAS_FILE_LOCK | FDB_FILE_LOCK_IMPLICIT); } @@ -1513,7 +1516,7 @@ F_BKGND_IX * flmBackgroundIndexGet( FLMUINT * puiThreadId) { RCODE rc = FERR_OK; - F_Thread * pThread; + IF_Thread * pThread; FLMUINT uiThreadId; F_BKGND_IX * pBackgroundIx = NULL; @@ -1526,7 +1529,7 @@ F_BKGND_IX * flmBackgroundIndexGet( for( ;;) { if( RC_BAD( rc = gv_FlmSysData.pThreadMgr->getNextGroupThread( - &pThread, FLM_BACKGROUND_INDEXING_THREAD_GROUP, &uiThreadId))) + &pThread, gv_uiBackIxThrdGroup, &uiThreadId))) { if( rc == FERR_NOT_FOUND) { @@ -1579,7 +1582,7 @@ FSTATIC RCODE flmIndexStatusCS( RCODE rc = FERR_OK; CS_CONTEXT * pCSContext = pDb->pCSContext; FCL_WIRE Wire( pCSContext, pDb); - void * pvMark = GedPoolMark( &pCSContext->pool); + void * pvMark = pCSContext->pool.poolMark(); // Set the temporary pool @@ -1622,7 +1625,7 @@ FSTATIC RCODE flmIndexStatusCS( Exit: - GedPoolReset( &pCSContext->pool, pvMark); + pCSContext->pool.poolReset( pvMark); return( rc); Transmission_Error: diff --git a/flaim/src/flist.cpp b/flaim/src/flist.cpp deleted file mode 100644 index d2b12f6..0000000 --- a/flaim/src/flist.cpp +++ /dev/null @@ -1,385 +0,0 @@ -//------------------------------------------------------------------------- -// Desc: List class. -// Tabs: 3 -// -// Copyright (c) 1997-2000,2003,2005-2006 Novell, Inc. All Rights Reserved. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of version 2 of the GNU General Public -// License as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, contact Novell, Inc. -// -// To contact Novell about this file by physical or electronic mail, -// you may find current contact information at www.novell.com -// -// $Id: flist.cpp 12263 2006-01-19 14:43:23 -0700 (Thu, 19 Jan 2006) dsanders $ -//------------------------------------------------------------------------- - -#include "flaimsys.h" - -/*************************************************************************** -* * -* F_ListMgr Class * -* * -****************************************************************************/ - -/**************************************************************************** -Desc: Setup the pLNode array and set the count. -****************************************************************************/ -RCODE F_ListMgr::Setup( - F_ListNode * pLNodes, - FLMUINT uiLNodeCnt) -{ - flmAssert( pLNodes && uiLNodeCnt ); - - // Set the pLNodes array to null values. - - m_uiLNodeCnt = uiLNodeCnt; - m_pLNodes = pLNodes; - - f_memset( pLNodes, 0, sizeof( F_ListNode) * uiLNodeCnt ); - return FERR_OK; -} - -/**************************************************************************** -Desc: Insert an item into the first of a list. -****************************************************************************/ -void F_ListMgr::InsertAtFirst( - FLMUINT uiList, // List to insert this item. - F_ListItem * pNewFirstItem) // New item to be inserted at the first. -{ - F_ListNode * pLNode; - - // Check bounds with assert. - // This should be fine because uiList values are defined. - - flmAssert( uiList < m_uiLNodeCnt ); - - pNewFirstItem->AddRef(); - - pLNode = &m_pLNodes[ uiList ]; - - if( pLNode->pNextItem == NULL) - { - // New last and first item. - - pLNode->pPrevItem = pNewFirstItem; - pNewFirstItem->SetNextListItem( uiList, NULL); - } - else - { - // Add this new item to the first of the list. - pLNode->pNextItem->SetPrevListItem( uiList, pNewFirstItem ); - pNewFirstItem->SetNextListItem( uiList, pLNode->pNextItem); - } - - pLNode->pNextItem = pNewFirstItem; - pNewFirstItem->SetPrevListItem( uiList, NULL); - pNewFirstItem->m_bInList = TRUE; - - // Increment the list's count element - pLNode->uiListCount++; - - return; -} - - -/**************************************************************************** -Desc: Insert an item into the end of a list. -****************************************************************************/ -void F_ListMgr::InsertAtEnd( - FLMUINT uiList, // List to insert this item. - F_ListItem * pNewLastItem) // New item to be inserted at the end. -{ - F_ListNode * pLNode; - - // Check bounds with assert. - // This should be fine because uiList values are defined. - - flmAssert( uiList < m_uiLNodeCnt ); - - pNewLastItem->AddRef(); - - pLNode = &m_pLNodes[ uiList ]; - - if( pLNode->pPrevItem == NULL) - { - // New last and first item. - pLNode->pNextItem = pNewLastItem; - pNewLastItem->SetPrevListItem( uiList, NULL); - } - else - { - // Add this new item to the end of the list. - pLNode->pPrevItem->SetNextListItem( uiList, pNewLastItem); - pNewLastItem->SetPrevListItem( uiList, pLNode->pPrevItem); - } - - pLNode->pPrevItem = pNewLastItem; - pNewLastItem->SetNextListItem( uiList, NULL); - pNewLastItem->m_bInList = TRUE; - - // Increment the list's count element - pLNode->uiListCount++; - - return; -} - -/**************************************************************************** -Desc: Obtain an item from the list. Do not remove the item from the list. -****************************************************************************/ -F_ListItem * F_ListMgr::GetItem( - FLMUINT uiList, // List to get the item from. - FLMUINT nth) // Which item to retrieve (0 == first) -{ - F_ListNode * pLNode; - F_ListItem * pListItem; - - // Check bounds with assert. - - flmAssert( uiList < m_uiLNodeCnt ); - - pLNode = &m_pLNodes[ uiList ]; - - pListItem = pLNode ? pLNode->pNextItem : NULL; - - while( nth-- ) - { - pListItem = pListItem->GetNextListItem( uiList ); - } - - return pListItem; -} - -/**************************************************************************** -Desc: Remove the supplied ListItem object from the specified list. -****************************************************************************/ -void F_ListMgr::RemoveItem( - FLMUINT uiList, - F_ListItem * pItem) -{ - F_ListNode * pMgrLNode; /* Manager's list node (head/tail pointers)*/ - F_ListItem * pPrevItem; - F_ListItem * pNextItem; - - flmAssert( uiList < m_uiLNodeCnt); - - pMgrLNode = &m_pLNodes[ uiList]; - - /* Get this item's Prev and Next items. */ - - pPrevItem = pItem->GetPrevListItem( uiList); - pNextItem = pItem->GetNextListItem( uiList); - - if( pPrevItem == NULL && pNextItem == NULL - && pMgrLNode->pPrevItem != pItem - && pMgrLNode->pNextItem != pItem) - { - /* If the item is not within the list then skip to the end. - Note: Need to also make sure this item is not the head or tail. */ - goto Exit; - } - - /* Determine if this item is pointed to by the head or tail pointers - that the list manager maintains. */ - - if( pMgrLNode->pPrevItem == pItem) - { - pMgrLNode->pPrevItem = pItem->GetPrevListItem( uiList); - } - - if( pMgrLNode->pNextItem == pItem) - { - pMgrLNode->pNextItem = pItem->GetNextListItem( uiList); - } - - /* If there is a prev item - change it's next ptr to be items next ptr */ - if( pPrevItem != NULL) - { - pPrevItem->SetNextListItem( uiList, pItem->GetNextListItem( uiList)); - } - - /* If there is a next item - change it's prev ptr to be items prev ptr */ - if( pNextItem != NULL) - { - pNextItem->SetPrevListItem( uiList, pItem->GetPrevListItem( uiList)); - } - - /* Clear out this items prev and next links */ - pItem->SetPrevListItem( uiList, NULL); - pItem->SetNextListItem( uiList, NULL); - pItem->m_bInList = FALSE; - - /* This list no longer needs a reference to this object. */ - pItem->Release(); - - /* Decrement this list's count element */ - pMgrLNode->uiListCount--; - -Exit: - return; -} - -/**************************************************************************** -Desc: Unlink all items from a single specified list or all lists. -****************************************************************************/ -RCODE F_ListMgr::ClearList( - FLMUINT uiList) // List number or FLM_ALL_LISTS -{ - FLMUINT uiListCnt; - F_ListNode * pLNode; - - // Check bounds with assert. - flmAssert( (FLM_ALL_LISTS == uiList) || (uiList < m_uiLNodeCnt)); - - if( uiList == FLM_ALL_LISTS) - { - uiList = 0; - uiListCnt = m_uiLNodeCnt; - pLNode = m_pLNodes; - } - else - { - uiListCnt = 1; - pLNode = &m_pLNodes[ uiList ]; - } - - for( ; uiListCnt--; pLNode++, uiList++) - { - F_ListItem * pItem; - F_ListItem * pNextItem; - - // Go through the list Releasing every list item. - - for( pItem = pLNode->pNextItem; pItem; pItem = pNextItem) - { - pNextItem = pItem->GetNextListItem( uiList); - - (void) RemoveItem( uiList, pItem); - } - - // At this point the ListCount should be at 0. - flmAssert( pLNode->uiListCount == 0); - - // Clear the managers head and tail list pointers. - pLNode->pNextItem = pLNode->pPrevItem = NULL; - } - return FERR_OK; -} - -/**************************************************************************** -Desc: Obtain an the number of items within a list. -****************************************************************************/ -FLMUINT F_ListMgr::GetCount( - FLMUINT uiList) // List to get the item count from. -{ - FLMUINT uiLNodeCnt; - FLMUINT uiCount = 0; - F_ListNode * pLNode; - - // Check bounds with assert. - flmAssert( (FLM_ALL_LISTS == uiList) || (uiList < m_uiLNodeCnt)); - - if( uiList == FLM_ALL_LISTS) - { - uiLNodeCnt = m_uiLNodeCnt; - pLNode = m_pLNodes; - } - else - { - uiLNodeCnt = 1; - pLNode = &m_pLNodes[ uiList]; - } - - /* Calculate the count for the list[s] */ - - for( ; uiLNodeCnt--; pLNode++) - { - uiCount += pLNode->uiListCount; - } - - return uiCount; -} - -/**************************************************************************** -Desc: Destructor -****************************************************************************/ -F_ListItem::~F_ListItem() -{ -#ifdef FLM_DEBUG - FLMUINT uiLoop; - F_ListNode * pTmpNd; - - flmAssert( m_bInList == FALSE); - - for( uiLoop = 0; uiLoop < m_uiLNodeCnt; uiLoop++) - { - pTmpNd = &m_pLNodes[ uiLoop]; - flmAssert( pTmpNd->pPrevItem == NULL && pTmpNd->pNextItem == NULL); - } -#endif -} - -/**************************************************************************** -Desc: Setup the pLNode array and set the count. -Visit: We may want to add code in the future to check if Setup() has - been previous called. If so recode for uiLNodeCnt to be zero. -****************************************************************************/ -RCODE F_ListItem::Setup( - F_ListMgr * pList, // List manager to use - F_ListNode * pLNodes, // Array of LNODEs to be used - FLMUINT uiLNodeCnt) // Number of LNODEs supplied. -{ - flmAssert( pList != NULL); - flmAssert( pLNodes != NULL); - flmAssert( uiLNodeCnt != 0); - - m_pListMgr = pList; - m_uiLNodeCnt = uiLNodeCnt; - m_pLNodes = pLNodes; - - f_memset( pLNodes, 0, sizeof( F_ListNode) * uiLNodeCnt ); - return FERR_OK; -} - -/**************************************************************************** -Desc: Remove this list item from all of the lists it is in. -****************************************************************************/ -RCODE F_ListItem::RemoveFromList( // Remove this list item from all lists. - FLMUINT uiList) // Which list to remove item from - // To remove item from all lists pass in - // FLM_ALL_LISTS define. -{ - - flmAssert( (uiList < m_uiLNodeCnt) || (uiList == FLM_ALL_LISTS)); - - if( uiList == FLM_ALL_LISTS) - { - FLMUINT uiListCnt = m_uiLNodeCnt; - F_ListNode * pLNode = m_pLNodes; - - uiList = 0; - - /* Remove this item from all lists. */ - - for( ; uiListCnt--; uiList++, pLNode++) - { - m_pListMgr->RemoveItem( uiList, this); - } - } - else - { - /* Remove item from a specific list. */ - m_pListMgr->RemoveItem( uiList, this); - } - - return FERR_OK; -} - diff --git a/flaim/src/flist.h b/flaim/src/flist.h deleted file mode 100644 index 990faa5..0000000 --- a/flaim/src/flist.h +++ /dev/null @@ -1,94 +0,0 @@ -//------------------------------------------------------------------------- -// Desc: List class definitions. -// Tabs: 3 -// -// Copyright (c) 1997-2000,2002-2006 Novell, Inc. All Rights Reserved. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of version 2 of the GNU General Public -// License as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, contact Novell, Inc. -// -// To contact Novell about this file by physical or electronic mail, -// you may find current contact information at www.novell.com -// -// $Id: flist.h 12329 2006-01-20 17:49:30 -0700 (Fri, 20 Jan 2006) ahodgkinson $ -//------------------------------------------------------------------------- - -#ifndef FLIST_H -#define FLIST_H - -#include "fpackon.h" -// IMPORTANT NOTE: No other include files should follow this one except -// for fpackoff.h - -#define FLM_ALL_LISTS 0xFFFF - -class F_ListMgr : public F_Base -{ -public: - - F_ListMgr() - { - m_uiLNodeCnt = 0; - m_pLNodes = NULL; - } - - virtual ~F_ListMgr() - { - (void) ClearList( FLM_ALL_LISTS); - } - - RCODE Setup( // Finish the setup operation. - F_ListNode * pLNodes, // LNodes to use - FLMUINT uiLNodeCnt); // Number of lists that this obj will - // manage. - - void InsertAtFirst( // Insert new list item at the first of - // the list. - FLMUINT uiList, // Which list to insert this item into - F_ListItem * pNewFirstItem); // New item to be inserted - - void InsertAtEnd( // Insert the new list item at the end of - // list - FLMUINT uiList, // Which list to insert this item into - F_ListItem * pNewLastItem); // New item to be inserted - - F_ListItem * GetItem( // Retrieve a specific item from the list - FLMUINT uiList, // Which list to get item from - FLMUINT nth); // Which item to retrieve (0 == first) - - void RemoveItem( // Remove supplied item from the specified list - FLMUINT uiList, - F_ListItem * pItem); - - FINLINE FLMUINT GetListCount() // Returns the number of lists that this - { // object manages. - return m_uiLNodeCnt; - } - - FLMUINT GetCount( // Returns the number of items within a list. - FLMUINT uiList); - - RCODE ClearList( // Unlink all items from a specified list. - FLMUINT uiList = 0); // Which list to clear. To clear all lists - // pass in the FLM_ALL_LISTS define. - -private: - - FLMUINT m_uiLNodeCnt; // Number of lists (F_ListNode lists) that this - // list object is managing. - F_ListNode * m_pLNodes; // The Lists (LNODEs) that this object - // manages. -}; - -#include "fpackoff.h" - -#endif diff --git a/flaim/src/flkeyret.cpp b/flaim/src/flkeyret.cpp index a52c458..3b21099 100644 --- a/flaim/src/flkeyret.cpp +++ b/flaim/src/flkeyret.cpp @@ -81,7 +81,7 @@ FLMEXP RCODE FLMAPI FlmKeyRetrieve( goto Exit; } - pvMark = GedPoolMark( &(pDb->TempPool)); + pvMark = pDb->TempPool.poolMark(); if( IsInCSMode( hDb)) { @@ -94,21 +94,23 @@ FLMEXP RCODE FLMAPI FlmKeyRetrieve( if( pKeyTree || (uiFlag & FO_LAST)) { - pSearchKeyBuf = (FLMBYTE *) GedPoolAlloc( &(pDb->TempPool), - MAX_KEY_SIZ + 4); + if( RC_BAD( rc = pDb->TempPool.poolAlloc( MAX_KEY_SIZ + 4, + (void **)&pSearchKeyBuf))) + { + goto Exit; + } } else { pSearchKeyBuf = pSmallBuf; } - pKeyBuf = (FLMBYTE *) GedPoolAlloc( &pDb->TempPool, MAX_KEY_SIZ + 4); - if( !pSearchKeyBuf || !pKeyBuf) + + if( RC_BAD( rc = pDb->TempPool.poolAlloc( MAX_KEY_SIZ + 4, + (void **)&pKeyBuf))) { - rc = RC_SET( FERR_MEM); goto Exit; } - /* Initialize the OPC */ - + if( RC_BAD( rc = fdbInit( pDb, FLM_READ_TRANS, FDB_TRANS_GOING_OK, 0, &bImplicitTrans))) { @@ -120,6 +122,7 @@ FLMEXP RCODE FLMAPI FlmKeyRetrieve( { goto Exit; } + if( RC_BAD( rc = KYFlushKeys( pDb))) { goto Exit; @@ -424,7 +427,7 @@ Exit: Exit_CS: - GedPoolReset( &(pDb->TempPool), pvMark); + pDb->TempPool.poolReset( pvMark); flmExit( FLM_KEY_RETRIEVE, pDb, rc); return( rc); @@ -448,7 +451,7 @@ FSTATIC RCODE flmKeyRetrieveCS( RCODE rc; CS_CONTEXT * pCSContext = pDb->pCSContext; FCL_WIRE Wire( pCSContext, pDb); - void * pvMark = GedPoolMark( &pCSContext->pool); + void * pvMark = pCSContext->pool.poolMark(); /* Set the record object so that it can be re-used, @@ -568,7 +571,7 @@ FSTATIC RCODE flmKeyRetrieveCS( Exit: - GedPoolReset( &pCSContext->pool, pvMark); + pCSContext->pool.poolReset( pvMark); return( rc); Transmission_Error: diff --git a/flaim/src/flmimon.h b/flaim/src/flmimon.h index 3de9dfb..17ef0c9 100644 --- a/flaim/src/flmimon.h +++ b/flaim/src/flmimon.h @@ -112,7 +112,7 @@ enum ButtonTypes Desc: The F_WebPage class, from which all of the various web page classes will be defined. *****************************************************************************/ -class F_WebPage : public F_Base +class F_WebPage : public F_Object { public: @@ -192,7 +192,7 @@ public: FINLINE int fnSendBuffer( const void * pvBuf, - size_t bufsz) + FLMSIZET bufsz) { return( gv_FlmSysData.HttpConfigParms.fnSendBuffer( m_pHRequest, pvBuf, bufsz)); @@ -225,7 +225,7 @@ public: void * pvHSession, const char * pcTag, const void * pvData, - size_t uiSize) + FLMSIZET uiSize) { return( gv_FlmSysData.HttpConfigParms.fnSetSessionValue( pvHSession, pcTag, pvData, uiSize)); @@ -235,7 +235,7 @@ public: void * pvHSession, const char * pcTag, void * pvData, - size_t * puiSize) + FLMSIZET * puiSize) { return( gv_FlmSysData.HttpConfigParms.fnGetSessionValue( pvHSession, pcTag, pvData, puiSize)); @@ -244,7 +244,7 @@ public: FINLINE int fnGetGblValue( const char * pcTag, void * pvData, - size_t * puiSize) + FLMSIZET * puiSize) { return( gv_FlmSysData.HttpConfigParms.fnGetGblValue( pcTag, pvData, puiSize)); @@ -253,7 +253,7 @@ public: FINLINE int fnSetGblValue( const char * pcTag, const void * pvData, - size_t uiSize) + FLMSIZET uiSize) { return( gv_FlmSysData.HttpConfigParms.fnSetGblValue( pcTag, pvData, uiSize)); @@ -261,7 +261,7 @@ public: FINLINE int fnRecvBuffer( void * pvBuf, - size_t * puiBufSize) + FLMSIZET * puiBufSize) { return( gv_FlmSysData.HttpConfigParms.fnRecvBuffer( m_pHRequest, pvBuf, puiBufSize)); @@ -671,7 +671,7 @@ Desc: The NameTableMgr class *****************************************************************************/ #define TABLE_ARRAY_SIZE 10 -class F_NameTableMgr : public F_Base +class F_NameTableMgr : public F_Object { public: @@ -698,7 +698,7 @@ private: F_NameTable * pNameTable; } m_tablearray[ TABLE_ARRAY_SIZE]; - f_randomGenerator m_rgen; + IF_RandomGenerator * m_pRandomGen; }; /**************************************************************************** @@ -717,7 +717,7 @@ typedef struct #define FLM_SECURE_PASSWORD "SecureCoreDbPassword" #define FLM_SECURE_EXPIRATION "SecureCoreDbExpiration" -class F_WebPageFactory : public F_Base +class F_WebPageFactory : public F_Object { public: F_WebPageFactory() { sortRegistry(); } @@ -731,7 +731,7 @@ public: void Release( F_WebPage ** ppPage); - FINLINE FLMINT Release( void) + FINLINE FLMINT FLMAPI Release( void) { flmAssert( 0); return( 0); @@ -833,23 +833,6 @@ private: DATASTRUCT * pDataStruct); }; -/**************************************************************************** -Desc: The class that displays the FFILE structures. -*****************************************************************************/ -class F_FileHdlPage : public F_WebPage -{ -public: - - RCODE display( - FLMUINT uiNumParams, - const char ** ppszParams); - -private: - - void write_data( - F_FileHdlImp * pFileHdl); -}; - /**************************************************************************** Desc: The class that displays the gv_FlmSysData.pFileHashTbl hash table. *****************************************************************************/ @@ -862,24 +845,6 @@ public: const char ** ppszParams); }; -/**************************************************************************** -Desc: The class that displays the gv_FlmSysData.pFileHdlMgr. -*****************************************************************************/ -class F_FileHdlMgrPage : public F_WebPage -{ -public: - - RCODE display( - FLMUINT uiNumParams, - const char ** ppszParams); - -private: - - void formatTime( - FLMUINT uiTimerUnits, - char * pszFormattedTime); -}; - /********************************************************* Desc: Return HTML code that defines the welcome page frames. There are two framesets. The first has one frame @@ -1032,18 +997,6 @@ public: const char ** ppszParams); }; -/**************************************************************************** -Desc: The class that displays information about FLAIM return codes -*****************************************************************************/ -class F_RCodeLookupPage : public F_WebPage -{ -public: - - RCODE display( - FLMUINT uiNumParams, - const char ** ppszParams); -}; - /**************************************************************************** Desc: The class that allows interaction with a database *****************************************************************************/ @@ -1479,8 +1432,8 @@ typedef struct focusTag typedef struct LockUserHeader { FLMBYTE szFileName[50]; - LOCK_USER * pDbLockUser; - LOCK_USER * pTxLockUser; + F_LOCK_USER * pDbLockUser; + F_LOCK_USER * pTxLockUser; struct LockUserHeader * pNext; } LOCK_USER_HEADER, * LOCK_USER_HEADER_p; @@ -1498,18 +1451,18 @@ typedef struct StatGatherTag FLMUINT uiStopTime; FLMUINT uiNumDbStats; FLMUINT uiNumLFileStats; - COUNT_TIME_STAT CommittedUpdTrans; - COUNT_TIME_STAT GroupCompletes; + F_COUNT_TIME_STAT CommittedUpdTrans; + F_COUNT_TIME_STAT GroupCompletes; FLMUINT64 ui64GroupFinished; - COUNT_TIME_STAT AbortedUpdTrans; - COUNT_TIME_STAT CommittedReadTrans; - COUNT_TIME_STAT AbortedReadTrans; - COUNT_TIME_STAT Reads; - COUNT_TIME_STAT Adds; - COUNT_TIME_STAT Modifies; - COUNT_TIME_STAT Deletes; - COUNT_TIME_STAT Queries; - COUNT_TIME_STAT QueryReads; + F_COUNT_TIME_STAT AbortedUpdTrans; + F_COUNT_TIME_STAT CommittedReadTrans; + F_COUNT_TIME_STAT AbortedReadTrans; + F_COUNT_TIME_STAT Reads; + F_COUNT_TIME_STAT Adds; + F_COUNT_TIME_STAT Modifies; + F_COUNT_TIME_STAT Deletes; + F_COUNT_TIME_STAT Queries; + F_COUNT_TIME_STAT QueryReads; FLMUINT64 ui64BlockCombines; FLMUINT64 ui64BlockSplits; DISKIO_STAT IOReads; @@ -1531,9 +1484,7 @@ typedef struct StatGatherTag DISKIO_STAT IOLogHdrWrites; DISKIO_STAT IORolledbackBlockWrites; FLMUINT uiWriteErrors; - COUNT_TIME_STAT NoLocks; - COUNT_TIME_STAT WaitingForLock; - COUNT_TIME_STAT HeldLock; + F_LOCK_STATS LockStats; FLM_CACHE_USAGE BlockCache; FLM_CACHE_USAGE RecordCache; FLMUINT uiDirtyBlocks; @@ -1603,11 +1554,11 @@ private: DISKIO_STAT * pOldIOStat); void printCountTimeRow( - FLMBOOL bHighlight, - const char * pszCategory, - COUNT_TIME_STAT * pStat, - COUNT_TIME_STAT * pOldStat, - FLMBOOL bPrintCountOnly = FALSE); + FLMBOOL bHighlight, + const char * pszCategory, + F_COUNT_TIME_STAT * pStat, + F_COUNT_TIME_STAT * pOldStat, + FLMBOOL bPrintCountOnly = FALSE); void printCacheStatRow( FLMBOOL bHighlight, @@ -1753,7 +1704,7 @@ typedef struct CheckStatusTag char * pszDataDir; char * pszRflDir; char * pszLogFileName; - F_FileHdl * pLogFile; + IF_FileHdl * pLogFile; F_NameTable * pNameTable; FLMBOOL bCheckingIndexes; FLMBOOL bRepairingIndexes; @@ -1767,7 +1718,7 @@ typedef struct CheckStatusTag DB_CHECK_PROGRESS Progress; FLMUINT uiLastTimeSetStatus; FLMUINT uiUpdateStatusInterval; - F_Thread * pThread; + IF_Thread * pThread; } CHECK_STATUS; /**************************************************************************** @@ -1860,7 +1811,7 @@ typedef struct IndexListStatusTag FLMUINT uiLastTimeSetStatus; FLMUINT uiUpdateStatusInterval; char szEndStatus [80]; - F_Thread * pThread; + IF_Thread * pThread; } IXLIST_STATUS; /**************************************************************************** @@ -1938,7 +1889,7 @@ void printAddress( Desc: Utility class to help prepare a character buffer for printing when the output buffer size is not known in advance. *****************************************************************************/ -class F_DynamicBuffer : public F_Base +class F_DynamicBuffer : public F_Object { public: @@ -1999,18 +1950,6 @@ private: }; -/********************************************************* -Desc: Displays the Server Lock Manager object... -**********************************************************/ -class F_ServerLockMgrPage : public F_WebPage -{ -public: - - RCODE display( - FLMUINT uiNumParams, - const char ** pszParams); -}; - /********************************************************* Desc: Processes Record add, modify, delete, retrieve requests as well as Record field copy, insert (child & sibling) and diff --git a/flaim/src/flmstat.cpp b/flaim/src/flmstat.cpp index bafa6c1..91a2f0f 100644 --- a/flaim/src/flmstat.cpp +++ b/flaim/src/flmstat.cpp @@ -803,37 +803,55 @@ FSTATIC RCODE flmUpdateDbStats( flmUpdateRTransStats( &pDestDb->ReadTransStats, &pSrcDb->ReadTransStats); + flmUpdateUTransStats( &pDestDb->UpdateTransStats, &pSrcDb->UpdateTransStats); + pDestDb->bHaveStats = TRUE; pDestDb->ui64NumCursors += pSrcDb->ui64NumCursors; pDestDb->ui64NumCursorReads += pSrcDb->ui64NumCursorReads; + flmUpdateCountTimeStats( &pDestDb->RecordAdds, - &pSrcDb->RecordAdds); + &pSrcDb->RecordAdds); + flmUpdateCountTimeStats( &pDestDb->RecordDeletes, - &pSrcDb->RecordDeletes); + &pSrcDb->RecordDeletes); + flmUpdateCountTimeStats( &pDestDb->RecordModifies, - &pSrcDb->RecordModifies); + &pSrcDb->RecordModifies); + pDestDb->ui64NumRecordReads += pSrcDb->ui64NumRecordReads; + flmUpdateBlockIOStats( &pDestDb->LFHBlockStats, - &pSrcDb->LFHBlockStats); + &pSrcDb->LFHBlockStats); + flmUpdateBlockIOStats( &pDestDb->AvailBlockStats, - &pSrcDb->AvailBlockStats); + &pSrcDb->AvailBlockStats); + flmUpdateDiskIOStats( &pDestDb->LogHdrWrites, - &pSrcDb->LogHdrWrites); + &pSrcDb->LogHdrWrites); + flmUpdateDiskIOStats( &pDestDb->LogBlockWrites, - &pSrcDb->LogBlockWrites); + &pSrcDb->LogBlockWrites); + flmUpdateDiskIOStats( &pDestDb->LogBlockRestores, - &pSrcDb->LogBlockRestores); + &pSrcDb->LogBlockRestores); + flmUpdateDiskIOStats( &pDestDb->LogBlockReads, - &pSrcDb->LogBlockReads); + &pSrcDb->LogBlockReads); + pDestDb->uiLogBlockChkErrs += pSrcDb->uiLogBlockChkErrs; pDestDb->uiReadErrors += pSrcDb->uiReadErrors; pDestDb->uiWriteErrors += pSrcDb->uiWriteErrors; - flmUpdateCountTimeStats( &pDestDb->NoLocks, &pSrcDb->NoLocks); - flmUpdateCountTimeStats( &pDestDb->WaitingForLock, - &pSrcDb->WaitingForLock); - flmUpdateCountTimeStats( &pDestDb->HeldLock, &pSrcDb->HeldLock); + + flmUpdateCountTimeStats( &pDestDb->LockStats.NoLocks, + &pSrcDb->LockStats.NoLocks); + + flmUpdateCountTimeStats( &pDestDb->LockStats.WaitingForLock, + &pSrcDb->LockStats.WaitingForLock); + + flmUpdateCountTimeStats( &pDestDb->LockStats.HeldLock, + &pSrcDb->LockStats.HeldLock); // Go through the LFILE statistics. diff --git a/flaim/src/flmstat.h b/flaim/src/flmstat.h index a166026..afc4b74 100644 --- a/flaim/src/flmstat.h +++ b/flaim/src/flmstat.h @@ -106,8 +106,8 @@ FINLINE void flmUpdateDiskIOStats( Desc: ****************************************************************************/ FINLINE void flmUpdateCountTimeStats( - COUNT_TIME_STAT * pDest, - COUNT_TIME_STAT * pSrc) + F_COUNT_TIME_STAT * pDest, + F_COUNT_TIME_STAT * pSrc) { pDest->ui64Count += pSrc->ui64Count; pDest->ui64ElapMilli += pSrc->ui64ElapMilli; diff --git a/flaim/src/flog.cpp b/flaim/src/flog.cpp index 98ba61f..656777d 100644 --- a/flaim/src/flog.cpp +++ b/flaim/src/flog.cpp @@ -24,8 +24,6 @@ #include "flaimsys.h" -// Static functions - FSTATIC void flmLogProcessFieldInfo( const char ** ppszFormat, FLMUINT * puiWidth, @@ -793,17 +791,17 @@ FSTATIC RCODE flmLogColorFormatter( } else { - FlmColorType eForeground = (FlmColorType)(uiWidth + 1); - FlmColorType eBackground = (FlmColorType)(uiPrecision + 1); + eColorType foreground = (eColorType)(uiWidth + 1); + eColorType background = (eColorType)(uiPrecision + 1); // Set a new foreground and/or background color - if( eForeground >= FLM_NUM_COLORS || eBackground >= FLM_NUM_COLORS) + if( foreground >= FLM_NUM_COLORS || background >= FLM_NUM_COLORS) { goto Exit; } - pLogMessage->setColor( eForeground, eBackground); + pLogMessage->setColor( foreground, background); } Exit: @@ -1081,8 +1079,8 @@ void F_LogMessage::pushForegroundColor( void) { if( m_uiForeColors < F_MAX_COLOR_STACK_SIZE) { - m_eForeColors[ F_MAX_COLOR_STACK_SIZE - - (++m_uiForeColors)] = m_eCurrentForeColor; + m_foreColors[ F_MAX_COLOR_STACK_SIZE - + (++m_uiForeColors)] = m_currentForeColor; } else { @@ -1097,8 +1095,8 @@ void F_LogMessage::pushBackgroundColor( void) { if( m_uiBackColors < F_MAX_COLOR_STACK_SIZE) { - m_eBackColors[ F_MAX_COLOR_STACK_SIZE - - (++m_uiBackColors)] = m_eCurrentBackColor; + m_backColors[ F_MAX_COLOR_STACK_SIZE - + (++m_uiBackColors)] = m_currentBackColor; } else { @@ -1111,7 +1109,7 @@ Desc: Pops the foreground color off of the top of the color stack ****************************************************************************/ void F_LogMessage::popForegroundColor( void) { - FlmColorType eForeColor = m_eCurrentForeColor; + eColorType foreColor = m_currentForeColor; // Pop a color from the color stack @@ -1119,13 +1117,13 @@ void F_LogMessage::popForegroundColor( void) { if( m_uiForeColors <= F_MAX_COLOR_STACK_SIZE) { - eForeColor = m_eForeColors[ + foreColor = m_foreColors[ F_MAX_COLOR_STACK_SIZE - m_uiForeColors]; } m_uiForeColors--; } - setColor( eForeColor, m_eCurrentBackColor); + setColor( foreColor, m_currentBackColor); } /**************************************************************************** @@ -1133,7 +1131,7 @@ Desc: Pops the background color off of the top of the color stack ****************************************************************************/ void F_LogMessage::popBackgroundColor( void) { - FlmColorType eBackColor = m_eCurrentBackColor; + eColorType backColor = m_currentBackColor; // Pop a color from the color stack @@ -1141,28 +1139,28 @@ void F_LogMessage::popBackgroundColor( void) { if( m_uiBackColors <= F_MAX_COLOR_STACK_SIZE) { - eBackColor = m_eBackColors[ + backColor = m_backColors[ F_MAX_COLOR_STACK_SIZE - m_uiBackColors]; } m_uiBackColors--; } - setColor( m_eCurrentForeColor, eBackColor); + setColor( m_currentForeColor, backColor); } /**************************************************************************** Desc: Sets the foreground and background colors of a message ****************************************************************************/ void F_LogMessage::setColor( - FlmColorType eForeColor, - FlmColorType eBackColor) + eColorType foreColor, + eColorType backColor) { - if( eForeColor != m_eCurrentForeColor || - eBackColor != m_eCurrentBackColor) + if( foreColor != m_currentForeColor || + backColor != m_currentBackColor) { - m_eCurrentForeColor = eForeColor; - m_eCurrentBackColor = eBackColor; - changeColor( m_eCurrentForeColor, m_eCurrentBackColor); + m_currentForeColor = foreColor; + m_currentBackColor = backColor; + changeColor( m_currentForeColor, m_currentBackColor); } } diff --git a/flaim/src/flopen.cpp b/flaim/src/flopen.cpp index d12efaa..22060e3 100644 --- a/flaim/src/flopen.cpp +++ b/flaim/src/flopen.cpp @@ -33,8 +33,9 @@ FSTATIC RCODE flmPhysFileOpen( F_Restore * pRestoreObj); FSTATIC RCODE flmReadFileHdr( - FDB * pDb, - FLMBYTE * tempBuf, + const char * pszDbPath, + DB_STATS * pDbStats, + FFILE * pFile, LOG_HDR * pLogHdr, FLMBOOL bAllowLimitedMode); @@ -42,14 +43,14 @@ FSTATIC void flmFreeCPInfo( CP_INFO ** ppCPInfoRV); FSTATIC RCODE flmCPThread( - F_Thread * pThread); + IF_Thread * pThread); FSTATIC RCODE flmDoRecover( FDB * pDb, F_Restore * pRestoreObj); FSTATIC RCODE flmDbMonitor( - F_Thread * pThread); + IF_Thread * pThread); /**************************************************************************** Desc : Opens an existing FLAIM database. @@ -97,7 +98,7 @@ FLMEXP RCODE FLMAPI FlmDbOpen( if (RC_BAD( rc = flmOpenFile( NULL, pszDbFileName, pszDataDir, pszRflDir, uiOpenFlags, FALSE, - NULL, NULL, pszPassword, (FDB * *)phDbRV))) + NULL, NULL, pszPassword, (FDB **)phDbRV))) { goto Exit; } @@ -129,11 +130,11 @@ RCODE flmOpenOrCreateDbClientServer( FLMUNICODE * puzDataDir = NULL; FLMUNICODE * puzRflDir = NULL; FLMUNICODE * puzTmp; - POOL pool; + F_Pool pool; FCL_WIRE Wire( pCSContext); FDB * pDb; - GedPoolInit( &pool, 128); + pool.poolInit( 128); // Allocate and initialize an FDB structure @@ -217,7 +218,7 @@ RCODE flmOpenOrCreateDbClientServer( // Convert the path to Unicode - GedPoolReset( &pool, NULL); + pool.poolReset(); if (RC_BAD( rc = fcsConvertNativeToUnicode( &pool, pszDictFileName, &puzTmp))) { @@ -234,7 +235,7 @@ RCODE flmOpenOrCreateDbClientServer( { // Convert the path to Unicode - GedPoolReset( &pool, NULL); + pool.poolReset(); if (RC_BAD( rc = fcsConvertNativeToUnicode( &pool, pszDictBuf, &puzTmp))) { @@ -290,7 +291,7 @@ Exit: { (void)FlmDbClose( (HFDB *)ppDb); } - GedPoolFree( &pool); + return( rc); Transmission_Error: @@ -311,19 +312,21 @@ RCODE flmAllocFdb( // Allocate the FDB structure. *ppDb = NULL; - if( RC_BAD( rc = f_calloc( (FLMUINT)sizeof( FDB), ppDb))) + if( RC_BAD( rc = f_calloc( sizeof( FDB), ppDb))) { goto Exit; } + pDb = *ppDb; - + pDb->hWaitSem = F_SEM_NULL; + // Initialize pool for temporary allocations, making the block size // what we need for most read operations - several Key buffers - GedPoolInit( &pDb->tmpKrefPool, 8192); - GedPoolInit( &pDb->TempPool, (MAX_KEY_SIZ * 4)); - -#if defined( FLM_DEBUG) && (defined( FLM_WIN) || defined( FLM_NLM)) + pDb->tmpKrefPool.poolInit( 8192); + pDb->TempPool.poolInit( MAX_KEY_SIZ * 4); + +#if defined( FLM_DEBUG) // Create a mutex for controlling access to the structure @@ -334,6 +337,11 @@ RCODE flmAllocFdb( } #endif + if( RC_BAD( rc = f_semCreate( &pDb->hWaitSem))) + { + goto Exit; + } + // Set up statistics. if (RC_BAD( rc = flmStatInit( &pDb->Stats, FALSE))) @@ -432,16 +440,16 @@ RCODE flmOpenFile( FLMUINT uiOpenFlags, FLMBOOL bInternalOpen, F_Restore * pRestoreObj, - F_FileHdlImp * pLockFileHdl, + IF_FileHdl * pLockFileHdl, const char * pszPassword, - FDB * * ppDb) + FDB ** ppDb) { - RCODE rc; - FLMBOOL bNewFile = FALSE; - FLMBOOL bMutexLocked = FALSE; - FLMBOOL bAllocatedFdb = FALSE; - FDB * pDb; - FLMBOOL bNeedToOpen = FALSE; + RCODE rc; + FLMBOOL bNewFile = FALSE; + FLMBOOL bMutexLocked = FALSE; + FLMBOOL bAllocatedFdb = FALSE; + FDB * pDb; + FLMBOOL bFirstOpen = FALSE; // Allocate and initialize an FDB structure @@ -471,7 +479,7 @@ RCODE flmOpenFile( if (!pFile) { - bNeedToOpen = TRUE; + bFirstOpen = TRUE; // May unlock and re-lock the global mutex. @@ -493,6 +501,7 @@ RCODE flmOpenFile( { goto Exit; } + flmAssert( !pLockFileHdl); bNewFile = TRUE; } @@ -513,13 +522,10 @@ RCODE flmOpenFile( // Assign the lock file handle pFile->pLockFileHdl = pLockFileHdl; - - // Set to NULL to prevent lock file from being released below - pLockFileHdl = NULL; bNewFile = TRUE; - bNeedToOpen = TRUE; + bFirstOpen = TRUE; } else { @@ -590,7 +596,7 @@ RCODE flmOpenFile( (void)flmStatGetDb( &pDb->Stats, pFile, 0, &pDb->pDbStats, NULL, NULL); - if (bNeedToOpen) + if (bFirstOpen) { if (RC_BAD( rc = flmPhysFileOpen( pDb, pszDbPath, pszRflDir, uiOpenFlags, bNewFile, @@ -599,6 +605,27 @@ RCODE flmOpenFile( goto Exit; } } + else + { + // Allocate the super file object + + flmAssert( !pDb->pSFileHdl); + + if( (pDb->pSFileHdl = f_new F_SuperFileHdl) == NULL) + { + rc = RC_SET( FERR_MEM); + goto Exit; + } + + flmAssert( pFile->FileHdr.uiVersionNum); + flmAssert( pFile->FileHdr.uiBlockSize); + + if( RC_BAD( rc = pDb->pSFileHdl->setup( + pFile->pszDbPath, pFile->pszDataDir, pFile->FileHdr.uiVersionNum))) + { + goto Exit; + } + } if (bNewFile && !(uiOpenFlags & FO_DONT_REDO_LOG)) { @@ -741,11 +768,11 @@ Desc: This routine obtains exclusive access to a database by creating ****************************************************************************/ RCODE flmCreateLckFile( const char * pszFilePath, - F_FileHdlImp ** ppLockFileHdlRV) + IF_FileHdl ** ppLockFileHdl) { RCODE rc = FERR_OK; char szLockPath [F_PATH_MAX_SIZE]; - F_FileHdlImp * pLockFileHdl = NULL; + IF_FileHdl * pLockFileHdl = NULL; FLMUINT uiBaseLen; // Extract the base name and put a .lck extension on it to create @@ -753,60 +780,20 @@ RCODE flmCreateLckFile( flmGetDbBasePath( szLockPath, pszFilePath, &uiBaseLen); f_strcpy( &szLockPath[ uiBaseLen], ".lck"); - - // Attempt to create the lock file. If that succeeds, we are - // OK to use the database. If it fails, the lock file may have - // been left because of a crash if FLAIM was not shut down properly. - // Hence, we first try to delete the file. If that succeeds, we - // then attempt to create the file again. If it, or the 2nd create - // fail, we simply return an access denied error. - -#ifndef FLM_UNIX - if( RC_BAD( gv_FlmSysData.pFileSystem->Create( szLockPath, - F_IO_RDWR | F_IO_EXCL | F_IO_SH_DENYRW | F_IO_DELETE_ON_CLOSE, - (F_FileHdl **)&pLockFileHdl))) + + if( RC_BAD( rc = gv_FlmSysData.pFileSystem->createLockFile( + szLockPath, &pLockFileHdl))) { - if( RC_BAD( gv_FlmSysData.pFileSystem->Delete( szLockPath))) - { - rc = RC_SET( FERR_IO_ACCESS_DENIED); - goto Exit; - } - else if( RC_BAD( gv_FlmSysData.pFileSystem->Create( szLockPath, - F_IO_RDWR | F_IO_EXCL | F_IO_SH_DENYRW | F_IO_DELETE_ON_CLOSE, - (F_FileHdl **)&pLockFileHdl))) - { - rc = RC_SET( FERR_IO_ACCESS_DENIED); - goto Exit; - } - } -#else - if( RC_BAD( gv_FlmSysData.pFileSystem->Create( szLockPath, - F_IO_RDWR | F_IO_EXCL | F_IO_SH_DENYRW, - (F_FileHdl **)&pLockFileHdl))) - { - if( RC_BAD( gv_FlmSysData.pFileSystem->Open( szLockPath, - F_IO_RDWR | F_IO_SH_DENYRW, (F_FileHdl **)&pLockFileHdl))) - { - rc = RC_SET( FERR_IO_ACCESS_DENIED); - goto Exit; - } - } - - if( RC_BAD( pLockFileHdl->Lock())) - { - rc = RC_SET( FERR_IO_ACCESS_DENIED); goto Exit; } -#endif - *ppLockFileHdlRV = pLockFileHdl; + *ppLockFileHdl = pLockFileHdl; pLockFileHdl = NULL; Exit: if (pLockFileHdl) { - (void)pLockFileHdl->Close(); pLockFileHdl->Release(); pLockFileHdl = NULL; } @@ -947,8 +934,8 @@ FSTATIC RCODE flmPhysFileOpen( bAllowLimitedMode = TRUE; } - if( RC_BAD( rc = flmReadFileHdr( pDb, pFile->pucLogHdrWriteBuf, &LogHdr, - bAllowLimitedMode))) + if( RC_BAD( rc = flmReadFileHdr( pszFilePath, pDb->pDbStats, pFile, + &LogHdr, bAllowLimitedMode))) { goto Exit; } @@ -969,34 +956,6 @@ FSTATIC RCODE flmPhysFileOpen( { goto Exit; } - - // Setup the FFILE's ECache object - - flmAssert( pFile->pECacheMgr == NULL); - if( gv_FlmSysData.bOkToUseESM) - { - if( (pFile->pECacheMgr = f_new FlmECache) == NULL) - { - rc = RC_SET( FERR_MEM); - goto Exit; - } - - if( !pFile->pECacheMgr->setupECache( pFile->FileHdr.uiBlockSize, - pFile->uiMaxFileSize)) - { - pFile->pECacheMgr->Release(); - pFile->pECacheMgr = NULL; - } - else - { - // Normally the ECacheMgr is set in flmLinkFdbToFile but - // we have to handle this special case here. When this - // FDB was linked there was no ECacheMgr. - - flmAssert( pDb->pSFileHdl != NULL); - pDb->pSFileHdl->setECacheMgr( pFile->pECacheMgr); - } - } } else { @@ -1011,6 +970,25 @@ FSTATIC RCODE flmPhysFileOpen( } } } + + // Allocate the super file object + + flmAssert( !pDb->pSFileHdl); + + if( (pDb->pSFileHdl = f_new F_SuperFileHdl) == NULL) + { + rc = RC_SET( FERR_MEM); + goto Exit; + } + + flmAssert( pFile->FileHdr.uiVersionNum); + flmAssert( pFile->FileHdr.uiBlockSize); + + if( RC_BAD( rc = pDb->pSFileHdl->setup( + pFile->pszDbPath, pFile->pszDataDir, pFile->FileHdr.uiVersionNum))) + { + goto Exit; + } // We must have exclusive access. Create a lock file for that // purpose, if there is not already a lock file. @@ -1037,11 +1015,6 @@ FSTATIC RCODE flmPhysFileOpen( Exit: - if (RC_BAD( rc)) - { - (void)pDb->pSFileHdl->ReleaseFiles( TRUE); - } - return( rc); } @@ -1098,8 +1071,8 @@ RCODE flmFindFile( FLMUINT uiBucket; FLMBOOL bMutexLocked = TRUE; FFILE * pFile; - char szDbPathStr1 [F_PATH_MAX_SIZE]; - char szDbPathStr2 [F_PATH_MAX_SIZE]; + char szDbPathStr1[ F_PATH_MAX_SIZE]; + char szDbPathStr2[ F_PATH_MAX_SIZE]; *ppFileRV = NULL; @@ -1107,7 +1080,8 @@ RCODE flmFindFile( // NOTE: On non-UNIX platforms, this will basically convert // the string to upper case. - if (RC_BAD( rc = f_pathToStorageString( pszDbPath, szDbPathStr1))) + if (RC_BAD( rc = gv_FlmSysData.pFileSystem->pathToStorageString( + pszDbPath, szDbPathStr1))) { goto Exit; } @@ -1123,17 +1097,18 @@ Retry: } pBucket = gv_FlmSysData.pFileHashTbl; - uiBucket = flmStrHashBucket( szDbPathStr1, pBucket, FILE_HASH_ENTRIES); + uiBucket = f_strHashBucket( szDbPathStr1, pBucket, FILE_HASH_ENTRIES); pFile = (FFILE *)pBucket [uiBucket].pFirstInBucket; while( pFile) { - if (RC_BAD( rc = f_pathToStorageString( pFile->pszDbPath, szDbPathStr2))) + if (RC_BAD( rc = gv_FlmSysData.pFileSystem->pathToStorageString( + pFile->pszDbPath, szDbPathStr2))) { goto Exit; } // Compare the strings. It is OK to use f_strcmp on all platforms - // because on non-UNIX platforms the calls to f_pathToStorageString + // because on non-UNIX platforms the calls to pathToStorageString // has already converted the characters to upper case - hence, we // are doing a case-insensitive comparison. @@ -1143,7 +1118,7 @@ Retry: if( pszDataDir && *pszDataDir) { - if( RC_BAD( rc = f_pathToStorageString( + if( RC_BAD( rc = gv_FlmSysData.pFileSystem->pathToStorageString( pszDataDir, szDbPathStr2))) { goto Exit; @@ -1151,7 +1126,7 @@ Retry: if( pFile->pszDataDir) { - if( RC_BAD( rc = f_pathToStorageString( + if( RC_BAD( rc = gv_FlmSysData.pFileSystem->pathToStorageString( pFile->pszDataDir, szDbPathStr1))) { goto Exit; @@ -1233,8 +1208,6 @@ RCODE flmAllocFile( FLMUINT uiDbNameLen = f_strlen( pszDbPath) + 1; FLMUINT uiDirNameLen; FFILE * pFile = NULL; - FFileItemId * pFileItemId1 = NULL; - FFileItemId * pFileItemId2 = NULL; uiDirNameLen = (pszDataDir && *pszDataDir) ? f_strlen( pszDataDir) + 1 @@ -1249,38 +1222,24 @@ RCODE flmAllocFile( pFile->uiFFileId = gv_FlmSysData.uiNextFFileId++; pFile->pCPInfo = NULL; pFile->uiFileExtendSize = DEFAULT_FILE_EXTEND_SIZE; - GedPoolInit( &pFile->krefPool, 8192); + pFile->krefPool.poolInit( 8192); // Allocate a buffer for writing the database header -#ifdef FLM_WIN - if ((pFile->pucLogHdrWriteBuf = (FLMBYTE *)VirtualAlloc( NULL, - (DWORD)MAX_BLOCK_SIZE, MEM_COMMIT, PAGE_READWRITE)) == NULL) + if( RC_BAD( rc = f_allocAlignedBuffer( MAX_BLOCK_SIZE, + (void **)&pFile->pucLogHdrWriteBuf))) { - rc = MapWinErrorToFlaim( GetLastError(), FERR_MEM); goto Exit; } + f_memset( pFile->pucLogHdrWriteBuf, 0, MAX_BLOCK_SIZE); -#elif defined( FLM_LINUX) || defined( FLM_SOLARIS) - if( (pFile->pucLogHdrWriteBuf = (FLMBYTE *)memalign( - sysconf(_SC_PAGESIZE), MAX_BLOCK_SIZE)) == NULL) - { - rc = MapErrnoToFlaimErr(errno, FERR_MEM); - goto Exit; - } - f_memset( pFile->pucLogHdrWriteBuf, 0, MAX_BLOCK_SIZE); -#else - if (RC_BAD( rc = f_calloc( MAX_BLOCK_SIZE, &pFile->pucLogHdrWriteBuf))) - { - goto Exit; - } -#endif // If a password was passed in, allocate a buffer for it. if (pszDbPassword && pszDbPassword[0]) { - if (RC_BAD( rc = f_calloc( f_strlen( pszDbPassword) + 1, &pFile->pszDbPassword))) + if (RC_BAD( rc = f_calloc( f_strlen( pszDbPassword) + 1, + &pFile->pszDbPassword))) { goto Exit; } @@ -1288,12 +1247,12 @@ RCODE flmAllocFile( } // Setup the write buffer managers. - - if ((pFile->pBufferMgr = f_new F_IOBufferMgr) == NULL) + + if( RC_BAD( rc = FlmAllocIOBufferMgr( &pFile->pBufferMgr))) { - rc = RC_SET( FERR_MEM); goto Exit; } + pFile->pBufferMgr->setMaxBuffers( MAX_PENDING_WRITES); pFile->pBufferMgr->setMaxBytes( MAX_WRITE_BUFFER_BYTES); @@ -1323,56 +1282,19 @@ RCODE flmAllocFile( } flmLinkFileToNUList( pFile); - // Allocate the lock objects - must be done AFTER setting up the - // file name stuff up above. - - if( (pFileItemId1 = f_new FFileItemId( pFile, TRUE)) == NULL) - { - rc = RC_SET( FERR_MEM); - goto Exit; - } - - if( (pFileItemId2 = f_new FFileItemId( pFile, FALSE)) == NULL) - { - rc = RC_SET( FERR_MEM); - goto Exit; - } - - // Allocate and initialize the file ID list - - if( (pFile->pFileIdList = f_new F_FileIdList) == NULL) - { - rc = RC_SET( FERR_MEM); - goto Exit; - } - - if( RC_BAD( rc = pFile->pFileIdList->setup())) - { - goto Exit; - } - // Allocate a lock object for write locking. - - if( (pFile->pWriteLockObj = - gv_FlmSysData.pServerLockMgr->GetLockObject( - pFileItemId1)) == NULL) + + if( RC_BAD( rc = FlmAllocLockObject( &pFile->pWriteLockObj))) { - rc = RC_SET( FERR_MEM); goto Exit; } - pFile->pWriteLockObj->AddRef(); - // Allocate a lock object for file locking. - - if( (pFile->pFileLockObj = - gv_FlmSysData.pServerLockMgr->GetLockObject( - pFileItemId2)) == NULL) + + if( RC_BAD( rc = FlmAllocLockObject( &pFile->pFileLockObj))) { - rc = RC_SET( FERR_MEM); goto Exit; } - pFile->pFileLockObj->AddRef(); // Initialize the maintenance thread's semaphore @@ -1385,16 +1307,6 @@ RCODE flmAllocFile( Exit: - if( pFileItemId1) - { - pFileItemId1->Release(); - } - - if( pFileItemId2) - { - pFileItemId2->Release(); - } - if( RC_BAD( rc)) { if( pFile) @@ -1411,25 +1323,26 @@ Desc: This routine reads the header information for an existing also reads the log file header record. *****************************************************************************/ FSTATIC RCODE flmReadFileHdr( - FDB * pDb, // Pointer to operation context - FLMBYTE * pBuf, // Internal buffer to be used for reading - LOG_HDR * pLogHdr, // Returns log header stuff - FLMBOOL bAllowLimitedMode) // Are we allowed to open in limited mode? + const char * pszDbPath, + DB_STATS * pDbStats, + FFILE * pFile, + LOG_HDR * pLogHdr, + FLMBOOL bAllowLimitedMode) { - RCODE rc = FERR_OK; - FFILE * pFile = pDb->pFile; - DB_STATS * pDbStats = pDb->pDbStats; - F_FileHdlImp * pCFileHdl; + RCODE rc = FERR_OK; + IF_FileHdl * pFileHdl = NULL; // Read and verify the file and log headers. - - if( RC_BAD( rc = pDb->pSFileHdl->GetFileHdl( 0, FALSE, &pCFileHdl))) + + if( RC_BAD( rc = gv_FlmSysData.pFileSystem->openFile( pszDbPath, + FLM_IO_RDWR | FLM_IO_SH_DENYNONE | FLM_IO_DIRECT, &pFileHdl))) { goto Exit; } if (RC_BAD( rc = flmReadAndVerifyHdrInfo( pDbStats, - pCFileHdl, pBuf, &pFile->FileHdr, pLogHdr, NULL))) + pFileHdl, pFile->pucLogHdrWriteBuf, + &pFile->FileHdr, pLogHdr, NULL))) { goto Exit; } @@ -1437,10 +1350,10 @@ FSTATIC RCODE flmReadFileHdr( // Shove stuff into the log header area of the pFile. // IMPORTANT NOTE! - This code assumes that DB_LOG_HEADER_START // is found in the first 2K of the file - i.e., it will be inside - // the pBuf that we read above. + // the pFile->pucLogHdrWriteBuf that we read above. f_memcpy( pFile->ucLastCommittedLogHdr, - &pBuf[ DB_LOG_HEADER_START], LOG_HEADER_SIZE); + &pFile->pucLogHdrWriteBuf[ DB_LOG_HEADER_START], LOG_HEADER_SIZE); // Create the database wrapping key from the data in Log Header @@ -1526,14 +1439,9 @@ FSTATIC RCODE flmReadFileHdr( pFile->ucLastCommittedLogHdr); Exit: - // Need to close the .db file so that we can set the block size. - // This will allow direct I/O to be used when accessing the file later. - - if( pCFileHdl) + if( pFileHdl) { - (void)pDb->pSFileHdl->ReleaseFile( (FLMUINT)0, TRUE); - pDb->pSFileHdl->SetBlockSize( pFile->FileHdr.uiBlockSize); - pDb->pSFileHdl->SetDbVersion( pFile->FileHdr.uiVersionNum); + pFileHdl->Release(); } return( rc); @@ -1593,19 +1501,14 @@ RCODE flmStartCPThread( // Set up the super file - if (RC_BAD( rc = pCPInfo->pSFileHdl->Setup( pFile->pFileIdList, - pFile->pszDbPath, - pFile->pszDataDir))) + flmAssert( pFile->FileHdr.uiVersionNum); + + if (RC_BAD( rc = pCPInfo->pSFileHdl->setup( + pFile->pszDbPath, pFile->pszDataDir, pFile->FileHdr.uiVersionNum))) { goto Exit; } - if (pFile->FileHdr.uiVersionNum) - { - pCPInfo->pSFileHdl->SetBlockSize( pFile->FileHdr.uiBlockSize); - pCPInfo->pSFileHdl->SetDbVersion( pFile->FileHdr.uiVersionNum); - } - if (RC_BAD( rc = flmStatInit( &pCPInfo->Stats, FALSE))) { goto Exit; @@ -1614,7 +1517,7 @@ RCODE flmStartCPThread( // Generate the thread name - if (RC_BAD( rc = f_pathReduce( pFile->pszDbPath, + if (RC_BAD( rc = gv_FlmSysData.pFileSystem->pathReduce( pFile->pszDbPath, szThreadName, szBaseName))) { goto Exit; @@ -1627,7 +1530,7 @@ RCODE flmStartCPThread( if (RC_BAD( rc = f_threadCreate( &pFile->pCPThrd, flmCPThread, szThreadName, - FLM_CHECKPOINT_THREAD_GROUP, 0, pCPInfo, NULL, 32000))) + gv_uiCPThrdGrp, 0, pCPInfo, NULL, 32000))) { goto Exit; } @@ -1655,7 +1558,7 @@ RCODE flmStartDbMonitorThread( if (RC_BAD( rc = f_threadCreate( &pFile->pMonitorThrd, flmDbMonitor, "FLAIM Database Monitor", - FLM_DB_MONITOR_THREAD_GROUP, 0, pFile, NULL, 32000))) + gv_uiDbThrdGrp, 0, pFile, NULL, 32000))) { goto Exit; } @@ -1671,8 +1574,9 @@ Desc: This routine functions as a thread. It monitors open files and close time. ****************************************************************************/ FSTATIC RCODE flmCPThread( - F_Thread * pThread) + IF_Thread * pThread) { + RCODE rc = FERR_OK; CP_INFO * pCPInfo = (CP_INFO *)pThread->getParm1(); FFILE * pFile = pCPInfo->pFile; F_SuperFileHdl * pSFileHdl = pCPInfo->pSFileHdl; @@ -1681,6 +1585,12 @@ FSTATIC RCODE flmCPThread( FLMINT iForceReason; FLMUINT uiCurrTime; DB_STATS * pDbStats; + F_SEM hWaitSem = F_SEM_NULL; + + if( RC_BAD( rc = f_semCreate( &hWaitSem))) + { + goto Exit; + } pThread->setThreadStatus( FLM_THREAD_STATUS_SLEEPING); while (!bTerminate) @@ -1759,15 +1669,14 @@ FSTATIC RCODE flmCPThread( pFile->FileHdr.uiBlockSize > gv_FlmSysData.SCacheMgr.uiMaxDirtyCache)) { - if (RC_BAD( dbWriteLock( pFile, pDbStats))) + if( RC_BAD( pFile->pWriteLockObj->lock( + hWaitSem, TRUE, FLM_NO_TIMEOUT, 0, + pDbStats ? &pDbStats->LockStats : NULL))) { - - // THIS SHOULD NEVER HAPPEN BECAUSE dbWriteLock will - // wait forever for the lock! - flmAssert( 0); continue; } + pThread->setThreadStatus( "Forcing checkpoint"); // Must wait for any RFL writes to complete. @@ -1776,11 +1685,13 @@ FSTATIC RCODE flmCPThread( } else { - if( RC_BAD( dbWriteLock( pFile, pDbStats, 0))) + if( RC_BAD( pFile->pWriteLockObj->lock( + hWaitSem, TRUE, FLM_NO_TIMEOUT, 0, + pDbStats ? &pDbStats->LockStats : NULL))) { continue; } - + pThread->setThreadStatus( FLM_THREAD_STATUS_RUNNING); // See if we actually need to do the checkpoint. If the @@ -1792,7 +1703,7 @@ FSTATIC RCODE flmCPThread( FB2UD( &pFile->ucLastCommittedLogHdr [LOG_CURR_TRANS_ID]) || !pFile->pRfl->seeIfRflWritesDone( FALSE)) { - dbWriteUnlock( pFile, pDbStats); + pFile->pWriteLockObj->unlock(); continue; } } @@ -1806,7 +1717,7 @@ FSTATIC RCODE flmCPThread( (void)flmStatUpdate( &gv_FlmSysData.Stats, &pCPInfo->Stats); } - dbWriteUnlock( pFile, pDbStats); + pFile->pWriteLockObj->unlock(); // Unlink FDB from the FFILE - will be relinked // by next thread that wakes us up. @@ -1831,10 +1742,22 @@ FSTATIC RCODE flmCPThread( pThread->setThreadStatus( FLM_THREAD_STATUS_SLEEPING); } + +Exit: pThread->setThreadStatus( FLM_THREAD_STATUS_TERMINATING); - flmFreeCPInfo( &pCPInfo); - return( FERR_OK); + + if( pCPInfo) + { + flmFreeCPInfo( &pCPInfo); + } + + if( hWaitSem != F_SEM_NULL) + { + f_semDestroy( &hWaitSem); + } + + return( rc); } /**************************************************************************** @@ -1912,13 +1835,9 @@ RCODE flmGetCSConnection( { RCODE rc = FERR_OK; FCL_WIRE Wire; - const char * pszHostName = NULL; FLMINT iSubProtocol; CS_CONTEXT * pCSContext = NULL; FUrl_p pUrl = NULL; - FCS_IPIS * pIpIStream = NULL; - FCS_IPOS * pIpOStream = NULL; - FCS_TCP_CLIENT * pTcpClient = NULL; FLMINT iIPPort = 0; FCS_BIOS * pBIStream = NULL; FCS_BIOS * pBOStream = NULL; @@ -1935,7 +1854,8 @@ RCODE flmGetCSConnection( { goto Exit; } - GedPoolInit( &pCSContext->pool, 8192); + + pCSContext->pool.poolInit( 8192); // Create a URL out of the URL name @@ -1967,21 +1887,7 @@ RCODE flmGetCSConnection( uiAddrType = pUrl->GetAddrType(); - if( iSubProtocol == TCP_SUB_PROTOCOL) - { - if( uiAddrType != FLM_CS_IP_ADDR) - { - rc = RC_SET( FERR_FAILURE); - goto Exit; - } - - iIPPort = pUrl->GetIPPort(); - if( (pszHostName = pUrl->GetIPHost()) == NULL) - { - pszHostName = "localhost"; - } - } - else if( iSubProtocol == STREAM_SUB_PROTOCOL) + if( iSubProtocol == STREAM_SUB_PROTOCOL) { if( uiAddrType == FLM_CS_IP_ADDR) { @@ -2008,43 +1914,7 @@ RCODE flmGetCSConnection( // Configure the I/O streams - if( iSubProtocol == TCP_SUB_PROTOCOL) - { - if ((pTcpClient = f_new FCS_TCP_CLIENT) == NULL) - { - rc = RC_SET( FERR_MEM); - goto Exit; - } - - if( RC_BAD( rc = pTcpClient->openConnection( pszHostName, - iIPPort, 30, 1200))) - { - goto Exit; - } - - if ((pIpIStream = f_new FCS_IPIS( pTcpClient)) == NULL) - { - rc = RC_SET( FERR_MEM); - goto Exit; - } - - if ((pIpOStream = f_new FCS_IPOS( pTcpClient)) == NULL) - { - rc = RC_SET( FERR_MEM); - goto Exit; - } - - if (RC_BAD( rc = pODataStream->setup( pIpOStream))) - { - goto Exit; - } - - if (RC_BAD( rc = pIDataStream->setup( pIpIStream))) - { - goto Exit; - } - } - else if( iSubProtocol == STREAM_SUB_PROTOCOL) + if( iSubProtocol == STREAM_SUB_PROTOCOL) { if ((pBIStream = f_new FCS_BIOS) == NULL) { @@ -2077,16 +1947,7 @@ RCODE flmGetCSConnection( goto Exit; } - if (iSubProtocol == TCP_SUB_PROTOCOL) - { - pCSContext->pTcpClient = pTcpClient; - pTcpClient = NULL; - pCSContext->pIStream = pIpIStream; - pIpIStream = NULL; - pCSContext->pOStream = pIpOStream; - pIpOStream = NULL; - } - else if (iSubProtocol == STREAM_SUB_PROTOCOL) + if (iSubProtocol == STREAM_SUB_PROTOCOL) { pCSContext->pIStream = pBIStream; pBIStream = NULL; @@ -2284,13 +2145,7 @@ Clear_Session_ID: pCSContext->pIStream = NULL; } - if( pCSContext->pTcpClient != NULL) - { - ((FCS_TCP_CLIENT *)pCSContext->pTcpClient)->Release(); - pCSContext->pTcpClient = NULL; - } - - GedPoolFree( &pCSContext->pool); + pCSContext->pool.poolFree(); f_free( ppCSContext); } @@ -2298,12 +2153,12 @@ Clear_Session_ID: Desc: ****************************************************************************/ RCODE flmDbMonitor( - F_Thread * pThread) + IF_Thread * pThread) { - RCODE rc = FERR_OK; - FFILE * pFile = (FFILE *)pThread->getParm1(); - FLMUINT uiLastRflEventTime = 0; - FLMUINT64 ui64LastRflEventSize = 0; + RCODE rc = FERR_OK; + FFILE * pFile = (FFILE *)pThread->getParm1(); + FLMUINT uiLastRflEventTime = 0; + FLMUINT64 ui64LastRflEventSize = 0; for (;;) { diff --git a/flaim/src/flprintf.cpp b/flaim/src/flprintf.cpp deleted file mode 100644 index ef78466..0000000 --- a/flaim/src/flprintf.cpp +++ /dev/null @@ -1,826 +0,0 @@ -//------------------------------------------------------------------------- -// Desc: sprintf type functionality. -// Tabs: 3 -// -// Copyright (c) 2003,2005-2006 Novell, Inc. All Rights Reserved. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of version 2 of the GNU General Public -// License as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, contact Novell, Inc. -// -// To contact Novell about this file by physical or electronic mail, -// you may find current contact information at www.novell.com -// -// $Id: flprintf.cpp 12329 2006-01-20 17:49:30 -0700 (Fri, 20 Jan 2006) ahodgkinson $ -//------------------------------------------------------------------------- - -#include "flaimsys.h" - -// Percent formating prefixes - -#define FLM_PREFIX_NONE 0 -#define FLM_PREFIX_MINUS 1 -#define FLM_PREFIX_PLUS 2 -#define FLM_PREFIX_POUND 3 - -// Width and Precision flags - -#define FLM_PRINTF_MINUS_FLAG 0x0001 -#define FLM_PRINTF_PLUS_FLAG 0x0002 -#define FLM_PRINTF_SPACE_FLAG 0x0004 -#define FLM_PRINTF_POUND_FLAG 0x0008 -#define FLM_PRINTF_ZERO_FLAG 0x0010 -#define FLM_PRINTF_SHORT_FLAG 0x0020 -#define FLM_PRINTF_LONG_FLAG 0x0040 -#define FLM_PRINTF_DOUBLE_FLAG 0x0080 -#define FLM_PRINTF_INT64_FLAG 0x0100 -#define FLM_PRINTF_COMMA_FLAG 0x0200 - -FSTATIC void flmSprintfParseArgs( - const char * pszFormat, - F_SPRINTF_INFO * pInfo, - f_va_list * args); - -FSTATIC void flmProcessFormatString( - FLMUINT uiLen, - F_SPRINTF_INFO * pInfo, - ...); - -FSTATIC FLMUINT flmPrintNumber( - FLMUINT64 ui64Val, - FLMUINT uiBase, - FLMBOOL bUpperCase, - FLMBOOL bCommas, - char * pszBuf); - -FSTATIC void flmSprintfProcessFieldInfo( - const char ** ppszFormat, - FLMUINT * puiWidth, - FLMUINT * puiPrecision, - FLMUINT * puiFlags, - f_va_list * args); - -FSTATIC void flmSprintfCharFormatter( - char ucFormatChar, - FLMUINT uiWidth, - FLMUINT uiPrecision, - FLMUINT uiFlags, - F_SPRINTF_INFO * pInfo, - f_va_list * args); - -FSTATIC void flmSprintfErrorFormatter( - char ucFormatChar, - FLMUINT uiWidth, - FLMUINT uiPrecision, - FLMUINT uiFlags, - F_SPRINTF_INFO * pInfo, - f_va_list * args); - -FSTATIC void flmSprintfNotHandledFormatter( - char ucFormatChar, - FLMUINT uiWidth, - FLMUINT uiPrecision, - FLMUINT uiFlags, - F_SPRINTF_INFO * pInfo, - f_va_list * args); - -FSTATIC void flmSprintfNumberFormatter( - char ucFormatChar, - FLMUINT uiWidth, - FLMUINT uiPrecision, - FLMUINT uiFlags, - F_SPRINTF_INFO * pInfo, - f_va_list * args); - -/**************************************************************************** -Desc: Parameter 'format' points to text following a '%' sign. Process - legal field information. Leave 'format' pointing at the format - specifier char. -****************************************************************************/ -FSTATIC void flmSprintfProcessFieldInfo( - const char ** ppszFormat, - FLMUINT * puiWidth, - FLMUINT * puiPrecision, - FLMUINT * puiFlags, - f_va_list * args) -{ - const char * pszFormat = *ppszFormat; - - // Process flags - - *puiFlags = 0; - for( ;;) - { - switch( *pszFormat) - { - case '-': - *puiFlags |= FLM_PRINTF_MINUS_FLAG; - break; - - case '+': - *puiFlags |= FLM_PRINTF_PLUS_FLAG; - break; - - case ' ': - *puiFlags |= FLM_PRINTF_SPACE_FLAG; - break; - - case '#': - *puiFlags |= FLM_PRINTF_POUND_FLAG; - break; - - case '0': - *puiFlags |= FLM_PRINTF_ZERO_FLAG; - break; - - case ',': - *puiFlags |= FLM_PRINTF_COMMA_FLAG; - break; - - default: - goto NoMoreFlags; - } - - pszFormat++; - } - -NoMoreFlags: - - // Process width - - *puiWidth = 0; - if( *pszFormat == '*') - { - *puiWidth = f_va_arg( *args, unsigned int); - pszFormat++; - } - else - { - while( *pszFormat >= '0' && *pszFormat <= '9') - { - *puiWidth = (*puiWidth * 10) + (*pszFormat - '0'); - pszFormat++; - } - } - - // Process precision - - *puiPrecision = 0; - if( *pszFormat == '.') - { - pszFormat++; - if( *pszFormat == '*') - { - *puiPrecision = f_va_arg( *args, unsigned int); - pszFormat++; - } - else while( *pszFormat >= '0' && *pszFormat <= '9') - { - *puiPrecision = (*puiPrecision * 10) + (*pszFormat - '0'); - pszFormat++; - } - } - - // Size modifiers - switch( *pszFormat) - { - case 'I': - if( pszFormat[ 1] == '6' && pszFormat[ 2] == '4') - { - *puiFlags |= FLM_PRINTF_INT64_FLAG; - pszFormat += 3; - } - else - { - flmAssert( 0); - } - break; - - case 'L': - *puiFlags |= FLM_PRINTF_DOUBLE_FLAG; - pszFormat++; - break; - - case 'l': - *puiFlags |= FLM_PRINTF_LONG_FLAG; - pszFormat++; - break; - - case 'h': - *puiFlags |= FLM_PRINTF_SHORT_FLAG; - pszFormat++; - break; - } - - *ppszFormat = pszFormat; - return; -} - -/**************************************************************************** -Desc: Handle text portions of the format string -****************************************************************************/ -FSTATIC void flmProcessFormatString( - FLMUINT uiLen, - F_SPRINTF_INFO * pInfo, - ...) -{ - f_va_list args; - - f_va_start( args, pInfo); - if( uiLen) - { - flmSprintfStringFormatter( 0, uiLen, uiLen, 0, pInfo, &args); - } - f_va_end( args); -} - -/**************************************************************************** -Desc: Parse arguments in format string, calling appropriate handlers -****************************************************************************/ -FSTATIC void flmSprintfParseArgs( - const char * pszFormat, - F_SPRINTF_INFO * pInfo, - f_va_list * args) -{ - char ucFormatChar; - FLMUINT uiFlags; - FLMUINT uiWidth; - FLMUINT uiPrecision; - const char * pszTextStart = pszFormat; - - while( (ucFormatChar = *pszFormat++) != 0) - { - if( ucFormatChar != '%') - { - continue; - } - - uiWidth = (FLMUINT)(pszFormat - pszTextStart - 1); - flmProcessFormatString( uiWidth, pInfo, pszTextStart); - - flmSprintfProcessFieldInfo( &pszFormat, &uiWidth, - &uiPrecision, &uiFlags, args); - - ucFormatChar = (unsigned char)*pszFormat++; - switch( ucFormatChar) - { - case '%': - case 'c': - flmSprintfCharFormatter( ucFormatChar, uiWidth, - uiPrecision, uiFlags, pInfo, args); - break; - - case 'd': - case 'i': - case 'o': - case 'u': - case 'x': - case 'X': - case 'p': - if( ucFormatChar == 'i') - { - ucFormatChar = 'd'; - } - - flmSprintfNumberFormatter( ucFormatChar, uiWidth, - uiPrecision, uiFlags, pInfo, args); - break; - - case 's': - case 'S': - case 'U': - flmSprintfStringFormatter( ucFormatChar, uiWidth, - uiPrecision, uiFlags, pInfo, args); - break; - - case 'e': - case 'E': - flmSprintfErrorFormatter( ucFormatChar, uiWidth, - uiPrecision, uiFlags, pInfo, args); - break; - - default: - flmSprintfNotHandledFormatter( ucFormatChar, uiWidth, - uiPrecision, uiFlags, pInfo, args); - break; - } - pszTextStart = pszFormat; - } - - flmProcessFormatString( (FLMUINT)(pszFormat - pszTextStart - 1), - pInfo, pszTextStart); -} - -/**************************************************************************** -Desc: Default string formatter. -****************************************************************************/ -void flmSprintfStringFormatter( - char ucFormatChar, - FLMUINT uiWidth, - FLMUINT uiPrecision, - FLMUINT uiFlags, - F_SPRINTF_INFO * pInfo, - f_va_list * args) -{ - static char pszNullPointerStr[] = ""; - FLMUINT uiOutputLen; - FLMUINT uiCount; - FLMUNICODE * pUnicode; - char * pszStr = f_va_arg( *args, char *); - char * pszDest = pInfo->pszDestStr; - - if( !pszStr) - { - uiOutputLen = f_strlen( pszNullPointerStr); - } - else if( ucFormatChar == 'S') - { - uiOutputLen = *pszStr++; - } - else - { - if( ucFormatChar == 'U') - { - uiOutputLen = 0; - pUnicode = (FLMUNICODE *)pszStr; - while( *pUnicode) - { - if( *pUnicode >= 32 && *pUnicode <= 127) - { - uiOutputLen++; - } - else - { - uiOutputLen += 7; - } - pUnicode++; - } - } - else - { - uiOutputLen = f_strlen( pszStr); - } - } - - if( uiPrecision > 0 && uiOutputLen > uiPrecision) - { - uiOutputLen = uiPrecision; - } - - uiCount = uiWidth - uiOutputLen; - - if( uiOutputLen < uiWidth && !(uiFlags & FLM_PRINTF_MINUS_FLAG)) - { - // Right justify - - f_memset( pszDest, ' ', uiCount); - pszDest += uiCount; - } - - if( !pszStr) - { - f_memcpy( pszDest, pszNullPointerStr, uiOutputLen); - pszDest += uiOutputLen; - } - else if( ucFormatChar == 'U') - { - FLMUINT uiBytesOutput = 0; - - for( pUnicode = (FLMUNICODE *)pszStr; - uiBytesOutput < uiOutputLen && *pUnicode; pUnicode++) - { - if( *pUnicode >= 32 && *pUnicode <= 127) - { - *pszDest++ = (char)*pUnicode; - uiBytesOutput++; - } - else - { - char szTmpBuf[ 8]; - FLMUINT uiTmpLen; - char * pszTmp; - - szTmpBuf[ 0] = '~'; - szTmpBuf[ 1] = '['; - uiTmpLen = flmPrintNumber( (FLMUINT64)(*pUnicode), - 16, TRUE, FALSE, &szTmpBuf[ 2]); - uiTmpLen += 2; - szTmpBuf[ uiTmpLen] = ']'; - szTmpBuf[ uiTmpLen + 1] = 0; - - pszTmp = szTmpBuf; - while( *pszTmp && uiBytesOutput < uiOutputLen) - { - *pszDest++ = *pszTmp; - pszTmp++; - uiBytesOutput++; - } - } - } - } - else - { - f_memcpy( pszDest, pszStr, uiOutputLen); - pszDest += uiOutputLen; - } - - if( uiOutputLen < uiWidth && (uiFlags & FLM_PRINTF_MINUS_FLAG)) - { - // Left justify - - f_memset( pszDest, ' ', uiCount); - pszDest += uiCount; - } - - *pszDest = 0; - uiCount = (FLMUINT)(pszDest - pInfo->pszDestStr); - pInfo->pszDestStr = pszDest; -} - -/**************************************************************************** -Desc: Converts a number to a string -****************************************************************************/ -FSTATIC FLMUINT flmPrintNumber( - FLMUINT64 ui64Val, - FLMUINT uiBase, - FLMBOOL bUpperCase, - FLMBOOL bCommas, - char * pszBuf) -{ - char ucChar; - FLMUINT uiOffset = 0; - FLMUINT uiDigitCount = 0; - FLMUINT uiLoop; - - // We don't support commas on bases other than 10 - - if( uiBase != 10) - { - bCommas = FALSE; - } - - // Build the number string from the value - - for( ;;) - { - ucChar = (char)(ui64Val % (FLMUINT64)uiBase); - pszBuf[ uiOffset++] = (char)(ucChar > 9 - ? ucChar + (bUpperCase ? 'A' : 'a') - 10 - : ucChar + '0'); - uiDigitCount++; - - if( (ui64Val = (ui64Val / (FLMUINT64)uiBase)) == (FLMUINT64)0) - { - break; - } - - if( bCommas && (uiDigitCount % 3) == 0) - { - pszBuf[ uiOffset++] = ','; - } - } - - // Reverse the string - - for( uiLoop = 0; uiLoop < uiOffset / 2; uiLoop++) - { - ucChar = pszBuf[ uiLoop]; - pszBuf[ uiLoop] = pszBuf[ uiOffset - uiLoop - 1]; - pszBuf[ uiOffset - uiLoop - 1] = ucChar; - } - - pszBuf[ uiOffset] = 0; - return( uiOffset); -} - -/**************************************************************************** -Desc: Default number formatter. - Format: %[flags][width][.prec]'E' -****************************************************************************/ -FSTATIC void flmSprintfNumberFormatter( - char ucFormatChar, - FLMUINT uiWidth, - FLMUINT uiPrecision, - FLMUINT uiFlags, - F_SPRINTF_INFO * pInfo, - f_va_list * args) -{ - FLMUINT uiCount; - FLMUINT uiPrefix = FLM_PREFIX_NONE; - FLMUINT uiLength; - FLMUINT uiBase = 10; - char ucNumberBuffer[ 64]; - FLMBOOL bUpperCase = FALSE; - FLMBOOL bCommas = FALSE; - char * pszTmp; - char * pszDest = pInfo->pszDestStr; - FLMUINT64 ui64Val; - - if( ucFormatChar == 'p') - { - ui64Val = (FLMUINT64)((FLMUINT)f_va_arg( *args, void *)); - uiFlags |= FLM_PRINTF_POUND_FLAG; - } - else if( ucFormatChar != 'd') - { - // Unsigned number - - if( uiFlags & FLM_PRINTF_SHORT_FLAG) - { - ui64Val = (FLMUINT64)((unsigned int)f_va_arg( *args, int)); - } - else if( uiFlags & (FLM_PRINTF_LONG_FLAG | FLM_PRINTF_DOUBLE_FLAG)) - { - ui64Val = (FLMUINT64)((unsigned long int)f_va_arg( *args, long int)); - } - else if( uiFlags & FLM_PRINTF_INT64_FLAG) - { - ui64Val = f_va_arg( *args, FLMUINT64); - } - else - { - ui64Val = (FLMUINT64)((unsigned int)f_va_arg( *args, int)); - } - } - else - { - // Signed number - - if( uiFlags & FLM_PRINTF_SHORT_FLAG) - { - ui64Val = (FLMUINT64)((FLMINT64)f_va_arg( *args, int)); - } - else if( uiFlags & (FLM_PRINTF_LONG_FLAG | FLM_PRINTF_DOUBLE_FLAG)) - { - ui64Val = (FLMUINT64)((FLMINT64)f_va_arg( *args, long int)); - } - else if( uiFlags & FLM_PRINTF_INT64_FLAG) - { - ui64Val = (FLMUINT64)f_va_arg( *args, FLMINT64); - } - else - { - ui64Val = (FLMUINT64)((FLMINT64)f_va_arg( *args, int)); - } - } - - switch( ucFormatChar) - { - case 'd': - { - if( ((FLMINT64)ui64Val) < 0) - { - uiPrefix = FLM_PREFIX_MINUS; - if( uiWidth > 0) - { - uiWidth--; - } - ui64Val = (FLMUINT64)(-(FLMINT64)ui64Val); - } - else if( uiFlags & FLM_PRINTF_PLUS_FLAG) - { - uiPrefix = FLM_PREFIX_PLUS; - if( uiWidth > 0) - { - uiWidth--; - } - } - break; - } - - case 'o': - { - uiBase = 8; - break; - } - - case 'x': - case 'X': - case 'p': - { - if( (uiFlags & FLM_PRINTF_POUND_FLAG) && ui64Val != (FLMUINT64)0) - { - uiPrefix = FLM_PREFIX_POUND; - if( uiWidth > 1) - { - uiWidth -= 2; - } - } - uiBase = 16; - break; - } - } - - if( ucFormatChar == 'X') - { - bUpperCase = TRUE; - } - - if( (uiFlags & FLM_PRINTF_COMMA_FLAG) && uiBase == 10) - { - bCommas = TRUE; - } - - uiLength = flmPrintNumber( ui64Val, uiBase, bUpperCase, - bCommas, ucNumberBuffer); - - if( uiWidth < uiLength) - { - uiWidth = uiLength; - } - - if( uiFlags & FLM_PRINTF_ZERO_FLAG) - { - // Zero fill - - uiPrecision = uiWidth; - } - else if( !(uiFlags & FLM_PRINTF_MINUS_FLAG)) - { - // Right justify - - while( uiWidth > uiLength && uiWidth > uiPrecision) - { - *pszDest++ = ' '; - uiWidth--; - } - } - - // Handle the prefix (if any) - - switch( uiPrefix) - { - case FLM_PREFIX_NONE: - break; - - case FLM_PREFIX_MINUS: - *pszDest++ = '-'; - break; - - case FLM_PREFIX_PLUS: - *pszDest++ = '+'; - break; - - case FLM_PREFIX_POUND: - { - *pszDest++ = '0'; - *pszDest++ = 'x'; - break; - } - - default: - flmAssert( 0); - break; - } - - // Handle the precision - - if( bCommas && uiPrecision && (uiPrecision % 4) == 0) - { - uiPrecision--; - } - - while( uiLength < uiPrecision) - { - if( bCommas && (uiPrecision % 4) == 0) - { - *pszDest++ = ','; - uiPrecision--; - uiWidth--; - continue; - } - - *pszDest++ = '0'; - uiPrecision--; - uiWidth--; - } - - // Output the number - - for( uiCount = uiLength, pszTmp = &ucNumberBuffer[ 0]; - uiCount > 0; uiCount--) - { - *pszDest++ = *pszTmp++; - } - - if( uiFlags & FLM_PRINTF_MINUS_FLAG) - { - // Left justify - while( uiLength < uiWidth) - { - *pszDest++ = ' '; - uiWidth--; - } - } - - *pszDest = 0; - pInfo->pszDestStr = pszDest; -} - -/**************************************************************************** -Desc: Default character formatter. - Prints the character specified by VALUE in 'c', or the '%' character. - Format: %[flags][width][.prec]'c' - flags = - width = - prec = -****************************************************************************/ -FSTATIC void flmSprintfCharFormatter( - char ucFormatChar, - FLMUINT , // uiWidth, - FLMUINT , // uiPrecision, - FLMUINT , // uiFlags, - F_SPRINTF_INFO * pInfo, - f_va_list * args) -{ - *pInfo->pszDestStr++ = (char)((ucFormatChar == '%') - ? '%' - : f_va_arg( *args, int)); - *pInfo->pszDestStr = 0; -} - -/**************************************************************************** -Desc: Default error formatter. -****************************************************************************/ -FSTATIC void flmSprintfErrorFormatter( - char ucFormatChar, - FLMUINT , // uiWidth, - FLMUINT , // uiPrecision, - FLMUINT , // uiFlags, - F_SPRINTF_INFO * pInfo, - f_va_list * args) -{ - FLMUINT uiErrorCode = (FLMUINT)f_va_arg( *args, unsigned); - - if( ucFormatChar == 'e') - { - pInfo->pszDestStr += - f_sprintf( pInfo->pszDestStr, "%s (%04X)", - FlmErrorString( (RCODE)uiErrorCode), - (unsigned)uiErrorCode); - } - else - { - pInfo->pszDestStr += - f_sprintf( pInfo->pszDestStr, "%04X", (unsigned)uiErrorCode); - } -} - -/**************************************************************************** -Desc: Unknown format handler -****************************************************************************/ -FSTATIC void flmSprintfNotHandledFormatter( - char , // ucFormatChar, - FLMUINT , // uiWidth, - FLMUINT , // uiPrecision, - FLMUINT , // uiFlags, - F_SPRINTF_INFO * pInfo, - f_va_list * ) // args) -{ - flmAssert( 0); - *pInfo->pszDestStr++ = '?'; - *pInfo->pszDestStr = 0; -} - -/**************************************************************************** -Desc: FLAIM's vsprintf -****************************************************************************/ -FLMINT f_vsprintf( - char * pszDestStr, - const char * pszFormat, - f_va_list * args) -{ - F_SPRINTF_INFO info; - - info.pszDestStr = pszDestStr; - flmSprintfParseArgs( pszFormat, &info, args); - *info.pszDestStr = 0; - - return( (FLMINT)(info.pszDestStr - pszDestStr)); -} - -/**************************************************************************** -Desc: FLAIM's sprintf -****************************************************************************/ -FLMEXP FLMINT FLMAPI f_sprintf( - char * pszDestStr, - const char * pszFormat, - ...) -{ - FLMINT iLen; - f_va_list args; - - f_va_start(args, pszFormat); - iLen = f_vsprintf( pszDestStr, pszFormat, &args); - f_va_end(args); - - return( iLen); -} diff --git a/flaim/src/flrddrct.cpp b/flaim/src/flrddrct.cpp index f7a2db7..7d2e6e3 100644 --- a/flaim/src/flrddrct.cpp +++ b/flaim/src/flrddrct.cpp @@ -170,7 +170,7 @@ Search_Record: goto Exit; } - flmUINT32ToBigEndian( (FLMUINT32)uiDrn, pSearchBuf); + f_UINT32ToBigEndian( (FLMUINT32)uiDrn, pSearchBuf); FSInitStackCache( &stack [0], BH_MAX_LEVELS); pStack = &stack[0]; bStackInitialized = TRUE; @@ -207,7 +207,7 @@ Search_Record: } if (uiKeyRelPos == BT_END_OF_DATA || - flmBigEndianToUINT32( pKeyBuf) > uiDrn) + f_bigEndianToUINT32( pKeyBuf) > uiDrn) { // Position to the last element in the block. @@ -244,7 +244,7 @@ Search_Record: } } - uiFoundDrn = flmBigEndianToUINT32( pKeyBuf); + uiFoundDrn = f_bigEndianToUINT32( pKeyBuf); if( uiFoundDrn == DRN_LAST_MARKER) { @@ -338,7 +338,7 @@ FSTATIC RCODE flmRecordRetrieveCS( { RCODE rc; CS_CONTEXT * pCSContext = pDb->pCSContext; - void * pvMark = GedPoolMark( &pCSContext->pool); + void * pvMark = pCSContext->pool.poolMark(); FCL_WIRE Wire( pCSContext, pDb); // Set the record object so that it can be re-used, @@ -431,7 +431,7 @@ FSTATIC RCODE flmRecordRetrieveCS( Exit: - GedPoolReset( &pCSContext->pool, pvMark); + pCSContext->pool.poolReset( pvMark); return( rc); Transmission_Error: diff --git a/flaim/src/flreduce.cpp b/flaim/src/flreduce.cpp index ae59b68..475a063 100644 --- a/flaim/src/flreduce.cpp +++ b/flaim/src/flreduce.cpp @@ -191,30 +191,30 @@ Transmission_Error: if( FSGetFileOffset( uiLogicalEOF) == 0) { - F_FileHdlImp * pFileHdl; + IF_FileHdl * pFileHdl = NULL; FLMUINT uiFileNumber = FSGetFileNumber( uiLogicalEOF) - 1; - FLMUINT uiFileSize; + FLMUINT64 ui64FileSize; FLMUINT uiTemp; - if( RC_BAD( rc = pDb->pSFileHdl->GetFileHdl( + if( RC_BAD( rc = pDb->pSFileHdl->getFileHdl( uiFileNumber, TRUE, &pFileHdl))) { goto Reduce_Size_Error; } - if( RC_BAD( rc = pFileHdl->Size( &uiFileSize))) + if( RC_BAD( rc = pFileHdl->size( &ui64FileSize))) { goto Reduce_Size_Error; } // Adjust to a block bounds - uiTemp = (uiFileSize / uiBlkSize) * uiBlkSize; - if( uiTemp < uiFileSize) + uiTemp = (FLMUINT)((ui64FileSize / uiBlkSize) * uiBlkSize); + if( uiTemp < ui64FileSize) { - uiFileSize = uiTemp + uiBlkSize; + ui64FileSize = uiTemp + uiBlkSize; } - uiLogicalEOF = FSBlkAddress( uiFileNumber, uiFileSize); + uiLogicalEOF = FSBlkAddress( uiFileNumber, (FLMUINT)ui64FileSize); } uiBlkAddr = uiLogicalEOF - uiBlkSize; @@ -273,8 +273,8 @@ Transmission_Error: if( FSGetFileOffset( uiLogicalEOF) == 0) { FLMUINT uiFileNumber = FSGetFileNumber( uiLogicalEOF); - FLMUINT uiFileOffset; - F_FileHdlImp * pFileHdl; + FLMUINT64 ui64FileOffset; + IF_FileHdl * pFileHdl = NULL; if( uiFileNumber <= 1) { @@ -288,18 +288,18 @@ Transmission_Error: // Compute the end of the previous block file. - if( RC_BAD( rc = pDb->pSFileHdl->GetFileHdl( + if( RC_BAD( rc = pDb->pSFileHdl->getFileHdl( uiFileNumber, TRUE, &pFileHdl))) { goto Exit; } - if( RC_BAD( rc = pFileHdl->Size( &uiFileOffset))) + if( RC_BAD( rc = pFileHdl->size( &ui64FileOffset))) { goto Exit; } - uiLogicalEOF = FSBlkAddress( uiFileNumber, uiFileOffset); + uiLogicalEOF = FSBlkAddress( uiFileNumber, (FLMUINT)ui64FileOffset); } uiLogicalEOF -= uiBlkSize; @@ -398,7 +398,7 @@ FSTATIC RCODE FLRReadBlkHdr( RCODE rc = FERR_OK; FLMUINT uiBytesRead; FLMUINT uiNumLooks; - F_FileHdlImp * pTmpFileHdl = NULL; + IF_FileHdl * pTmpFileHdl = NULL; SCACHE * pBlkSCache; DB_STATS * pDbStats = pDb->pDbStats; LFILE_STATS * pLFileStats; @@ -431,10 +431,10 @@ FSTATIC RCODE FLRReadBlkHdr( f_timeGetTimeStamp( &StartTime); } - if( RC_OK( rc = pDb->pSFileHdl->GetFileHdl( + if( RC_OK( rc = pDb->pSFileHdl->getFileHdl( FSGetFileNumber( uiBlkAddress), TRUE, &pTmpFileHdl))) { - rc = pTmpFileHdl->Read( FSGetFileOffset( uiBlkAddress), + rc = pTmpFileHdl->read( FSGetFileOffset( uiBlkAddress), BH_OVHD, pucBlockHeader, &uiBytesRead); } @@ -506,7 +506,7 @@ FSTATIC RCODE FLRReadBlkHdr( { if (rc != FERR_IO_END_OF_FILE && rc != FERR_MEM) { - pDb->pSFileHdl->ReleaseFile( FSGetFileNumber( uiBlkAddress), + pDb->pSFileHdl->releaseFile( FSGetFileNumber( uiBlkAddress), TRUE); } goto Exit; @@ -796,7 +796,7 @@ FSTATIC RCODE FLRMoveBtreeBlk( } else { - rc = FSBtScanNonLeafData( pStack, flmBigEndianToUINT32( ucSearchKey)); + rc = FSBtScanNonLeafData( pStack, f_bigEndianToUINT32( ucSearchKey)); } if( RC_BAD( rc)) { diff --git a/flaim/src/flsweep.cpp b/flaim/src/flsweep.cpp index f11a0ee..df6b2ba 100644 --- a/flaim/src/flsweep.cpp +++ b/flaim/src/flsweep.cpp @@ -27,7 +27,7 @@ /**************************************************************************** Desc: ****************************************************************************/ -class DbDict : public F_Base +class DbDict : public F_Object { public: @@ -72,7 +72,7 @@ private: /**************************************************************************** Desc: ****************************************************************************/ -class DbWalk : public F_Base +class DbWalk : public F_Object { public: diff --git a/flaim/src/flutil.cpp b/flaim/src/flutil.cpp deleted file mode 100644 index a6ca4d9..0000000 --- a/flaim/src/flutil.cpp +++ /dev/null @@ -1,706 +0,0 @@ -//------------------------------------------------------------------------- -// Desc: Various utility functions -// Tabs: 3 -// -// Copyright (c) 1991-1993,1996-2000,2002-2006 Novell, Inc. All Rights Reserved. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of version 2 of the GNU General Public -// License as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, contact Novell, Inc. -// -// To contact Novell about this file by physical or electronic mail, -// you may find current contact information at www.novell.com -// -// $Id: flutil.cpp 12329 2006-01-20 17:49:30 -0700 (Fri, 20 Jan 2006) ahodgkinson $ -//------------------------------------------------------------------------- - -#include "flaimsys.h" - -#define HANDLE_NEGATIVE \ - if( value < 0) \ - { *ptr++ = '-'; \ - absValue = (FLMUINT)(-(value)); \ - } \ - else absValue = (FLMUINT)value; - -#define HANDLE_DNEGATIVE \ - if( value < 0) \ - { *ptr++ = '-'; \ - absValue = (FLMUINT)(-(value)); \ - } \ - else absValue = (FLMUINT)value; - -#define PUSH_DIGITS( v) \ - {register FLMUINT reg = v; \ - do{ *sp++ = (FLMBYTE)((reg % 10) + '0'); \ - } while( reg /= 10); \ - } - -#define POP_DIGITS \ - while( stack < sp--)\ - *ptr++ = *sp; \ - *ptr = '\0'; - -#if defined( FLM_NLM) && defined ( __MWERKS__) - void abort(void); -#endif - -/**************************************************************************** -Desc: Unsigned word to NATIVE value - null terminate the native string -****************************************************************************/ -FLMEXP char * FLMAPI f_uwtoa( - FLMUINT16 value, - char * ptr) -{ - char stack[ 10]; - char * sp = stack; - - PUSH_DIGITS( value); - POP_DIGITS; - - return( ptr); -} - -/**************************************************************************** -Desc: Native to UDWORD value. Supports 0x codes. Non digits NOT ALLOWED - NO LEADING SPACES ALLOWED ! ! ! No checks for overflow over 4 bytes! -****************************************************************************/ -FLMEXP FLMUINT FLMAPI f_atoud( - const char * pszBuf) -{ - FLMUINT uiValue; - FLMBOOL bAllowHex = FALSE; - - if( *pszBuf == NATIVE_ZERO && - (*(pszBuf + 1) == NATIVE_LOWER_X || *(pszBuf + 1) == NATIVE_UPPER_X)) - { - pszBuf += 2; - bAllowHex = TRUE; - } - - uiValue = 0; - while( *pszBuf) - { - if( *pszBuf >= '0' && *pszBuf <= '9') - { - if( !bAllowHex) - { - uiValue *= 10; - } - else - { - uiValue <<= 4; - } - - uiValue += (FLMUINT)(*pszBuf - '0'); - } - else if( bAllowHex) - { - if( *pszBuf >= 'A' && *pszBuf <= 'F') - { - uiValue <<= 4; - uiValue += (FLMUINT)(*pszBuf - 'A') + 10; - } - else if( *pszBuf >= 'a' && *pszBuf <= 'f') - { - uiValue <<= 4; - uiValue += (FLMUINT)(*pszBuf - 'a') + 10; - } - else - { - break; - } - } - else - { - break; - } - pszBuf++; - } - - return( uiValue); -} - -/**************************************************************************** -Desc: Unsigned double (4 byte) number to native value & null terminate -****************************************************************************/ -FLMEXP char * FLMAPI f_udtoa( - FLMUINT value, - char * ptr) -{ - char stack[ 10]; - char * sp = stack; - - PUSH_DIGITS( value); - POP_DIGITS; - - return( ptr); -} - -/**************************************************************************** -Desc: Word to native value - null terminate the native string -****************************************************************************/ -FLMEXP char * FLMAPI f_wtoa( - FLMINT16 value, - char * ptr) -{ - char stack[ 10]; - char * sp = stack; - FLMUINT absValue; - - HANDLE_NEGATIVE; - PUSH_DIGITS( absValue); - POP_DIGITS; - - return( ptr); -} - -/**************************************************************************** -Desc: Double (4 byte) number to native value - null terminate the string -****************************************************************************/ -FLMEXP char * FLMAPI f_dtoa( - FLMINT value, - char * ptr) -{ - char stack[ 10]; - char * sp = stack; - FLMUINT absValue; - - HANDLE_DNEGATIVE; - PUSH_DIGITS( absValue); - POP_DIGITS; - - return( ptr); -} - -/**************************************************************************** -Desc: Ascii to integer -****************************************************************************/ -FLMEXP FLMINT FLMAPI f_atoi( - const char * ptr) -{ - return( f_atod( ptr)); -} - -/**************************************************************************** -Desc: native to long -****************************************************************************/ -FLMEXP FLMINT FLMAPI f_atol( - const char * ptr) -{ - return( f_atod( ptr)); -} - -/**************************************************************************** -Desc: Native to DWORD value. Supports 0x codes. Non digits NOT ALLOWED - NO LEADING SPACES ALLOWED ! ! ! No checks for overflow over 4 bytes! -****************************************************************************/ -FLMEXP FLMINT FLMAPI f_atod( - const char * pszBuf) -{ - FLMINT iValue; - FLMBOOL bNeg = FALSE; - - if( *pszBuf == '-') - { - bNeg = TRUE; - pszBuf++; - } - else if( *pszBuf == '+') - { - pszBuf++; - } - - iValue = (FLMINT)f_atoud( pszBuf); - return( bNeg ? -iValue : iValue); -} - -/**************************************************************************** -Desc: Utility function to return the maximum size of a hex number - represented as a string. -****************************************************************************/ -FINLINE FLMUINT maxHexSize( - FLMUINT uiSizeOfPtr) -{ - return uiSizeOfPtr * 2; -} - -/**************************************************************************** -Desc: Utility function to return the maximum size of a decimal number - represented as a string. -****************************************************************************/ -FINLINE FLMUINT maxDecimalSize( - FLMUINT uiSizeOfPtr) -{ - switch (uiSizeOfPtr) - { - case 4: - return 10; - case 8: - return 20; - default: - flmAssert( 0); - return 0; - } -} - -/**************************************************************************** -Desc: Compares two Unicode strings -****************************************************************************/ -FLMEXP FLMINT FLMAPI f_unicmp( - const FLMUNICODE * puzStr1, - const FLMUNICODE * puzStr2) -{ - while( *puzStr1 == *puzStr2 && *puzStr1) - { - puzStr1++; - puzStr2++; - } - - return( (FLMINT)*puzStr1 - (FLMINT)*puzStr2); -} - -/**************************************************************************** -Desc: Returns the length of a unicode string -****************************************************************************/ -FLMEXP FLMUINT FLMAPI f_unilen( - const FLMUNICODE * puzStr) -{ - FLMUINT uiLen = 0; - - if( !puzStr) - { - goto Exit; - } - - while( *puzStr) - { - puzStr++; - uiLen++; - } - -Exit: - - return( uiLen); -} - -/**************************************************************************** -Desc: Finds a substring -****************************************************************************/ -FLMEXP FLMUNICODE * FLMAPI f_uniindex( - const FLMUNICODE * puzStr, - const FLMUNICODE * puzSearch) -{ - const FLMUNICODE * puzSearchPos; - const FLMUNICODE * puzStrPos; - FLMUNICODE uFirstChar; - - if( !puzStr || !puzSearch || (uFirstChar = *puzSearch) == 0) - { - return( NULL); - } - - do - { - while( *puzStr) - { - if( *puzStr == uFirstChar) - { - break; - } - puzStr++; - } - - if( *puzStr == 0) - { - return( NULL); - } - - if( *(puzSearch + 1) == 0) - { - return( (FLMUNICODE *)puzStr); - } - - for( puzSearchPos = puzSearch + 1, puzStrPos = puzStr + 1; - *puzSearchPos == *puzStrPos; puzSearchPos++, puzStrPos++) - { - if( puzSearchPos[ 1] == 0) - { - return( (FLMUNICODE *)puzStr); - } - } - - puzStr++; - } while( *puzStr); - - return( NULL); -} - -/**************************************************************************** -Desc: The equivalent of strncmp for unicode strings. -****************************************************************************/ -FLMEXP FLMINT FLMAPI f_unincmp( - const FLMUNICODE * puzStr1, - const FLMUNICODE * puzStr2, - FLMUINT uiLen) -{ - if( !uiLen) - { - return( 0); - } - - while( *puzStr1 == *puzStr2 && *puzStr1 && --uiLen) - { - puzStr1++; - puzStr2++; - } - - return( *puzStr1 - *puzStr2); -} - -/**************************************************************************** -Desc: Compares two strings, one Unicode and one native -****************************************************************************/ -FLMEXP FLMINT FLMAPI f_uninativecmp( - const FLMUNICODE * puzStr1, - const char * pszStr2) -{ - while( *puzStr1 == ((FLMUNICODE)f_toascii( *pszStr2)) && *puzStr1) - { - puzStr1++; - pszStr2++; - } - - return( (FLMINT)*puzStr1 - (FLMINT)*pszStr2); -} - -/**************************************************************************** -Desc: Compares two strings, one Unicode and one native -****************************************************************************/ -FLMEXP FLMINT FLMAPI f_uninativencmp( - const FLMUNICODE * puzStr1, - const char * pszStr2, - FLMUINT uiCount) -{ - if( !uiCount) - { - return( 0); - } - - while( uiCount && - *puzStr1 == ((FLMUNICODE)f_toascii( *pszStr2)) && *puzStr1) - { - puzStr1++; - pszStr2++; - uiCount--; - } - - return( uiCount ? ((FLMINT)*puzStr1 - (FLMINT)*pszStr2) : 0); -} - -/**************************************************************************** -Desc: Copies a unicode string -****************************************************************************/ -FLMEXP FLMUNICODE * FLMAPI f_unicpy( - FLMUNICODE * puzDestStr, - const FLMUNICODE * puzSrcStr) -{ - const FLMUNICODE * puzSrc = puzSrcStr; - FLMUNICODE * puzDest = puzDestStr; - - while( *puzSrc) - { - *puzDest++ = *puzSrc++; - } - - *puzDest = 0; - return( puzDestStr); -} - -/**************************************************************************** -Desc: Copies a native string into a Unicode buffer -****************************************************************************/ -FLMEXP void FLMAPI f_nativetounistrcpy( - FLMUNICODE * puzDest, - const char * pszSrc) -{ - while( *pszSrc) - { - *puzDest++ = f_toascii( *pszSrc++); - } - *puzDest = 0; -} - -/**************************************************************************** -Desc: Abort function. Required only when compiling with Codewarrior. For - some reason we don't have an implementation of this in any of the libraries - we are linking against. -****************************************************************************/ -#if defined( FLM_NLM) && defined( __MWERKS__) -void abort(void) -{ - flmAssert(0); -} -#endif - -/*************************************************************************** -Desc: Sort an array of items -****************************************************************************/ -void f_qsort( - void * pvBuffer, - FLMUINT uiLowerBounds, - FLMUINT uiUpperBounds, - F_SORT_COMPARE_FUNC fnCompare, - F_SORT_SWAP_FUNC fnSwap) -{ - FLMUINT uiLBPos; - FLMUINT uiUBPos; - FLMUINT uiMIDPos; - FLMUINT uiCurrentPos; - FLMUINT uiLeftItems; - FLMUINT uiRightItems; - FLMINT iCompare; - -Iterate_Larger_Half: - - uiUBPos = uiUpperBounds; - uiLBPos = uiLowerBounds; - uiMIDPos = (uiUpperBounds + uiLowerBounds + 1) / 2; - uiCurrentPos = uiMIDPos; - - for (;;) - { - while (uiLBPos == uiMIDPos || - ((iCompare = - fnCompare( pvBuffer, uiLBPos, uiCurrentPos)) < 0)) - { - if( uiLBPos >= uiUpperBounds) - { - break; - } - uiLBPos++; - } - - while( uiUBPos == uiMIDPos || - (((iCompare = - fnCompare( pvBuffer, uiCurrentPos, uiUBPos)) < 0))) - { - if (!uiUBPos) - { - break; - } - uiUBPos--; - } - - if( uiLBPos < uiUBPos) - { - // Exchange [uiLBPos] with [uiUBPos]. - - fnSwap( pvBuffer, uiLBPos, uiUBPos); - uiLBPos++; - uiUBPos--; - } - else - { - break; - } - } - - // Check for swap( LB, MID ) - cases 3 and 4 - - if( uiLBPos < uiMIDPos ) - { - - // Exchange [uiLBPos] with [uiMIDPos] - - fnSwap( pvBuffer, uiMIDPos, uiLBPos); - uiMIDPos = uiLBPos; - } - else if( uiMIDPos < uiUBPos ) - { - // Exchange [uUBPos] with [uiMIDPos] - - fnSwap( pvBuffer, uiMIDPos, uiUBPos); - uiMIDPos = uiUBPos; - } - - // Check the left piece. - - uiLeftItems = (uiLowerBounds + 1 < uiMIDPos) - ? uiMIDPos - uiLowerBounds - : 0; - - uiRightItems = (uiMIDPos + 1 < uiUpperBounds) - ? uiUpperBounds - uiMIDPos - : 0; - - if( uiLeftItems < uiRightItems) - { - // Recurse on the LEFT side and goto the top on the RIGHT side. - - if( uiLeftItems) - { - f_qsort( pvBuffer, uiLowerBounds, uiMIDPos - 1, fnCompare, fnSwap); - } - - uiLowerBounds = uiMIDPos + 1; - goto Iterate_Larger_Half; - } - else if( uiLeftItems) - { - // Recurse on the RIGHT side and goto the top for the LEFT side. - - if (uiRightItems ) - { - f_qsort( pvBuffer, uiMIDPos + 1, uiUpperBounds, fnCompare, fnSwap); - } - - uiUpperBounds = uiMIDPos - 1; - goto Iterate_Larger_Half; - } -} - -/*************************************************************************** -Desc: -****************************************************************************/ -FLMINT flmQSortUINTCompare( - void * pvBuffer, - FLMUINT uiPos1, - FLMUINT uiPos2) -{ - FLMUINT uiLeft = *(((FLMUINT *)pvBuffer) + uiPos1); - FLMUINT uiRight = *(((FLMUINT *)pvBuffer) + uiPos2); - - if( uiLeft < uiRight) - { - return( -1); - } - else if( uiLeft > uiRight) - { - return( 1); - } - - return( 0); -} - -/*************************************************************************** -Desc: -****************************************************************************/ -void flmQSortUINTSwap( - void * pvBuffer, - FLMUINT uiPos1, - FLMUINT uiPos2) -{ - FLMUINT * puiArray = (FLMUINT *)pvBuffer; - FLMUINT uiTmp = puiArray[ uiPos1]; - - puiArray[ uiPos1] = puiArray[ uiPos2]; - puiArray[ uiPos2] = uiTmp; -} - -/**************************************************************************** -Desc: Determine if a token is a number. -****************************************************************************/ -FLMEXP FLMBOOL FLMAPI tokenIsNum( - const char * pszToken, - FLMUINT * puiNum) -{ - FLMBOOL bIsNum = TRUE; - FLMUINT uiNum; - FLMBOOL bAllowHex = FALSE; - - if (*pszToken == 0) - { - bIsNum = FALSE; - goto Exit; - } - - if (*pszToken == '0' && - (*(pszToken + 1) == 'x' || *(pszToken + 1) == 'X')) - { - pszToken += 2; - bAllowHex = TRUE; - } - - uiNum = 0; - while (*pszToken) - { - if (*pszToken >= '0' && *pszToken <= '9') - { - if (!bAllowHex) - { - if (uiNum > (FLMUINT)(-1) / 10) - { - - // Number would overflow. - - bIsNum = FALSE; - goto Exit; - } - else - { - uiNum *= 10; - } - } - else - { - if (uiNum > (FLMUINT)(-1) >> 4) - { - - // Number would overflow. - - bIsNum = FALSE; - goto Exit; - } - uiNum <<= 4; - } - uiNum += (FLMUINT)(*pszToken - '0'); - } - else if (bAllowHex) - { - if (uiNum > (FLMUINT)(-1) >> 4) - { - - // Number would overflow. - - bIsNum = FALSE; - goto Exit; - } - if (*pszToken >= 'A' && *pszToken <= 'F') - { - uiNum <<= 4; - uiNum += (FLMUINT)(*pszToken - 'A') + 10; - } - else if (*pszToken >= 'a' && *pszToken <= 'f') - { - uiNum <<= 4; - uiNum += (FLMUINT)(*pszToken - 'a') + 10; - } - else - { - bIsNum = FALSE; - goto Exit; - } - } - else - { - bIsNum = FALSE; - goto Exit; - } - pszToken++; - } - - *puiNum = uiNum; - -Exit: - - return( bIsNum); -} diff --git a/flaim/src/flverify.cpp b/flaim/src/flverify.cpp index a9c800d..0cc2787 100644 --- a/flaim/src/flverify.cpp +++ b/flaim/src/flverify.cpp @@ -1205,12 +1205,12 @@ eCorruptionType flmVerifyKey( FLMUINT uiCaseBits; FLMUINT uiFieldType; - bIxAsia = (uiIxLang >= FIRST_DBCS_LANG && uiIxLang <= LAST_DBCS_LANG) + bIxAsia = (uiIxLang >= FLM_FIRST_DBCS_LANG && uiIxLang <= FLM_LAST_DBCS_LANG) ? TRUE : FALSE; - bIxArab = (uiIxLang == AR_LANG || uiIxLang == FA_LANG || - uiIxLang == HE_LANG || uiIxLang == UR_LANG) + bIxArab = (uiIxLang == FLM_AR_LANG || uiIxLang == FLM_FA_LANG || + uiIxLang == FLM_HE_LANG || uiIxLang == FLM_UR_LANG) ? TRUE : FALSE; @@ -1317,7 +1317,7 @@ eCorruptionType flmVerifyKey( if (pIfd->uiFlags & IFD_COMPOUND) { - if (flmBigEndianToUINT16( &pKey[uiJ + 1]) != pIfd->uiFldNum) + if (f_bigEndianToUINT16( &pKey[uiJ + 1]) != pIfd->uiFldNum) { return (FLM_BAD_CONTEXT_KEY); } @@ -1335,7 +1335,7 @@ eCorruptionType flmVerifyKey( uiH < uiTrueNumIxFields; uiH++, pTmpIfd++) { - if (flmBigEndianToUINT16( &pKey[uiJ + 1]) == pTmpIfd->uiFldNum) + if (f_bigEndianToUINT16( &pKey[uiJ + 1]) == pTmpIfd->uiFldNum) { break; } @@ -1911,7 +1911,7 @@ eCorruptionType flmVerifyElement( f_memcpy( &ucRecBuff[uiElmPKCLen], pElmKey, uiElmKeyLen); } - pStateInfo->uiElmDrn = flmBigEndianToUINT32( ucRecBuff); + pStateInfo->uiElmDrn = f_bigEndianToUINT32( ucRecBuff); if (pStateInfo->uiElmDrn == DRN_LAST_MARKER && uiBlkType == BHT_LEAF) { FLMUINT uiTempDrn; diff --git a/flaim/src/fmisc.cpp b/flaim/src/fmisc.cpp index 3e35598..e867dd5 100644 --- a/flaim/src/fmisc.cpp +++ b/flaim/src/fmisc.cpp @@ -24,97 +24,6 @@ #include "flaimsys.h" -/**************************************************************************** -Desc: FLAIM language code table -****************************************************************************/ -static char flmLangTable[ LAST_LANG + LAST_LANG] = -{ - 'U', 'S', // English, United States - 'A', 'F', // Afrikaans - 'A', 'R', // Arabic - 'C', 'A', // Catalan - 'H', 'R', // Croatian - 'C', 'Z', // Czech - 'D', 'K', // Danish - 'N', 'L', // Dutch - 'O', 'Z', // English, Australia - 'C', 'E', // English, Canada - 'U', 'K', // English, United Kingdom - 'F', 'A', // Farsi - 'S', 'U', // Finnish - 'C', 'F', // French, Canada - 'F', 'R', // French, France - 'G', 'A', // Galician - 'D', 'E', // German, Germany - 'S', 'D', // German, Switzerland - 'G', 'R', // Greek - 'H', 'E', // Hebrew - 'M', 'A', // Hungarian - 'I', 'S', // Icelandic - 'I', 'T', // Italian - 'N', 'O', // Norwegian - 'P', 'L', // Polish - 'B', 'R', // Portuguese, Brazil - 'P', 'O', // Portuguese, Portugal - 'R', 'U', // Russian - 'S', 'L', // Slovak - 'E', 'S', // Spanish - 'S', 'V', // Swedish - 'Y', 'K', // Ukrainian - 'U', 'R', // Urdu - 'T', 'K', // Turkey - 'J', 'P', // Japanese - 'K', 'R', // Korean - 'C', 'T', // Chinese-Traditional - 'C', 'S', // Chinese-Simplified - 'L', 'A' // Future asian language -}; - -/**************************************************************************** -Desc: Determine the language number from the 2 byte language code -****************************************************************************/ -FLMEXP FLMUINT FLMAPI FlmLanguage( - char * pszLanguageCode) -{ - char cFirstChar = *pszLanguageCode; - char cSecondChar = *(pszLanguageCode + 1); - FLMUINT uiTablePos; - - for (uiTablePos = 0; uiTablePos < (LAST_LANG+LAST_LANG); uiTablePos += 2 ) - { - if (flmLangTable[ uiTablePos] == cFirstChar && - flmLangTable[ uiTablePos + 1] == cSecondChar) - { - - // Return uiTablePos div 2 - - return( uiTablePos >> 1); - } - } - - // Language not found, return default US language - - return( US_LANG); -} - -/**************************************************************************** -Desc: Determine the language code from the language number -****************************************************************************/ -FLMEXP void FLMAPI FlmGetLanguage( - FLMUINT uiLangNum, - char * pszLanguageCode) -{ - if (uiLangNum >= LAST_LANG) - { - uiLangNum = US_LANG; - } - - uiLangNum += uiLangNum; - *pszLanguageCode++ = flmLangTable[ uiLangNum]; - *pszLanguageCode++ = flmLangTable[ uiLangNum + 1]; - *pszLanguageCode = 0; -} - /**************************************************************************** Desc: Returns TRUE if the passed in RCODE indicates that a corruption has occured in a FLAIM database file. diff --git a/flaim/src/fmutxref.h b/flaim/src/fmutxref.h deleted file mode 100644 index 24c00f9..0000000 --- a/flaim/src/fmutxref.h +++ /dev/null @@ -1,95 +0,0 @@ -//------------------------------------------------------------------------- -// Desc: Definitions for mutex handling class -// Tabs: 3 -// -// Copyright (c) 1998-2000,2002-2006 Novell, Inc. All Rights Reserved. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of version 2 of the GNU General Public -// License as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, contact Novell, Inc. -// -// To contact Novell about this file by physical or electronic mail, -// you may find current contact information at www.novell.com -// -// $Id: fmutxref.h 12329 2006-01-20 17:49:30 -0700 (Fri, 20 Jan 2006) ahodgkinson $ -//------------------------------------------------------------------------- - -#ifndef FMUTXREF_H -#define FMUTXREF_H - -#include "fpackon.h" -// IMPORTANT NOTE: No other include files should follow this one except -// for fpackoff.h - -/**************************************************************************** -Desc: This object provides management and use of a mutex -****************************************************************************/ -class F_MutexRef : public F_Base -{ -public: - F_MutexRef( // Constructor - F_MUTEX * phMutex) // Actual semaphore object to use. - { - m_phMutex = phMutex; - m_uiLockCount = 0; - }; - - virtual ~F_MutexRef() // Destructor - make sure lock count == 0. - { - /* Unlock the semaphore if it is locked. - - The semaphore could be still locked on an error condition within the - users code. - */ - if( m_uiLockCount != 0) - { - (void)f_mutexUnlock( *m_phMutex); - } - }; - - void Lock() // Locks the semaphore - { - if( m_phMutex) - { - if( !m_uiLockCount) - { - (void)f_mutexLock( *m_phMutex); - } - m_uiLockCount++; - } - }; - - void Unlock() // Unlock the semaphore - { - if( m_phMutex) - { - //flmAssert( m_uiLockCount != 0); // Should not be zero - if( !( --m_uiLockCount)) - { - (void)f_mutexUnlock( *m_phMutex); - } - } - }; - -private: - - FLMUINT m_uiLockCount; // Number of times the semaphore has - // been locked by the thread. - F_MUTEX * m_phMutex; // Pointer to semaphore. If NULL, - // there is no need to lock and - // unlock the semaphore because the - // objects it is controlling are NOT - // shared. -}; - -#include "fpackoff.h" - -#endif diff --git a/flaim/src/fnlm.cpp b/flaim/src/fnlm.cpp deleted file mode 100644 index 316b784..0000000 --- a/flaim/src/fnlm.cpp +++ /dev/null @@ -1,3946 +0,0 @@ -//------------------------------------------------------------------------- -// Desc: I/O for Netware OS -// Tabs: 3 -// -// Copyright (c) 1998-2003,2005-2006 Novell, Inc. All Rights Reserved. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of version 2 of the GNU General Public -// License as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, contact Novell, Inc. -// -// To contact Novell about this file by physical or electronic mail, -// you may find current contact information at www.novell.com -// -// $Id: fnlm.cpp 12362 2006-03-09 12:11:37 -0700 (Thu, 09 Mar 2006) dsanders $ -//------------------------------------------------------------------------- - -#include "flaimsys.h" - -#if defined( FLM_NLM) - -#define F_IO_MAX_CREATION_TRIES 10 -#define zMAX_COMPONENT_NAME 256 -#define zGET_INFO_VARIABLE_DATA_SIZE (zMAX_COMPONENT_NAME * 2) - -#define zOK 0 // the operation succeeded -#define zERR_NO_MEMORY 20000 // insufficent memory to complete the request -#define zERR_NOT_SUPPORTED 20011 // the operation is not supported -#define zERR_CONNECTION_NOT_LOGGED_IN 20007 // the connection has not been logged in -#define zERR_END_OF_FILE 20100 // read past the end of file -#define zERR_OUT_OF_SPACE 20103 // no available disk space is left -#define zERR_BAD_FILE_HANDLE 20401 // the file handle is out of range, bad instance, or doesn't exist -#define zERR_INVALID_NAME 20403 // path name is invalid -- bad syntax -#define zERR_INVALID_CHAR_IN_NAME 20404 // path name had an invalid character -#define zERR_INVALID_PATH 20405 // the path is syntactically incorrect -#define zERR_NAME_NOT_FOUND_IN_DIRECTORY 20407 // name does not exist in the direcory being searched -#define zERR_NO_NAMES_IN_PATH 20409 // a NULL file name was given -#define zERR_NO_MORE_NAMES_IN_PATH 20410 // doing a wild search but ran out of names to search -#define zERR_PATH_MUST_BE_FULLY_QUALIFIED 20411 // path name must be fully qualified in this context -#define zERR_FILE_ALREADY_EXISTS 20412 // the given file already exists -#define zERR_NAME_NO_LONGER_VALID 20413 // the dir/file name is no longer valid -#define zERR_DIRECTORY_NOT_EMPTY 20417 // the directory still has files in it -#define zERR_NO_FILES_FOUND 20424 // no files matched the given wildcard pattern -#define zERR_DIR_CANNOT_BE_OPENED 20435 // the requested parent was not found -#define zERR_NO_OPEN_PRIVILEGE 20438 // no the right privileges to open the file -#define zERR_NO_MORE_CONTEXT_HANDLE_IDS 20439 // there are no more available context handle IDs -#define zERR_INVALID_PATH_FORMAT 20441 // the pathFormat is either invalid or unsupported -#define zERR_ALL_FILES_IN_USE 20500 // all files were in use -#define zERR_SOME_FILES_IN_USE 20501 // some of the files were in use -#define zERR_ALL_FILES_READ_ONLY 20502 // all files were READONLY -#define zERR_SOME_FILES_READ_ONLY 20503 // some of the files were READONLY -#define zERR_ALL_NAMES_EXIST 20504 // all of the names already existed -#define zERR_SOME_NAMES_EXIST 20505 // some of the names already existed -#define zERR_NO_RENAME_PRIVILEGE 20506 // you do not have privilege to rename the file -#define zERR_RENAME_DIR_INVALID 20507 // the selected directory may not be renamed -#define zERR_RENAME_TO_OTHER_VOLUME 20508 // a rename/move may not move the beast to a different volume -#define zERR_CANT_RENAME_DATA_STREAMS 20509 // not allowed to rename a data stream -#define zERR_FILE_RENAME_IN_PROGRESS 20510 // the file is already being renamed by a different process -#define zERR_CANT_RENAME_TO_DELETED 20511 // only deleted files may be renamed to a deleted state -#define zERR_HOLE_IN_DIO_FILE 20651 // DIO files cannot have holes -#define zERR_BEYOND_EOF 20652 // DIO files cannot be read beyond EOF -#define zERR_INVALID_PATH_SEPARATOR 20704 // the name space does not support the requested path separator type -#define zERR_VOLUME_SEPARATOR_NOT_SUPPORTED 20705 // the name space does not support volume separators -#define zERR_BAD_VOLUME_NAME 20800 // the given volume name is syntactically incorrect -#define zERR_VOLUME_NOT_FOUND 20801 // the given volume name could not be found -#define zERR_NO_SET_PRIVILEGE 20850 // does not have rights to modify metadata -#define zERR_NO_CREATE_PRIVILEGE 20851 // does not have rights to create an object -#define zERR_ACCESS_DENIED 20859 // authorization/attributes denied access -#define zERR_NO_WRITE_PRIVILEGE 20860 // no granted write privileges -#define zERR_NO_READ_PRIVILEGE 20861 // no granted read privileges -#define zERR_NO_DELETE_PRIVILEGE 20862 // no delete privileges -#define zERR_SOME_NO_DELETE_PRIVILEGE 20863 // on wildcard some do not have delete privileges -#define zERR_NO_SUCH_OBJECT 20867 // no such object in the naming services -#define zERR_CANT_DELETE_OPEN_FILE 20868 // cant delete an open file without rights -#define zERR_NO_CREATE_DELETE_PRIVILEGE 20869 // no delete on create privileges -#define zERR_NO_SALVAGE_PRIVILEGE 20870 // no privileges to salvage this file -#define zERR_FILE_READ_LOCKED 20905 // cant grant read access to the file -#define zERR_FILE_WRITE_LOCKED 20906 // cant grant write access to the file - -#define zRR_READ_ACCESS 0x00000001 -#define zRR_WRITE_ACCESS 0x00000002 -#define zRR_DENY_READ 0x00000004 -#define zRR_DENY_WRITE 0x00000008 -#define zRR_SCAN_ACCESS 0x00000010 -#define zRR_ENABLE_IO_ON_COMPRESSED_DATA 0x00000100 -#define zRR_LEAVE_FILE_COMPRESSED 0x00000200 -#define zRR_DELETE_FILE_ON_CLOSE 0x00000400 -#define zRR_FLUSH_ON_CLOSE 0x00000800 -#define zRR_PURGE_IMMEDIATE_ON_CLOSE 0x00001000 -#define zRR_DIO_MODE 0x00002000 -#define zRR_ALLOW_SECURE_DIRECTORY_ACCESS 0x00020000 -#define zRR_TRANSACTION_ACTIVE 0x00100000 -#define zRR_READ_ACCESS_TO_SNAPSHOT 0x04000000 -#define zRR_DENY_RW_OPENER_CAN_REOPEN 0x08000000 -#define zRR_CREATE_WITHOUT_READ_ACCESS 0x10000000 -#define zRR_OPENER_CAN_DELETE_WHILE_OPEN 0x20000000 -#define zRR_CANT_DELETE_WHILE_OPEN 0x40000000 -#define zRR_DONT_UPDATE_ACCESS_TIME 0x80000000 - -#define zFA_READ_ONLY 0x00000001 -#define zFA_HIDDEN 0x00000002 -#define zFA_SYSTEM 0x00000004 -#define zFA_EXECUTE 0x00000008 -#define zFA_SUBDIRECTORY 0x00000010 -#define zFA_ARCHIVE 0x00000020 -#define zFA_SHAREABLE 0x00000080 -#define zFA_SMODE_BITS 0x00000700 -#define zFA_NO_SUBALLOC 0x00000800 -#define zFA_TRANSACTION 0x00001000 -#define zFA_NOT_VIRTUAL_FILE 0x00002000 -#define zFA_IMMEDIATE_PURGE 0x00010000 -#define zFA_RENAME_INHIBIT 0x00020000 -#define zFA_DELETE_INHIBIT 0x00040000 -#define zFA_COPY_INHIBIT 0x00080000 -#define zFA_IS_ADMIN_LINK 0x00100000 -#define zFA_IS_LINK 0x00200000 -#define zFA_REMOTE_DATA_INHIBIT 0x00800000 -#define zFA_COMPRESS_FILE_IMMEDIATELY 0x02000000 -#define zFA_DATA_STREAM_IS_COMPRESSED 0x04000000 -#define zFA_DO_NOT_COMPRESS_FILE 0x08000000 -#define zFA_CANT_COMPRESS_DATA_STREAM 0x20000000 -#define zFA_ATTR_ARCHIVE 0x40000000 -#define zFA_VOLATILE 0x80000000 - -#define zNSPACE_DOS 0 -#define zNSPACE_MAC 1 -#define zNSPACE_UNIX 2 -#define zNSPACE_LONG 4 -#define zNSPACE_DATA_STREAM 6 -#define zNSPACE_EXTENDED_ATTRIBUTE 7 -#define zNSPACE_INVALID (-1) -#define zNSPACE_DOS_MASK (1 << zNSPACE_DOS) -#define zNSPACE_MAC_MASK (1 << zNSPACE_MAC) -#define zNSPACE_UNIX_MASK (1 << zNSPACE_UNIX) -#define zNSPACE_LONG_MASK (1 << zNSPACE_LONG) -#define zNSPACE_DATA_STREAM_MASK (1 << zNSPACE_DATA_STREAM) -#define zNSPACE_EXTENDED_ATTRIBUTE_MASK (1 << zNSPACE_EXTENDED_ATTRIBUTE) -#define zNSPACE_ALL_MASK (0xffffffff) - -#define zMODE_VOLUME_ID 0x80000000 -#define zMODE_UTF8 0x40000000 -#define zMODE_DELETED 0x20000000 -#define zMODE_LINK 0x10000000 - -#define zCREATE_OPEN_IF_THERE 0x00000001 -#define zCREATE_TRUNCATE_IF_THERE 0x00000002 -#define zCREATE_DELETE_IF_THERE 0x00000004 - -#define zMATCH_ALL_DERIVED_TYPES 0x00000001 -#define zMATCH_HIDDEN 0x1 -#define zMATCH_NON_HIDDEN 0x2 -#define zMATCH_DIRECTORY 0x4 -#define zMATCH_NON_DIRECTORY 0x8 -#define zMATCH_SYSTEM 0x10 -#define zMATCH_NON_SYSTEM 0x20 -#define zMATCH_ALL (~0) - -#define zSETSIZE_NON_SPARSE_FILE 0x00000001 -#define zSETSIZE_NO_ZERO_FILL 0x00000002 -#define zSETSIZE_UNDO_ON_ERR 0x00000004 -#define zSETSIZE_PHYSICAL_ONLY 0x00000008 -#define zSETSIZE_LOGICAL_ONLY 0x00000010 -#define zSETSIZE_COMPRESSED 0x00000020 - -#define zMOD_FILE_ATTRIBUTES 0x00000001 -#define zMOD_CREATED_TIME 0x00000002 -#define zMOD_ARCHIVED_TIME 0x00000004 -#define zMOD_MODIFIED_TIME 0x00000008 -#define zMOD_ACCESSED_TIME 0x00000010 -#define zMOD_METADATA_MODIFIED_TIME 0x00000020 -#define zMOD_OWNER_ID 0x00000040 -#define zMOD_ARCHIVER_ID 0x00000080 -#define zMOD_MODIFIER_ID 0x00000100 -#define zMOD_METADATA_MODIFIER_ID 0x00000200 -#define zMOD_PRIMARY_NAMESPACE 0x00000400 -#define zMOD_DELETED_INFO 0x00000800 -#define zMOD_MAC_METADATA 0x00001000 -#define zMOD_UNIX_METADATA 0x00002000 -#define zMOD_EXTATTR_FLAGS 0x00004000 -#define zMOD_VOL_ATTRIBUTES 0x00008000 -#define zMOD_VOL_NDS_OBJECT_ID 0x00010000 -#define zMOD_VOL_MIN_KEEP_SECONDS 0x00020000 -#define zMOD_VOL_MAX_KEEP_SECONDS 0x00040000 -#define zMOD_VOL_LOW_WATER_MARK 0x00080000 -#define zMOD_VOL_HIGH_WATER_MARK 0x00100000 -#define zMOD_POOL_ATTRIBUTES 0x00200000 -#define zMOD_POOL_NDS_OBJECT_ID 0x00400000 -#define zMOD_VOL_DATA_SHREDDING_COUNT 0x00800000 -#define zMOD_VOL_QUOTA 0x01000000 - -/*************************************************************************** -Desc: -***************************************************************************/ -enum zGetInfoMask_t -{ - zGET_STD_INFO = 0x1, - zGET_NAME = 0x2, - zGET_ALL_NAMES = 0x4, - zGET_PRIMARY_NAMESPACE = 0x8, - zGET_TIMES_IN_SECS = 0x10, - zGET_TIMES_IN_MICROS = 0x20, - zGET_IDS = 0x40, - zGET_STORAGE_USED = 0x80, - zGET_BLOCK_SIZE = 0x100, - zGET_COUNTS = 0x200, - zGET_EXTENDED_ATTRIBUTE_INFO = 0x400, - zGET_DATA_STREAM_INFO = 0x800, - zGET_DELETED_INFO = 0x1000, - zGET_MAC_METADATA = 0x2000, - zGET_UNIX_METADATA = 0x4000, - zGET_EXTATTR_FLAGS = 0x8000, - zGET_VOLUME_INFO = 0x10000, - zGET_VOL_SALVAGE_INFO = 0x20000, - zGET_POOL_INFO = 0x40000 -}; - -/*************************************************************************** -Desc: -***************************************************************************/ -enum -{ - zINFO_VERSION_A = 1 -}; - -/*************************************************************************** -Desc: -***************************************************************************/ -typedef enum FileType_t -{ - zFILE_UNKNOWN, - zFILE_REGULAR, - zFILE_EXTENDED_ATTRIBUTE, - zFILE_NAMED_DATA_STREAM, - zFILE_PIPE, - zFILE_VOLUME, - zFILE_POOL, - zFILE_MAX -} FileType_t; - -/*************************************************************************** -Desc: -***************************************************************************/ -typedef struct GUID_t -{ - LONG timeLow; - WORD timeMid; - WORD timeHighAndVersion; - BYTE clockSeqHighAndReserved; - BYTE clockSeqLow; - BYTE node[ 6]; -} GUID_t; - -/*************************************************************************** -Desc: -***************************************************************************/ -typedef struct zMacInfo_s -{ - BYTE finderInfo[32]; - BYTE proDOSInfo[6]; - BYTE filler[2]; - LONG dirRightsMask; -} zMacInfo_s; - -/*************************************************************************** -Desc: -***************************************************************************/ -typedef struct zUnixInfo_s -{ - LONG fMode; - LONG rDev; - LONG myFlags; - LONG nfsUID; - LONG nfsGID; - LONG nwUID; - LONG nwGID; - LONG nwEveryone; - LONG nwUIDRights; - LONG nwGIDRights; - LONG nwEveryoneRights; - BYTE acsFlags; - BYTE firstCreated; - FLMINT16 variableSize; -} zUnixInfo_s; - -typedef struct zVolumeInfo_s -{ - GUID_t volumeID; - GUID_t ndsObjectID; - LONG volumeState; - LONG nameSpaceMask; - - struct - { - FLMUINT64 enabled; - FLMUINT64 enableModMask; - FLMUINT64 supported; - } features; - - FLMUINT64 maximumFileSize; - FLMUINT64 totalSpaceQuota; - FLMUINT64 numUsedBytes; - FLMUINT64 numObjects; - FLMUINT64 numFiles; - LONG authModelID; - LONG dataShreddingCount; - - struct - { - FLMUINT64 purgeableBytes; - FLMUINT64 nonPurgeableBytes; - FLMUINT64 numDeletedFiles; - FLMUINT64 oldestDeletedTime; - LONG minKeepSeconds; - LONG maxKeepSeconds; - LONG lowWaterMark; - LONG highWaterMark; - } salvage; - - struct - { - FLMUINT64 numCompressedFiles; - FLMUINT64 numCompDelFiles; - FLMUINT64 numUncompressibleFiles; - FLMUINT64 numPreCompressedBytes; - FLMUINT64 numCompressedBytes; - } comp; - -} zVolumeInfo_s; - -/*************************************************************************** -Desc: -***************************************************************************/ -typedef struct zPoolInfo_s -{ - GUID_t poolID; - GUID_t ndsObjectID; - LONG poolState; - LONG nameSpaceMask; - - struct - { - FLMUINT64 enabled; - FLMUINT64 enableModMask; - FLMUINT64 supported; - } features; - - FLMUINT64 totalSpace; - FLMUINT64 numUsedBytes; - FLMUINT64 purgeableBytes; - FLMUINT64 nonPurgeableBytes; -} zPoolInfo_s; - -/*************************************************************************** -Desc: -***************************************************************************/ -typedef struct zInfo_s -{ - LONG infoVersion; - FLMINT totalBytes; - FLMINT nextByte; - LONG padding; - FLMUINT64 retMask; - - struct - { - FLMUINT64 zid; - FLMUINT64 dataStreamZid; - FLMUINT64 parentZid; - FLMUINT64 logicalEOF; - GUID_t volumeID; - LONG fileType; - LONG fileAttributes; - LONG fileAttributesModMask; - LONG padding; - } std; - - struct - { - FLMUINT64 physicalEOF; - FLMUINT64 dataBytes; - FLMUINT64 metaDataBytes; - } storageUsed; - - LONG primaryNameSpaceID; - LONG nameStart; - - struct - { - LONG numEntries; - LONG fileNameArray; - } names; - - struct - { - FLMUINT64 created; - FLMUINT64 archived; - FLMUINT64 modified; - FLMUINT64 accessed; - FLMUINT64 metaDataModified; - } time; - - struct - { - GUID_t owner; - GUID_t archiver; - GUID_t modifier; - GUID_t metaDataModifier; - } id; - - struct - { - LONG size; - LONG sizeShift; - } blockSize; - - struct - { - LONG open; - LONG hardLink; - } count; - - struct - { - LONG count; - LONG totalNameSize; - FLMUINT64 totalDataSize; - } dataStream; - - struct - { - LONG count; - LONG totalNameSize; - FLMUINT64 totalDataSize; - } extAttr; - - struct - { - FLMUINT64 time; - GUID_t id; - } deleted; - - struct - { - zMacInfo_s info; - } macNS; - - struct - { - zUnixInfo_s info; - LONG offsetToData; - } unixNS; - - zVolumeInfo_s vol; - zPoolInfo_s pool; - LONG extAttrUserFlags; - BYTE variableData[zGET_INFO_VARIABLE_DATA_SIZE]; - -} zInfo_s; - -RCODE DfsMapError( - LONG lResult, - RCODE defaultRc); - -LONG FlaimToNDSOpenFlags( - FLMUINT uiAccess, - FLMBOOL bDoDirectIo); - -FLMUINT FlaimToNSSOpenFlags( - FLMUINT uiAccess, - FLMBOOL bDoDirectIo); - -typedef FLMINT (* zROOT_KEY_FUNC)( - FLMUINT connectionID, - FLMINT64 * retRootKey); - -typedef FLMINT (* zCLOSE_FUNC)( - FLMINT64 key); - -typedef FLMINT (* zCREATE_FUNC)( - FLMINT64 key, - FLMUINT taskID, - FLMUINT64 xid, - FLMUINT nameSpace, - const void * path, - FLMUINT fileType, - FLMUINT64 fileAttributes, - FLMUINT createFlags, - FLMUINT requestedRights, - FLMINT64 * retKey); - -typedef FLMINT (* zOPEN_FUNC)( - FLMINT64 key, - FLMUINT taskID, - FLMUINT nameSpace, - const void * path, - FLMUINT requestedRights, - FLMINT64 * retKey); - -typedef FLMINT (* zDELETE_FUNC)( - FLMINT64 key, - FLMUINT64 xid, - FLMUINT nameSapce, - const void * path, - FLMUINT match, - FLMUINT deleteFlags); - -typedef FLMINT (* zREAD_FUNC)( - FLMINT64 key, - FLMUINT64 xid, - FLMUINT64 startingOffset, - FLMUINT bytesToRead, - void * retBuffer, - FLMUINT * retBytesRead); - -typedef FLMINT (* zDIO_READ_FUNC)( - FLMINT64 key, - FLMUINT64 unitOffset, - FLMUINT unitsToRead, - FLMUINT callbackData, - void (*dioReadCallBack)( - FLMUINT reserved, - FLMUINT callbackData, - FLMUINT retStatus), - void * retBuffer); - -typedef FLMINT (* zGET_INFO_FUNC)( - FLMINT64 key, - FLMUINT64 getInfoMask, - FLMUINT sizeRetGetInfo, - FLMUINT infoVersion, - zInfo_s * retGetInfo); - -typedef FLMINT (* zMODIFY_INFO_FUNC)( - FLMINT64 key, - FLMUINT64 xid, - FLMUINT64 modifyInfoMask, - FLMUINT sizeModifyInfo, - FLMUINT infoVersion, - const zInfo_s * modifyInfo); - -typedef FLMINT (* zSET_EOF_FUNC)( - FLMINT64 key, - FLMUINT64 xid, - FLMUINT64 startingOffset, - FLMUINT flags); - -typedef FLMINT (* zWRITE_FUNC)( - FLMINT64 key, - FLMUINT64 xid, - FLMUINT64 startingOffset, - FLMUINT bytesToWrite, - const void * buffer, - FLMUINT * retBytesWritten); - -typedef FLMINT (* zDIO_WRITE_FUNC)( - FLMINT64 key, - FLMUINT64 unitOffset, - FLMUINT unitsToWrite, - FLMUINT callbackData, - void (*dioWriteCallBack)( - FLMUINT reserved, - FLMUINT callbackData, - FLMUINT retStatus), - const void * buffer); - -typedef FLMINT (* zRENAME_FUNC)( - FLMINT64 key, - FLMUINT64 xid, - FLMUINT srcNameSpace, - const void * srcPath, - FLMUINT srcMatchAttributes, - FLMUINT dstNameSpace, - const void * dstPath, - FLMUINT renameFlags); - -typedef BOOL (* zIS_NSS_VOLUME_FUNC)( - const char * path); - -FSTATIC zIS_NSS_VOLUME_FUNC gv_zIsNSSVolumeFunc = NULL; -FSTATIC zROOT_KEY_FUNC gv_zRootKeyFunc = NULL; -FSTATIC zCLOSE_FUNC gv_zCloseFunc = NULL; -FSTATIC zCREATE_FUNC gv_zCreateFunc = NULL; -FSTATIC zOPEN_FUNC gv_zOpenFunc = NULL; -FSTATIC zDELETE_FUNC gv_zDeleteFunc = NULL; -FSTATIC zREAD_FUNC gv_zReadFunc = NULL; -FSTATIC zDIO_READ_FUNC gv_zDIOReadFunc = NULL; -FSTATIC zGET_INFO_FUNC gv_zGetInfoFunc = NULL; -FSTATIC zMODIFY_INFO_FUNC gv_zModifyInfoFunc = NULL; -FSTATIC zSET_EOF_FUNC gv_zSetEOFFunc = NULL; -FSTATIC zWRITE_FUNC gv_zWriteFunc = NULL; -FSTATIC zDIO_WRITE_FUNC gv_zDIOWriteFunc = NULL; -FSTATIC zRENAME_FUNC gv_zRenameFunc = NULL; -extern RCODE gv_CriticalFSError; - -FSTATIC void ConvertToQualifiedNWPath( - const char * pInputPath, - char * pQualifiedPath); - -FSTATIC RCODE nssTurnOffRenameInhibit( - const char * pszFileName); - -FSTATIC LONG ConvertPathToLNameFormat( - const char * pPath, - LONG * plVolumeID, - FLMBOOL * pbNssVolume, - FLMBYTE * pLNamePath, - LONG * plLNamePathCount); - -FSTATIC void DirectIONoWaitCallBack( - LONG unknownAlwaysZero, - LONG callbackData, - LONG completionCode); - -FSTATIC void nssDioCallback( - FLMUINT reserved, - FLMUINT UserData, - FLMUINT retStatus); - -FSTATIC RCODE MapNSSToFlaimError( - FLMINT lStatus, - RCODE defaultRc); - -FLMINT64 gv_NssRootKey; -FLMBOOL gv_bNSSKeyInitialized = FALSE; - -/*************************************************************************** -Desc: Initialize the root NSS key. -***************************************************************************/ -RCODE nssInitialize( void) -{ - RCODE rc = FERR_OK; - FLMINT lStatus; - - if (!gv_bNSSKeyInitialized) - { - // Import the required NSS functions - - if( (gv_zIsNSSVolumeFunc = (zIS_NSS_VOLUME_FUNC)ImportPublicSymbol( - (unsigned long)f_getNLMHandle(), - (unsigned char *)"\x0C" "zIsNSSVolume")) == NULL) - { - // NSS is not available on this server. Jump to exit. - goto Exit; - } - - if( (gv_zRootKeyFunc = (zROOT_KEY_FUNC)ImportPublicSymbol( - (unsigned long)f_getNLMHandle(), - (unsigned char *)"\x08" "zRootKey")) == NULL) - { - flmAssert( 0); - rc = RC_SET( FERR_INITIALIZING_IO_SYSTEM); - goto Exit; - } - - if( (gv_zCloseFunc = (zCLOSE_FUNC)ImportPublicSymbol( - (unsigned long)f_getNLMHandle(), - (unsigned char *)"\x06" "zClose")) == NULL) - { - flmAssert( 0); - rc = RC_SET( FERR_INITIALIZING_IO_SYSTEM); - goto Exit; - } - - if( (gv_zCreateFunc = (zCREATE_FUNC)ImportPublicSymbol( - (unsigned long)f_getNLMHandle(), - (unsigned char *)"\x07" "zCreate")) == NULL) - { - flmAssert( 0); - rc = RC_SET( FERR_INITIALIZING_IO_SYSTEM); - goto Exit; - } - - if( (gv_zOpenFunc = (zOPEN_FUNC)ImportPublicSymbol( - (unsigned long)f_getNLMHandle(), - (unsigned char *)"\x05" "zOpen")) == NULL) - { - flmAssert( 0); - rc = RC_SET( FERR_INITIALIZING_IO_SYSTEM); - goto Exit; - } - - if( (gv_zDeleteFunc = (zDELETE_FUNC)ImportPublicSymbol( - (unsigned long)f_getNLMHandle(), - (unsigned char *)"\x07" "zDelete")) == NULL) - { - flmAssert( 0); - rc = RC_SET( FERR_INITIALIZING_IO_SYSTEM); - goto Exit; - } - - if( (gv_zReadFunc = (zREAD_FUNC)ImportPublicSymbol( - (unsigned long)f_getNLMHandle(), - (unsigned char *)"\x05" "zRead")) == NULL) - { - flmAssert( 0); - rc = RC_SET( FERR_INITIALIZING_IO_SYSTEM); - goto Exit; - } - - if( (gv_zDIOReadFunc = (zDIO_READ_FUNC)ImportPublicSymbol( - (unsigned long)f_getNLMHandle(), - (unsigned char *)"\x08" "zDIORead")) == NULL) - { - flmAssert( 0); - rc = RC_SET( FERR_INITIALIZING_IO_SYSTEM); - goto Exit; - } - - if( (gv_zGetInfoFunc = (zGET_INFO_FUNC)ImportPublicSymbol( - (unsigned long)f_getNLMHandle(), - (unsigned char *)"\x08" "zGetInfo")) == NULL) - { - flmAssert( 0); - rc = RC_SET( FERR_INITIALIZING_IO_SYSTEM); - goto Exit; - } - - if( (gv_zModifyInfoFunc = (zMODIFY_INFO_FUNC)ImportPublicSymbol( - (unsigned long)f_getNLMHandle(), - (unsigned char *)"\x0B" "zModifyInfo")) == NULL) - { - flmAssert( 0); - rc = RC_SET( FERR_INITIALIZING_IO_SYSTEM); - goto Exit; - } - - if( (gv_zSetEOFFunc = (zSET_EOF_FUNC)ImportPublicSymbol( - (unsigned long)f_getNLMHandle(), - (unsigned char *)"\x07" "zSetEOF")) == NULL) - { - flmAssert( 0); - rc = RC_SET( FERR_INITIALIZING_IO_SYSTEM); - goto Exit; - } - - if( (gv_zWriteFunc = (zWRITE_FUNC)ImportPublicSymbol( - (unsigned long)f_getNLMHandle(), - (unsigned char *)"\x06" "zWrite")) == NULL) - { - flmAssert( 0); - rc = RC_SET( FERR_INITIALIZING_IO_SYSTEM); - goto Exit; - } - - if( (gv_zDIOWriteFunc = (zDIO_WRITE_FUNC)ImportPublicSymbol( - (unsigned long)f_getNLMHandle(), - (unsigned char *)"\x09" "zDIOWrite")) == NULL) - { - flmAssert( 0); - rc = RC_SET( FERR_INITIALIZING_IO_SYSTEM); - goto Exit; - } - - if( (gv_zRenameFunc = (zRENAME_FUNC)ImportPublicSymbol( - (unsigned long)f_getNLMHandle(), - (unsigned char *)"\x07" "zRename")) == NULL) - { - flmAssert( 0); - rc = RC_SET( FERR_INITIALIZING_IO_SYSTEM); - goto Exit; - } - - // Get the NSS root key - - if ((lStatus = gv_zRootKeyFunc( 0, &gv_NssRootKey)) != zOK) - { - rc = MapNSSToFlaimError( lStatus, FERR_INITIALIZING_IO_SYSTEM); - goto Exit; - } - gv_bNSSKeyInitialized = TRUE; - } - -Exit: - - return( rc); -} - -/*************************************************************************** -Desc: Close the root NSS key. -***************************************************************************/ -void nssUninitialize( void) -{ - if (gv_bNSSKeyInitialized) - { - (void)gv_zCloseFunc( gv_NssRootKey); - gv_bNSSKeyInitialized = FALSE; - } -} - -/*************************************************************************** -Desc: Maps NDS errors to IO errors. - fix: The set of return codes returned by the NDS I/O functions (like - NDSOpenStreamFile) is defined in "nw500\errors.h" Unfortunately, - some of the names used for the return codes are used in other include - files. Because of the conflict, it has been decided to use the - integers associated with the names, rather than the names - themselves. This needs to be fixed. -***************************************************************************/ -RCODE MapNWtoFlaimError( - LONG lResult, - RCODE defaultRc - ) -{ - RCODE rc; - switch (lResult) - { - case 128: // ERR_LOCK_FAIL - case 147: // ERR_NO_READ_PRIVILEGE - case 148: // ERR_NO_WRITE_PRIVILEGE - case 168: // ERR_ACCESS_DENIED - rc = RC_SET( FERR_IO_ACCESS_DENIED); - break; - - case 136: //ERR_INVALID_FILE_HANDLE - rc = RC_SET( FERR_IO_BAD_FILE_HANDLE); - break; - - case 001: //ERR_INSUFFICIENT_SPACE - case 153: //ERR_DIRECTORY_FULL - rc = RC_SET( FERR_IO_DISK_FULL); - break; - - case 130: //ERR_NO_OPEN_PRIVILEGE - case 165: //ERR_INVALID_OPENCREATE_MODE - rc = RC_SET( FERR_IO_OPEN_ERR); - break; - - case 158: //ERR_BAD_FILE_NAME - rc = RC_SET( FERR_IO_PATH_NOT_FOUND); - break; - - case 129: //ERR_OUT_OF_HANDLES - rc = RC_SET( FERR_IO_TOO_MANY_OPEN_FILES); - break; - - case 139: //ERR_NO_RENAME_PRIVILEGE - case 154: //ERR_RENAME_ACROSS_VOLUME - case 164: //ERR_RENAME_DIR_INVALID - rc = RC_SET( FERR_IO_RENAME_FAILURE); - break; - - case 222: //ERR_BAD_PASSWORD - case 223: //ERR_PASSWORD_EXPIRED - rc = RC_SET( FERR_IO_INVALID_PASSWORD); - break; - - case 156: //ERR_INVALID_PATH - rc = RC_SET( FERR_IO_INVALID_PATH); - break; - - case 122: //ERR_CONNECTION_ALREADY_TEMPORARY - case 123: //ERR_CONNECTION_ALREADY_LOGGED_IN - case 124: //ERR_CONNECTION_NOT_AUTHENTICATED - case 125: //ERR_CONNECTION_NOT_LOGGED_IN - case 224: //ERR_NO_LOGIN_CONNECTIONS_AVAILABLE - rc = RC_SET( FERR_IO_CONNECT_ERROR); - break; - - default: - rc = RC_SET( defaultRc); - break; - } - return( rc ); -} - -/*************************************************************************** -Desc: Maps NSS errors to IO errors. -***************************************************************************/ -FSTATIC RCODE MapNSSToFlaimError( - FLMINT lStatus, - RCODE defaultRc) -{ - RCODE rc; - - switch (lStatus) - { - case zERR_FILE_ALREADY_EXISTS: - case zERR_DIRECTORY_NOT_EMPTY: - case zERR_DIR_CANNOT_BE_OPENED: - case zERR_NO_SET_PRIVILEGE: - case zERR_NO_CREATE_PRIVILEGE: - case zERR_ACCESS_DENIED: - case zERR_NO_WRITE_PRIVILEGE: - case zERR_NO_READ_PRIVILEGE: - case zERR_NO_DELETE_PRIVILEGE: - case zERR_SOME_NO_DELETE_PRIVILEGE: - case zERR_CANT_DELETE_OPEN_FILE: - case zERR_NO_CREATE_DELETE_PRIVILEGE: - case zERR_NO_SALVAGE_PRIVILEGE: - case zERR_FILE_READ_LOCKED: - case zERR_FILE_WRITE_LOCKED: - rc = RC_SET( FERR_IO_ACCESS_DENIED); - break; - - case zERR_BAD_FILE_HANDLE: - rc = RC_SET( FERR_IO_BAD_FILE_HANDLE); - break; - - case zERR_OUT_OF_SPACE: - rc = RC_SET( FERR_IO_DISK_FULL); - break; - - case zERR_NO_OPEN_PRIVILEGE: - rc = RC_SET( FERR_IO_OPEN_ERR); - break; - - case zERR_NAME_NOT_FOUND_IN_DIRECTORY: - case zERR_NO_FILES_FOUND: - case zERR_VOLUME_NOT_FOUND: - case zERR_NO_SUCH_OBJECT: - rc = RC_SET( FERR_IO_PATH_NOT_FOUND); - break; - - case zERR_NO_MORE_CONTEXT_HANDLE_IDS: - rc = RC_SET( FERR_IO_TOO_MANY_OPEN_FILES); - break; - case zERR_ALL_FILES_IN_USE: - case zERR_SOME_FILES_IN_USE: - case zERR_ALL_FILES_READ_ONLY: - case zERR_SOME_FILES_READ_ONLY: - case zERR_ALL_NAMES_EXIST: - case zERR_SOME_NAMES_EXIST: - case zERR_NO_RENAME_PRIVILEGE: - case zERR_RENAME_DIR_INVALID: - case zERR_RENAME_TO_OTHER_VOLUME: - case zERR_CANT_RENAME_DATA_STREAMS: - case zERR_FILE_RENAME_IN_PROGRESS: - case zERR_CANT_RENAME_TO_DELETED: - rc = RC_SET( FERR_IO_RENAME_FAILURE); - break; - - case zERR_INVALID_NAME: - case zERR_INVALID_CHAR_IN_NAME: - case zERR_INVALID_PATH: - case zERR_NO_NAMES_IN_PATH: - case zERR_NO_MORE_NAMES_IN_PATH: - case zERR_PATH_MUST_BE_FULLY_QUALIFIED: - case zERR_NAME_NO_LONGER_VALID: - case zERR_INVALID_PATH_FORMAT: - case zERR_INVALID_PATH_SEPARATOR: - case zERR_VOLUME_SEPARATOR_NOT_SUPPORTED: - case zERR_BAD_VOLUME_NAME: - rc = RC_SET( FERR_IO_INVALID_PATH); - break; - case zERR_CONNECTION_NOT_LOGGED_IN: - rc = RC_SET( FERR_IO_CONNECT_ERROR); - break; - case zERR_NO_MEMORY: - rc = RC_SET( FERR_MEM); - break; - case zERR_NOT_SUPPORTED: - rc = RC_SET( FERR_NOT_IMPLEMENTED); - break; - case zERR_END_OF_FILE: - case zERR_BEYOND_EOF: - rc = RC_SET( FERR_IO_END_OF_FILE); - break; - - default: - rc = RC_SET( defaultRc); - break; - } - return( rc ); -} - -/*************************************************************************** -Desc: Maps direct IO errors to IO errors. -fix: we shouldn't have 2 copies of this function. this is just temporary. - long term, we need to make the FDFS.CPP version public. -***************************************************************************/ -RCODE DfsMapError( - LONG lResult, - RCODE defaultRc - ) -{ - switch (lResult) - { - case DFSHoleInFileError: - case DFSOperationBeyondEndOfFile: - return( RC_SET( FERR_IO_END_OF_FILE)); - case DFSHardIOError: - case DFSInvalidFileHandle: - return( RC_SET( FERR_IO_BAD_FILE_HANDLE)); - case DFSNoReadPrivilege: - return( RC_SET( FERR_IO_ACCESS_DENIED)); - case DFSInsufficientMemory: - return( RC_SET( FERR_MEM)); - default: - return( RC_SET( defaultRc)); - } -} - - -/**************************************************************************** -Desc: Map flaim I/O flags to NDS I/O flags -****************************************************************************/ -LONG FlaimToNDSOpenFlags( - FLMUINT uiAccess, - FLMBOOL bDoDirectIo - ) -{ - LONG lFlags = NO_RIGHTS_CHECK_ON_OPEN_BIT | ALLOW_SECURE_DIRECTORY_ACCESS_BIT; - - if (uiAccess & (F_IO_RDONLY | F_IO_RDWR)) - { - lFlags |= READ_ACCESS_BIT; - } - if (uiAccess & F_IO_RDWR) - { - lFlags |= WRITE_ACCESS_BIT; - } - - if (uiAccess & F_IO_SH_DENYRW ) - { - lFlags |= DENY_READ_BIT; - } - if (uiAccess & (F_IO_SH_DENYWR | F_IO_SH_DENYRW)) - { - lFlags |= DENY_WRITE_BIT; - } - if (bDoDirectIo) - { - lFlags |= NEVER_READ_AHEAD_BIT; - } - return( lFlags ); -} - -/**************************************************************************** -Desc: Map flaim I/O flags to NDS I/O flags for NSS volumes -****************************************************************************/ -FLMUINT FlaimToNSSOpenFlags( - FLMUINT uiAccess, - FLMBOOL bDoDirectIo) -{ - FLMUINT lFlags = zRR_ALLOW_SECURE_DIRECTORY_ACCESS | - zRR_CANT_DELETE_WHILE_OPEN; - - if (uiAccess & (F_IO_RDONLY | F_IO_RDWR)) - { - lFlags |= zRR_READ_ACCESS; - } - if (uiAccess & F_IO_RDWR) - { - lFlags |= zRR_WRITE_ACCESS; - } - - if (uiAccess & F_IO_SH_DENYRW) - { - lFlags |= zRR_DENY_READ; - } - if (uiAccess & (F_IO_SH_DENYWR | F_IO_SH_DENYRW)) - { - lFlags |= zRR_DENY_WRITE; - } - if (bDoDirectIo) - { - lFlags |= zRR_DIO_MODE; - } - return( lFlags ); -} - -/**************************************************************************** -Desc: Map flaim I/O flags to NetWare I/O flags -****************************************************************************/ -LONG FlaimToNWOpenFlags( - FLMUINT uiAccess, - FLMBOOL bDoDirectIo - ) -{ - LONG lFlags = 0; - - if (uiAccess & (F_IO_RDONLY | F_IO_RDWR)) - { - lFlags |= READ_ACCESS_BIT; - } - if (uiAccess & F_IO_RDWR) - { - lFlags |= WRITE_ACCESS_BIT; - } - - if (uiAccess & F_IO_SH_DENYRW ) - { - lFlags |= DENY_READ_BIT; - } - if (uiAccess & (F_IO_SH_DENYWR | F_IO_SH_DENYRW)) - { - lFlags |= DENY_WRITE_BIT; - } - if (bDoDirectIo) - { - lFlags |= NEVER_READ_AHEAD_BIT; - } - return( lFlags ); -} - -/**************************************************************************** -Desc: Default Constructor for F_FileHdl class -****************************************************************************/ -F_FileHdlImp::F_FileHdlImp() -{ - // Should call the base class constructor automatically. - - m_lFileHandle = -1; - m_lOpenAttr = 0; - m_uiCurrentPos = 0; - m_lVolumeID = F_NW_DEFAULT_VOLUME_NUMBER; - m_bDoSuballocation = FALSE; - m_lLNamePathCount = 0; - m_pszIoPath = NULL; - m_uiExtendSize = 0; - m_uiMaxAutoExtendSize = gv_FlmSysData.uiMaxFileSize; - - // Direct IO members - m_bDoDirectIO = FALSE; // TRUE = do direct IO-style read/writes - m_lSectorsPerBlock = 0; - m_lMaxBlocks = 0; - - m_bNSS = FALSE; - m_bNSSFileOpen = FALSE; -} - -/*************************************************************************** -Desc: Open or create a file. -***************************************************************************/ -RCODE F_FileHdlImp::OpenOrCreate( - const char * pFileName, - FLMUINT uiAccess, - FLMBOOL bCreateFlag) -{ - RCODE rc = FERR_OK; - LONG unused; - void * unused2; - char * pszQualifiedPath = NULL; - LONG lErrorCode; - FLMBYTE * pTmpLNamePath; - char * pSaveFileName; - FLMBYTE * pLNamePath; - LONG * plLNamePathCount; - LONG LNamePathCount; - struct VolumeInformationStructure * - pVolumeInfo; - char * pszTemp; - char * pIoDirPath; - FLMBOOL bNssVolume = FALSE; - - if( RC_BAD( rc = GET_FS_ERROR())) - { - goto Exit; - } - - m_bDoDirectIO = (uiAccess & F_IO_DIRECT) ? TRUE : FALSE; - - if( uiAccess & F_IO_DELETE_ON_CLOSE) - { - if( !m_pszIoPath) - { - if( RC_BAD( rc = f_alloc( F_PATH_MAX_SIZE, &m_pszIoPath))) - { - goto Exit; - } - } - f_strcpy( m_pszIoPath, pFileName); - m_bDeleteOnClose = TRUE; - } - else - { - m_bDeleteOnClose = FALSE; - } - - if (RC_BAD( rc = f_alloc( - (FLMUINT)(F_PATH_MAX_SIZE + - F_PATH_MAX_SIZE + - F_PATH_MAX_SIZE + - F_PATH_MAX_SIZE + - sizeof( struct VolumeInformationStructure) + - F_PATH_MAX_SIZE), - &pszQualifiedPath))) - { - goto Exit; - } - - pTmpLNamePath = (((FLMBYTE *)pszQualifiedPath) + F_PATH_MAX_SIZE); - pSaveFileName = (((char *)pTmpLNamePath) + F_PATH_MAX_SIZE); - pIoDirPath = (((char *)pSaveFileName) + F_PATH_MAX_SIZE); - pVolumeInfo = (struct VolumeInformationStructure *) - (((char *)pIoDirPath) + F_PATH_MAX_SIZE); - pszTemp = (char *)(((char *)(pVolumeInfo)) + - sizeof( struct VolumeInformationStructure)); - - - /* Save the file name in case we have to create the directory. */ - - if((bCreateFlag) && (uiAccess & F_IO_CREATE_DIR)) - { - f_strcpy( pSaveFileName, pFileName); - } - - if( !m_pszIoPath) - { - pLNamePath = pTmpLNamePath; - plLNamePathCount = &LNamePathCount; - } - else - { - pLNamePath = (FLMBYTE *)m_pszIoPath; - plLNamePathCount = &m_lLNamePathCount; - } - - ConvertToQualifiedNWPath( pFileName, pszQualifiedPath); - - lErrorCode = ConvertPathToLNameFormat( - pszQualifiedPath, - &m_lVolumeID, - &bNssVolume, - pLNamePath, - plLNamePathCount); - if( lErrorCode != 0) - { - rc = MapNWtoFlaimError( lErrorCode, FERR_PARSING_FILE_NAME); - goto Exit; - } - - // Determine if the volume is NSS or not - - if (gv_bNSSKeyInitialized && bNssVolume) - { - m_bNSS = TRUE; - } - - if ( m_bDoDirectIO ) - { - if (!m_bNSS) - { - lErrorCode = - ReturnVolumeMappingInformation( m_lVolumeID, pVolumeInfo); - if (lErrorCode != 0) - { - rc = DfsMapError( lErrorCode, FERR_INITIALIZING_IO_SYSTEM); - goto Exit; - } - - m_lSectorsPerBlock = (LONG)(pVolumeInfo->VolumeAllocationUnitSizeInBytes / - NLM_SECTOR_SIZE); - m_lMaxBlocks = (LONG)(gv_FlmSysData.uiMaxFileSize / - (FLMUINT)pVolumeInfo->VolumeAllocationUnitSizeInBytes); - } - else - { - m_lMaxBlocks = (LONG)(gv_FlmSysData.uiMaxFileSize / (FLMUINT)65536); - } - } - - /* - Set up the file characteristics requested by caller. - */ - - if (bCreateFlag) - { - - // File is to be created - - if (NWTestIfFileExists( pszQualifiedPath ) == FERR_OK) - { - if (uiAccess & F_IO_EXCL) - { - rc = RC_SET( FERR_IO_ACCESS_DENIED); - goto Exit; - } - - (void)NWDeleteFile( pszQualifiedPath); - } - } - - /* Try to create or open the file */ - - if (m_bNSS) - { - FLMINT lStatus; - - if (bCreateFlag) - { - FLMUINT64 qFileAttr; - - qFileAttr = (FLMUINT64)(((m_bDoSuballocation) - ? (FLMUINT)(zFA_DO_NOT_COMPRESS_FILE) - : (FLMUINT)(zFA_NO_SUBALLOC | - zFA_DO_NOT_COMPRESS_FILE)) | - zFA_IMMEDIATE_PURGE); - -Retry_NSS_Create: - - m_lOpenAttr = FlaimToNSSOpenFlags( uiAccess, m_bDoDirectIO); - if ((lStatus = gv_zCreateFunc( gv_NssRootKey, 1, 0, - zNSPACE_LONG | zMODE_UTF8, pszQualifiedPath, zFILE_REGULAR, - qFileAttr, zCREATE_DELETE_IF_THERE, (FLMUINT)m_lOpenAttr, - &m_NssKey)) != zOK) - { - if (uiAccess & F_IO_CREATE_DIR) - { - uiAccess &= ~F_IO_CREATE_DIR; - - // Remove the file name for which we are creating the directory. - - if( f_pathReduce( pSaveFileName, pIoDirPath, pszTemp) == FERR_OK) - { - F_FileSystemImp FileSystem; - - if (RC_OK( FileSystem.CreateDir( pIoDirPath))) - goto Retry_NSS_Create; - } - } - rc = MapNSSToFlaimError( lStatus, - (RCODE)(m_bDoDirectIO - ? (RCODE)FERR_DIRECT_CREATING_FILE - : (RCODE)FERR_CREATING_FILE)); - goto Exit; - } - } - else - { - m_lOpenAttr = FlaimToNSSOpenFlags( uiAccess, m_bDoDirectIO); - if ((lStatus = gv_zOpenFunc( - gv_NssRootKey, // FLMINT64 key - 1, // FLMUINT taskID - zNSPACE_LONG | zMODE_UTF8, // FLMUINT nameSpace - pszQualifiedPath, // const void * path - (FLMUINT)m_lOpenAttr, // FLMUINT requestedRights - &m_NssKey)) != zOK) - { - rc = MapNSSToFlaimError( lStatus, - (RCODE)(m_bDoDirectIO - ? (RCODE)FERR_DIRECT_OPENING_FILE - : (RCODE)FERR_OPENING_FILE)); - goto Exit; - } - } - m_bNSSFileOpen = TRUE; - } - else - { - if (bCreateFlag) - { - m_lOpenAttr = (LONG)(((m_bDoSuballocation) - ? (LONG)(DO_NOT_COMPRESS_FILE_BIT) - : (LONG)(NO_SUBALLOC_BIT | - DO_NOT_COMPRESS_FILE_BIT)) | - IMMEDIATE_PURGE_BIT); - -Retry_Create: - lErrorCode = CreateFile( - 0, // Connection ID - 1, // Task ID - m_lVolumeID, // Volume ID - 0, // (path base) 0 because we supply fully-qualified path - (BYTE *)pLNamePath,// LNAME-array format path - *plLNamePathCount, // LNAME-array size - LONGNameSpace, // LONGNameSpace - m_lOpenAttr, - 0xff, // 0xff, 0, DELETE_FILE_ON_CREATE_BIT, READ_ACCESS_BIT|WRITE_ACCESS_BIT - PrimaryDataStream, // PrimaryDataStream - &m_lFileHandle, - &unused, // return the directory number - &unused2 // union DirUnion *Entry; - ); - - if ((lErrorCode != 0) && (uiAccess & F_IO_CREATE_DIR)) - { - uiAccess &= ~F_IO_CREATE_DIR; - - /* Remove the file name for which we are creating the directory. */ - - if( f_pathReduce( pSaveFileName, pIoDirPath, pszTemp) == FERR_OK) - { - F_FileSystemImp FileSystem; - - if (RC_OK( FileSystem.CreateDir( pIoDirPath))) - goto Retry_Create; - } - } - - // Too many error codes map to 255, so we put in a special - // case check here. - - if( lErrorCode == 255) - { - rc = RC_SET( FERR_IO_ACCESS_DENIED); - goto Exit; - } - } - else - { - m_lOpenAttr = FlaimToNWOpenFlags(uiAccess, m_bDoDirectIO); - lErrorCode = OpenFile( - 0, // Connection ID - 1, // Task ID - m_lVolumeID, // Volume ID - 0, // (path base) 0 because we supply fully-qualified path - (BYTE *)pLNamePath, // LNAME-array format path - *plLNamePathCount, // LNAME-array size - LONGNameSpace, // LONGNameSpace - 0, // ?? LONG MatchBits, - m_lOpenAttr, - PrimaryDataStream, - &m_lFileHandle, - &unused, // return the directory number - &unused2 // union DirUnion *Entry; - ); - - /* - Too many error codes map to 255, so we put in a special - case check here. - */ - - if( lErrorCode == 255) - { - rc = RC_SET( FERR_IO_PATH_NOT_FOUND); - goto Exit; - } - } - - /* Check if the file operation was successful */ - - if ( lErrorCode != 0) - { - rc = MapNWtoFlaimError( lErrorCode, - (RCODE)(bCreateFlag - ? (RCODE)(m_bDoDirectIO - ? (RCODE)FERR_DIRECT_CREATING_FILE - : (RCODE)FERR_CREATING_FILE) - : (RCODE)(m_bDoDirectIO - ? (RCODE)FERR_DIRECT_OPENING_FILE - : (RCODE)FERR_OPENING_FILE))); - goto Exit; - } - - if (bCreateFlag) - { - /* Close and reopen the file after creating it. */ - - // Revoke the file handle rights and close the file - // (signified by passing 2 for the QueryFlag parameter). - // If this call fails and returns a 255 error, it may - // indicate that the FILESYS.NLM being used on the server - // does not implement option 2 for the QueryFlag parameter. - // In this case, we will default to our old behavior - // and simply call CloseFile. This, potentially, will - // not free all of the lock objects and could result in - // a memory leak in filesys.nlm. However, we want to - // at least make sure that there is a corresponding - // RevokeFileHandleRights or CloseFile call for every - // file open / create call. - - if( (lErrorCode = RevokeFileHandleRights( 0, 1, - m_lFileHandle, 2, m_lOpenAttr & 0x0000000F, &unused)) == 0xFF) - { - lErrorCode = CloseFile( 0, 1, m_lFileHandle); - } - m_lOpenAttr = 0; - - if ( lErrorCode != 0 ) - { - rc = MapNWtoFlaimError(lErrorCode, FERR_CLOSING_FILE); - goto Exit; - } - - m_lOpenAttr = FlaimToNWOpenFlags(uiAccess, m_bDoDirectIO); - lErrorCode = OpenFile( /* moved to vswitch.386 */ - 0, // Connection ID - 1, // Task ID - m_lVolumeID, // Volume ID - 0, // (path base) 0 because we supply fully-qualified path - (BYTE *)pLNamePath,// LNAME-array format path - *plLNamePathCount,// LNAME-array size - LONGNameSpace, // LONGNameSpace - 0, // ?? LONG MatchBits, - m_lOpenAttr, - PrimaryDataStream, - &m_lFileHandle, - &unused, // return the directory number - &unused2 // union DirUnion *Entry; - ); - - if ( lErrorCode != 0 ) - { - /* - Too many error codes map to 255, so we put in a special - case check here. - */ - - if( lErrorCode == 255) - { - rc = RC_SET( FERR_IO_PATH_NOT_FOUND); - } - else - { - rc = MapNWtoFlaimError( lErrorCode, - (RCODE)(m_bDoDirectIO - ? (RCODE)FERR_DIRECT_OPENING_FILE - : (RCODE)FERR_OPENING_FILE)); - } - goto Exit; - } - } - - if ( m_bDoDirectIO ) - { - lErrorCode = SwitchToDirectFileMode(0, m_lFileHandle); - if (lErrorCode != 0) - { - if (RevokeFileHandleRights( 0, 1, - m_lFileHandle, 2, m_lOpenAttr & 0x0000000F, &unused) == 0xFF) - { - (void)CloseFile( 0, 1, m_lFileHandle); - } - rc = MapNWtoFlaimError( lErrorCode, - (RCODE)(bCreateFlag - ? (RCODE)FERR_DIRECT_CREATING_FILE - : (RCODE)FERR_DIRECT_OPENING_FILE)); - goto Exit; - } - } - } - -Exit: - - if (RC_BAD( rc)) - { - m_lFileHandle = -1; - m_lOpenAttr = 0; - m_bNSSFileOpen = FALSE; - } - - if (pszQualifiedPath) - { - f_free( &pszQualifiedPath); - } - - return( rc ); -} - -/**************************************************************************** -Desc: Create a file -****************************************************************************/ -RCODE F_FileHdlImp::Create( - const char * pIoPath, - FLMUINT uiIoFlags) -{ - RCODE rc = FERR_OK; - - flmAssert( m_bFileOpened == FALSE); - - if( RC_BAD( rc = GET_FS_ERROR())) - { - goto Exit; - } - - if( RC_BAD( rc = OpenOrCreate( pIoPath, uiIoFlags, TRUE))) - { - goto Exit; - } - - m_bFileOpened = TRUE; - m_uiCurrentPos = 0; - m_bOpenedExclusive = (uiIoFlags & F_IO_SH_DENYRW) ? TRUE : FALSE; - -Exit: - - return( rc); -} - -/**************************************************************************** -Desc: -****************************************************************************/ -RCODE F_FileHdlImp::CreateUnique( - char * pIoPath, - const char * pszFileExtension, - FLMUINT uiIoFlags) -{ - RCODE rc = FERR_OK; - char * pszTmp; - FLMBOOL bModext = TRUE; - FLMUINT uiBaseTime = 0; - char ucHighByte = 0; - char ucFileName[ F_FILENAME_SIZE]; - char szDirPath[ F_PATH_MAX_SIZE]; - char szTmpPath[ F_PATH_MAX_SIZE]; - FLMUINT uiCount; - - f_memset( ucFileName, 0, sizeof( ucFileName)); - - flmAssert( m_bFileOpened == FALSE); - - if( RC_BAD( rc = GET_FS_ERROR())) - { - goto Exit; - } - - f_strcpy( szDirPath, pIoPath); - - // Search backwards replacing trailing spaces with NULLs. - - pszTmp = szDirPath; - pszTmp += (f_strlen( pszTmp) - 1); - while ((*pszTmp == 0x20) && pszTmp >= szDirPath) - { - *pszTmp = 0; - pszTmp--; - } - - /* Append a backslash if one isn't already there. */ - - if (pszTmp >= szDirPath && *pszTmp != '\\') - { - pszTmp++; - *pszTmp++ = '\\'; - } - else - { - pszTmp++; - } - *pszTmp = 0; - - if ((pszFileExtension) && (f_strlen( pszFileExtension) >= 3)) - { - bModext = FALSE; - } - - uiCount = 0; - do - { - f_pathCreateUniqueName( &uiBaseTime, ucFileName, pszFileExtension, - &ucHighByte, bModext); - - f_strcpy( szTmpPath, szDirPath); - f_pathAppend( szTmpPath, ucFileName); - - rc = Create( szTmpPath, uiIoFlags | F_IO_EXCL); - - if (rc == FERR_IO_DISK_FULL) - { - (void)NWDeleteFile( szTmpPath); - goto Exit; - } - - if ((rc == FERR_IO_PATH_NOT_FOUND) || (rc == FERR_IO_INVALID_PASSWORD)) - { - goto Exit; - } - } while ((rc != FERR_OK) && (uiCount++ < F_IO_MAX_CREATION_TRIES)); - - // Check if the path was created - - if ((uiCount >= F_IO_MAX_CREATION_TRIES) && (rc != FERR_OK)) - { - rc = RC_SET( FERR_IO_PATH_CREATE_FAILURE); - goto Exit; - } - - m_bFileOpened = TRUE; - m_bOpenedExclusive = (uiIoFlags & F_IO_SH_DENYRW) ? TRUE : FALSE; - - // Created file name needs to be returned. - - f_strcpy( pIoPath, szTmpPath); - -Exit: - - return( rc); -} - -/**************************************************************************** -Desc: Open a file -****************************************************************************/ -RCODE F_FileHdlImp::Open( - const char * pIoPath, - FLMUINT uiIoFlags) -{ - RCODE rc = FERR_OK; - FLMUINT uiStartTime; - FLMUINT ui15Secs; - FLMUINT uiCurrTime; - - flmAssert( m_bFileOpened == FALSE); - - if( RC_BAD( rc = GET_FS_ERROR())) - { - goto Exit; - } - - // Loop on error open conditions. - - FLM_SECS_TO_TIMER_UNITS(15 /*seconds*/, ui15Secs); - uiStartTime = FLM_GET_TIMER(); - - do - { - if( RC_OK( rc = OpenOrCreate( pIoPath, uiIoFlags, FALSE))) - break; - - if( rc != FERR_IO_TOO_MANY_OPEN_FILES) - { - goto Exit; - } - - // If for some reason we cannot open the file, then - // try to close some other file handle in the list. - - if( RC_BAD( gv_FlmSysData.pFileHdlMgr->ReleaseOneAvail())) - { - goto Exit; - } - - f_sleep( 50); - uiCurrTime = FLM_GET_TIMER(); - } while( FLM_ELAPSED_TIME( uiCurrTime, uiStartTime) < ui15Secs); - - if ( RC_BAD(rc) ) - { - goto Exit; - } - - m_bFileOpened = TRUE; - m_uiCurrentPos = 0; - m_bOpenedReadOnly = (uiIoFlags & F_IO_RDONLY) ? TRUE : FALSE; - m_bOpenedExclusive = (uiIoFlags & F_IO_SH_DENYRW) ? TRUE : FALSE; - -Exit: - - return( rc); -} - - -/**************************************************************************** -Desc: Close a file -****************************************************************************/ -RCODE F_FileHdlImp::Close() -{ - LONG unused; - FLMBOOL bDeleteAllowed = TRUE; - RCODE rc = FERR_OK; - - if( !m_bFileOpened) - { - goto Exit; - } - - if( RC_BAD( rc = GET_FS_ERROR())) - { - bDeleteAllowed = FALSE; - } - - if (m_bNSS) - { - if (m_bNSSFileOpen) - { - (void)gv_zCloseFunc( m_NssKey); - m_bNSSFileOpen = FALSE; - } - } - else - { - // Revoke the file handle rights and close the file - // (signified by passing 2 for the QueryFlag parameter). - // If this call fails and returns a 255 error, it may - // indicate that the FILESYS.NLM being used on the server - // does not implement option 2 for the QueryFlag parameter. - // In this case, we will default to our old behavior - // and simply call CloseFile. This, potentially, will - // not free all of the lock objects and could result in - // a memory leak in filesys.nlm. However, we want to - // at least make sure that there is a corresponding - // RevokeFileHandleRights or CloseFile call for every - // file open / create call. - - if( RevokeFileHandleRights( 0, 1, - m_lFileHandle, 2, m_lOpenAttr & 0x0000000F, &unused) == 0xFF) - { - (void)CloseFile( 0, 1, m_lFileHandle); - } - } - - m_lOpenAttr = 0; - m_lFileHandle = -1; - m_bFileOpened = m_bOpenedReadOnly = m_bOpenedExclusive = FALSE; - - if( m_bDeleteOnClose) - { - if( bDeleteAllowed) - { - if (m_bNSS) - { - (void)gv_zDeleteFunc( gv_NssRootKey, 0, zNSPACE_LONG | zMODE_UTF8, - m_pszIoPath, zMATCH_ALL, 0); - } - else - { - (void)EraseFile( 0, 1, m_lVolumeID, 0, (BYTE *)m_pszIoPath, - m_lLNamePathCount, LONGNameSpace, 0); - } - } - - m_bDeleteOnClose = FALSE; - m_lLNamePathCount = 0; - } - - if( m_pszIoPath) - { - f_free( &m_pszIoPath); - } - -Exit: - - return( rc); -} - -/**************************************************************************** -Desc: Read from a file -****************************************************************************/ -RCODE F_FileHdlImp::Read( - FLMUINT uiReadOffset, - FLMUINT uiBytesToRead, - void * pvBuffer, - FLMUINT * puiBytesReadRV) -{ - RCODE rc; - - if( RC_BAD( rc = GET_FS_ERROR())) - { - goto Exit; - } - - if ( m_bDoDirectIO ) - { - rc = _DirectIORead( uiReadOffset, uiBytesToRead, pvBuffer, puiBytesReadRV ); - } - else - { - rc = _Read( uiReadOffset, uiBytesToRead, pvBuffer, puiBytesReadRV ); - } - -Exit: - - return( rc ); -} - - -/**************************************************************************** -Desc: Read from a file -****************************************************************************/ -RCODE F_FileHdlImp::_Read( - FLMUINT uiReadOffset, - FLMUINT uiBytesToRead, - void * pvBuffer, - FLMUINT * puiBytesReadRV) -{ - RCODE rc = FERR_OK; - FCBType * fcb; - LONG lBytesRead; - LONG lErr; - - flmAssert( m_bFileOpened == TRUE); - - if( puiBytesReadRV) - { - *puiBytesReadRV = 0; - } - - if( RC_BAD( rc = GET_FS_ERROR())) - { - goto Exit; - } - - if (uiReadOffset == F_IO_CURRENT_POS) - uiReadOffset = m_uiCurrentPos; - - if (m_bNSS) - { - FLMINT lStatus; - FLMUINT nBytesRead; - - if ((lStatus = gv_zReadFunc( m_NssKey, 0, (FLMUINT64)uiReadOffset, - (FLMUINT)uiBytesToRead, pvBuffer, - &nBytesRead)) != zOK) - { - rc = MapNSSToFlaimError( lStatus, FERR_READING_FILE); - goto Exit; - } - - if( puiBytesReadRV) - { - *puiBytesReadRV = (FLMUINT)nBytesRead; - } - - if ((FLMUINT)nBytesRead < uiBytesToRead) - { - rc = RC_SET( FERR_IO_END_OF_FILE); - } - m_uiCurrentPos = uiReadOffset + (FLMUINT)nBytesRead; - } - else - { - lErr = MapFileHandleToFCB( m_lFileHandle, &fcb ); - if ( lErr != 0 ) - { - rc = MapNWtoFlaimError( lErr, FERR_SETTING_UP_FOR_READ); - goto Exit; - } - lErr = ReadFile( fcb->Station, m_lFileHandle, uiReadOffset, - uiBytesToRead, &lBytesRead, pvBuffer); - if ( lErr == 0 ) - { - if( puiBytesReadRV) - { - *puiBytesReadRV = (FLMUINT) lBytesRead; - } - - if (lBytesRead < (LONG)uiBytesToRead) - { - rc = RC_SET( FERR_IO_END_OF_FILE); - } - m_uiCurrentPos = uiReadOffset + lBytesRead; - } - else - { - rc = MapNWtoFlaimError(lErr, FERR_READING_FILE); - } - } - -Exit: - - return( rc); -} - -/**************************************************************************** -Desc: Returns m_uiCurrentPos -****************************************************************************/ -RCODE F_FileHdlImp::Tell( - FLMUINT * puiOffset) -{ - RCODE rc; - - if( RC_OK( rc = GET_FS_ERROR())) - { - *puiOffset = m_uiCurrentPos; - } - - return( rc); -} - -/**************************************************************************** -Desc: Calls the Direct IO-style read routine -Note: Where possible, the caller should attempt to read on sector - boundaries and full sectors. This routine will do the - necessary work if this is not done, but it will be less - efficient. -****************************************************************************/ -RCODE F_FileHdlImp::_DirectIORead( - FLMUINT uiReadOffset, - FLMUINT uiBytesToRead, - void * pvBuffer, - FLMUINT * puiBytesReadRV) -{ - RCODE rc = FERR_OK; - FLMBYTE * pucBuffer = (FLMBYTE *)pvBuffer; - LONG lStartSector; - LONG lSectorCount; - LONG lResult; - BYTE ucSectorBuf [NLM_SECTOR_SIZE]; - FLMUINT uiBytesToCopy; - FLMUINT uiSectorOffset; - FLMUINT uiTotal; - FLMINT lStatus; - - flmAssert( m_bFileOpened == TRUE); - - if( puiBytesReadRV) - { - *puiBytesReadRV = 0; - } - - if( RC_BAD( rc = GET_FS_ERROR())) - { - goto Exit; - } - - if (uiReadOffset == F_IO_CURRENT_POS) - uiReadOffset = m_uiCurrentPos; - - /* Calculate the starting sector. */ - - lStartSector = uiReadOffset / NLM_SECTOR_SIZE; - - /* - See if the offset is on a sector boundary. If not, we must read - into the local sector buffer and then copy into the buffer. - We must also read into the local buffer if our read size is less - than the sector size. - */ - - if ((uiReadOffset % NLM_SECTOR_SIZE != 0) || - (uiBytesToRead < NLM_SECTOR_SIZE)) - { - if (m_bNSS) - { - if ((lStatus = gv_zDIOReadFunc( m_NssKey, - (FLMUINT64)lStartSector, 1, - (FLMUINT)0, NULL, ucSectorBuf)) != zOK) - { - rc = MapNSSToFlaimError( lStatus, FERR_DIRECT_READING_FILE); - goto Exit; - } - } - else - { - lResult = DirectReadFile( - 0, - m_lFileHandle, - lStartSector, - 1, - ucSectorBuf - ); - if (lResult != 0) - { - rc = DfsMapError( lResult, FERR_DIRECT_READING_FILE); - goto Exit; - } - } - - /* Copy the part of the sector that was requested into the buffer. */ - - uiSectorOffset = uiReadOffset % NLM_SECTOR_SIZE; - - if ((uiBytesToCopy = uiBytesToRead) > NLM_SECTOR_SIZE - uiSectorOffset) - uiBytesToCopy = NLM_SECTOR_SIZE - uiSectorOffset; - f_memcpy( pucBuffer, &ucSectorBuf [uiSectorOffset], uiBytesToCopy); - pucBuffer += uiBytesToCopy; - uiBytesToRead -= (FLMUINT)uiBytesToCopy; - m_uiCurrentPos += (FLMUINT)uiBytesToCopy; - - if( puiBytesReadRV) - { - (*puiBytesReadRV) += (FLMUINT)uiBytesToCopy; - } - - /* See if we got everything we wanted to with this read. */ - - if (!uiBytesToRead) - goto Exit; - - /* Go to the next sector boundary */ - - lStartSector++; - } - - /* - At this point, we are poised to read on a sector boundary. See if we - have at least one full sector to read. If so, we can read it directly - into the provided buffer. If not, we must use the temporary sector - buffer. - */ - - if (uiBytesToRead >= NLM_SECTOR_SIZE) - { - lSectorCount = (LONG)(uiBytesToRead / NLM_SECTOR_SIZE); -Try_Read: - if (m_bNSS) - { - if ((lStatus = gv_zDIOReadFunc( m_NssKey, - (FLMUINT64)lStartSector, - (FLMUINT)lSectorCount, - (FLMUINT)0, NULL, pucBuffer)) != zOK) - { - if ((lStatus == zERR_END_OF_FILE || lStatus == zERR_BEYOND_EOF) && - (lSectorCount > 1)) - { - - // See if we can read one less sector. We will return - // FERR_IO_END_OF_FILE in this case. - - lSectorCount--; - rc = RC_SET( FERR_IO_END_OF_FILE); - goto Try_Read; - } - rc = MapNSSToFlaimError( lStatus, FERR_DIRECT_READING_FILE); - goto Exit; - } - } - else - { - lResult = DirectReadFile( - 0, - m_lFileHandle, - lStartSector, - lSectorCount, - pucBuffer - ); - if (lResult != 0) - { - if ((lResult == DFSOperationBeyondEndOfFile) && - (lSectorCount > 1)) - { - - // See if we can read one less sector. We will return - // FERR_IO_END_OF_FILE in this case. - - lSectorCount--; - rc = RC_SET( FERR_IO_END_OF_FILE); - goto Try_Read; - } - rc = DfsMapError( lResult, FERR_DIRECT_READING_FILE); - goto Exit; - } - } - uiTotal = (FLMUINT)(lSectorCount * NLM_SECTOR_SIZE); - pucBuffer += uiTotal; - m_uiCurrentPos += uiTotal; - - if( puiBytesReadRV) - { - (*puiBytesReadRV) += uiTotal; - } - uiBytesToRead -= uiTotal; - - /* - See if we got everything we wanted to or could with this read. - */ - - if ((!uiBytesToRead) || (rc == FERR_IO_END_OF_FILE)) - goto Exit; - - /* Go to the next sector after the ones we just read. */ - - lStartSector += lSectorCount; - } - - /* - At this point, we have less than a sector's worth to read, so we must - read it into a local buffer. - */ - - if (m_bNSS) - { - if ((lStatus = gv_zDIOReadFunc( m_NssKey, - (FLMUINT64)lStartSector, 1, - (FLMUINT)0, NULL, ucSectorBuf)) != zOK) - { - rc = MapNSSToFlaimError( lStatus, FERR_DIRECT_READING_FILE); - goto Exit; - } - } - else - { - lResult = DirectReadFile( - 0, - m_lFileHandle, - lStartSector, - 1, - ucSectorBuf - ); - if (lResult != 0) - { - rc = DfsMapError( lResult, FERR_DIRECT_READING_FILE); - goto Exit; - } - } - - /* Copy the part of the sector that was requested into the buffer. */ - - m_uiCurrentPos += uiBytesToRead; - - if( puiBytesReadRV) - { - (*puiBytesReadRV) += uiBytesToRead; - } - - f_memcpy( pucBuffer, ucSectorBuf, uiBytesToRead); - -Exit: - - return( rc); -} - -/**************************************************************************** -Desc: Might call the direct IO routine in the future -Note: This function assumes that the pvBuffer that is passed in is - a multiple of a sector size (512 bytes). -****************************************************************************/ -RCODE F_FileHdlImp::SectorRead( - FLMUINT uiReadOffset, - FLMUINT uiBytesToRead, - void * pvBuffer, - FLMUINT * puiBytesReadRV) -{ - RCODE rc = FERR_OK; - - if( RC_BAD( rc = GET_FS_ERROR())) - { - goto Exit; - } - - if ( m_bDoDirectIO ) - { - rc = _DirectIOSectorRead( uiReadOffset, uiBytesToRead, - pvBuffer, puiBytesReadRV); - } - else - { - rc = _Read( uiReadOffset, uiBytesToRead, pvBuffer, puiBytesReadRV); - } - -Exit: - - return( rc); -} - -/**************************************************************************** -Desc: Calls the direct IO Read routine -Note: This function assumes that the pvBuffer that is passed in is - a multiple of a sector size (512 bytes). -****************************************************************************/ -RCODE F_FileHdlImp::_DirectIOSectorRead( - FLMUINT uiReadOffset, - FLMUINT uiBytesToRead, - void * pvBuffer, - FLMUINT * puiBytesReadRV) -{ - RCODE rc = FERR_OK; - LONG lStartSector; - LONG lSectorCount; - LONG lResult; - FLMINT lStatus; - - flmAssert( m_bFileOpened == TRUE); - - if( RC_BAD( rc = GET_FS_ERROR())) - { - goto Exit; - } - - if (uiReadOffset == F_IO_CURRENT_POS) - uiReadOffset = m_uiCurrentPos; - - if (uiReadOffset % NLM_SECTOR_SIZE != 0) - { - rc = _Read( uiReadOffset, uiBytesToRead, pvBuffer, puiBytesReadRV); - goto Exit; - } - - /* Calculate the starting sector. */ - - lStartSector = uiReadOffset / NLM_SECTOR_SIZE; - lSectorCount = (LONG)(uiBytesToRead / NLM_SECTOR_SIZE); - if (uiBytesToRead % NLM_SECTOR_SIZE != 0) - lSectorCount++; - -Try_Read: - if (m_bNSS) - { - if ((lStatus = gv_zDIOReadFunc( m_NssKey, - (FLMUINT64)lStartSector, - (FLMUINT)lSectorCount, - (FLMUINT)0, NULL, pvBuffer)) != zOK) - { - if ((lStatus == zERR_END_OF_FILE || lStatus == zERR_BEYOND_EOF) && - (lSectorCount > 1)) - { - - // See if we can read one less sector. We will return - // FERR_IO_END_OF_FILE in this case. - - lSectorCount--; - uiBytesToRead = (FLMUINT)(lSectorCount * NLM_SECTOR_SIZE); - rc = RC_SET( FERR_IO_END_OF_FILE); - goto Try_Read; - } - uiBytesToRead = 0; - rc = MapNSSToFlaimError( lStatus, FERR_DIRECT_READING_FILE); - goto Exit; - } - } - else - { - lResult = DirectReadFile( 0, m_lFileHandle, - lStartSector, lSectorCount,(BYTE *)pvBuffer); - if (lResult != 0) - { - if ((lResult == DFSOperationBeyondEndOfFile) && - (lSectorCount > 1)) - { - // See if we can read one less sector. We will return - // FERR_IO_END_OF_FILE in this case. - - lSectorCount--; - uiBytesToRead = (FLMUINT)(lSectorCount * NLM_SECTOR_SIZE); - rc = RC_SET( FERR_IO_END_OF_FILE); - goto Try_Read; - } - uiBytesToRead = 0; - rc = DfsMapError( lResult, FERR_DIRECT_READING_FILE); - goto Exit; - } - } - m_uiCurrentPos += uiBytesToRead; - -Exit: - - if( puiBytesReadRV) - { - *puiBytesReadRV = uiBytesToRead; - } - - return( rc); -} - - -/**************************************************************************** -Desc: Sets current position of file. -****************************************************************************/ -RCODE F_FileHdlImp::Seek( - FLMUINT uiOffset, - FLMINT iWhence, - FLMUINT * puiNewOffset) -{ - RCODE rc = FERR_OK; - - if( RC_BAD( rc = GET_FS_ERROR())) - { - goto Exit; - } - - switch (iWhence) - { - case F_IO_SEEK_CUR: - m_uiCurrentPos += uiOffset; - break; - case F_IO_SEEK_SET: - m_uiCurrentPos = uiOffset; - break; - case F_IO_SEEK_END: - rc = Size( &m_uiCurrentPos ); - if( rc) - { - goto Exit; - } - break; - default: - rc = RC_SET( FERR_NOT_IMPLEMENTED); - goto Exit; - } - *puiNewOffset = m_uiCurrentPos; -Exit: - return( rc); -} - -/**************************************************************************** -Desc: Return the size of the file -****************************************************************************/ -RCODE F_FileHdlImp::Size( - FLMUINT * puiSize) -{ - LONG lErr; - LONG lSize; - RCODE rc = FERR_OK; - - if( RC_BAD( rc = GET_FS_ERROR())) - { - goto Exit; - } - - if (m_bNSS) - { - FLMINT lStatus; - zInfo_s Info; - - if ((lStatus = gv_zGetInfoFunc( m_NssKey, - zGET_STORAGE_USED, - sizeof( Info), zINFO_VERSION_A, - &Info)) != zOK) - { - rc = MapNSSToFlaimError( lStatus, FERR_GETTING_FILE_INFO); - goto Exit; - } - flmAssert( Info.infoVersion == zINFO_VERSION_A); - *puiSize = (FLMUINT)Info.std.logicalEOF; - } - else - { - lErr = GetFileSize( 0, m_lFileHandle, &lSize); - if ( lErr != 0 ) - { - rc = MapNWtoFlaimError( lErr, FERR_GETTING_FILE_SIZE); - } - *puiSize = (FLMUINT)lSize; - } - -Exit: - - return( rc ); -} - -/**************************************************************************** -Desc: Truncate the file to the indicated size -WARNING: Direct IO methods are calling this method. Make sure that all changes - to this method work in direct IO mode. -****************************************************************************/ -RCODE F_FileHdlImp::Truncate( - FLMUINT uiSize) -{ - LONG lErr; - RCODE rc = FERR_OK; - - flmAssert( m_bFileOpened == TRUE); - - if( RC_BAD( rc = GET_FS_ERROR())) - { - goto Exit; - } - - if (m_bNSS) - { - FLMINT lStatus; - - if ((lStatus = gv_zSetEOFFunc( m_NssKey, 0, (FLMUINT64)uiSize, - zSETSIZE_NON_SPARSE_FILE | - zSETSIZE_NO_ZERO_FILL | - zSETSIZE_UNDO_ON_ERR)) != zOK) - { - rc = MapNSSToFlaimError( lStatus, FERR_TRUNCATING_FILE); - goto Exit; - } - } - else - { - if ((lErr = SetFileSize( - 0, - m_lFileHandle, - uiSize, - TRUE // Return freed sectors to the OS - )) != 0) - { - rc = MapNWtoFlaimError( lErr, FERR_TRUNCATING_FILE); - goto Exit; - } - } - if (m_uiCurrentPos > uiSize) - { - m_uiCurrentPos = uiSize; - } -Exit: - return( rc); -} - -/**************************************************************************** -Desc: Write to a file -****************************************************************************/ -RCODE F_FileHdlImp::Write( - FLMUINT uiWriteOffset, - FLMUINT uiBytesToWrite, - const void * pvBuffer, - FLMUINT * puiBytesWrittenRV) -{ - RCODE rc = FERR_OK; - - if( RC_BAD( rc = GET_FS_ERROR())) - { - goto Exit; - } - - if( m_bDoDirectIO) - { - rc = _DirectIOWrite( uiWriteOffset, uiBytesToWrite, - pvBuffer, puiBytesWrittenRV); - } - else - { - rc = _Write( uiWriteOffset, uiBytesToWrite, - pvBuffer, puiBytesWrittenRV); - } - -Exit: - - return( rc ); -} - - -/**************************************************************************** -Desc: Write to a file -****************************************************************************/ -RCODE F_FileHdlImp::_Write( - FLMUINT uiWriteOffset, - FLMUINT uiBytesToWrite, - const void * pvBuffer, - FLMUINT * puiBytesWrittenRV) -{ - RCODE rc = FERR_OK; - LONG lErr; - FCBType * fcb; - - flmAssert( m_bFileOpened == TRUE); - - *puiBytesWrittenRV = 0; - - if( RC_BAD( rc = GET_FS_ERROR())) - { - goto Exit; - } - - if (uiWriteOffset == F_IO_CURRENT_POS) - { - uiWriteOffset = m_uiCurrentPos; - } - else - { - m_uiCurrentPos = uiWriteOffset; - } - - if( m_bNSS) - { - FLMINT lStatus; - FLMUINT nBytesWritten; - - if( (lStatus = gv_zWriteFunc( m_NssKey, 0, (FLMUINT64)uiWriteOffset, - (FLMUINT)uiBytesToWrite, pvBuffer, &nBytesWritten)) != zOK) - { - rc = MapNSSToFlaimError( lStatus, FERR_WRITING_FILE); - goto Exit; - } - - if( nBytesWritten != (FLMUINT)uiBytesToWrite) - { - rc = RC_SET( FERR_IO_DISK_FULL); - goto Exit; - } - } - else - { - if( (lErr = MapFileHandleToFCB( m_lFileHandle, &fcb )) != 0) - { - rc = MapNWtoFlaimError( lErr, FERR_SETTING_UP_FOR_WRITE); - goto Exit; - } - - if( (lErr = WriteFile( fcb->Station, m_lFileHandle, uiWriteOffset, - uiBytesToWrite, (void *)pvBuffer)) != 0) - { - rc = MapNWtoFlaimError( lErr, FERR_WRITING_FILE); - goto Exit; - } - } - - *puiBytesWrittenRV = uiBytesToWrite; - m_uiCurrentPos = uiWriteOffset + uiBytesToWrite; - -Exit: - - return( rc); -} - -/**************************************************************************** -Desc: Calls the direct IO Write routine. -****************************************************************************/ -RCODE F_FileHdlImp::_DirectIOWrite( - FLMUINT uiWriteOffset, - FLMUINT uiBytesToWrite, - const void * pvBuffer, - FLMUINT * puiBytesWrittenRV) -{ - RCODE rc = FERR_OK; - FLMBYTE * pucBuffer = (FLMBYTE *)pvBuffer; - LONG lStartSector; - LONG lSectorCount; - LONG lResult; - BYTE ucSectorBuf[ NLM_SECTOR_SIZE]; - FLMUINT uiBytesToCopy; - FLMUINT uiSectorOffset; - FLMUINT uiTotal; - FLMINT lStatus; - - flmAssert( m_bFileOpened == TRUE); - - *puiBytesWrittenRV = 0; - - if( RC_BAD( rc = GET_FS_ERROR())) - { - goto Exit; - } - - if( uiWriteOffset == F_IO_CURRENT_POS) - { - uiWriteOffset = m_uiCurrentPos; - } - else - { - m_uiCurrentPos = uiWriteOffset; - } - - // Calculate the starting sector - - lStartSector = uiWriteOffset / NLM_SECTOR_SIZE; - - - // See if the offset is on a sector boundary. If not, we must first read - // the sector into memory, overwrite it with data from the input - // buffer and write it back out again. - - if( (uiWriteOffset % NLM_SECTOR_SIZE != 0) || - (uiBytesToWrite < NLM_SECTOR_SIZE)) - { - if( m_bNSS) - { - if( (lStatus = gv_zDIOReadFunc( m_NssKey, - (FLMUINT64)lStartSector, - (FLMUINT)1, (FLMUINT)0, NULL, ucSectorBuf)) != zOK) - { - if (lStatus == zERR_END_OF_FILE || lStatus == zERR_BEYOND_EOF) - { - f_memset( ucSectorBuf, 0, sizeof( ucSectorBuf)); - - // Expand the file - - if( RC_BAD( rc = Expand( lStartSector, 1))) - { - goto Exit; - } - } - else - { - rc = MapNSSToFlaimError( lStatus, FERR_DIRECT_READING_FILE); - goto Exit; - } - } - } - else - { - lResult = DirectReadFile( 0, m_lFileHandle, lStartSector, - 1, ucSectorBuf); - - if( lResult == DFSHoleInFileError || - lResult == DFSOperationBeyondEndOfFile ) - { - f_memset( ucSectorBuf, 0, sizeof( ucSectorBuf)); - - // Expand the file - - if( RC_BAD( rc = Expand( lStartSector, 1))) - { - goto Exit; - } - } - else if( lResult != 0) - { - rc = DfsMapError( lResult, FERR_DIRECT_READING_FILE); - goto Exit; - } - } - - // Copy the part of the buffer that is being written back into - // the sector buffer. - - uiSectorOffset = uiWriteOffset % NLM_SECTOR_SIZE; - - if( (uiBytesToCopy = uiBytesToWrite) > NLM_SECTOR_SIZE - uiSectorOffset) - { - uiBytesToCopy = NLM_SECTOR_SIZE - uiSectorOffset; - } - - f_memcpy( &ucSectorBuf [uiSectorOffset], pucBuffer, uiBytesToCopy); - pucBuffer += uiBytesToCopy; - uiBytesToWrite -= (FLMUINT)uiBytesToCopy; - m_uiCurrentPos += (FLMUINT)uiBytesToCopy; - (*puiBytesWrittenRV) += (FLMUINT)uiBytesToCopy; - - // Write the sector buffer back out - - if( RC_BAD( rc = WriteSectors( &ucSectorBuf [0], lStartSector, 1, NULL))) - { - goto Exit; - } - - // See if we wrote everything we wanted to with this write - - if (!uiBytesToWrite) - { - goto Exit; - } - - // Go to the next sector boundary - - lStartSector++; - } - - // At this point, we are poised to write on a sector boundary. See if we - // have at least one full sector to write. If so, we can write it directly - // from the provided buffer. If not, we must use the temporary sector - // buffer. - - if( uiBytesToWrite >= NLM_SECTOR_SIZE) - { - lSectorCount = (LONG)(uiBytesToWrite / NLM_SECTOR_SIZE); - - if( RC_BAD( rc = WriteSectors( (void *)pucBuffer, lStartSector, - lSectorCount, NULL))) - { - goto Exit; - } - - uiTotal = (FLMUINT)(lSectorCount * NLM_SECTOR_SIZE); - pucBuffer += uiTotal; - m_uiCurrentPos += uiTotal; - (*puiBytesWrittenRV) += uiTotal; - uiBytesToWrite -= uiTotal; - - // See if we wrote everything we wanted to with this write - - if( !uiBytesToWrite) - { - goto Exit; - } - - // Go to the next sector after the ones we just wrote - - lStartSector += lSectorCount; - } - - // At this point, we have less than a sector's worth to write, so we must - // first read the sector from disk, alter it, and then write it back out. - - if( m_bNSS) - { - if( (lStatus = gv_zDIOReadFunc( m_NssKey, (FLMUINT64)lStartSector, - (FLMUINT)1, (FLMUINT)0, NULL, ucSectorBuf)) != zOK) - { - if( lStatus == zERR_END_OF_FILE || lStatus == zERR_BEYOND_EOF) - { - f_memset( ucSectorBuf, 0, sizeof( ucSectorBuf)); - - // Expand the file - - if( RC_BAD( rc = Expand( lStartSector, 1))) - { - goto Exit; - } - } - else - { - rc = MapNSSToFlaimError( lStatus, FERR_DIRECT_READING_FILE); - goto Exit; - } - } - } - else - { - lResult = DirectReadFile( 0, m_lFileHandle, lStartSector, - 1, ucSectorBuf); - - if( lResult == DFSHoleInFileError) - { - f_memset( ucSectorBuf, 0, sizeof( ucSectorBuf)); - - // Expand the file - - if( RC_BAD( rc = Expand( lStartSector, 1))) - { - goto Exit; - } - } - else if( lResult != 0) - { - rc = DfsMapError( lResult, FERR_DIRECT_READING_FILE); - goto Exit; - } - } - - // Copy the rest of the output buffer into the sector buffer - - f_memcpy( ucSectorBuf, pucBuffer, uiBytesToWrite); - - // Write the sector back to disk - - if( RC_BAD( rc = WriteSectors( &ucSectorBuf [0], lStartSector, 1, NULL))) - { - goto Exit; - } - - m_uiCurrentPos += uiBytesToWrite; - (*puiBytesWrittenRV) += uiBytesToWrite; - -Exit: - - return( rc); -} - -/*************************************************************************** -Desc: Expand a file for writing. -***************************************************************************/ -RCODE F_FileHdlImp::Expand( - LONG lStartSector, - LONG lSectorsToAlloc) -{ - RCODE rc = FERR_OK; - LONG lResult; - LONG lBlockNumber; - LONG lStartBlockNumber; - LONG lNumBlocksToAlloc; - LONG lNumBlocksAllocated; - LONG lMinToAlloc; - LONG lLastBlockNumber; - LONG lTotalToAlloc; - LONG lExtendSize; - FLMUINT uiFileSize; - FLMUINT uiRequestedExtendSize = m_uiExtendSize; - FLMBOOL bVerifyFileSize = FALSE; - - if( RC_BAD( rc = GET_FS_ERROR())) - { - goto Exit; - } - - // If the requested extend size is the "special" value of ~0, - // we will set the requested size to 0, so that we will use the - // minimum default below. This allows us to somewhat emulate what - // the Window's code does. - - if( uiRequestedExtendSize == (FLMUINT)(~0)) - { - uiRequestedExtendSize = 0; - } - - if( m_bNSS) - { - lStartBlockNumber = lStartSector / (65536 / NLM_SECTOR_SIZE); - lLastBlockNumber = (lStartSector + lSectorsToAlloc) / (65536 / NLM_SECTOR_SIZE); - lExtendSize = uiRequestedExtendSize / 65536; - } - else - { - lStartBlockNumber = lStartSector / m_lSectorsPerBlock; - lLastBlockNumber = (lStartSector + lSectorsToAlloc) / m_lSectorsPerBlock; - lExtendSize = uiRequestedExtendSize / (m_lSectorsPerBlock * NLM_SECTOR_SIZE); - } - - // Last block number better be greater than or equal to - // start block number. - - flmAssert( lLastBlockNumber >= lStartBlockNumber); - lMinToAlloc = (lLastBlockNumber - lStartBlockNumber) + 1; - - if( lExtendSize < 5) - { - lExtendSize = 5; - } - - // Allocate up to lExtendSize blocks at a time - hopefully this will be - // more efficient. - - if( lMinToAlloc < lExtendSize) - { - lTotalToAlloc = lExtendSize; - } - else if( lMinToAlloc % lExtendSize == 0) - { - lTotalToAlloc = lMinToAlloc; - } - else - { - // Keep the total blocks to allocate a multiple of lExtendSize. - - lTotalToAlloc = lMinToAlloc - - (lMinToAlloc % lExtendSize) + lExtendSize; - } - - lNumBlocksToAlloc = lTotalToAlloc; - lBlockNumber = lStartBlockNumber; - lNumBlocksAllocated = 0; - - // Must not go over maximum file size. - - if( lStartBlockNumber + lTotalToAlloc > m_lMaxBlocks) - { - lNumBlocksToAlloc = lTotalToAlloc = m_lMaxBlocks - lStartBlockNumber; - - if( lTotalToAlloc < lMinToAlloc) - { - rc = RC_SET( FERR_IO_DISK_FULL); - goto Exit; - } - } - - if( m_bNSS) - { - FLMINT lStatus; - - for( ;;) - { - if( (lStatus = gv_zSetEOFFunc( m_NssKey, 0, - (FLMUINT64)lBlockNumber * 65536 + lNumBlocksToAlloc * 65536, - zSETSIZE_NO_ZERO_FILL | zSETSIZE_NON_SPARSE_FILE)) != zOK) - { - if( lStatus == zERR_OUT_OF_SPACE) - { - if( lNumBlocksToAlloc > lMinToAlloc) - { - lNumBlocksToAlloc--; - continue; - } - } - - rc = MapNSSToFlaimError( lStatus, FERR_EXPANDING_FILE); - goto Exit; - } - else - { - break; - } - } - } - else - { - for (;;) - { - lResult = ExpandFileInContiguousBlocks( 0, m_lFileHandle, - lBlockNumber, lNumBlocksToAlloc, -1, -1); - - // If we couldn't allocate space, see if we can free some of - // the limbo space on the volume. - - if( lResult == DFSInsufficientSpace || lResult == DFSBoundryError) - { - // May not have been able to get contiguous space for - // multiple blocks. If we were asking for more than - // one, reduce the number we are asking for and try - // again. - - if( lNumBlocksToAlloc > 1) - { - lNumBlocksToAlloc--; - continue; - } - - // If we could not even get one block, it is time to - // try and free some limbo space. - - lResult = FreeLimboVolumeSpace( (LONG)m_lVolumeID, 1); - if( lResult == DFSInsufficientLimboFileSpace) - { - // It is not an error to be out of space if - // we successfully allocated at least the minimum - // number of blocks needed. - - if( lNumBlocksAllocated >= lMinToAlloc) - { - break; - } - else - { - rc = RC_SET( FERR_IO_DISK_FULL); - goto Exit; - } - } - - continue; - } - else if( lResult == DFSOverlapError) - { - lResult = 0; - bVerifyFileSize = TRUE; - - // If lNumBlocksToAlloc is greater than one, we - // don't know exactly where the hole is, so we need - // to try filling exactly one block right where - // we are at. - - // If lNumBlocksToAlloc is exactly one, we know that - // we have a block right where we are at, so we let - // the code fall through as if the expand had - // succeeded. - - if( lNumBlocksToAlloc > 1) - { - // If we have an overlap, try getting one block at - // the current block number - need to make sure this - // is not where the hole is at. - - lNumBlocksToAlloc = 1; - continue; - } - } - else if (lResult != 0) - { - rc = DfsMapError( lResult, FERR_EXPANDING_FILE); - goto Exit; - } - - lNumBlocksAllocated += lNumBlocksToAlloc; - lBlockNumber += lNumBlocksToAlloc; - - if( lNumBlocksAllocated >= lTotalToAlloc) - { - break; - } - else if( lNumBlocksToAlloc > lTotalToAlloc - lNumBlocksAllocated) - { - lNumBlocksToAlloc = lTotalToAlloc - lNumBlocksAllocated; - } - } - - // If bVerifyFileSize is TRUE, we had an overlap error, which means - // that we may have had a hole in the file. In that case, we - // do NOT want to truncate the file to an incorrect size, so we - // get the current file size to make sure we are not reducing it - // down inappropriately. NOTE: This is not foolproof - if we have - // a hole that is exactly the size we asked for, we will not verify - // the file size. - - uiFileSize = (FLMUINT)(lStartBlockNumber + lNumBlocksAllocated) * - (FLMUINT)m_lSectorsPerBlock * (FLMUINT)NLM_SECTOR_SIZE; - - if( bVerifyFileSize) - { - LONG lCurrFileSize; - - lResult = GetFileSize( 0, m_lFileHandle, &lCurrFileSize); - - if( lResult != DFSNormalCompletion) - { - rc = DfsMapError( lResult, FERR_GETTING_FILE_SIZE); - goto Exit; - } - - if( (FLMUINT)lCurrFileSize > uiFileSize) - { - uiFileSize = (FLMUINT)lCurrFileSize; - } - } - - // This call of SetFileSize is done to force the directory entry file size - // to account for the newly allocated blocks. It also forces the directory - // entry to be updated on disk. If we didn't do this here, the directory - // entry's file size on disk would not account for this block. - // Thus, if we crashed after writing data to this - // newly allocated block, we would lose the data in the block. - - lResult = SetFileSize( 0, m_lFileHandle, uiFileSize, FALSE); - - if( lResult != DFSNormalCompletion) - { - rc = DfsMapError( lResult, FERR_TRUNCATING_FILE); - goto Exit; - } - } - -Exit: - - return( rc); -} - -/**************************************************************************** -Desc: Calls the direct IO Write routine. Handles both asynchronous writes - and synchronous writes. -****************************************************************************/ -RCODE F_FileHdlImp::WriteSectors( - void * pvBuffer, - LONG lStartSector, - LONG lSectorCount, - F_IOBuffer * pBufferObj, - FLMBOOL * pbDidAsync) -{ - RCODE rc = FERR_OK; - LONG lResult; - FLMBOOL bAlreadyExpanded = FALSE; - FLMINT lStatus; - FLMBOOL bMadePending; - - if( RC_BAD( rc = GET_FS_ERROR())) - { - goto Exit; - } - - // Keep trying write until we succeed or get an error we can't deal with. - // Actually, this will NOT loop forever. At most, it will try twice - - // and then it is only when we get a hole in the file error. - - bMadePending = FALSE; - for (;;) - { - if (m_bNSS) - { - if( pBufferObj) - { - if (!bMadePending) - { - flmAssert( pbDidAsync); - pBufferObj->makePending(); - bMadePending = TRUE; - } - lStatus = gv_zDIOWriteFunc( m_NssKey, - (FLMUINT64)lStartSector, - (FLMUINT)lSectorCount, - (FLMUINT)pBufferObj, - nssDioCallback, - pvBuffer); - } - else - { - lStatus = gv_zDIOWriteFunc( m_NssKey, - (FLMUINT64)lStartSector, - (FLMUINT)lSectorCount, (FLMUINT)0, NULL, pvBuffer); - } - - // We may need to allocate space to do this write - - if (lStatus == zERR_END_OF_FILE || - lStatus == zERR_BEYOND_EOF || - lStatus == zERR_HOLE_IN_DIO_FILE) - { - if (bAlreadyExpanded) - { - flmAssert( 0); - rc = MapNSSToFlaimError( lStatus, FERR_DIRECT_WRITING_FILE); - goto Exit; - } - - // Expand the file - - if (RC_BAD( rc = Expand( lStartSector, lSectorCount))) - { - goto Exit; - } - bAlreadyExpanded = TRUE; - continue; - } - else if (lStatus != 0) - { - rc = MapNSSToFlaimError( lStatus, FERR_DIRECT_WRITING_FILE); - goto Exit; - } - else - { - if (pBufferObj) - { - *pbDidAsync = TRUE; - } - break; - } - } - else - { - LONG lSize; - FLMBOOL bNeedToWriteEOF; - - // Determine if this write will change the EOF. If so, pre-expand - // the file. - - lResult = GetFileSize( 0, m_lFileHandle, &lSize); - if (lResult != 0) - { - rc = MapNWtoFlaimError( lResult, FERR_GETTING_FILE_SIZE); - goto Exit; - } - - bNeedToWriteEOF = (lSize < (lStartSector + lSectorCount) * NLM_SECTOR_SIZE) - ? TRUE - : FALSE; - - if( pBufferObj) - { - if (!bMadePending) - { - flmAssert( pbDidAsync); - pBufferObj->makePending(); - bMadePending = TRUE; - } - - lResult = DirectWriteFileNoWait( 0, m_lFileHandle, - lStartSector,lSectorCount, - (BYTE *)pvBuffer, DirectIONoWaitCallBack, - (LONG)pBufferObj); - } - else - { - lResult = DirectWriteFile( 0, m_lFileHandle, - lStartSector, lSectorCount, (BYTE *)pvBuffer); - } - - // We may need to allocate space to do this write - - if( lResult == DFSHoleInFileError || - lResult == DFSOperationBeyondEndOfFile) - { - if( bAlreadyExpanded) - { - flmAssert( 0); - rc = DfsMapError( lResult, FERR_DIRECT_WRITING_FILE); - goto Exit; - } - - // Expand the file - - if( RC_BAD( rc = Expand( lStartSector, lSectorCount))) - { - goto Exit; - } - - bAlreadyExpanded = TRUE; - - // The Expand method forces the file EOF in the directory - // entry to be written to disk. - - bNeedToWriteEOF = FALSE; - continue; - } - else if (lResult != 0) - { - rc = DfsMapError( lResult, FERR_DIRECT_WRITING_FILE); - goto Exit; - } - else - { - if( pBufferObj) - { - *pbDidAsync = TRUE; - } - - // If bNeedToWriteEOF is TRUE, we need to force EOF to disk. - - if( bNeedToWriteEOF) - { - LONG lFileSizeInSectors; - LONG lExtraSectors; - - // Set the EOF to the nearest block boundary - so we don't - // have to do this very often. - - lFileSizeInSectors = lStartSector + lSectorCount; - lExtraSectors = lFileSizeInSectors % m_lSectorsPerBlock; - - if (lExtraSectors) - { - lFileSizeInSectors += (m_lSectorsPerBlock - lExtraSectors); - } - - if ((lResult = SetFileSize( 0, m_lFileHandle, - (FLMUINT)lFileSizeInSectors * NLM_SECTOR_SIZE, - FALSE)) != 0) - { - rc = DfsMapError( lResult, FERR_TRUNCATING_FILE); - goto Exit; - } - } - - break; - } - } - } - -Exit: - - return( rc); -} - -/**************************************************************************** -Desc: Legacy async I/O completion callback -****************************************************************************/ -FSTATIC void DirectIONoWaitCallBack( - LONG unknownAlwaysZero, - LONG callbackData, - LONG completionCode) -{ - F_IOBuffer * pIOBuffer = (F_IOBuffer *)callbackData; - - F_UNREFERENCED_PARM( unknownAlwaysZero); - - pIOBuffer->signalComplete( - (RCODE)(completionCode == DFSNormalCompletion - ? FERR_OK - : DfsMapError( completionCode, FERR_DIRECT_WRITING_FILE))); -} - -/**************************************************************************** -Desc: NSS async I/O completion callback -****************************************************************************/ -FSTATIC void nssDioCallback( - FLMUINT reserved, - FLMUINT callbackData, - FLMUINT completionCode) -{ - F_IOBuffer * pIOBuffer = (F_IOBuffer *)callbackData; - - F_UNREFERENCED_PARM( reserved); - - pIOBuffer->signalComplete( - (RCODE)(completionCode == zOK - ? FERR_OK - : MapNSSToFlaimError( completionCode, FERR_DIRECT_WRITING_FILE))); -} - -/**************************************************************************** -Desc: Might call the direct IO Write routine in the future -Note: This routine assumes that the size of pvBuffer is a multiple of - sector size (512 bytes) and can be used to write out full - sectors. Even if uiBytesToWrite does not account for full sectors, - data from the buffer will still be written out - a partial sector - on disk will not be preserved. -****************************************************************************/ -RCODE F_FileHdlImp::SectorWrite( - FLMUINT uiWriteOffset, - FLMUINT uiBytesToWrite, - const void * pvBuffer, - FLMUINT uiBufferSize, - F_IOBuffer * pBufferObj, - FLMUINT * puiBytesWrittenRV, - FLMBOOL bZeroFill) -{ - RCODE rc = FERR_OK; - - F_UNREFERENCED_PARM( uiBufferSize); - - if( RC_BAD( rc = GET_FS_ERROR())) - { - goto Exit; - } - - if ( m_bDoDirectIO) - { - rc = _DirectIOSectorWrite( uiWriteOffset, uiBytesToWrite, pvBuffer, - pBufferObj, puiBytesWrittenRV, bZeroFill); - } - else - { - flmAssert( pBufferObj == NULL); - rc = _Write( uiWriteOffset, uiBytesToWrite, pvBuffer, puiBytesWrittenRV); - } - -Exit: - - return( rc); -} - - -/**************************************************************************** -Desc: Calls the direct IO-style write routine. -Note: This routine assumes that the size of pvBuffer is a multiple of - sector size (512 bytes) and can be used to write out full - sectors. Even if uiBytesToWrite does not account for full sectors, - data from the buffer will still be written out - a partial sector - on disk will not be preserved. -****************************************************************************/ -RCODE F_FileHdlImp::_DirectIOSectorWrite( - FLMUINT uiWriteOffset, - FLMUINT uiBytesToWrite, - const void * pvBuffer, - F_IOBuffer * pBufferObj, - FLMUINT * puiBytesWrittenRV, - FLMBOOL bZeroFill) -{ - RCODE rc = FERR_OK; - LONG lStartSector; - LONG lSectorCount; - FLMBOOL bDidAsync = FALSE; - - flmAssert( m_bFileOpened == TRUE); - - if( RC_BAD( rc = GET_FS_ERROR())) - { - goto Exit; - } - - if (uiWriteOffset == F_IO_CURRENT_POS) - { - uiWriteOffset = m_uiCurrentPos; - } - else - { - m_uiCurrentPos = uiWriteOffset; - } - - if (uiWriteOffset % NLM_SECTOR_SIZE != 0) - { - rc = Write( uiWriteOffset, uiBytesToWrite, pvBuffer, - puiBytesWrittenRV); - goto Exit; - } - - // Calculate the starting sector and number of sectors to write - - lStartSector = uiWriteOffset / NLM_SECTOR_SIZE; - lSectorCount = (LONG)(uiBytesToWrite / NLM_SECTOR_SIZE); - if (uiBytesToWrite % NLM_SECTOR_SIZE != 0) - { - FLMBYTE * pucBuffer = (FLMBYTE *)pvBuffer; - - lSectorCount++; - - if (bZeroFill) - { - // Zero out the part of the buffer that was not included in - // uiBytesToWrite - because it will still be written to disk. - - f_memset( &pucBuffer [uiBytesToWrite], 0, - (FLMUINT)(NLM_SECTOR_SIZE - (uiBytesToWrite % NLM_SECTOR_SIZE))); - } - } - - if( RC_BAD( rc = WriteSectors( (void *)pvBuffer, lStartSector, lSectorCount, - pBufferObj, &bDidAsync))) - { - goto Exit; - } - - m_uiCurrentPos += uiBytesToWrite; - - if( puiBytesWrittenRV) - { - *puiBytesWrittenRV = uiBytesToWrite; - } - -Exit: - - if( !bDidAsync && pBufferObj) - { - pBufferObj->notifyComplete( rc); - } - - return( rc); -} - -/**************************************************************************** -Desc: Determine if a file or directory exists -****************************************************************************/ -RCODE NWTestIfFileExists( - const char * pPath) -{ - RCODE rc = FERR_OK; - LONG unused; - FLMBYTE ucPseudoLNamePath[ F_PATH_MAX_SIZE + 1]; - FLMBYTE ucLNamePath[ F_PATH_MAX_SIZE]; - LONG lVolumeID; - LONG lPathID; - LONG lLNamePathCount; - LONG lDirectoryID; - LONG lErrorCode; - - if( RC_BAD( rc = GET_FS_ERROR())) - { - goto Exit; - } - - f_strcpy( (char *)&ucPseudoLNamePath[1], pPath); - ucPseudoLNamePath[0] = (char)f_strlen( pPath); - - if( (lErrorCode = ConvertPathString( 0, 0, ucPseudoLNamePath, &lVolumeID, - &lPathID, ucLNamePath, &lLNamePathCount)) != 0) - { - goto Exit; - } - - if( (lErrorCode = MapPathToDirectoryNumber( 0, lVolumeID, 0, ucLNamePath, - lLNamePathCount, LONGNameSpace, &lDirectoryID, &unused)) != 0) - { - goto Exit; - } - -Exit: - - if( lErrorCode == 255 || lErrorCode == 156) - { - // Too many error codes map to 255, so we put in a special - // case check here - - rc = RC_SET( FERR_IO_PATH_NOT_FOUND); - } - else if( lErrorCode ) - { - rc = MapNWtoFlaimError( lErrorCode, FERR_CHECKING_FILE_EXISTENCE); - } - - return( rc); -} - -/**************************************************************************** -Desc: Delete a file -****************************************************************************/ -RCODE NWDeleteFile( - const char * pPath) -{ - RCODE rc = FERR_OK; - LONG lErrorCode; - char pszQualifiedPath[ F_PATH_MAX_SIZE]; - FLMBYTE ucLNamePath[ F_PATH_MAX_SIZE + 1]; - LONG lLNamePathCount; - LONG lVolumeID; - FLMBOOL bNssVolume = FALSE; - - if( RC_BAD( rc = GET_FS_ERROR())) - { - goto Exit; - } - - ConvertToQualifiedNWPath( pPath, pszQualifiedPath); - - if( (lErrorCode = ConvertPathToLNameFormat( pszQualifiedPath, &lVolumeID, - &bNssVolume, ucLNamePath, &lLNamePathCount)) != 0) - { - rc = MapNWtoFlaimError( lErrorCode, FERR_RENAMING_FILE); - goto Exit; - } - - if( gv_bNSSKeyInitialized && bNssVolume) - { - if( (lErrorCode = gv_zDeleteFunc( gv_NssRootKey, 0, - zNSPACE_LONG | zMODE_UTF8, - pszQualifiedPath, zMATCH_ALL, 0)) != zOK) - { - rc = MapNSSToFlaimError( lErrorCode, FERR_DELETING_FILE); - goto Exit; - } - } - else - { - if( (lErrorCode = EraseFile( 0, 1, lVolumeID, 0, ucLNamePath, - lLNamePathCount, LONGNameSpace, 0)) != 0) - { - // Too many error codes map to 255, so we put in a special - // case check here. - - if( lErrorCode == 255) - { - rc = RC_SET( FERR_IO_PATH_NOT_FOUND); - } - else - { - rc = MapNWtoFlaimError( lErrorCode, FERR_DELETING_FILE); - } - - goto Exit; - } - } - -Exit: - - return( rc); -} - -/**************************************************************************** -Desc: Turn off the rename inhibit bit for a file in an NSS volume. -****************************************************************************/ -FSTATIC RCODE nssTurnOffRenameInhibit( - const char * pszFileName) -{ - RCODE rc = FERR_OK; - zInfo_s Info; - FLMINT64 NssKey; - FLMBOOL bFileOpened = FALSE; - FLMINT lStatus; - FLMUINT nOpenAttr; - - nOpenAttr = FlaimToNSSOpenFlags( (FLMUINT)(F_IO_RDWR | - F_IO_SH_DENYNONE), FALSE); - - if( (lStatus = gv_zOpenFunc( gv_NssRootKey, 1, zNSPACE_LONG | zMODE_UTF8, - pszFileName, nOpenAttr, &NssKey)) != zOK) - { - rc = MapNSSToFlaimError( lStatus, FERR_OPENING_FILE); - goto Exit; - } - - bFileOpened = TRUE; - - // Get the file attributes. - - if( (lStatus = gv_zGetInfoFunc( NssKey, zGET_STD_INFO, sizeof( Info), - zINFO_VERSION_A, &Info)) != zOK) - { - rc = MapNSSToFlaimError( lStatus, FERR_GETTING_FILE_INFO); - goto Exit; - } - - flmAssert( Info.infoVersion == zINFO_VERSION_A); - - // See if the rename inhibit bit is set. - - if( Info.std.fileAttributes & zFA_RENAME_INHIBIT) - { - // Turn bit off - - Info.std.fileAttributes = 0; - - // Specify which bits to modify - only rename inhibit in this case - - Info.std.fileAttributesModMask = zFA_RENAME_INHIBIT; - - if( (lStatus = gv_zModifyInfoFunc( NssKey, 0, zMOD_FILE_ATTRIBUTES, - sizeof( Info), zINFO_VERSION_A, &Info)) != zOK) - { - rc = MapNSSToFlaimError( lStatus, FERR_SETTING_FILE_INFO); - goto Exit; - } - } - -Exit: - - if( bFileOpened) - { - (void)gv_zCloseFunc( NssKey); - } - - return( rc); -} - -/**************************************************************************** -Desc: Rename a file -Notes: Currently, this function doesn't support moving the file from one - volume to another. (There is a CopyFileToFile function that could - be used to do the move.) The toolkit function does appear to - support moving (copy/delete) the file. - - This function does support renaming directories. -****************************************************************************/ -RCODE NWRenameFile( - const char * pOldFilePath, - const char * pNewFilePath) -{ - RCODE rc = FERR_OK; - LONG unused; - FLMBYTE ucOldLNamePath[ F_PATH_MAX_SIZE + 1]; - LONG lOldLNamePathCount; - FLMBYTE ucNewLNamePath[ F_PATH_MAX_SIZE + 1]; - LONG lNewLNamePathCount; - LONG lVolumeID; - LONG lErrorCode; - FLMBYTE ucPseudoLNamePath[ F_PATH_MAX_SIZE + 1]; - LONG lPathID; - LONG lIsFile; - FLMBOOL bIsDirectory; - struct ModifyStructure modifyStruct; - LONG lDirectoryID; - LONG lFileAttributes; - LONG lMatchBits; - FLMBOOL bNssVolume = - (FLMBOOL)(gv_zIsNSSVolumeFunc - ? (gv_zIsNSSVolumeFunc( (const char *)pOldFilePath) - ? TRUE - : FALSE) - : FALSE); - - if( RC_BAD( rc = GET_FS_ERROR())) - { - goto Exit; - } - - if( gv_bNSSKeyInitialized && bNssVolume) - { - FLMINT lStatus; - FLMBOOL bTurnedOffRenameInhibit = FALSE; - -Retry_Nss_Rename: - - if( (lStatus = gv_zRenameFunc( gv_NssRootKey, 0, - zNSPACE_LONG | zMODE_UTF8, pOldFilePath, zMATCH_ALL, - zNSPACE_LONG | zMODE_UTF8, pNewFilePath, 0)) != zOK) - { - if( lStatus == zERR_NO_RENAME_PRIVILEGE && !bTurnedOffRenameInhibit) - { - // Attempt to turn off rename inhibit. This isn't always the - // reason for zERR_NO_RENAME_PRIVILEGE, but it is one we - // definitely need to take care of. - - if( RC_BAD( rc = nssTurnOffRenameInhibit( pOldFilePath))) - { - goto Exit; - } - - bTurnedOffRenameInhibit = TRUE; - goto Retry_Nss_Rename; - } - - rc = MapNSSToFlaimError( lStatus, FERR_RENAMING_FILE); - goto Exit; - } - } - else - { - f_strcpy( (char *)&ucPseudoLNamePath[1], pOldFilePath); - ucPseudoLNamePath[0] = (char)f_strlen( (const char *)&ucPseudoLNamePath[1] ); - - if( (lErrorCode = ConvertPathString( 0, 0, ucPseudoLNamePath, &lVolumeID, - &lPathID, (BYTE *)ucOldLNamePath, &lOldLNamePathCount)) != 0) - { - goto Exit; - } - - if( (lErrorCode = MapPathToDirectoryNumber( 0, lVolumeID, 0, - (BYTE *)ucOldLNamePath, lOldLNamePathCount, LONGNameSpace, - &lDirectoryID, &lIsFile)) != 0) - { - goto Exit; - } - - if( lIsFile) - { - bIsDirectory = FALSE; - lMatchBits = 0; - } - else - { - bIsDirectory = TRUE; - lMatchBits = SUBDIRECTORY_BIT; - } - - f_strcpy( (char *)&ucPseudoLNamePath[1], pNewFilePath); - ucPseudoLNamePath[0] = (char)f_strlen( (const char *)&ucPseudoLNamePath[1]); - - if( (lErrorCode = ConvertPathString( 0, 0, ucPseudoLNamePath, &unused, - &lPathID, (BYTE *)ucNewLNamePath, &lNewLNamePathCount)) != 0) - { - goto Exit; - } - - { - struct DirectoryStructure * pFileInfo; - - if( (lErrorCode = VMGetDirectoryEntry( lVolumeID, - lDirectoryID & 0x00ffffff, &pFileInfo)) != 0) - { - goto Exit; - } - - lFileAttributes = pFileInfo->DFileAttributes; - } - - if( lFileAttributes & RENAME_INHIBIT_BIT ) - { - f_memset(&modifyStruct, 0, sizeof(modifyStruct)); - modifyStruct.MFileAttributesMask = RENAME_INHIBIT_BIT; - - if( (lErrorCode = ModifyDirectoryEntry( 0, 1, lVolumeID, 0, - (BYTE *)ucOldLNamePath, lOldLNamePathCount, LONGNameSpace, - lMatchBits, LONGNameSpace, &modifyStruct, - MFileAttributesBit, 0)) != 0) - { - goto Exit; - } - } - - lErrorCode = RenameEntry( 0, 1, lVolumeID, 0, ucOldLNamePath, - lOldLNamePathCount, LONGNameSpace, lMatchBits, - (BYTE)bIsDirectory ? 1 : 0, 0, ucNewLNamePath, lNewLNamePathCount, - TRUE, TRUE); - - if( lFileAttributes & RENAME_INHIBIT_BIT ) - { - FLMBYTE * pFileName; - - if( lErrorCode ) - { - pFileName = ucOldLNamePath; - lNewLNamePathCount = lOldLNamePathCount; - } - else - { - pFileName = ucNewLNamePath; - } - - // Turn the RENAME_INHIBIT_BIT back on - - f_memset(&modifyStruct, 0, sizeof(modifyStruct)); - modifyStruct.MFileAttributes = RENAME_INHIBIT_BIT; - modifyStruct.MFileAttributesMask = RENAME_INHIBIT_BIT; - - (void)ModifyDirectoryEntry( 0, 1, lVolumeID, 0, (BYTE *)pFileName, - lNewLNamePathCount, LONGNameSpace, lMatchBits, LONGNameSpace, - &modifyStruct, MFileAttributesBit, 0); - } - } - -Exit: - - if( !gv_bNSSKeyInitialized || !bNssVolume) - { - if( lErrorCode ) - { - // Too many error codes map to 255, so we put in a special - // case check here. - - if( lErrorCode == 255) - { - rc = RC_SET( FERR_IO_PATH_NOT_FOUND); - } - else - { - rc = MapNWtoFlaimError( lErrorCode, FERR_RENAMING_FILE); - } - } - } - - return( rc); -} - -/**************************************************************************** -Desc: Convert the given path to NetWare LName format. -Input: pPath = qualified netware path of the format: - volume:directory_1\...\directory_n\filename.ext -Output: plVolumeID = NetWare volume ID - pLNamePath = NetWare LName format path - - Netware expects paths to be in LName format: - ... - where is a one-byte length and is a path component. - - Example: 6SYSTEM4Fred - note that the 6 and 4 are binary, not ASCII - - plLNamePathCount = number of path components in pLNamePath -****************************************************************************/ -FSTATIC LONG ConvertPathToLNameFormat( - const char * pPath, - LONG * plVolumeID, - FLMBOOL * pbNssVolume, - FLMBYTE * pLNamePath, - LONG * plLNamePathCount) -{ - FLMBYTE ucPseudoLNamePath[ F_PATH_MAX_SIZE + 1]; - LONG lPathID; - LONG lErrorCode = 0; - - *pLNamePath = 0; - *plLNamePathCount = 0; - -#ifdef FLM_DEBUG - if( RC_BAD( GET_FS_ERROR())) - { - lErrorCode = 255; - goto Exit; - } -#endif - - *pbNssVolume = (FLMBOOL)(gv_zIsNSSVolumeFunc - ? (gv_zIsNSSVolumeFunc( (const char *)pPath) - ? TRUE - : FALSE) - : FALSE); - - if( gv_bNSSKeyInitialized && *pbNssVolume) - { - f_strcpy( (char *)pLNamePath, pPath); - *plLNamePathCount = 1; - } - else - { - f_strcpy( (char *)&ucPseudoLNamePath[1], pPath); - ucPseudoLNamePath[0] = (FLMBYTE)f_strlen( (const char *)&ucPseudoLNamePath[1]); - - if( (lErrorCode = ConvertPathString( 0, 0, ucPseudoLNamePath, plVolumeID, - &lPathID, (BYTE *)pLNamePath, plLNamePathCount)) != 0) - { - goto Exit; - } - } - -Exit: - - return( lErrorCode ); -} - -/**************************************************************************** -Desc: Convert the given path to a NetWare format. The format isn't - critical, it just needs to be consistent. See below for a - description of the format chosen. -Input: pInputPath = a path to a file -Output: pszQualifiedPath = qualified netware path of the format: - volume:directory_1\...\directory_n\filename.ext - - If no volume is given, "SYS:" is the default. -****************************************************************************/ -FSTATIC void ConvertToQualifiedNWPath( - const char * pInputPath, - char * pszQualifiedPath) -{ - char ucFileName [F_FILENAME_SIZE]; - char ucVolume [MAX_NETWARE_VOLUME_NAME+1]; - char ucPath [F_PATH_MAX_SIZE + 1]; - - // Separate path into its components: volume, path... - - f_pathParse( pInputPath, NULL, ucVolume, ucPath, ucFileName); - - // Rebuild path to a standard, fully-qualified format, defaulting the - // volume if one isn't specified. - - *pszQualifiedPath = 0; - if( ucVolume [0]) - { - // Append the volume specified by the user. - - f_strcat( pszQualifiedPath, ucVolume ); - } - else - { - // No volume specified, use the default - - f_strcat( pszQualifiedPath, "SYS:"); - } - - if( ucPath [0]) - { - // User specified a path... - - if( ucPath[0] == '\\' || ucPath[0] == '/' ) - { - // Append the path to the volume without the leading slash - - f_strcat( pszQualifiedPath, &ucPath [1]); - } - else - { - // Append the path to the volume - - f_strcat( pszQualifiedPath, ucPath); - } - } - - if( ucFileName [0]) - { - // Append the file name to the path - - f_pathAppend( pszQualifiedPath, ucFileName); - } -} - -#endif - -/**************************************************************************** -Desc: -****************************************************************************/ -#if defined( FLM_OSX) -void gv_fnlm() -{ -} -#endif diff --git a/flaim/src/fnlm.h b/flaim/src/fnlm.h deleted file mode 100644 index 31ab254..0000000 --- a/flaim/src/fnlm.h +++ /dev/null @@ -1,236 +0,0 @@ -//------------------------------------------------------------------------- -// Desc: I/O for Netware OS - class definitions -// Tabs: 3 -// -// Copyright (c) 2000-2006 Novell, Inc. All Rights Reserved. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of version 2 of the GNU General Public -// License as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, contact Novell, Inc. -// -// To contact Novell about this file by physical or electronic mail, -// you may find current contact information at www.novell.com -// -// $Id: fnlm.h 12329 2006-01-20 17:49:30 -0700 (Fri, 20 Jan 2006) ahodgkinson $ -//------------------------------------------------------------------------- - -#ifndef FNLM_H -#define FNLM_H - -#include "fpackon.h" - -// IMPORTANT NOTE: No other include files should follow this one except -// for fpackoff.h - -// NOTE: We WANT this header file to come after fpackon.h so that it will -// be byte packed. - -// #include "zomni.h" - -#define NLM_SECTOR_SIZE 512 - -RCODE NWTestIfFileExists( - const char * pPath); - -RCODE NWDeleteFile( - const char * pPath); - -RCODE NWRenameFile( - const char * pOldFilePath, - const char * pNewFilePath); - -class F_FileHdlImp : public F_FileHdlImpBase -{ -public: - - F_FileHdlImp(); // F_FileHdlImp Constructor - - virtual ~F_FileHdlImp( void) - { - if( m_bFileOpened) - { - (void)Close(); - } - } - - RCODE Setup( - FLMUINT uiFileId); - - RCODE Close(); - - RCODE Create( - const char * pIoPath, - FLMUINT uiIoFlags); - - RCODE CreateUnique( - char * pIoPath, - const char * pszFileExtension, - FLMUINT uiIoFlags); - - RCODE Open( - const char * pIoPath, - FLMUINT uiIoFlags); - - FINLINE RCODE Flush( void) - { - return( FERR_OK); - } - - RCODE Read( - FLMUINT uiOffset, - FLMUINT uiLength, - void * pvBuffer, - FLMUINT * puiBytesRead); - - RCODE Seek( - FLMUINT uiOffset, - FLMINT iWhence, - FLMUINT * puiNewOffset); - - RCODE Size( - FLMUINT * puiSize); - - RCODE Tell( - FLMUINT * puiOffset); - - RCODE Truncate( - FLMUINT uiSize); - - RCODE Write( - FLMUINT uiOffset, - FLMUINT uiLength, - const void * pvBuffer, - FLMUINT * puiBytesWritten); - - RCODE SectorRead( - FLMUINT uiReadOffset, - FLMUINT uiBytesToRead, - void * pvBuffer, - FLMUINT * puiBytesReadRV); - - RCODE SectorWrite( - FLMUINT uiWriteOffset, - FLMUINT uiBytesToWrite, - const void * pvBuffer, - FLMUINT uiBufferSize, - F_IOBuffer * pBufferObj, - FLMUINT * puiBytesWrittenRV, - FLMBOOL bZeroFill = TRUE); - - FINLINE FLMBOOL CanDoAsync( void) - { - return( m_bDoDirectIO); - } - - FINLINE void setExtendSize( - FLMUINT uiExtendSize) - { - m_uiExtendSize = uiExtendSize; - } - - FINLINE void setMaxAutoExtendSize( - FLMUINT uiMaxAutoExtendSize) - { - m_uiMaxAutoExtendSize = uiMaxAutoExtendSize; - } - - FINLINE void setSuballocation( - FLMBOOL bDoSuballocation) - { - m_bDoSuballocation = bDoSuballocation; - } - - FINLINE FLMUINT GetSectorSize( void) - { - return( NLM_SECTOR_SIZE); - } - - FINLINE void SetBlockSize( FLMUINT) - { - } - -private: - - RCODE OpenOrCreate( - const char * pszFileName, - FLMUINT uiAccess, - FLMBOOL bCreateFlag); - - RCODE _Read( - FLMUINT uiOffset, - FLMUINT uiLength, - void * pvBuffer, - FLMUINT * puiBytesRead); - - RCODE _DirectIORead( - FLMUINT uiOffset, - FLMUINT uiLength, - void * pvBuffer, - FLMUINT * puiBytesRead); - - RCODE _DirectIOSectorRead( - FLMUINT uiReadOffset, - FLMUINT uiBytesToRead, - void * pvBuffer, - FLMUINT * puiBytesReadRV); - - RCODE _Write( - FLMUINT uiWriteOffset, - FLMUINT uiBytesToWrite, - const void * pvBuffer, - FLMUINT * puiBytesWrittenRV); - - RCODE _DirectIOWrite( - FLMUINT uiWriteOffset, - FLMUINT uiBytesToWrite, - const void * pvBuffer, - FLMUINT * puiBytesWrittenRV); - - RCODE Expand( - LONG lStartSector, - LONG lSectorsToAlloc); - - RCODE WriteSectors( - void * pvBuffer, - LONG lStartSector, - LONG lSectorCount, - F_IOBuffer * pBufferObj, - FLMBOOL * pbDidAsync = NULL); - - RCODE _DirectIOSectorWrite( - FLMUINT uiWriteOffset, - FLMUINT uiBytesToWrite, - const void * pvBuffer, - F_IOBuffer * pBufferObj, - FLMUINT * puiBytesWrittenRV, - FLMBOOL bZeroFill); - - LONG m_lFileHandle; - LONG m_lOpenAttr; - LONG m_lVolumeID; - LONG m_lLNamePathCount; - FLMBOOL m_bDoSuballocation; - FLMUINT m_uiExtendSize; - FLMUINT m_uiMaxAutoExtendSize; - FLMBOOL m_bDoDirectIO; - LONG m_lSectorsPerBlock; - LONG m_lMaxBlocks; - FLMUINT m_uiCurrentPos; - FLMBOOL m_bNSS; - FLMINT64 m_NssKey; - FLMBOOL m_bNSSFileOpen; - - friend class F_FileHdlPage; -}; - -#include "fpackoff.h" - -#endif diff --git a/flaim/src/fntable.cpp b/flaim/src/fntable.cpp index a5fb6c1..0b066fa 100644 --- a/flaim/src/fntable.cpp +++ b/flaim/src/fntable.cpp @@ -119,7 +119,7 @@ Desc: Constructor ****************************************************************************/ F_NameTable::F_NameTable() { - GedPoolInit( &m_pool, 1024); + m_pool.poolInit( 1024); m_ppSortedByTagName = NULL; m_ppSortedByTagNum = NULL; m_ppSortedByTagTypeAndName = NULL; @@ -134,7 +134,7 @@ Desc: Destructor F_NameTable::~F_NameTable() { clearTable(); - GedPoolFree( &m_pool); + m_pool.poolFree(); } /**************************************************************************** @@ -142,8 +142,8 @@ Desc: Free everything in the table ****************************************************************************/ void F_NameTable::clearTable( void) { - GedPoolFree( &m_pool); - GedPoolInit( &m_pool, 1024); + m_pool.poolFree(); + m_pool.poolInit( 1024); // NOTE: Only one allocation is used for m_ppSortedByTagName, // m_ppSortedByTagNum, and m_ppSortedByTagTypeAndName - there is no @@ -802,11 +802,11 @@ RCODE F_NameTable::allocTag( // Create a new tag info structure. - pvMark = GedPoolMark( &m_pool); - if ((pTagInfo = (FLM_TAG_INFO *)GedPoolCalloc( &m_pool, - sizeof( FLM_TAG_INFO))) == NULL) + pvMark = m_pool.poolMark(); + + if( RC_BAD( rc = m_pool.poolCalloc( sizeof( FLM_TAG_INFO), + (void **)&pTagInfo))) { - rc = RC_SET( FERR_MEM); goto Exit; } @@ -815,21 +815,22 @@ RCODE F_NameTable::allocTag( if (puzTagName) { uiNameSize = (f_unilen( puzTagName) + 1) * sizeof( FLMUNICODE); - if ((pTagInfo->puzTagName = (FLMUNICODE *)GedPoolAlloc( &m_pool, - uiNameSize)) == NULL) + + if( RC_BAD( rc = m_pool.poolAlloc( uiNameSize, + (void **)&pTagInfo->puzTagName))) { - rc = RC_SET( FERR_MEM); goto Exit; } - f_memcpy( pTagInfo->puzTagName, puzTagName, uiNameSize); + + f_memcpy( (void *)pTagInfo->puzTagName, puzTagName, uiNameSize); } else { uiNameSize = (f_strlen( pszTagName) + 1) * sizeof( FLMUNICODE); - if ((pTagInfo->puzTagName = (FLMUNICODE *)GedPoolAlloc( &m_pool, - uiNameSize)) == NULL) + + if( RC_BAD( rc = m_pool.poolAlloc( uiNameSize, + (void **)&pTagInfo->puzTagName))) { - rc = RC_SET( FERR_MEM); goto Exit; } @@ -850,11 +851,11 @@ Exit: if (RC_BAD( rc)) { - GedPoolReset( &m_pool, pvMark); + m_pool.poolReset( pvMark); pTagInfo = NULL; } + *ppTagInfo = pTagInfo; - return( rc); } @@ -862,8 +863,7 @@ Exit: Desc: Allocate the sort tables. ****************************************************************************/ RCODE F_NameTable::reallocSortTables( - FLMUINT uiNewTblSize - ) + FLMUINT uiNewTblSize) { RCODE rc = FERR_OK; FLM_TAG_INFO ** ppNewTbl; @@ -1051,7 +1051,7 @@ ExitCS: // Position to the first record in the B-Tree. - flmUINT32ToBigEndian( 0, ucDrnBuf); + f_UINT32ToBigEndian( 0, ucDrnBuf); if (RC_BAD( rc = FSBtSearch( pDb, pLFile, &pStack, ucDrnBuf, 4, ZERO_DOMAIN))) { @@ -1062,7 +1062,7 @@ ExitCS: while (pStack->uiCmpStatus != BT_END_OF_DATA) { - if ((uiDrn = flmBigEndianToUINT32( ucKeyBuf)) == DRN_LAST_MARKER) + if ((uiDrn = f_bigEndianToUINT32( ucKeyBuf)) == DRN_LAST_MARKER) { break; } diff --git a/flaim/src/fobjtrck.cpp b/flaim/src/fobjtrck.cpp deleted file mode 100644 index 43be788..0000000 --- a/flaim/src/fobjtrck.cpp +++ /dev/null @@ -1,789 +0,0 @@ -//------------------------------------------------------------------------- -// Desc: Object reference tracker -// Tabs: 3 -// -// Copyright (c) 1999-2006 Novell, Inc. All Rights Reserved. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of version 2 of the GNU General Public -// License as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, contact Novell, Inc. -// -// To contact Novell about this file by physical or electronic mail, -// you may find current contact information at www.novell.com -// -// $Id: fobjtrck.cpp 12329 2006-01-20 17:49:30 -0700 (Fri, 20 Jan 2006) ahodgkinson $ -//------------------------------------------------------------------------- - -#include "flaimsys.h" - -#if defined( FLM_UNIX) && !defined( FLM_OSX) - #include -#endif - -/**************************************************************************** -The NetWare Internal Debugger encrypts all symbols by XORing each character -in the symbol name with the character at the corresponding position in the -following mask. To see how the crypt mask is defined in NetWare, see -SYMDEB.386 in the NetWare source. We have three options: - - 1. We can just emulate the internal debugger and decrypt the symbol, - print it, and reencrypt it each time we want to display it (less than - efficient). - 2. We can make a decrypted copy of the symbols we are interested in on - module init, then use our own copy and free it on module exit. - 3. We can use the symbol list, but decrypt character by character into - an internal string buffer, then print the buffer. -****************************************************************************/ - -#ifdef FLM_NLM - extern "C" - { - void GetClosestSymbol( - BYTE * szBuffer, - LONG udAddress); - } -#endif - -/**************************************************************************** -Desc: -****************************************************************************/ -F_ObjRefTracker::F_ObjRefTracker(void) -{ - m_hRefListMutex = F_MUTEX_NULL; - m_pListManager = NULL;; - m_pFileSystem = NULL; - m_pszObjName[ 0] = '\0'; - m_bLocalFS = FALSE; - m_pAddrFmtHook = NULL; - m_pUserData = NULL; - m_pModHandle = NULL; -} - -/**************************************************************************** -Desc: Allocates required memory and initializes a local file system -****************************************************************************/ -RCODE F_ObjRefTracker::setup( - const char * pszObjName, - FLMBOOL bLogToFile) -{ - RCODE rc = FERR_OK; - char pszTmpBuf[ FORTRACK_MAX_OBJ_NAME_LEN + 5]; - char * pucTmp; - - // Allocate a mutex - - if( RC_BAD( rc = f_mutexCreate( &m_hRefListMutex))) - { - goto Exit; - } - - // Allocate the list - - if( (m_pListManager = f_new F_ListMgr) == NULL) - { - rc = RC_SET( FERR_MEM); - goto Exit; - } - - if( RC_BAD( m_pListManager->Setup( &m_lnode, 1))) - { - goto Exit; - } - - // Create a local file system object - - if( bLogToFile) - { - if( (m_pFileSystem = f_new F_FileSystemImp) == NULL) - { - rc = RC_SET( FERR_MEM); - goto Exit; - } - m_bLocalFS = TRUE; - } - - if( f_strlen( pszObjName) <= FORTRACK_MAX_OBJ_NAME_LEN) - { - f_strcpy( m_pszObjName, pszObjName); - } - else - { - f_sprintf( m_pszObjName, "OBJTRCK"); - } - - // Set the log path - - f_strcpy( pszTmpBuf, m_pszObjName); - pucTmp = pszTmpBuf; - while( *pucTmp) - { - if( *pucTmp >= 'a' && *pucTmp <= 'z') - { - *pucTmp = (*pucTmp - 'a') + 'A'; - } - pucTmp++; - } - f_strcat( pszTmpBuf, ".OTL"); - -#ifdef FLM_NLM - f_strcpy( m_pLogPath, "SYS:SYSTEM"); - f_pathAppend( m_pLogPath, pszTmpBuf); -#else - f_strcpy( m_pLogPath, pszTmpBuf); -#endif - -Exit: - - return( rc); -} - -/**************************************************************************** -Desc: -****************************************************************************/ -F_ObjRefTracker::~F_ObjRefTracker(void) -{ - if( m_pListManager) - { - m_pListManager->Release(); - m_pListManager = NULL; - } - - if( m_hRefListMutex != F_MUTEX_NULL) - { - f_mutexDestroy( &m_hRefListMutex); - } - - if( m_pFileSystem && m_bLocalFS) - { - m_pFileSystem->Release(); - } -} - -/**************************************************************************** -Desc: Track the given reference. -****************************************************************************/ -void F_ObjRefTracker::trackRef( - void * pReferenceID, - void * pSubrefID) -{ - TrackingRecord * pTrackingRec = NULL; - void ** pStack; - - if( m_hRefListMutex == F_MUTEX_NULL) - { - // Reference Tracking has not been initialized, just exit. - - goto Exit; - } - - if( !pReferenceID) - { - // Do not track NULL references - - goto Exit; - } - - // If there is insufficient memory to allocate a tracking record, - // then we will never know if this reference is properly released. - - if( (pTrackingRec = f_new TrackingRecord( pReferenceID, pSubrefID)) == NULL) - { - char pucMessage[ 100]; - - logError( "trackRef: Insufficient memory to allocate tracking record"); - f_sprintf( pucMessage, "\treference %x.%x will not be tracked", - (unsigned)((FLMUINT)pReferenceID), (unsigned)((FLMUINT)pSubrefID)); - logError( pucMessage); - goto Exit; - } - - if( RC_BAD( pTrackingRec->Setup( m_pListManager, &m_lnode, 1))) - { - goto Exit; - } - - //Lock the list - f_mutexLock( m_hRefListMutex); - - // Add the tracking record to the list - m_pListManager->InsertAtEnd( 0, pTrackingRec); - - //Unlock the list - f_mutexUnlock( m_hRefListMutex); - - pStack = (void **)pTrackingRec->getStack(); - getCallStack( pStack, CTRC_STACK_SIZE, /*skip = */ 1); - -Exit: - return; -} - -/**************************************************************************** -Desc: This reference has been released, don't track it any more. -****************************************************************************/ -void F_ObjRefTracker::untrackRef( - void * pReferenceID, - void * pSubrefID) -{ - TrackingRecord * pTrackingRec = NULL; - FLMBOOL bListLocked = FALSE; - - if( m_hRefListMutex == F_MUTEX_NULL) - { - // Reference Tracking has not been initialized, just exit. - - goto Exit; - } - - if( !pReferenceID) - { - goto Exit; - } - - // Lock the list - - f_mutexLock( m_hRefListMutex); - bListLocked = TRUE; - - // Try to find the reference in the list - - pTrackingRec = (TrackingRecord *) m_pListManager->GetItem( 0, 0); - while( pTrackingRec) - { - if( pTrackingRec->getReferenceID() == pReferenceID - && pTrackingRec->getSubrefID() == pSubrefID) - { - // The reference has been found. - - pTrackingRec->RemoveFromList(); - pTrackingRec->Release(); - break; - } - - pTrackingRec = (TrackingRecord *) pTrackingRec->GetNextListItem(); - } - - if( !pTrackingRec) - { - // The reference was never tracked. This isn't supposed to happen. - - char pucMessage[100]; - - f_sprintf( pucMessage, - "untrackRef: Reference %x.%x was not tracked", - (unsigned)((FLMUINT)pReferenceID), (unsigned)((FLMUINT)pSubrefID)); - logError( pucMessage); - logError( "\tModify code to track this reference"); - goto Exit; - } - -Exit: - - if( bListLocked) - { - f_mutexUnlock( m_hRefListMutex); - } -} - -/**************************************************************************** -Desc: Check the list for references that were never released. -****************************************************************************/ -void F_ObjRefTracker::checkForUnreleasedRefs( - FLMUINT * puiCount) -{ - RCODE rc = FERR_OK; - TrackingRecord * pTrackingRec; - FLMUINT uiFileCursor; - FLMUINT uiLoop; - char pucSymbol[ 125]; - char pucBuffer[ 150]; - FLMBOOL bHeaderDisplayed; - F_FileHdl * pFileHdl = NULL; - FLMBOOL bListLocked = FALSE; - FLMUINT uiCount = 0; - - if( m_hRefListMutex == F_MUTEX_NULL) - { - logError( "checkForUnreleasedReferences: Reference tracking " - "was not initialized"); - goto Exit; - } - - if( m_pFileSystem) - { - if( RC_BAD( rc = m_pFileSystem->Open( m_pLogPath, - F_IO_RDWR | F_IO_EXCL | F_IO_SH_DENYNONE, - &pFileHdl))) - { - if( RC_BAD( rc = m_pFileSystem->Create( m_pLogPath, - F_IO_RDWR | F_IO_EXCL | F_IO_SH_DENYNONE, - &pFileHdl))) - { - goto Exit; - } - } - } - - // Find EOF so text can be appended to the trace file. - - if( pFileHdl) - { - if( RC_BAD( rc = pFileHdl->Size( &uiFileCursor))) - { - goto Exit; - } - } - - // Lock the list - - f_mutexLock( m_hRefListMutex); - bListLocked = TRUE; - bHeaderDisplayed = FALSE; - - // Process all unreleased references - - for( pTrackingRec = (TrackingRecord *) m_pListManager->GetItem( 0, 0); - pTrackingRec; - pTrackingRec = (TrackingRecord *) m_pListManager->GetItem( 0, 0)) - { - void ** pStack; - - uiCount++; - if( !bHeaderDisplayed) - { - f_sprintf( pucBuffer, "Unreleased references of type [%s]\n", - m_pszObjName); - - if( RC_BAD( rc = logMessage( pucBuffer, pFileHdl, uiFileCursor))) - { - goto Exit; - } - - bHeaderDisplayed = TRUE; - } - - if( RC_BAD( rc = logMessage( " ", pFileHdl, uiFileCursor))) - { - goto Exit; - } - - f_sprintf( pucBuffer, " Unreleased reference (%X.%X) from thread: %X\n", - (unsigned)((FLMUINT)pTrackingRec->getReferenceID()), - (unsigned)((FLMUINT)pTrackingRec->getSubrefID()), - (unsigned) pTrackingRec->getThreadID()); - - if( RC_BAD( rc = logMessage( pucBuffer, pFileHdl, uiFileCursor))) - { - goto Exit; - } - - pStack = (void **) pTrackingRec->getStack(); - for( uiLoop = 0; pStack[ uiLoop]; uiLoop++ ) - { - formatAddress( pucSymbol, sizeof( pucSymbol), pStack[ uiLoop]); - f_sprintf( pucBuffer, " %-45.45s [addr = %8.8x]\n", pucSymbol, - (unsigned)((FLMUINT)pStack[ uiLoop])); - - if( RC_BAD( rc = logMessage( pucBuffer, pFileHdl, uiFileCursor))) - { - goto Exit; - } - } - - m_pListManager->RemoveItem( 0, pTrackingRec); - } - -Exit: - - if( bListLocked) - { - f_mutexUnlock( m_hRefListMutex); - } - - if( pFileHdl) - { - pFileHdl->Close(); - pFileHdl->Release(); - } - - if( puiCount) - { - *puiCount = uiCount; - } -} - -/**************************************************************************** -Desc: Sets the address coonversion callback function -****************************************************************************/ -void F_ObjRefTracker::setAddressFormatter( - ADDR_FMT_HOOK pFunc, - void * pvUserData) -{ - m_pAddrFmtHook = pFunc; - m_pUserData = pvUserData; -} - -/**************************************************************************** -Desc: Converts a return address to displayable format -****************************************************************************/ -void F_ObjRefTracker::formatAddress( - char * pucBuffer, - FLMUINT uiSize, - void * pAddress) -{ -#ifdef FLM_WIN - PIMAGEHLP_SYMBOL pihs = NULL; -#ifdef FLM_64BIT - DWORD64 displacement; -#else - DWORD displacement; -#endif - RCODE rc = FERR_OK; -#endif - - if( m_pAddrFmtHook) - { - pucBuffer[ 0] = '\0'; - m_pAddrFmtHook( this, pAddress, (FLMBYTE *)pucBuffer, uiSize, m_pUserData); - return; - } - -#if defined( FLM_NLM) - - if( uiSize == 0) - { - return; - } - - GetClosestSymbol( (BYTE *)pucBuffer, (LONG)pAddress); - - return; - -#elif defined( FLM_WIN) - - if( RC_OK( rc = f_alloc( sizeof( IMAGEHLP_SYMBOL) + 100, &pihs))) - { - pihs->SizeOfStruct = sizeof(IMAGEHLP_SYMBOL); - pihs->Address = (FLMUINT)pAddress; //stackFrame.AddrPC.Offset; - pihs->MaxNameLength = (FLMINT32)uiSize; - - if ( SymGetSymFromAddr( GetCurrentProcess(), (FLMUINT)pAddress, - &displacement, pihs ) ) - { - wsprintf( pucBuffer, "%s + %X", - (char *)pihs->Name, (unsigned)displacement); - } - else - { - wsprintf( pucBuffer, "0x%08X", (unsigned)((FLMUINT)pAddress)); - } - } - else - { - wsprintf( pucBuffer, "0x%08X", (unsigned)((FLMUINT)pAddress)); - } - - f_free( &pihs); - -#else -#ifdef HAVE_DLADDR - Dl_info dlip; - if (dladdr(pAddress, &dlip) != 0 && dlip.dli_sname) - { - const char *filename; - if (dlip.dli_saddr != pAddress) - { - filename = strrchr(dlip.dli_fname, '/'); - if (!filename) - filename = dlip.dli_fname; - else - filename++; // skip over slash - f_sprintf( pucBuffer, "0x%08x (%s)", (unsigned)((FLMUINT)pAddress), - filename); - } - else - f_sprintf( pucBuffer, "%s", dlip.dli_sname); - return; - } -#endif - f_sprintf( pucBuffer, "0x%08x", (unsigned)((FLMUINT)pAddress)); -#endif -} - -/**************************************************************************** -Desc: Walk the BP chain down the call stack, gathering return addresses. -****************************************************************************/ -#if defined( FLM_WIN) && !defined( FLM_64BIT) -void F_ObjRefTracker::getCallStack( - void * stack[], - FLMUINT uiCount, - FLMUINT uiSkip) -{ - STACKFRAME stackFrame; - FLMINT32 ui32LastBP; - FLMUINT uiLoop; - - F_UNREFERENCED_PARM( uiSkip); - ZeroMemory( (PVOID)&stackFrame, sizeof(STACKFRAME) ); - - // TDOMAN: do this in assembly since we aren't sure we can rely on the - // GetThreadContext and StackWalk API's - _asm - { - mov ui32LastBP, ebp // save off next bp - } - - // while you can continue walking the stack... - for ( uiLoop = 0; uiLoop < uiCount; uiLoop++ ) - { - // TDOMAN: we have to walk the stack ourselves since the VC4x API's - // don't appear to be consistently reliable. - __try - { - // TDOMAN: don't crash if the last bp wasn't want we expected - _asm - { - push esi - push edi - mov edi, ui32LastBP - mov esi, [edi] - cmp esi, edi - jbe Done - mov ui32LastBP, esi // save off next bp - mov esi, [edi + 4] - mov stackFrame, esi // setup AddrPC - pop edi - pop esi - } - } - __except (EXCEPTION_EXECUTE_HANDLER) - { - // If you do want to get these exceptions, you can turn off stack - // walking by setting fStackWalk to FALSE. - goto Done; - } - stack[ uiLoop] = (void *)(FLMUINT)stackFrame.AddrPC.Offset; - } - -Done: - stack[ uiLoop] = (void *)0; -} -#endif - -/**************************************************************************** -Desc: -****************************************************************************/ -#if defined( FLM_UNIX) || defined( FLM_64BIT) -void F_ObjRefTracker::getCallStack( - void * stack[], - FLMUINT, //uiCount, - FLMUINT) //uiSkip) -{ - // Not supported on this platform - stack[0] = (void *)0; -} -#endif - -/**************************************************************************** -****************************************************************************/ -#if defined( FLM_NLM) - - void *DMGetEBP(void); - -#if defined( __MWERKS__) - - - void *DMGetEBP(void) - { - __asm - { - mov eax,[ebp] - } - } // end of assembly - -#else - - #pragma aux DMGetEBP = "mov eax,ebp"; - -#endif - -/**************************************************************************** -Desc: -****************************************************************************/ -void * DMValueAtStackOffset(void *pos, int offset); - -#if defined( __MWERKS__) - - void *DMValueAtStackOffset(void *, int ) - { - __asm - { - mov eax,[ebp+0x8] - mov ebx,[ebp+0xC] - mov eax,ss:[eax+ebx] - } - } - -#else - - #pragma aux DMValueAtStackOffset = "mov eax,ss:[eax+ebx]" parm [eax] [ebx]; - -#endif - -/**************************************************************************** -Desc: Traces back COUNT entries on the call stack, storing - them in STACK. Note that this code requires that DS be build using the - Watcom /of+ option, (or equivalent) to generate traceable stack frames by - emitting prelude code for every function that looks something like that - of the SubRoutine below: - - Caller: - push Parms ; caller pushes parameters - call SubRoutine ; caller pushes his own return address - add esp, parmSize ; caller clears parameters from stack - ... - SubRoutine: - push ebp ; pushes caller's frame pointer - mov ebp, esp ; creates SubRoutine's frame pointer - ... - pop ebp ; restores caller's frame pointer - ret ; returns to caller - - In this scheme, the MOV instruction in the prelude code always sets EBP - pointing to the PUSHed value of the previous (caller's) frame pointer - (see the first instruction in SubRoutine above). We discard the first - 'skipCount' + 1 return addresses because we aren't interested in the fact - that the caller called DMAlloc, which called DMAllocFromTag, - which called getCallStack. - The stack trace loop terminates when it detects a return address that is - outside of NDS code space (start and limit are stored in the load def - struct - module handle). Some inline assembly is used to access the stack - like data (see DMGetEBP and DMValueAtStackOffset above). -****************************************************************************/ -void F_ObjRefTracker::getCallStack( - void * stack[], - FLMUINT uiCount, - FLMUINT uiSkipCount) -{ - FLMUINT uiLoop; - void * rtnAddr; - void * ebp = DMGetEBP(); - - while( uiSkipCount--) - { - ebp = DMValueAtStackOffset( ebp, 0); - } - rtnAddr = DMValueAtStackOffset( ebp, 4); - - for( uiLoop = 0; --uiCount; ) - { - void *oldebp; - - stack[ uiLoop++] = rtnAddr; - if( !ebp) - { - break; - } - - oldebp = ebp; - ebp = DMValueAtStackOffset( ebp, 0); // Caller's frame ptr - - if ( !ebp || ebp <= oldebp || ebp > (void *)((char *)oldebp+3000)) - { - break; - } - - rtnAddr = DMValueAtStackOffset( ebp, 4); // Caller's return addr - } - stack[ uiLoop] = 0; - return; -} -#endif // defined( FLM_NLM) - -/**************************************************************************** -Desc: Log an error message -****************************************************************************/ -void F_ObjRefTracker::logError( - const char * pucMessage) -{ - char pucBuffer[ 120]; - FLMUINT uiDummy = 0; - - f_sprintf( pucBuffer, "Error: %s", pucMessage); - logMessage( pucBuffer, NULL, uiDummy); - - flmAssert(0); -} - -/**************************************************************************** -Desc: Log a message to the trace file and to the DS trace screen -****************************************************************************/ -RCODE F_ObjRefTracker::logMessage( - const char * message, - F_FileHdl * pFileHdl, - FLMUINT & fileCursor) -{ - RCODE rc = FERR_OK; - FLMUINT uiBytesWritten; - FLMBOOL bFileOpened = FALSE; - const char * pCarriageReturn = "\n"; - - if( !pFileHdl && m_pFileSystem) - { - if( RC_BAD( rc = m_pFileSystem->Open( - m_pLogPath, F_IO_RDWR | F_IO_SH_DENYNONE, &pFileHdl))) - { - if( RC_BAD( rc = m_pFileSystem->Create( - m_pLogPath, F_IO_RDWR | F_IO_EXCL | F_IO_SH_DENYNONE, - &pFileHdl))) - { - goto Exit; - } - } - - bFileOpened = TRUE; - flmAssert( pFileHdl); - - //Find EOF so text can be appended to the trace file. - if( RC_BAD( rc = pFileHdl->Size( &fileCursor))) - { - goto Exit; - } - } - - if( pFileHdl) - { - if( RC_BAD( rc = pFileHdl->Write( - fileCursor, (FLMUINT)f_strlen(message), - (void *)message, &uiBytesWritten))) - { - goto Exit; - } - fileCursor += uiBytesWritten; - - if( RC_BAD( rc = pFileHdl->Write( - fileCursor, (FLMUINT)f_strlen(pCarriageReturn), - (void *)pCarriageReturn, &uiBytesWritten))) - { - fileCursor += uiBytesWritten; - } - } - -Exit: - - if( bFileOpened) - { - pFileHdl->Close(); - pFileHdl->Release(); - } - - return( rc); -} diff --git a/flaim/src/fobjtrck.h b/flaim/src/fobjtrck.h deleted file mode 100644 index d653081..0000000 --- a/flaim/src/fobjtrck.h +++ /dev/null @@ -1,168 +0,0 @@ -//------------------------------------------------------------------------- -// Desc: Object reference tracker - definitions. -// Tabs: 3 -// -// Copyright (c) 1999-2000,2002-2006 Novell, Inc. All Rights Reserved. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of version 2 of the GNU General Public -// License as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, contact Novell, Inc. -// -// To contact Novell about this file by physical or electronic mail, -// you may find current contact information at www.novell.com -// -// $Id: fobjtrck.h 12329 2006-01-20 17:49:30 -0700 (Fri, 20 Jan 2006) ahodgkinson $ -//------------------------------------------------------------------------- - -#ifndef FOBJTRCK_H -#define FOBJTRCK_H - -#include "fpackon.h" -// IMPORTANT NOTE: No other include files should follow this one except -// for fpackoff.h - -/* -Forward references -*/ - -class F_ObjRefTracker; - -/* -Callbacks -*/ - -typedef RCODE (* ADDR_FMT_HOOK)( // Address formatter / translator - F_ObjRefTracker * pRefTracker, // Reference tracker object - void * pAddress, // Pointer to the address - FLMBYTE * pucBuffer, // Buffer for formatted address - FLMUINT uiSize, // Size of buffer - void * pvUserData); // User-supplied callback data - -/**************************************************************************** - Object reference tracker -****************************************************************************/ - -class F_ObjRefTracker -{ -public: - - F_ObjRefTracker( void); - - virtual ~F_ObjRefTracker( void); - - RCODE setup( - const char * pszObjName, - FLMBOOL bLogToFile = FALSE); - - void trackRef( - void * pReferenceID, - void * pSubrefID = NULL); - - void untrackRef( - void * referenceID, - void * subrefID = NULL); - - void checkForUnreleasedRefs( - FLMUINT * puiCount = NULL); - - void setAddressFormatter( - ADDR_FMT_HOOK pFunc, - void * pvUserData); - - FINLINE void setModuleHandle( - void * pModHandle) - { - m_pModHandle = pModHandle; - } - -private: - - F_MUTEX m_hRefListMutex; - F_ListMgr * m_pListManager; - F_ListNode m_lnode; - - FLMUINT m_lOptions; - FLMUINT m_lCallStackDepth; - -#define FORTRACK_MAX_OBJ_NAME_LEN 63 - char m_pszObjName[ FORTRACK_MAX_OBJ_NAME_LEN + 1]; - F_FileSystemImp * m_pFileSystem; - FLMBOOL m_bLocalFS; // Was the file system allocated for this object? - ADDR_FMT_HOOK m_pAddrFmtHook; - void * m_pUserData; - void * m_pModHandle; - char m_pLogPath[ F_PATH_MAX_SIZE]; - - void formatAddress( - char * pucBuffer, - FLMUINT uiSize, - void * pAddress); - - static void getCallStack( - void * stack[], - FLMUINT uiCount, - FLMUINT uiSkip); - - void logError( - const char * pucMessage); - - RCODE logMessage( - const char * pucMessage, - F_FileHdl * pFileHdl, - FLMUINT & uiFileCursor); -}; - -# define CTRC_STACK_SIZE 20 - -class TrackingRecord : public F_ListItem -{ -public: - - TrackingRecord( void * pReferenceID, void * pSubrefID) - { - m_pReferenceID = pReferenceID; - m_pSubrefID = pSubrefID; - m_uiThreadID = f_threadId(); - f_memset( m_stack, 0, sizeof(m_stack)); - } - - virtual ~TrackingRecord() - { - } - - void * getReferenceID() - { - return m_pReferenceID; - } - void * getSubrefID() - { - return m_pSubrefID; - } - FLMUINT getThreadID() - { - return m_uiThreadID; - } - void * getStack() - { - return m_stack; - } - -private: - - void * m_pReferenceID; - void * m_pSubrefID; - FLMUINT m_uiThreadID; - void * m_stack[CTRC_STACK_SIZE+1]; -}; - -#include "fpackoff.h" - -#endif //FORTRACK_H diff --git a/flaim/src/fposix.cpp b/flaim/src/fposix.cpp deleted file mode 100644 index 83b601f..0000000 --- a/flaim/src/fposix.cpp +++ /dev/null @@ -1,1598 +0,0 @@ -//------------------------------------------------------------------------- -// Desc: Posix File I/O -// Tabs: 3 -// -// Copyright (c) 1999-2006 Novell, Inc. All Rights Reserved. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of version 2 of the GNU General Public -// License as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, contact Novell, Inc. -// -// To contact Novell about this file by physical or electronic mail, -// you may find current contact information at www.novell.com -// -// $Id: fposix.cpp 12331 2006-01-23 10:19:55 -0700 (Mon, 23 Jan 2006) ahodgkinson $ -//------------------------------------------------------------------------- - -#include "flaimsys.h" - -#if defined( FLM_UNIX) - -#ifdef FLM_AIX - #ifndef _LARGE_FILES - #define _LARGE_FILES - #endif - #include -#endif - -#include -#include - -#if !defined( O_SYNC) - #define O_SYNC 0 -#endif - -#if !defined( O_DSYNC) - #define O_DSYNC O_SYNC -#endif - -#define MAX_CREATION_TRIES 10 - -#if defined( FLM_SOLARIS) - #include -#elif defined( FLM_LINUX) - #include -#endif - -extern RCODE gv_CriticalFSError; - -/**************************************************************************** -Desc: -****************************************************************************/ -#if defined( FLM_UNIX) -F_FileHdlImp::F_FileHdlImp() -{ - m_fd = INVALID_HANDLE_VALUE; - m_uiMaxAutoExtendSize = gv_FlmSysData.uiMaxFileSize; - m_uiBlockSize = 0; - m_uiBytesPerSector = 0; - m_uiNotOnSectorBoundMask = 0; - m_uiGetSectorBoundMask = 0; - m_uiExtendSize = 0; - m_uiCurrentPos = 0; - m_bDoDirectIO = FALSE; - m_bCanDoAsync = FALSE; - m_pucAlignedBuff = NULL; - m_uiAlignedBuffSize = 0; -} -#endif - -/**************************************************************************** -Desc: -****************************************************************************/ -#if defined( FLM_UNIX) -F_FileHdlImp::~F_FileHdlImp() -{ - if( m_bFileOpened) - { - Close(); - } - - if( m_pucAlignedBuff) - { - free( m_pucAlignedBuff); - } -} -#endif - -/*************************************************************************** -Desc: Open or create a file. -***************************************************************************/ -#if defined( FLM_UNIX) -RCODE F_FileHdlImp::OpenOrCreate( - const char * pFileName, - FLMUINT uiAccess, - FLMBOOL bCreateFlag) -{ - RCODE rc = FERR_OK; - FLMBOOL bDoDirectIO = FALSE; - char szSaveFileName[ F_PATH_MAX_SIZE]; - int openFlags = O_RDONLY; - - if( RC_BAD( rc = GET_FS_ERROR())) - { - goto Exit; - } - -#if defined( FLM_LINUX) || defined( FLM_SOLARIS) - bDoDirectIO = (uiAccess & F_IO_DIRECT) ? TRUE : FALSE; -#endif - - // HPUX needs this defined to access files larger than 2 GB. The Linux - // man pages *say* it's needed although as of Suse 9.1 it actually - // isn't. Including this flag on Linux anyway just it case... - -#if defined( FLM_HPUX) || defined( FLM_LINUX) - openFlags |= O_LARGEFILE; -#endif - if( uiAccess & F_IO_DELETE_ON_CLOSE) - { - if( !m_pszIoPath) - { - if( RC_BAD( rc = f_alloc( F_PATH_MAX_SIZE, &m_pszIoPath))) - { - goto Exit; - } - } - - f_strcpy( m_pszIoPath, pFileName); - m_bDeleteOnClose = TRUE; - } - else - { - m_bDeleteOnClose = FALSE; - } - - // Save the file name in case we have to create the directory - - if( bCreateFlag && (uiAccess & F_IO_CREATE_DIR)) - { - f_strcpy( szSaveFileName, pFileName); - } - - if( bCreateFlag) - { - openFlags |= O_CREAT; - - if( uiAccess & F_IO_EXCL) - { - openFlags |= O_EXCL; - } - } - - if( uiAccess & F_IO_TRUNC) - { - openFlags |= O_TRUNC; - } - - if( !(uiAccess & F_IO_RDONLY)) - { - openFlags |= O_RDWR; - } - - // If doing direct IO, need to get the sector size. - - if( bDoDirectIO) - { - if( !m_uiBlockSize) - { - bDoDirectIO = FALSE; - } - else - { - if( RC_BAD( rc = gv_FlmSysData.pFileSystem->GetSectorSize( - pFileName, &m_uiBytesPerSector))) - { - goto Exit; - } - - m_uiNotOnSectorBoundMask = m_uiBytesPerSector - 1; - m_uiGetSectorBoundMask = ~m_uiNotOnSectorBoundMask; - - // Can't do direct IO if the block size isn't a multiple of - // the sector size. - - if( m_uiBlockSize < m_uiBytesPerSector || - m_uiBlockSize % m_uiBytesPerSector != 0) - { - bDoDirectIO = FALSE; - } - else - { -#if defined( FLM_LINUX) - FLMUINT uiMajor = gv_FlmSysData.uiLinuxMajorVer; - FLMUINT uiMinor = gv_FlmSysData.uiLinuxMinorVer; - FLMUINT uiRevision = gv_FlmSysData.uiLinuxRevision; - - if( uiMajor > 2 || (uiMajor == 2 && uiMinor > 6) || - (uiMajor == 2 && uiMinor == 6 && uiRevision >= 5)) - { - openFlags |= O_DIRECT; - - if( gv_FlmSysData.bOkToDoAsyncWrites) - { - m_bCanDoAsync = TRUE; - } - } - else - { - bDoDirectIO = FALSE; - } -#else - if( gv_FlmSysData.bOkToDoAsyncWrites) - { - m_bCanDoAsync = TRUE; - } -#endif - } - } - } - -Retry_Create: - - // Try to create or open the file - - if( (m_fd = open( pFileName, openFlags, 0600)) == INVALID_HANDLE_VALUE) - { - if( (errno == ENOENT) && (uiAccess & F_IO_CREATE_DIR)) - { - char szTemp[ F_PATH_MAX_SIZE]; - char ioDirPath[ F_PATH_MAX_SIZE]; - - uiAccess &= ~F_IO_CREATE_DIR; - - // Remove the file name for which we are creating the directory - - if( RC_OK( f_pathReduce( szSaveFileName, ioDirPath, szTemp))) - { - F_FileSystemImp FileSystem; - - if( RC_BAD( rc = FileSystem.CreateDir( ioDirPath))) - { - goto Exit; - } - - goto Retry_Create; - } - } -#ifdef FLM_LINUX - else if( errno == EINVAL && bDoDirectIO) - { - openFlags &= ~O_DIRECT; - bDoDirectIO = FALSE; - m_bCanDoAsync = FALSE; - goto Retry_Create; - } -#endif - - rc = MapErrnoToFlaimErr( errno, FERR_OPENING_FILE); - goto Exit; - } - -#if defined( FLM_SOLARIS) - if( bDoDirectIO) - { - directio( m_fd, DIRECTIO_ON); - } -#endif - - m_bDoDirectIO = bDoDirectIO; - -Exit: - - if( RC_BAD( rc)) - { - m_fd = INVALID_HANDLE_VALUE; - m_bDoDirectIO = FALSE; - m_bCanDoAsync = FALSE; - } - - return( rc); -} -#endif - -/**************************************************************************** -Desc: Create a file -****************************************************************************/ -#if defined( FLM_UNIX) -RCODE F_FileHdlImp::Create( - const char * pIoPath, - FLMUINT uiIoFlags) -{ - RCODE rc = FERR_OK; - - flmAssert( !m_bFileOpened); - - if( RC_BAD( rc = GET_FS_ERROR())) - { - goto Exit; - } - - if( RC_BAD( rc = OpenOrCreate( pIoPath, uiIoFlags, TRUE))) - { - goto Exit; - } - - m_bFileOpened = TRUE; - m_uiCurrentPos = 0; - m_bOpenedExclusive = (uiIoFlags & F_IO_SH_DENYRW) ? TRUE : FALSE; - -Exit: - - return( rc); -} -#endif - -/**************************************************************************** -Desc: -****************************************************************************/ -#if defined( FLM_UNIX) -RCODE F_FileHdlImp::CreateUnique( - char * pIoPath, - const char * pszFileExtension, - FLMUINT uiIoFlags) -{ - RCODE rc = FERR_OK; - char * pszTmp; - FLMBOOL bModext = TRUE; - FLMUINT uiBaseTime = 0; - char ucHighByte = 0; - char ucFileName[ F_FILENAME_SIZE]; - char * pDirPath; - char szDirPath[ F_PATH_MAX_SIZE]; - char szTmpPath[ F_PATH_MAX_SIZE]; - FLMUINT uiCount; - - flmAssert( !m_bFileOpened); - f_memset( ucFileName, 0, sizeof( ucFileName)); - - if( RC_BAD( rc = GET_FS_ERROR())) - { - goto Exit; - } - - if( !pIoPath || pIoPath[ 0] == '\0') - { - f_strcpy( szDirPath, "./"); - } - else - { - f_strcpy( szDirPath, pIoPath); - } - - pDirPath = szDirPath; - - // Search backwards replacing trailing spaces with NULLs. - - pszTmp = pDirPath; - pszTmp += (f_strlen( pszTmp) - 1); - - while ((*pszTmp == ' ') && pszTmp >= pDirPath) - { - *pszTmp = 0; - pszTmp--; - } - - // Append a slash if one isn't already there - - if( pszTmp >= pDirPath && *pszTmp != '/') - { - pszTmp++; - *pszTmp++ = '/'; - } - else - { - pszTmp++; - } - - *pszTmp = 0; - - if( (pszFileExtension) && (f_strlen( pszFileExtension) >= 3)) - { - bModext = FALSE; - } - - uiCount = 0; - do - { - f_pathCreateUniqueName( &uiBaseTime, ucFileName, pszFileExtension, - &ucHighByte, bModext); - - f_strcpy( szTmpPath, pDirPath); - f_pathAppend( szTmpPath, ucFileName); - - rc = Create( szTmpPath, uiIoFlags | F_IO_EXCL); - - if( rc == FERR_IO_DISK_FULL) - { - F_FileSystemImp FileSystem; - - FileSystem.Delete( pDirPath); - goto Exit; - } - - if( rc == FERR_IO_PATH_NOT_FOUND || rc == FERR_IO_INVALID_PASSWORD) - { - goto Exit; - } - } while( rc != FERR_OK && (uiCount++ < MAX_CREATION_TRIES)); - - // Check if the path was created - - if( uiCount >= MAX_CREATION_TRIES && rc != FERR_OK) - { - rc = RC_SET( FERR_IO_PATH_CREATE_FAILURE); - goto Exit; - } - - m_bFileOpened = TRUE; - m_bOpenedExclusive = (uiIoFlags & F_IO_SH_DENYRW) ? TRUE : FALSE; - - // Created file name needs to be returned. - - f_strcpy( pIoPath, szTmpPath); - -Exit: - - return( rc); -} -#endif - -/**************************************************************************** -Desc: Open a file -****************************************************************************/ -#if defined( FLM_UNIX) -RCODE F_FileHdlImp::Open( - const char * pIoPath, - FLMUINT uiIoFlags) -{ - RCODE rc = FERR_OK; - - flmAssert( !m_bFileOpened); - - if( RC_BAD( rc = GET_FS_ERROR())) - { - goto Exit; - } - - // Loop on error open conditions. - - for( ;;) - { - if( RC_BAD( rc = OpenOrCreate( pIoPath, uiIoFlags, FALSE))) - { - if( rc != FERR_IO_TOO_MANY_OPEN_FILES) - { - goto Exit; - } - - // If for some reason we cannot open the file, then - // try to close some other file handle in the list. - - if( RC_BAD( rc = gv_FlmSysData.pFileHdlMgr->ReleaseOneAvail())) - { - goto Exit; - } - - continue; - } - - break; - } - - m_bFileOpened = TRUE; - m_uiCurrentPos = 0; - m_bOpenedReadOnly = (uiIoFlags & F_IO_RDONLY) ? TRUE : FALSE; - m_bOpenedExclusive = (uiIoFlags & F_IO_SH_DENYRW) ? TRUE : FALSE; - -Exit: - - return( rc); -} -#endif - -/**************************************************************************** -Desc: Close a file -****************************************************************************/ -#if defined( FLM_UNIX) -RCODE F_FileHdlImp::Close( void) -{ - FLMBOOL bDeleteAllowed = TRUE; - RCODE rc = FERR_OK; - - if( !m_bFileOpened) - { - goto Exit; - } - - flmAssert( m_fd != INVALID_HANDLE_VALUE); - close( m_fd); - - m_fd = INVALID_HANDLE_VALUE; - m_bFileOpened = m_bOpenedReadOnly = m_bOpenedExclusive = FALSE; - - if( m_bDeleteOnClose) - { - flmAssert( m_pszIoPath); - - if( bDeleteAllowed) - { - F_FileSystemImp FileSystem; - - FileSystem.Delete( m_pszIoPath); - } - - m_bDeleteOnClose = FALSE; - } - - if( m_pszIoPath) - { - f_free( &m_pszIoPath); - } - -Exit: - - return( rc); -} -#endif - -/**************************************************************************** -Desc: Make sure all file data is safely on disk -****************************************************************************/ -#if defined( FLM_UNIX) -RCODE F_FileHdlImp::Flush( void) -{ -#ifdef FLM_SOLARIS - - // Direct I/O on Solaris is ADVISORY, meaning that the - // operating system may or may not actually honor the - // option for some or all operations on a given file. - // Thus, the only way to guarantee that writes are on disk - // is to call fdatasync. - // - // If a process is killed (with SIGKILL or SIGTERM), the - // dirty cache buffers associated with open files will be discarded unless - // the process intercepts the signal and properly closes the files. - // - // NOTES FROM THE UNIX MAN PAGES ON SIGNALS - // - // When killing a process or series of processes, it is common sense - // to start trying with the least dangerous signal, SIGTERM. That way, - // programs that care about an orderly shutdown get the chance to follow - // the procedures that they have been designed to execute when getting - // the SIGTERM signal, such as cleaning up and closing open files. If you - // send a SIGKILL to a process, you remove any chance for the process - // to do a tidy cleanup and shutdown, which might have unfortunate - // consequences. - - if( fdatasync( m_fd) != 0) - { - return( MapErrnoToFlaimErr( errno, FERR_FLUSHING_FILE)); - } - -#else - - if( !m_bDoDirectIO) - { - #ifdef FLM_OSX - if( fsync( m_fd) != 0) - #else - if( fdatasync( m_fd) != 0) - #endif - { - return( MapErrnoToFlaimErr( errno, FERR_FLUSHING_FILE)); - } - } - -#endif - - return( FERR_OK); -} -#endif - -/**************************************************************************** -Desc: Read from a file -****************************************************************************/ -#if defined( FLM_UNIX) -RCODE F_FileHdlImp::DirectRead( - FLMUINT uiReadOffset, - FLMUINT uiBytesToRead, - void * pvBuffer, - FLMBOOL bBuffHasFullSectors, - FLMUINT * puiBytesRead) -{ - RCODE rc = FERR_OK; - FLMUINT uiBytesRead; - FLMBYTE * pucReadBuffer; - FLMBYTE * pucDestBuffer; - FLMUINT uiMaxBytesToRead; - FLMINT iTmp; - FLMBOOL bHitEOF; - - flmAssert( m_bFileOpened); - flmAssert( m_bDoDirectIO); - - if( puiBytesRead) - { - *puiBytesRead = 0; - } - - if( RC_BAD( rc = GET_FS_ERROR())) - { - goto Exit; - } - - if( uiReadOffset == F_IO_CURRENT_POS) - { - uiReadOffset = m_uiCurrentPos; - } - - // This loop does multiple reads (if necessary) to get all of the - // data. It uses aligned buffers and reads at sector offsets. - - pucDestBuffer = (FLMBYTE *)pvBuffer; - for (;;) - { - // See if we are using an aligned buffer. If not, allocate - // one (if not already allocated), and use it. - - if( (uiReadOffset & m_uiNotOnSectorBoundMask) || - (((FLMUINT)pucDestBuffer) & m_uiNotOnSectorBoundMask) || - ((uiBytesToRead & m_uiNotOnSectorBoundMask) && - (!bBuffHasFullSectors))) - { - if( !m_pucAlignedBuff) - { - if( RC_BAD( rc = AllocAlignBuffer())) - { - goto Exit; - } - } - - pucReadBuffer = m_pucAlignedBuff; - - // Must read enough bytes to cover all of the sectors that - // contain the data we are trying to read. The value of - // (uiReadOffset & m_uiNotOnSectorBoundMask) will give us the - // number of additional bytes that are in the sector prior to - // the read offset. We then round that up to the next sector - // to get the total number of bytes we are going to read. - - uiMaxBytesToRead = RoundUpToSectorMultiple( uiBytesToRead + - (uiReadOffset & m_uiNotOnSectorBoundMask)); - - // Can't read more than the aligned buffer will hold. - - if( uiMaxBytesToRead > m_uiAlignedBuffSize) - { - uiMaxBytesToRead = m_uiAlignedBuffSize; - } - } - else - { - uiMaxBytesToRead = RoundUpToSectorMultiple( uiBytesToRead); - flmAssert( uiMaxBytesToRead >= uiBytesToRead); - pucReadBuffer = pucDestBuffer; - } - - bHitEOF = FALSE; - - if( (iTmp = pread( m_fd, pucReadBuffer, - uiMaxBytesToRead, GetSectorStartOffset( uiReadOffset))) == -1) - { - rc = MapErrnoToFlaimErr( errno, FERR_READING_FILE); - goto Exit; - } - uiBytesRead = (FLMUINT)iTmp; - - if( uiBytesRead < uiMaxBytesToRead) - { - bHitEOF = TRUE; - } - - // If the offset we want to read from is not on a sector - // boundary, increment the read buffer pointer to the - // offset where the data we need starts and decrement the - // bytes read by the difference between the start of the - // sector and the actual read offset. - - if( uiReadOffset & m_uiNotOnSectorBoundMask) - { - pucReadBuffer += (uiReadOffset & m_uiNotOnSectorBoundMask); - flmAssert( uiBytesRead >= m_uiBytesPerSector); - uiBytesRead -= (uiReadOffset & m_uiNotOnSectorBoundMask); - } - - // If bytes read is more than we actually need, truncate it back - // so that we only copy what we actually need. - - if( uiBytesRead > uiBytesToRead) - { - uiBytesRead = uiBytesToRead; - } - - uiBytesToRead -= uiBytesRead; - - if( puiBytesRead) - { - (*puiBytesRead) += uiBytesRead; - } - - m_uiCurrentPos = uiReadOffset + uiBytesRead; - - // If using a different buffer for reading, copy the - // data read into the destination buffer. - - if( pucDestBuffer != pucReadBuffer) - { - f_memcpy( pucDestBuffer, pucReadBuffer, uiBytesRead); - } - - if( !uiBytesToRead) - { - break; - } - - // Still more to read - did we hit EOF above? - - if( bHitEOF) - { - rc = RC_SET( FERR_IO_END_OF_FILE); - break; - } - - pucDestBuffer += uiBytesRead; - uiReadOffset += uiBytesRead; - } - -Exit: - - return( rc); -} -#endif - -/**************************************************************************** -Desc: Read from a file -****************************************************************************/ -#if defined( FLM_UNIX) -RCODE F_FileHdlImp::Read( - FLMUINT uiReadOffset, - FLMUINT uiBytesToRead, - void * pvBuffer, - FLMUINT * puiBytesRead) -{ - RCODE rc = FERR_OK; - FLMINT iBytesRead; - - flmAssert( m_bFileOpened); - - if( m_bDoDirectIO) - { - rc = DirectRead( uiReadOffset, uiBytesToRead, - pvBuffer, FALSE, puiBytesRead); - goto Exit; - } - - if( RC_BAD( rc = GET_FS_ERROR())) - { - goto Exit; - } - - if( uiReadOffset == F_IO_CURRENT_POS) - { - uiReadOffset = m_uiCurrentPos; - } - - if( (iBytesRead = pread( m_fd, pvBuffer, uiBytesToRead, uiReadOffset)) == -1) - { - rc = MapErrnoToFlaimErr(errno, FERR_READING_FILE); - goto Exit; - } - - if( puiBytesRead) - { - *puiBytesRead = (FLMUINT)iBytesRead; - } - - m_uiCurrentPos = uiReadOffset + (FLMUINT)iBytesRead; - - if( (FLMUINT)iBytesRead < uiBytesToRead) - { - rc = RC_SET( FERR_IO_END_OF_FILE); - goto Exit; - } - -Exit: - - return( rc); -} -#endif - -/**************************************************************************** -Desc: -Note: This function assumes that the pvBuffer that is passed in is - a multiple of a the sector size. -****************************************************************************/ -#if defined( FLM_UNIX) -RCODE F_FileHdlImp::SectorRead( - FLMUINT uiReadOffset, - FLMUINT uiBytesToRead, - void * pvBuffer, - FLMUINT * puiBytesRead) -{ - if( m_bDoDirectIO) - { - return( DirectRead( uiReadOffset, uiBytesToRead, - pvBuffer, TRUE, puiBytesRead)); - } - else - { - return( Read( uiReadOffset, uiBytesToRead, pvBuffer, puiBytesRead)); - } -} -#endif - -/**************************************************************************** -Desc: Sets current position of file. -Note: F_IO_SEEK_END is not supported. -****************************************************************************/ -#if defined( FLM_UNIX) -RCODE F_FileHdlImp::Seek( - FLMUINT uiOffset, - FLMINT iWhence, - FLMUINT * puiNewOffset) -{ - RCODE rc = FERR_OK; - - if( RC_BAD( rc = GET_FS_ERROR())) - { - goto Exit; - } - - switch( iWhence) - { - case F_IO_SEEK_CUR: - { - m_uiCurrentPos += uiOffset; - break; - } - - case F_IO_SEEK_SET: - { - m_uiCurrentPos = uiOffset; - break; - } - - case F_IO_SEEK_END: - { - if( RC_BAD( rc = Size( &m_uiCurrentPos))) - { - goto Exit; - } - break; - } - - default: - { - rc = RC_SET( FERR_NOT_IMPLEMENTED); - goto Exit; - } - } - - *puiNewOffset = m_uiCurrentPos; - -Exit: - - return( rc); -} -#endif - -/**************************************************************************** -Desc: Return the size of the file -****************************************************************************/ -#if defined( FLM_UNIX) -RCODE F_FileHdlImp::Size( - FLMUINT * puiSize) -{ - RCODE rc = FERR_OK; - struct stat statBuf; - - if( RC_BAD( rc = GET_FS_ERROR())) - { - goto Exit; - } - - if( fstat( m_fd, &statBuf) == -1) - { - rc = MapErrnoToFlaimErr( errno, FERR_GETTING_FILE_SIZE); - goto Exit; - } - - // VISIT: We need to change the file handle interface to return 64-bit - // sizes and offsets. When this is done, remove the FLMUINT typecast below. - - *puiSize = (FLMUINT)statBuf.st_size; - -Exit: - - return( rc); -} -#endif - -/**************************************************************************** -Desc: Returns m_uiCurrentPos -****************************************************************************/ -#if defined( FLM_UNIX) -RCODE F_FileHdlImp::Tell( - FLMUINT * puiOffset) -{ - RCODE rc = FERR_OK; - - if( RC_BAD( rc = GET_FS_ERROR())) - { - goto Exit; - } - - *puiOffset = m_uiCurrentPos; - -Exit: - - return( rc); -} -#endif - -/**************************************************************************** -Desc: Truncate the file to the indicated size -WARNING: Direct IO methods are calling this method. Make sure that all - changes to this method work in direct IO mode. -****************************************************************************/ -#if defined( FLM_UNIX) -RCODE F_FileHdlImp::Truncate( - FLMUINT uiSize) -{ - RCODE rc = FERR_OK; - - flmAssert( m_bFileOpened); - - if( RC_BAD( rc = GET_FS_ERROR())) - { - goto Exit; - } - - if( ftruncate( m_fd, uiSize) == -1) - { - rc = MapErrnoToFlaimErr( errno, FERR_TRUNCATING_FILE); - goto Exit; - } - -Exit: - - return( rc); -} -#endif - -/**************************************************************************** -Desc: Write to a file -****************************************************************************/ -#if defined( FLM_UNIX) -RCODE F_FileHdlImp::Write( - FLMUINT uiWriteOffset, - FLMUINT uiBytesToWrite, - const void * pvBuffer, - FLMUINT * puiBytesWrittenRV) -{ - RCODE rc = FERR_OK; - FLMINT iBytesWritten = 0; - - flmAssert( m_bFileOpened); - - if( m_bDoDirectIO) - { - rc = DirectWrite( uiWriteOffset, uiBytesToWrite, pvBuffer, - uiBytesToWrite, NULL, puiBytesWrittenRV, FALSE, TRUE); - - goto Exit; - } - - if( RC_BAD( rc = GET_FS_ERROR())) - { - goto Exit; - } - - if( uiWriteOffset == F_IO_CURRENT_POS) - { - uiWriteOffset = m_uiCurrentPos; - } - - if( (iBytesWritten = pwrite(m_fd, pvBuffer, uiBytesToWrite, - uiWriteOffset)) == -1) - { - rc = MapErrnoToFlaimErr( errno, FERR_WRITING_FILE); - goto Exit; - } - - if( puiBytesWrittenRV) - { - *puiBytesWrittenRV = (FLMUINT)iBytesWritten; - } - - m_uiCurrentPos = uiWriteOffset + (FLMUINT)iBytesWritten; - - if( (FLMUINT)iBytesWritten < uiBytesToWrite) - { - rc = RC_SET( FERR_IO_DISK_FULL); - goto Exit; - } - -Exit: - - return( rc); -} -#endif - -/**************************************************************************** -Desc: Allocate an aligned buffer. -****************************************************************************/ -#if defined( FLM_UNIX) -RCODE F_FileHdlImp::AllocAlignBuffer( void) -{ -#if !defined( FLM_LINUX) && !defined( FLM_SOLARIS) - return( RC_SET( FERR_NOT_IMPLEMENTED)); -#else - RCODE rc = FERR_OK; - - if( m_pucAlignedBuff) - { - goto Exit; - } - - // Allocate at least 64K - this will handle most read and write - // operations and will also be a multiple of the sector size most of - // the time. The calculation below rounds it up to the next sector - // boundary if it is not already on one. - - m_uiAlignedBuffSize = RoundUpToSectorMultiple( 64 * 1024); - - if( (m_pucAlignedBuff = (FLMBYTE *)memalign( - sysconf(_SC_PAGESIZE), m_uiAlignedBuffSize)) == NULL) - { - m_uiAlignedBuffSize = 0; - rc = MapErrnoToFlaimErr( errno, FERR_MEM); - goto Exit; - } - -Exit: - - return( rc); -#endif -} -#endif - -/**************************************************************************** -Desc: -Note: This routine assumes that the size of pvBuffer is a multiple of - sector size and can be used to write out full sectors. Even if - uiBytesToWrite does not account for full sectors, data from the - buffer will still be written out - a partial sector on disk will - not be preserved. -****************************************************************************/ -#if defined( FLM_UNIX) -RCODE F_FileHdlImp::DirectWrite( - FLMUINT uiWriteOffset, - FLMUINT uiBytesToWrite, - const void * pvBuffer, - FLMUINT, - F_IOBuffer * pBufferObj, - FLMUINT * puiBytesWrittenRV, - FLMBOOL bBuffHasFullSectors, - FLMBOOL bZeroFill) -{ - RCODE rc = FERR_OK; - FLMUINT uiBytesRead; - FLMUINT uiMaxBytesToWrite; - FLMUINT uiBytesBeingOutput; - FLMBYTE * pucWriteBuffer; - FLMBYTE * pucSrcBuffer; - FLMBOOL bDidAsync = FALSE; - FLMUINT uiLastWriteOffset; - FLMUINT uiLastWriteSize; - - flmAssert( m_bFileOpened); - -#ifdef FLM_DEBUG - if( pBufferObj != NULL) - { - flmAssert( m_bCanDoAsync); - } -#endif - - if( puiBytesWrittenRV) - { - *puiBytesWrittenRV = 0; - } - - if( RC_BAD( rc = GET_FS_ERROR())) - { - goto Exit; - } - - if( uiWriteOffset == F_IO_CURRENT_POS) - { - uiWriteOffset = m_uiCurrentPos; - } - - // This loop is for direct IO - must make sure we use - // aligned buffers. - - pucSrcBuffer = (FLMBYTE *)pvBuffer; - for (;;) - { - // See if we are using an aligned buffer. If not, allocate - // one (if not already allocated), and use it. - - if( (uiWriteOffset & m_uiNotOnSectorBoundMask) || - (((FLMUINT)pucSrcBuffer) & m_uiNotOnSectorBoundMask) || - ((uiBytesToWrite & m_uiNotOnSectorBoundMask) && !bBuffHasFullSectors)) - { - // Cannot be using a temporary write buffer if we are doing - // asynchronous writes! - - flmAssert( !pBufferObj || !m_bCanDoAsync); - - if( !m_pucAlignedBuff) - { - if( RC_BAD( rc = AllocAlignBuffer())) - { - goto Exit; - } - } - pucWriteBuffer = m_pucAlignedBuff; - - // Must write enough bytes to cover all of the sectors that - // contain the data we are trying to write out. The value of - // (uiWriteOffset & m_uiNotOnSectorBoundMask) will give us the - // number of additional bytes that are in the sector prior to - // the read offset. We then round to the next sector to get the - // total number of bytes we are going to write. - - uiMaxBytesToWrite = RoundUpToSectorMultiple( uiBytesToWrite + - (uiWriteOffset & m_uiNotOnSectorBoundMask)); - - // Can't write more than the aligned buffer will hold. - - if( uiMaxBytesToWrite > m_uiAlignedBuffSize) - { - uiMaxBytesToWrite = m_uiAlignedBuffSize; - uiBytesBeingOutput = uiMaxBytesToWrite - - (uiWriteOffset & m_uiNotOnSectorBoundMask); - } - else - { - uiBytesBeingOutput = uiBytesToWrite; - } - - // If the write offset is not on a sector boundary, or if - // we are writing a partial sector, we must read the - // sector into the buffer. - - if( (uiWriteOffset & m_uiNotOnSectorBoundMask) || - (uiBytesBeingOutput < m_uiBytesPerSector && !bBuffHasFullSectors)) - { - // Read the first sector that is to be written out. - // Read one sector's worth of data - so that we will - // preserve what is already in the sector before - // writing it back out again. - - if( RC_BAD( rc = Read( GetSectorStartOffset( uiWriteOffset), - m_uiBytesPerSector, pucWriteBuffer, &uiBytesRead))) - { - if( rc != FERR_IO_END_OF_FILE) - { - goto Exit; - } - - rc = FERR_OK; - f_memset( &pucWriteBuffer[ uiBytesRead], 0, - m_uiBytesPerSector - uiBytesRead); - } - } - - // Finally, copy the data from the source buffer into the - // write buffer. - - f_memcpy( &pucWriteBuffer[ uiWriteOffset & m_uiNotOnSectorBoundMask], - pucSrcBuffer, uiBytesBeingOutput); - } - else - { - uiMaxBytesToWrite = RoundUpToSectorMultiple( uiBytesToWrite); - uiBytesBeingOutput = uiBytesToWrite; - pucWriteBuffer = pucSrcBuffer; - - if( bZeroFill && uiMaxBytesToWrite > uiBytesToWrite) - { - f_memset( &pucWriteBuffer[ uiBytesToWrite], 0, - uiMaxBytesToWrite - uiBytesToWrite); - } - } - - // Position the file to the nearest sector below the write offset. - - uiLastWriteOffset = GetSectorStartOffset( uiWriteOffset); - uiLastWriteSize = uiMaxBytesToWrite; - - if( !m_bCanDoAsync || !pBufferObj) - { - FLMINT iBytesWritten; - - if( (iBytesWritten = pwrite( m_fd, - pucWriteBuffer, uiMaxBytesToWrite, uiLastWriteOffset)) == -1) - { - rc = MapErrnoToFlaimErr( errno, FERR_WRITING_FILE); - goto Exit; - } - - if( (FLMUINT)iBytesWritten < uiMaxBytesToWrite) - { - rc = RC_SET( FERR_IO_DISK_FULL); - goto Exit; - } - } - else - { - struct aiocb * pAio = pBufferObj->getAIOStruct(); - - f_memset( pAio, 0, sizeof( struct aiocb)); - pAio->aio_lio_opcode = LIO_WRITE; - pAio->aio_sigevent.sigev_notify = SIGEV_NONE; - pAio->aio_fildes = m_fd; - pAio->aio_offset = uiLastWriteOffset; - pAio->aio_nbytes = uiMaxBytesToWrite; - pAio->aio_buf = pucWriteBuffer; - - if( aio_write( pAio) == -1) - { - rc = MapErrnoToFlaimErr( errno, FERR_WRITING_FILE); - goto Exit; - } - - pBufferObj->makePending(); - bDidAsync = TRUE; - } - - uiBytesToWrite -= uiBytesBeingOutput; - if( puiBytesWrittenRV) - { - (*puiBytesWrittenRV) += uiBytesBeingOutput; - } - - m_uiCurrentPos = uiWriteOffset + uiBytesBeingOutput; - - if( !uiBytesToWrite) - { - break; - } - - flmAssert( !pBufferObj); - - pucSrcBuffer += uiBytesBeingOutput; - uiWriteOffset += uiBytesBeingOutput; - } - -Exit: - - if( !bDidAsync && pBufferObj) - { - pBufferObj->notifyComplete( rc); - } - - return( rc); -} -#endif - -/**************************************************************************** -Desc: Returns flag indicating whether or not we can do async writes. -****************************************************************************/ -#if defined( FLM_UNIX) -FLMBOOL F_FileHdlImp::CanDoAsync( void) -{ - return( m_bCanDoAsync); -} -#endif - -/**************************************************************************** -Desc: Attempts to lock byte 0 of the file. This method is used to - lock byte 0 of the .lck file to ensure that only one process - has access to a database. -****************************************************************************/ -#if defined( FLM_UNIX) -RCODE F_FileHdlImp::Lock( void) -{ - RCODE rc = FERR_OK; - struct flock LockStruct; - - // Lock first byte in file - - f_memset( &LockStruct, 0, sizeof( LockStruct)); - LockStruct.l_type = F_WRLCK; - LockStruct.l_whence = SEEK_SET; - LockStruct.l_start = 0; - LockStruct.l_len = 1; - - if( fcntl( m_fd, F_SETLK, &LockStruct) == -1) - { - rc = RC_SET( FERR_IO_FILE_LOCK_ERR); - goto Exit; - } - -Exit: - - return( rc); -} -#endif - -/**************************************************************************** -Desc: Attempts to unlock byte 0 of the file. -****************************************************************************/ -#if defined( FLM_UNIX) -RCODE F_FileHdlImp::Unlock( void) -{ - struct flock LockStruct; - RCODE rc = FERR_OK; - - // Lock first byte in file - - f_memset( &LockStruct, 0, sizeof( LockStruct)); - LockStruct.l_type = F_UNLCK; - LockStruct.l_whence = SEEK_SET; - LockStruct.l_start = 0; - LockStruct.l_len = 1; - - if( fcntl( m_fd, F_SETLK, &LockStruct) == -1) - { - rc = RC_SET( FERR_IO_FILE_UNLOCK_ERR); - goto Exit; - } - -Exit: - - return( rc); -} -#endif - -/*************************************************************************** -Desc: Determines the kernel version of a linux system -***************************************************************************/ -#if defined( FLM_LINUX) -void flmGetLinuxKernelVersion( - FLMUINT * puiMajor, - FLMUINT * puiMinor, - FLMUINT * puiRevision) -{ - int fd = INVALID_HANDLE_VALUE; - int iBytesRead; - char szBuffer [80]; - char * pszVer; - FLMUINT uiMajorVer = 0; - FLMUINT uiMinorVer = 0; - FLMUINT uiRevision = 0; - - if( (fd = open( "/proc/version", O_RDONLY, 0600)) == INVALID_HANDLE_VALUE) - { - goto Exit; - } - - if( (iBytesRead = read( fd, szBuffer, sizeof( szBuffer))) == -1) - { - goto Exit; - } - if( (pszVer = f_strstr( szBuffer, "version ")) == NULL) - { - goto Exit; - } - pszVer += 8; - - while( *pszVer >= '0' && *pszVer <= '9') - { - uiMajorVer *= 10; - uiMajorVer += (FLMUINT)(*pszVer - '0'); - pszVer++; - } - - if( *pszVer == '.') - { - pszVer++; - while (*pszVer >= '0' && *pszVer <= '9') - { - uiMinorVer *= 10; - uiMinorVer += (FLMUINT)(*pszVer - '0'); - pszVer++; - } - } - - if( *pszVer == '.') - { - pszVer++; - while (*pszVer >= '0' && *pszVer <= '9') - { - uiRevision *= 10; - uiRevision += (FLMUINT)(*pszVer - '0'); - pszVer++; - } - } - -Exit: - - if( fd != INVALID_HANDLE_VALUE) - { - close( fd); - } - - if( puiMajor) - { - *puiMajor = uiMajorVer; - } - - if( puiMinor) - { - *puiMinor = uiMinorVer; - } - - if( puiRevision) - { - *puiRevision = uiRevision; - } -} -#endif - -/*************************************************************************** -Desc: Determines if the linux system we are running on is 2.4 or greater. -***************************************************************************/ -#if defined( FLM_LINUX) -FLMUINT flmGetLinuxMaxFileSize( - FLMUINT uiSizeofFLMUINT) -{ - FLMUINT uiMaxFileSize = MAX_FILE_SIZE_VER40; - - // Determine if we are on 32 or 64 bit platform. If on 64 bit, we can - // support the larger file size. Otherwise, we have to open up the - // /proc/version file and see if we are linux version 2.4 or greater. - - // NOTE: The only reason we are passing uiSizeofFLMUINT in as a parameter is - // to spoof the compiler so it won't give us a warning. If we did - // if (sizeof( FLMUINT) > 4) the compiler would give us a warning that the - // condition is either always TRUE or FALSE (depending on whether we are - // on a 32 bit or 64 bit platform. - - if( uiSizeofFLMUINT > 4) - { - uiMaxFileSize = F_MAXIMUM_FILE_SIZE; - goto Exit; - } - - flmAssert( gv_FlmSysData.uiLinuxMajorVer); - - // Is version 2.4 or greater? - - if( gv_FlmSysData.uiLinuxMajorVer > 2 || - (gv_FlmSysData.uiLinuxMajorVer == 2 && - gv_FlmSysData.uiLinuxMinorVer >= 4)) - { - uiMaxFileSize = F_MAXIMUM_FILE_SIZE; - } - -Exit: - - return( uiMaxFileSize); -} -#endif - -/**************************************************************************** -Desc: This routine gets the block size for the file system a file belongs to. -****************************************************************************/ -#if defined( FLM_UNIX) -FLMUINT flmGetFSBlockSize( - const char * pszFileName) -{ -#define DEFAULT_FS_BSIZE 1024 - FLMUINT uiFSBlkSize = DEFAULT_FS_BSIZE; - char szTmpBuf[ F_PATH_MAX_SIZE]; - char * pszTmp; - const char * pszDir; - - f_strcpy( szTmpBuf, pszFileName); - pszTmp = szTmpBuf + f_strlen( szTmpBuf) - 1; - - while( pszTmp != &szTmpBuf[ 0] && *pszTmp != '/') - { - pszTmp--; - } - - if( *pszTmp == '/') - { - if( pszTmp == &szTmpBuf[ 0]) - { - pszTmp++; - } - - *pszTmp = 0; - pszDir = szTmpBuf; - } - else - { - pszDir = "."; - } - -#if defined( FLM_SOLARIS) - - struct statvfs statfsbuf; - - if( statvfs( pszDir, &statfsbuf) == 0) - { - uiFSBlkSize = (FLMUINT)statfsbuf.f_bsize; - } - -#elif defined( FLM_LINUX) - - struct statfs statfsbuf; - - if( statfs( pszDir, &statfsbuf) == 0) - { - uiFSBlkSize = (FLMUINT)statfsbuf.f_bsize; - } - -#endif - - return( uiFSBlkSize); -} -#endif - -/**************************************************************************** -Desc: -****************************************************************************/ -#if defined( FLM_SOLARIS) && defined( FLM_SPARC) && !defined( FLM_GNUC) -static void sparc_asm_code( void) -{ - asm( ".align 8"); - asm( ".global sparc_atomic_add_32"); - asm( ".type sparc_atomic_add_32, #function"); - asm( "sparc_atomic_add_32:"); - asm( " membar #LoadLoad | #LoadStore | #StoreStore | #StoreLoad"); - asm( " ld [%o0], %l0"); - asm( " add %l0, %o1, %l2"); - asm( " cas [%o0], %l0, %l2"); - asm( " cmp %l0, %l2"); - asm( " bne sparc_atomic_add_32"); - asm( " nop"); - asm( " add %l2, %o1, %o0"); - asm( " membar #LoadLoad | #LoadStore | #StoreStore | #StoreLoad"); - asm( "retl"); - asm( "nop"); - - asm( ".align 8"); - asm( ".global sparc_atomic_xchg_32"); - asm( ".type sparc_atomic_xchg_32, #function"); - asm( "sparc_atomic_xchg_32:"); - asm( " membar #LoadLoad | #LoadStore | #StoreStore | #StoreLoad"); - asm( " ld [%o0], %l0"); - asm( " mov %o1, %l1"); - asm( " cas [%o0], %l0, %l1"); - asm( " cmp %l0, %l1"); - asm( " bne sparc_atomic_xchg_32"); - asm( " nop"); - asm( " mov %l0, %o0"); - asm( " membar #LoadLoad | #LoadStore | #StoreStore | #StoreLoad"); - asm( "retl"); - asm( "nop"); -} -#endif - -#endif // FLM_UNIX - -/**************************************************************************** -Desc: -****************************************************************************/ -#if defined( FLM_WATCOM_NLM) -int fposixDummy(void) -{ - return( 0); -} -#endif diff --git a/flaim/src/fposix.h b/flaim/src/fposix.h deleted file mode 100644 index df8f59e..0000000 --- a/flaim/src/fposix.h +++ /dev/null @@ -1,225 +0,0 @@ -//------------------------------------------------------------------------- -// Desc: Posix File I/O - definitions -// Tabs: 3 -// -// Copyright (c) 1997-2006 Novell, Inc. All Rights Reserved. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of version 2 of the GNU General Public -// License as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, contact Novell, Inc. -// -// To contact Novell about this file by physical or electronic mail, -// you may find current contact information at www.novell.com -// -// $Id: fposix.h 12330 2006-01-23 10:07:04 -0700 (Mon, 23 Jan 2006) ahodgkinson $ -//------------------------------------------------------------------------- - -#ifndef FPOSIX_H -#define FPOSIX_H - -#include "fpackon.h" - -// IMPORTANT NOTE: No other include files should follow this one except -// for fpackoff.h - - -#define INVALID_HANDLE_VALUE (-1) - -/**************************************************************************** -Desc: -****************************************************************************/ -class F_FileHdlImp : public F_FileHdlImpBase -{ -public: - - F_FileHdlImp(); - - virtual ~F_FileHdlImp(); - - RCODE Setup( - FLMUINT uiFileId); - - RCODE Close( void); - - RCODE Create( - const char * pIoPath, - FLMUINT uiIoFlags); - - RCODE CreateUnique( - char * pIoPath, - const char * pszFileExtension, - FLMUINT uiIoFlags); - - RCODE Open( - const char * pIoPath, - FLMUINT uiIoFlags); - - RCODE Flush( void); - - RCODE Read( - FLMUINT uiOffset, - FLMUINT uiLength, - void * pvBuffer, - FLMUINT * puiBytesRead); - - RCODE Seek( - FLMUINT uiOffset, - FLMINT iWhence, - FLMUINT * puiNewOffset); - - RCODE Size( - FLMUINT * puiSize); - - RCODE Tell( - FLMUINT * puiOffset); - - RCODE Truncate( - FLMUINT uiSize); - - RCODE Write( - FLMUINT uiOffset, - FLMUINT uiLength, - const void * pvBuffer, - FLMUINT * puiBytesWritten); - - RCODE SectorRead( - FLMUINT uiReadOffset, - FLMUINT uiBytesToRead, - void * pvBuffer, - FLMUINT * puiBytesReadRV); - - RCODE SectorWrite( - FLMUINT uiWriteOffset, - FLMUINT uiBytesToWrite, - const void * pvBuffer, - FLMUINT uiBufferSize, - F_IOBuffer * pBufferObj, - FLMUINT * puiBytesWrittenRV, - FLMBOOL bZeroFill = TRUE) - { - if( m_bDoDirectIO) - { - return( DirectWrite( uiWriteOffset, uiBytesToWrite, - pvBuffer, uiBufferSize, pBufferObj, puiBytesWrittenRV, TRUE, - bZeroFill)); - } - else - { - return( Write( uiWriteOffset, uiBytesToWrite, - pvBuffer, puiBytesWrittenRV)); - } - } - - FLMBOOL CanDoAsync( void); - - FINLINE FLMBOOL UsingDirectIo( void) - { - return( m_bDoDirectIO); - } - - FINLINE void setExtendSize( - FLMUINT uiExtendSize) - { - m_uiExtendSize = uiExtendSize; - } - - FINLINE void setMaxAutoExtendSize( - FLMUINT uiMaxAutoExtendSize) - { - m_uiMaxAutoExtendSize = uiMaxAutoExtendSize; - } - - RCODE Lock( void); - - RCODE Unlock( void); - - FINLINE void SetBlockSize( - FLMUINT uiBlockSize) - { - m_uiBlockSize = uiBlockSize; - } - - FINLINE FLMUINT GetSectorSize( void) - { - return( m_uiBytesPerSector); - } - -private: - - RCODE OpenOrCreate( - const char * pFileName, - FLMUINT uiAccess, - FLMBOOL bCreateFlag); - - FINLINE FLMUINT RoundUpToSectorMultiple( - FLMUINT uiBytes) - { - return( (uiBytes + m_uiNotOnSectorBoundMask) & - m_uiGetSectorBoundMask); - } - - FINLINE FLMUINT GetSectorStartOffset( - FLMUINT uiOffset) - { - return( uiOffset & m_uiGetSectorBoundMask); - } - - RCODE DirectRead( - FLMUINT uiReadOffset, - FLMUINT uiBytesToRead, - void * pvBuffer, - FLMBOOL bBuffHasFullSectors, - FLMUINT * puiBytesRead); - - RCODE DirectWrite( - FLMUINT uiWriteOffset, - FLMUINT uiBytesToWrite, - const void * pvBuffer, - FLMUINT uiBufferSize, - F_IOBuffer * pBufferObj, - FLMUINT * puiBytesWrittenRV, - FLMBOOL bBuffHasFullSectors, - FLMBOOL bZeroFill); - - RCODE AllocAlignBuffer( void); - - int m_fd; - FLMUINT m_uiBlockSize; - FLMUINT m_uiBytesPerSector; - FLMUINT m_uiNotOnSectorBoundMask; - FLMUINT m_uiGetSectorBoundMask; - FLMUINT m_uiCurrentPos; - FLMUINT m_uiExtendSize; - FLMUINT m_uiMaxAutoExtendSize; - FLMBOOL m_bCanDoAsync; - FLMBOOL m_bDoDirectIO; - FLMBYTE * m_pucAlignedBuff; - FLMUINT m_uiAlignedBuffSize; - - friend class F_FileHdlPage; -}; - -FLMUINT flmGetFSBlockSize( - const char * pszFileName); - -#ifdef FLM_LINUX - void flmGetLinuxKernelVersion( - FLMUINT * puiMajor, - FLMUINT * puiMinor, - FLMUINT * puiRevision); - - FLMUINT flmGetLinuxMaxFileSize( - FLMUINT uiSizeofFLMUINT); -#endif - -#include "fpackoff.h" - -#endif diff --git a/flaim/src/fqcur.cpp b/flaim/src/fqcur.cpp index a30f95c..cae2d29 100644 --- a/flaim/src/fqcur.cpp +++ b/flaim/src/fqcur.cpp @@ -36,7 +36,7 @@ POOL_STATS g_QueryPoolStats = {0,0}; FSTATIC RCODE flmCurCopyQTInfo( QTINFO * pSrc, QTINFO * pDest, - POOL * pPool); + F_Pool * pPool); FSTATIC void flmCurClearSelect( CURSOR * pCursor); @@ -164,8 +164,8 @@ FLMEXP RCODE FLMAPI FlmCursorInit( // Initialize cursor members - GedSmartPoolInit( &pCursor->QueryPool, &g_QueryPoolStats); - GedSmartPoolInit( &pCursor->SQPool, &g_SQPoolStats); + pCursor->QueryPool.smartPoolInit( &g_QueryPoolStats); + pCursor->SQPool.smartPoolInit( &g_SQPoolStats); pCursor->pDb = pDb; pCursor->uiContainer = uiContainer; @@ -177,16 +177,15 @@ FLMEXP RCODE FLMAPI FlmCursorInit( pCursor->uiCursorId = FCS_INVALID_ID; pCursor->QTInfo.uiExpecting = FLM_Q_OPERAND; - pCursor->QTInfo.uiFlags = FLM_NOCASE | FLM_WILD; + pCursor->QTInfo.uiFlags = FLM_COMP_CASE_INSENSITIVE | FLM_COMP_WILD; Exit: if (RC_BAD( rc)) { if (pCursor) { - GedPoolFree( &pCursor->QueryPool); - - GedPoolFree( &pCursor->SQPool); + pCursor->QueryPool.poolFree(); + pCursor->SQPool.poolFree(); f_free( &pCursor); } } @@ -201,7 +200,7 @@ Desc: Copies a passed-in query tree into a new tree, using the passed-in FSTATIC RCODE flmCurCopyQTInfo( QTINFO * pSrc, QTINFO * pDest, - POOL * pPool) + F_Pool * pPool) { RCODE rc = FERR_OK; FQNODE * pDestParentNode; @@ -397,8 +396,8 @@ FLMEXP RCODE FLMAPI FlmCursorClone( // Initialize cursor members - GedSmartPoolInit( &pDestCursor->QueryPool, &g_QueryPoolStats); - GedSmartPoolInit( &pDestCursor->SQPool, &g_SQPoolStats); + pDestCursor->QueryPool.smartPoolInit( &g_QueryPoolStats); + pDestCursor->SQPool.smartPoolInit( &g_SQPoolStats); // Set up a tree info structure for query declaration. @@ -500,7 +499,7 @@ void flmSQFree( } } - GedPoolFree( &pSubQuery->OptPool); + pSubQuery->OptPool.poolFree(); // Free up the file system cursors, if any. @@ -544,11 +543,11 @@ void flmCurFree( // Free the memory associated with any subqueries. flmCurFreeSQList( pCursor, TRUE); - GedPoolFree( &pCursor->SQPool); + pCursor->SQPool.poolFree(); // Free the memory associated with the pool structures - GedPoolFree( &pCursor->QueryPool); + pCursor->QueryPool.poolFree(); if (pCursor->pDRNSet) { pCursor->pDRNSet->Release(); @@ -711,9 +710,9 @@ FSTATIC void flmCurClearSelect( pCursor->QTInfo.pCurAtomNode = NULL; pCursor->QTInfo.uiNestLvl = 0; pCursor->QTInfo.uiExpecting = FLM_Q_OPERAND; - pCursor->QTInfo.uiFlags = FLM_NOCASE | FLM_WILD; + pCursor->QTInfo.uiFlags = FLM_COMP_CASE_INSENSITIVE | FLM_COMP_WILD; - GedPoolReset( &pCursor->QueryPool, NULL); + pCursor->QueryPool.poolReset(); pCursor->uiLastRecID = 0; pCursor->ReadRc = FERR_OK; @@ -881,7 +880,8 @@ FSTATIC RCODE flmCurSetPos( // Initialize an FDB structure for various and sundry operations. pDb = pDestCursor->pDb; - pvMark = GedPoolMark( &pDb->TempPool); + pvMark = pDb->TempPool.poolMark(); + if( RC_BAD( rc = flmCurDbInit( pDestCursor))) { goto Exit; @@ -1091,15 +1091,18 @@ FSTATIC RCODE flmCurSetPos( pDestCursor->pCurrSubQuery = pDestSubQuery; Exit: + if (pRecord) { pRecord->Release(); } + if (pDb) { - GedPoolReset( &pDb->TempPool, pvMark); - (void)fdbExit( pDb); + pDb->TempPool.poolReset( pvMark); + fdbExit( pDb); } + return( rc); } @@ -1382,7 +1385,7 @@ FSTATIC RCODE flmCurSetAbsolutePos( if (pCursor->uiTimeLimit) { - FLM_TIMER_UNITS_TO_SECS( pCursor->uiTimeLimit, uiSeconds); + uiSeconds = FLM_TIMER_UNITS_TO_SECS( pCursor->uiTimeLimit); if (!uiSeconds) { uiSeconds = 1; @@ -1665,8 +1668,7 @@ FLMEXP RCODE FLMAPI FlmCursorConfig( uiTimeLimit = pCursor->uiTimeLimit = (FLMUINT)Value1; if (uiTimeLimit) { - FLM_SECS_TO_TIMER_UNITS( uiTimeLimit, - pCursor->uiTimeLimit); + pCursor->uiTimeLimit = FLM_SECS_TO_TIMER_UNITS( uiTimeLimit); } break; } @@ -2630,7 +2632,7 @@ void flmCurFreeSQList( if (bFreeEverything) { - GedPoolReset( &pCursor->SQPool, NULL); + pCursor->SQPool.poolReset(); pCursor->pSubQueryList = NULL; } } diff --git a/flaim/src/fqdecl.cpp b/flaim/src/fqdecl.cpp index 20c5a53..6480b9a 100644 --- a/flaim/src/fqdecl.cpp +++ b/flaim/src/fqdecl.cpp @@ -43,8 +43,8 @@ FSTATIC RCODE flmSendCursorFrom( NODE * pRootNode; NODE * pChildNode = NULL; NODE * pTmp; - POOL * pPool = pWire->getPool(); - void * pvMark = GedPoolMark( pPool); + F_Pool * pPool = pWire->getPool(); + void * pvMark = pPool->poolMark(); FLMUINT uiTmp; CS_CONTEXT * pCSContext = pWire->getContext(); @@ -143,7 +143,7 @@ FSTATIC RCODE flmSendCursorFrom( Exit: - GedPoolReset( pPool, pvMark); + pPool->poolReset( pvMark); return( rc); } @@ -162,8 +162,8 @@ FSTATIC RCODE flmSendCursorWhere( FLMUINT uiOperator; FLMUINT uiLastFlags = 0; QTYPES eOp; - POOL * pPool = pWire->getPool(); - void * pvMark = GedPoolMark( pPool); + F_Pool * pPool = pWire->getPool(); + void * pvMark = pPool->poolMark(); CS_CONTEXT * pCSContext = pWire->getContext(); if ((pRootNode = GedNodeMake( pPool, FCS_ITERATOR_WHERE, &rc)) == NULL) @@ -491,7 +491,7 @@ Test_Sib: Exit: - GedPoolReset( pPool, pvMark); + pPool->poolReset( pvMark); return( rc); } diff --git a/flaim/src/fqeval.cpp b/flaim/src/fqeval.cpp index 60633a6..04f2fd3 100644 --- a/flaim/src/fqeval.cpp +++ b/flaim/src/fqeval.cpp @@ -29,7 +29,7 @@ FSTATIC FLMUINT flmCurEvalTrueFalse( FSTATIC RCODE flmCurGetAtomFromRec( FDB * pDb, - POOL * pPool, + F_Pool * pPool, FQATOM * pTreeAtom, FlmRecord * pRecord, QTYPES eFldType, @@ -39,7 +39,7 @@ FSTATIC RCODE flmCurGetAtomFromRec( FSTATIC RCODE flmFieldIterate( FDB * pDb, - POOL * pPool, + F_Pool * pPool, QTYPES eFldType, FQNODE * pOpCB, FlmRecord * pRecord, @@ -473,7 +473,7 @@ Desc: Gets a value from the passed-in record field and stuffs it into the RCODE flmCurGetAtomVal( FlmRecord * pRecord, void * pField, - POOL * pPool, + F_Pool * pPool, QTYPES eFldType, FQATOM * pResult) { @@ -511,8 +511,8 @@ RCODE flmCurGetAtomVal( } else { - if ((pResult->val.pucBuf = (FLMBYTE *) GedPoolAlloc( - pPool, 1)) == NULL) + if( RC_BAD( rc = pPool->poolAlloc( 1, + (void **)&pResult->val.pucBuf))) { rc = RC_SET( FERR_MEM); break; @@ -662,10 +662,9 @@ RCODE flmCurGetAtomVal( } else { - if ((pResult->val.pucBuf = (FLMBYTE *) GedPoolAlloc( - pPool, 1)) == NULL) + if( RC_BAD( rc = pPool->poolAlloc( 1, + (void **)&pResult->val.pucBuf))) { - rc = RC_SET( FERR_MEM); break; } @@ -766,7 +765,7 @@ Desc: Given a list of FQATOMs containing alternate field paths, finds ****************************************************************************/ FSTATIC RCODE flmCurGetAtomFromRec( FDB * pDb, - POOL * pPool, + F_Pool * pPool, FQATOM * pTreeAtom, FlmRecord * pRecord, QTYPES eFldType, @@ -986,12 +985,12 @@ FSTATIC RCODE flmCurGetAtomFromRec( } else if (pTmpResult->eType) { - if ((pTmpResult->pNext = - (FQATOM *)GedPoolCalloc( pPool, sizeof( FQATOM))) == NULL) + if( RC_BAD( rc = pPool->poolCalloc( sizeof( FQATOM), + (void **)&pTmpResult->pNext))) { - rc = RC_SET( FERR_MEM); goto Exit; } + pTmpResult = pTmpResult->pNext; } @@ -1096,7 +1095,7 @@ Desc: Iterate to the next occurrance of a field. ****************************************************************************/ FSTATIC RCODE flmFieldIterate( FDB * pDb, - POOL * pPool, + F_Pool * pPool, QTYPES eFldType, FQNODE * pOpCB, FlmRecord * pRecord, @@ -1208,7 +1207,7 @@ FSTATIC RCODE flmCurEvalArithOp( FQNODE * pRightOpCB = NULL; FQNODE * pLeftOpCB = NULL; FQNODE * pOpCB = NULL; - POOL * pTmpPool = &pDb->TempPool; + F_Pool * pTmpPool = &pDb->TempPool; FLMBOOL bSavedInvisTrans; RCODE TempRc; @@ -1442,8 +1441,7 @@ Get_Operand: if (pRightOpCB) { if (RC_BAD( rc = flmFieldIterate( pDb, pTmpPool, eFldType, - pRightOpCB, pRecord, bHaveKey, TRUE, FLM_FLD_FIRST, pRhs - ))) + pRightOpCB, pRecord, bHaveKey, TRUE, FLM_FLD_FIRST, pRhs))) { goto Exit; } @@ -1456,10 +1454,9 @@ Get_Operand: // Set up for next result - if ((pTmpQAtom->pNext = (FQATOM *) GedPoolCalloc( - pTmpPool, sizeof( FQATOM))) == NULL) + if( RC_BAD( rc = pTmpPool->poolCalloc( sizeof( FQATOM), + (void **)&pTmpQAtom->pNext))) { - rc = RC_SET( FERR_MEM); goto Exit; } @@ -1581,7 +1578,8 @@ void flmCompareOperands( case FLM_MATCH_OP: { - if ((pLhs->uiFlags & FLM_WILD) || (pRhs->uiFlags & FLM_WILD)) + if ((pLhs->uiFlags & FLM_COMP_WILD) || + (pRhs->uiFlags & FLM_COMP_WILD)) { *puiTrueFalse = flmCurDoMatchOp( pLhs, pRhs, uiLang, FALSE, FALSE); } @@ -1701,8 +1699,8 @@ RCODE flmCurEvalCompareOp( FQNODE * pOpCB = NULL; RCODE TempRc; FLMBOOL bSavedInvisTrans; - POOL * pTmpPool = &pDb->TempPool; - void * pvMark = GedPoolMark( pTmpPool); + F_Pool * pTmpPool = &pDb->TempPool; + void * pvMark = pTmpPool->poolMark(); pResult->eType = FLM_BOOL_VAL; pResult->pNext = NULL; @@ -2158,7 +2156,7 @@ Exit: } } - GedPoolReset( pTmpPool, pvMark); + pTmpPool->poolReset( pvMark); return (rc); } @@ -2254,8 +2252,7 @@ Get_Operand: else if (eType == FLM_FLD_PATH) { if (RC_BAD( rc = flmCurGetAtomFromRec( pDb, &pDb->TempPool, - pTmpQNode->pQAtom, pRecord, NO_TYPE, FALSE, pTmpQAtom, bHaveKey - ))) + pTmpQNode->pQAtom, pRecord, NO_TYPE, FALSE, pTmpQAtom, bHaveKey))) { goto Exit; } @@ -2503,7 +2500,7 @@ RCODE flmCurEvalCriteria( QTYPES eType; FDB * pDb = pCursor->pDb; FQNODE * pQNode; - void * pTmpMark = GedPoolMark( &pDb->TempPool); + void * pTmpMark = pDb->TempPool.poolMark(); FLMUINT uiResult = 0; FQNODE * pOpCB = NULL; RCODE TempRc; @@ -2684,7 +2681,7 @@ Exit: } } - GedPoolReset( &pDb->TempPool, pTmpMark); + pDb->TempPool.poolReset( pTmpMark); *puiResult = uiResult; return (rc); } diff --git a/flaim/src/fqget.cpp b/flaim/src/fqget.cpp index a343e65..2e14cd6 100644 --- a/flaim/src/fqget.cpp +++ b/flaim/src/fqget.cpp @@ -36,7 +36,7 @@ Desc: Makes a SET_DEL from a record. RCODE flmCurMakeKeyFromRec( FDB * pDb, IXD * pIxd, - POOL * pPool, + F_Pool * pPool, FlmRecord * pRec, FLMBYTE ** ppucKeyBuffer, FLMUINT * puiKeyLen) @@ -78,10 +78,8 @@ RCODE flmCurMakeKeyFromRec( if (!(*ppucKeyBuffer)) { - if ((*ppucKeyBuffer = (FLMBYTE *)GedPoolCalloc( - pPool, MAX_KEY_SIZ)) == NULL) + if( RC_BAD( rc = pPool->poolCalloc( MAX_KEY_SIZ, (void **)ppucKeyBuffer))) { - rc = RC_SET( FERR_MEM); goto Exit; } } @@ -117,7 +115,7 @@ RCODE flmCurSetPosFromDRN( { RCODE rc = FERR_OK; FlmRecord * pRec = NULL; - POOL * pTempPool; + F_Pool * pTempPool; FDB * pDb = NULL; IXD * pIxd; LFILE * pLFile; @@ -318,7 +316,7 @@ FLMEXP RCODE FLMAPI FlmCursorCompareDRNs( RCODE rc = FERR_OK; CURSOR * pCursor = (CURSOR *)hCursor; FDB * pDb = NULL; - POOL * pTempPool; + F_Pool * pTempPool; FLMBYTE * pucKey1; FLMUINT uiKey1Len; FLMBYTE * pucKey2; @@ -638,7 +636,7 @@ FLMEXP RCODE FLMAPI FlmCursorCompareDRNs( } else { - FLM_SECS_TO_TIMER_UNITS( uiTimeLimit, pCursor->uiTimeLimit); + pCursor->uiTimeLimit = FLM_SECS_TO_TIMER_UNITS( uiTimeLimit); } // Perform the count operation. diff --git a/flaim/src/fqkeys.cpp b/flaim/src/fqkeys.cpp index 2e05938..3c44c37 100644 --- a/flaim/src/fqkeys.cpp +++ b/flaim/src/fqkeys.cpp @@ -1645,8 +1645,8 @@ RCODE flmBuildFromAndUntilKeys( uiUntilKeyPos = 0; *pbExclusiveUntilKey = TRUE; - bDBCSLanguage = (uiLanguage >= FIRST_DBCS_LANG) && - (uiLanguage <= LAST_DBCS_LANG) + bDBCSLanguage = (uiLanguage >= FLM_FIRST_DBCS_LANG) && + (uiLanguage <= FLM_LAST_DBCS_LANG) ? TRUE : FALSE; @@ -1782,7 +1782,7 @@ RCODE flmBuildFromAndUntilKeys( FLMBYTE * pValue = (FLMBYTE *) pCurPred->pVal->val.pucBuf; FLMUINT uiValueLen = pCurPred->pVal->uiBufLen; - bCaseInsensitive = (FLMBOOL)((pCurPred->pVal->uiFlags & FLM_NOCASE) + bCaseInsensitive = (FLMBOOL)((pCurPred->pVal->uiFlags & FLM_COMP_CASE_INSENSITIVE) ? TRUE : FALSE); @@ -1809,7 +1809,7 @@ RCODE flmBuildFromAndUntilKeys( bDoKeyMatch = bDoMatchBegin = TRUE; } - if (pCurPred->pVal->uiFlags & FLM_WILD) + if (pCurPred->pVal->uiFlags & FLM_COMP_WILD) { if (!bDoFirstSubstring) { @@ -1893,7 +1893,7 @@ RCODE flmBuildFromAndUntilKeys( // Take the flags from the pVal and NOT from the // predicate. - if (pCurPred->pVal->uiFlags & FLM_WILD) + if (pCurPred->pVal->uiFlags & FLM_COMP_WILD) { // Select the best substring. The case of @@ -2361,13 +2361,13 @@ FSTATIC RCODE flmAddKeyPiece( if (pIfd->uiFlags & IFD_CONTEXT) { pFromKey[uiFromKeyPos] = KY_CONTEXT_PREFIX; - flmUINT16ToBigEndian( (FLMUINT16) pIfd->uiFldNum, &pFromKey[uiFromKeyPos + 1]); + f_UINT16ToBigEndian( (FLMUINT16) pIfd->uiFldNum, &pFromKey[uiFromKeyPos + 1]); uiFromKeyPos += KY_CONTEXT_LEN; if (uiUntilKeyPos + KY_CONTEXT_LEN < uiMaxKeySize) { pUntilKey[uiUntilKeyPos] = KY_CONTEXT_PREFIX; - flmUINT16ToBigEndian( (FLMUINT16) pIfd->uiFldNum, &pUntilKey[uiUntilKeyPos + 1]); + f_UINT16ToBigEndian( (FLMUINT16) pIfd->uiFldNum, &pUntilKey[uiUntilKeyPos + 1]); uiUntilKeyPos += KY_CONTEXT_LEN; } @@ -2539,7 +2539,7 @@ FSTATIC RCODE flmAddTextPiece( FLMUINT uiCaseLen; FLMBOOL bIsDBCS; - bIsDBCS = (uiLanguage >= FIRST_DBCS_LANG && uiLanguage <= LAST_DBCS_LANG) + bIsDBCS = (uiLanguage >= FLM_FIRST_DBCS_LANG && uiLanguage <= FLM_LAST_DBCS_LANG) ? TRUE : FALSE; *pbOriginalCharsLost = FALSE; @@ -2635,7 +2635,7 @@ FSTATIC RCODE flmAddTextPiece( // use it here instead of SC_MIXED. pDestKey[uiDestKeyLen - 1] = - (FLMBYTE) ((uiLanguage != (FLMUINT) GR_LANG) + (FLMBYTE) ((uiLanguage != (FLMUINT) FLM_GR_LANG) ? COLL_MARKER | SC_MIXED : COLL_MARKER | SC_LOWER); diff --git a/flaim/src/fqlog.cpp b/flaim/src/fqlog.cpp index 3e9e003..cf8bc19 100644 --- a/flaim/src/fqlog.cpp +++ b/flaim/src/fqlog.cpp @@ -844,8 +844,7 @@ Desc: This routine logs the query criteria for a cursor. void flmLogQuery( F_LogMessage * pLogMsg, FLMUINT uiIndent, - CURSOR * pCursor - ) + CURSOR * pCursor) { SUBQUERY * pSubQuery; QTYPES eParentOp = (pCursor->pSubQueryList && diff --git a/flaim/src/fqopt.cpp b/flaim/src/fqopt.cpp index 0861e90..6537ab8 100644 --- a/flaim/src/fqopt.cpp +++ b/flaim/src/fqopt.cpp @@ -116,7 +116,7 @@ FINLINE void flmClipSubQuery( } FSTATIC RCODE flmAllocIndexInfo( - POOL * pPool, + F_Pool * pPool, QINDEX ** ppIndex, QINDEX ** ppIndexList, IXD * pIxd); @@ -129,7 +129,7 @@ FSTATIC RCODE flmSQGetDrnRanges( FSTATIC RCODE flmSQGenPredicateList( FDB * pDb, SUBQUERY * pSubQuery, - POOL * pPool, + F_Pool * pPool, QPREDICATE * * ppPredicateList, FLMUINT * puiTotalPredicates, FLMBOOL * pbHaveUserPredicates); @@ -154,7 +154,7 @@ FSTATIC RCODE flmSQGetSuitableIndexes( CURSOR * pCursor, SUBQUERY * pSubQuery, FLMUINT uiContainer, - POOL * pPool, + F_Pool * pPool, QPREDICATE * pPredicateList, FLMUINT uiTotalPredicates, FLMBOOL bHaveUserPredicates, @@ -190,7 +190,7 @@ FSTATIC RCODE flmSQChooseBestIndex( FLMUINT uiForceIndex, FLMUINT bForceFirstToLastKey, SUBQUERY * pSubQuery, - POOL * pTempPool, + F_Pool * pTempPool, QPREDICATE * pPredicateList, FLMUINT uiTotalPredicates, FLMBOOL bHaveUserPredicates); @@ -317,7 +317,7 @@ Desc: Generate the predicate list for a sub-query. FSTATIC RCODE flmSQGenPredicateList( FDB * pDb, SUBQUERY * pSubQuery, - POOL * pPool, + F_Pool * pPool, QPREDICATE * * ppPredicateList, FLMUINT * puiTotalPredicates, FLMBOOL * pbHaveUserPredicates) @@ -358,12 +358,12 @@ FSTATIC RCODE flmSQGenPredicateList( // Better be a parent node that is the operator for // this field. - if ((pPredicate = (QPREDICATE *)GedPoolCalloc( pPool, - sizeof( QPREDICATE))) == NULL) + if( RC_BAD( rc = pPool->poolCalloc( sizeof( QPREDICATE), + (void **)&pPredicate))) { - rc = RC_SET( FERR_MEM); goto Exit; } + (*puiTotalPredicates)++; pPredicate->puiFldPath = pQNode->pQAtom->val.QueryFld.puiFldPath; if (pQNode->pQAtom->uiFlags & FLM_SINGLE_VALUED) @@ -566,7 +566,7 @@ Exit: Desc: Allocate a QINDEX structure for an index. ****************************************************************************/ FSTATIC RCODE flmAllocIndexInfo( - POOL * pPool, + F_Pool * pPool, QINDEX ** ppIndex, QINDEX ** ppIndexList, IXD * pIxd) @@ -574,11 +574,11 @@ FSTATIC RCODE flmAllocIndexInfo( RCODE rc = FERR_OK; QINDEX * pIndex; - if ((pIndex = (QINDEX *)GedPoolCalloc( pPool, sizeof( QINDEX))) == NULL) + if( RC_BAD( rc = pPool->poolCalloc( sizeof( QINDEX), (void **)&pIndex))) { - rc = RC_SET( FERR_MEM); goto Exit; } + *ppIndex = pIndex; // The following items are initialized because of the calloc: @@ -592,13 +592,11 @@ FSTATIC RCODE flmAllocIndexInfo( // Allocate space for a list of predicate pointers // for each IFD. - - if ((pIndex->ppFieldPredicateList = - (QFIELD_PREDICATE **)GedPoolCalloc( pPool, - sizeof( QFIELD_PREDICATE *) * - pIndex->uiNumFields)) == NULL) + + if( RC_BAD( rc = pPool->poolCalloc( + sizeof( QFIELD_PREDICATE *) * pIndex->uiNumFields, + (void **)&pIndex->ppFieldPredicateList))) { - rc = RC_SET( FERR_MEM); goto Exit; } @@ -609,8 +607,11 @@ FSTATIC RCODE flmAllocIndexInfo( { (*ppIndexList)->pPrev = pIndex; } + *ppIndexList = pIndex; + Exit: + return( rc); } @@ -832,7 +833,7 @@ FSTATIC RCODE flmSQGetSuitableIndexes( CURSOR * pCursor, SUBQUERY * pSubQuery, FLMUINT uiContainer, - POOL * pPool, + F_Pool * pPool, QPREDICATE * pPredicateList, FLMUINT uiTotalPredicates, FLMBOOL bHaveUserPredicates, @@ -1030,12 +1031,12 @@ FSTATIC RCODE flmSQGetSuitableIndexes( // Add this predicate to the list of predicates for this IFD. - if ((pFieldPredicate = (QFIELD_PREDICATE *)GedPoolAlloc( pPool, - sizeof( QFIELD_PREDICATE))) == NULL) + if( RC_BAD( rc = pPool->poolAlloc( sizeof( QFIELD_PREDICATE), + (void **)&pFieldPredicate))) { - rc = RC_SET( FERR_MEM); goto Exit; } + pFieldPredicate->pIfd = pIfd; pFieldPredicate->pPredicate = pPredicate; pFieldPredicate->uiRank = flmCurCalcPredicateRank( pPredicate, @@ -1198,11 +1199,10 @@ Process_IFD: } // Add this predicate to the list of predicates for this IFD. - - if ((pFieldPredicate = (QFIELD_PREDICATE *)GedPoolAlloc( - pPool, sizeof( QFIELD_PREDICATE))) == NULL) + + if( RC_BAD( rc = pPool->poolAlloc( sizeof( QFIELD_PREDICATE), + (void **)&pFieldPredicate))) { - rc = RC_SET( FERR_MEM); goto Exit; } @@ -1416,7 +1416,7 @@ FSTATIC RCODE flmSQEvaluateCurrIndexKey( if ((pTmpFSIndexCursor = *ppTmpFSIndexCursor) == NULL) { if ((pTmpFSIndexCursor = *ppTmpFSIndexCursor = - new FSIndexCursor) == NULL) + f_new FSIndexCursor) == NULL) { rc = RC_SET( FERR_MEM); goto Exit; @@ -1592,7 +1592,7 @@ FSTATIC RCODE flmSQChooseBestIndex( FLMUINT uiForceIndex, FLMUINT bForceFirstToLastKey, SUBQUERY * pSubQuery, - POOL * pTempPool, + F_Pool * pTempPool, QPREDICATE * pPredicateList, FLMUINT uiTotalPredicates, FLMBOOL bHaveUserPredicates) @@ -1657,23 +1657,21 @@ FSTATIC RCODE flmSQChooseBestIndex( // Allocate space for a second list of predicate pointers // for each IFD. This one is used to keep track of which // predicate we are on when we are generating keys. - - if ((ppFieldCurrPredicate = - (QFIELD_PREDICATE **)GedPoolCalloc( pTempPool, - sizeof( QFIELD_PREDICATE *) * uiMaxIfds)) == NULL) + + if( RC_BAD( rc = pTempPool->poolCalloc( + sizeof( QFIELD_PREDICATE *) * uiMaxIfds, + (void **)&ppFieldCurrPredicate))) { - rc = RC_SET( FERR_MEM); goto Exit; } // Allocate space for the array that will be passed into the // key generation routine. - - if ((ppPredicateList = - (QPREDICATE **)GedPoolCalloc( pTempPool, - sizeof( QPREDICATE *) * uiMaxIfds)) == NULL) + + if( RC_BAD( rc = pTempPool->poolCalloc( + sizeof( QPREDICATE *) * uiMaxIfds, + (void **)&ppPredicateList))) { - rc = RC_SET( FERR_MEM); goto Exit; } } @@ -2345,7 +2343,7 @@ RCODE flmCurOptimize( DB_STATS * pDbStats; QPREDICATE * pPredicateList = NULL; FLMUINT uiTotalPredicates = 0; - POOL * pTempPool; + F_Pool * pTempPool; void * pvMark; qOptTypes eOptType; FLMBOOL bFromSubQuerySubsumed = FALSE; @@ -2378,7 +2376,7 @@ RCODE flmCurOptimize( pSubQuery = pCursor->pSubQueryList; pTempPool = &pDb->TempPool; - pvMark = GedPoolMark( pTempPool); + pvMark = pTempPool->poolMark(); bChoosingIndex = (FLMBOOL)((pCursor->uiIndexNum == FLM_SELECT_INDEX) ? (FLMBOOL)TRUE : (FLMBOOL)FALSE); @@ -2387,7 +2385,7 @@ RCODE flmCurOptimize( for(;;) { - GedPoolReset( pTempPool, pvMark); + pTempPool->poolReset( pvMark); // First create the predicate list for the sub-query - so // that it only has to be done once. This call also verifies diff --git a/flaim/src/fqparse.cpp b/flaim/src/fqparse.cpp index 1b213ae..ea52213 100644 --- a/flaim/src/fqparse.cpp +++ b/flaim/src/fqparse.cpp @@ -37,6 +37,10 @@ FSTATIC RCODE tokenGet( QTYPES * peType, FLMUINT * puiTokenBufSize); +FSTATIC FLMBOOL tokenIsNum( + const char * pszToken, + FLMUINT * puiNum); + FSTATIC FLMBOOL tokenIsOperator( const char * pszToken, QTYPES * peOperator); @@ -1462,3 +1466,102 @@ Exit: return( rc); } + +/**************************************************************************** +Desc: Determine if a token is a number. +****************************************************************************/ +FSTATIC FLMBOOL tokenIsNum( + const char * pszToken, + FLMUINT * puiNum) +{ + FLMBOOL bIsNum = TRUE; + FLMUINT uiNum; + FLMBOOL bAllowHex = FALSE; + + if (*pszToken == 0) + { + bIsNum = FALSE; + goto Exit; + } + + if (*pszToken == '0' && + (*(pszToken + 1) == 'x' || *(pszToken + 1) == 'X')) + { + pszToken += 2; + bAllowHex = TRUE; + } + + uiNum = 0; + while (*pszToken) + { + if (*pszToken >= '0' && *pszToken <= '9') + { + if (!bAllowHex) + { + if (uiNum > (FLMUINT)(-1) / 10) + { + + // Number would overflow. + + bIsNum = FALSE; + goto Exit; + } + else + { + uiNum *= 10; + } + } + else + { + if (uiNum > (FLMUINT)(-1) >> 4) + { + + // Number would overflow. + + bIsNum = FALSE; + goto Exit; + } + uiNum <<= 4; + } + uiNum += (FLMUINT)(*pszToken - '0'); + } + else if (bAllowHex) + { + if (uiNum > (FLMUINT)(-1) >> 4) + { + + // Number would overflow. + + bIsNum = FALSE; + goto Exit; + } + if (*pszToken >= 'A' && *pszToken <= 'F') + { + uiNum <<= 4; + uiNum += (FLMUINT)(*pszToken - 'A') + 10; + } + else if (*pszToken >= 'a' && *pszToken <= 'f') + { + uiNum <<= 4; + uiNum += (FLMUINT)(*pszToken - 'a') + 10; + } + else + { + bIsNum = FALSE; + goto Exit; + } + } + else + { + bIsNum = FALSE; + goto Exit; + } + pszToken++; + } + + *puiNum = uiNum; + +Exit: + + return( bIsNum); +} diff --git a/flaim/src/fqprep.cpp b/flaim/src/fqprep.cpp index d8a8817..8764547 100644 --- a/flaim/src/fqprep.cpp +++ b/flaim/src/fqprep.cpp @@ -52,11 +52,11 @@ FSTATIC RCODE flmCurDoDeMorgan( FSTATIC RCODE flmCurCopyQTree( FQNODE * pSrcTree, FQNODE * * ppDestTree, - POOL * pPool); + F_Pool * pPool); FSTATIC RCODE flmCurStratify( CURSOR * pCursor, - POOL * pPool, + F_Pool * pPool, FLMBOOL * pbStratified, FQNODE * * ppTree); @@ -104,14 +104,13 @@ FSTATIC RCODE flmCurAddSubQuery( RCODE rc = FERR_OK; SUBQUERY * pSubQuery; - if ((pSubQuery = (SUBQUERY *)GedPoolCalloc( &pCursor->SQPool, - sizeof( SUBQUERY))) == NULL) + if( RC_BAD( rc = pCursor->SQPool.poolCalloc( sizeof( SUBQUERY), + (void **)&pSubQuery))) { - rc = RC_SET( FERR_MEM); goto Exit; } - - GedSmartPoolInit( &pSubQuery->OptPool, &g_SubQueryOptPoolStats); + + pSubQuery->OptPool.smartPoolInit( &g_SubQueryOptPoolStats); pSubQuery->pTree = pQNode; @@ -601,7 +600,7 @@ RCODE flmCurCopyQNode( FQNODE * pSrcNode, QTINFO * pDestQTInfo, FQNODE * * ppDestNode, - POOL * pPool) + F_Pool * pPool) { RCODE rc = FERR_OK; FLMUINT * pTmpPath; @@ -671,10 +670,9 @@ RCODE flmCurCopyQNode( // needs to be reversed because it is reversed back in the call // to flmCurMakeQNode below. - if ((pTmpPath = (FLMUINT *)GedPoolCalloc( pPool, - ((uiPathCnt + 1) * sizeof( FLMUINT)))) == NULL) + if( RC_BAD( rc = pPool->poolCalloc( + (uiPathCnt + 1) * sizeof( FLMUINT), (void **)&pTmpPath))) { - rc = RC_SET( FERR_MEM); break; } @@ -769,11 +767,10 @@ RCODE flmCurCopyQNode( if ((pSrcNode->pQAtom->val.QueryFld.pvUserData) && (pSrcNode->pQAtom->val.QueryFld.uiUserDataLen)) { - if ((pDestNd->pQAtom->val.QueryFld.pvUserData = - GedPoolAlloc( pPool, - pSrcNode->pQAtom->val.QueryFld.uiUserDataLen)) == NULL) + if( RC_BAD( rc = pPool->poolAlloc( + pSrcNode->pQAtom->val.QueryFld.uiUserDataLen, + &pDestNd->pQAtom->val.QueryFld.pvUserData))) { - rc = RC_SET( FERR_MEM); goto Exit; } @@ -802,7 +799,7 @@ Desc: Copies a passed-in query tree into a new tree, using the passed-in FSTATIC RCODE flmCurCopyQTree( FQNODE * pSrcTree, FQNODE * * ppDestTree, - POOL * pPool) + F_Pool * pPool) { RCODE rc = FERR_OK; FQNODE * pQNode; @@ -882,7 +879,7 @@ Ret: ****************************************************************************/ FSTATIC RCODE flmCurStratify( CURSOR * pCursor, - POOL * pPool, + F_Pool * pPool, FLMBOOL * pbStratified, FQNODE * * ppTree) { @@ -902,7 +899,7 @@ FSTATIC RCODE flmCurStratify( FQNODE * pAndParent; FQNODE * pCurrNode; FLMBOOL bStratified = TRUE; - void * pvMark = GedPoolMark( pPool); + void * pvMark = pPool->poolMark(); FLMUINT uiCount = 0; FLMUINT uiStartTime = FLM_GET_TIMER(); FLMUINT uiCheckTime = 0; @@ -913,7 +910,7 @@ FSTATIC RCODE flmCurStratify( if (gv_FlmSysData.uiMaxStratifyIterations && gv_FlmSysData.uiMaxStratifyTime) { - FLM_SECS_TO_TIMER_UNITS( gv_FlmSysData.uiMaxStratifyTime, uiTimeOut); + uiTimeOut = FLM_SECS_TO_TIMER_UNITS( gv_FlmSysData.uiMaxStratifyTime); } else { @@ -944,7 +941,7 @@ FSTATIC RCODE flmCurStratify( uiCheckTime = FLM_GET_TIMER(); if( uiTimeOut && FLM_ELAPSED_TIME( uiCheckTime, uiStartTime) > uiTimeOut) { - GedPoolReset( pPool, pvMark); + pPool->poolReset( pvMark); rc = flmCurCopyQTree( pCursor->QTInfo.pSaveQuery, &pTree, pPool); diff --git a/flaim/src/fqread.cpp b/flaim/src/fqread.cpp index b350bad..d289462 100644 --- a/flaim/src/fqread.cpp +++ b/flaim/src/fqread.cpp @@ -46,10 +46,10 @@ FSTATIC RCODE flmCurCSPerformRead( FLMUINT * puiDrnRV, FLMUINT * puiCountRV) { + RCODE rc = FERR_OK; CS_CONTEXT * pCSContext = pCursor->pCSContext; FCL_WIRE Wire( pCSContext); - void * pvMark = GedPoolMark( &pCSContext->pool); - RCODE rc = FERR_OK; + void * pvMark = pCSContext->pool.poolMark(); FLMUINT uiCSOp = 0; // If there is no VALID id for the cursor, get one. @@ -178,7 +178,7 @@ FSTATIC RCODE flmCurCSPerformRead( Exit: - GedPoolReset( &pCSContext->pool, pvMark); + pCSContext->pool.poolReset( pvMark); return( rc); Transmission_Error: diff --git a/flaim/src/fqsrch.cpp b/flaim/src/fqsrch.cpp index 4f45f1a..3e8d93a 100644 --- a/flaim/src/fqsrch.cpp +++ b/flaim/src/fqsrch.cpp @@ -82,6 +82,36 @@ FSTATIC RCODE flmCurEvalSingleRec( FLMUINT * puiCount, FLMUINT * puiSkipCount); +/**************************************************************************** +Desc: This routine will do all the setup needed to establish a sub-query as + the current subquery for the query. +****************************************************************************/ +class F_DRNCompare : public IF_ResultSetCompare +{ + RCODE FLMAPI compare( + const void * pvData1, + FLMUINT uiLength1, + const void * pvData2, + FLMUINT uiLength2, + FLMINT * piCompare) + { + F_UNREFERENCED_PARM( uiLength1); + F_UNREFERENCED_PARM( uiLength2); + + if( *((FLMUINT *)pvData1) < *((FLMUINT *)pvData2)) + { + *piCompare = -1; + } + else if( *((FLMUINT *)pvData1) > *((FLMUINT *)pvData2)) + { + *piCompare = 1; + } + + *piCompare = 0; + return( NE_FLM_OK); + } +}; + /**************************************************************************** Desc: This routine will do all the setup needed to establish a sub-query as the current subquery for the query. @@ -125,16 +155,16 @@ Desc: Validate a record that has passed the search criteria. This routine against the result set, if there is one. ****************************************************************************/ FSTATIC RCODE flmCurRecValidate( - eFlmFuncs eFlmFuncId, - CURSOR * pCursor, - SUBQUERY * pSubQuery, - FLMUINT * puiSkipCount, - FLMUINT * puiCount, - FLMBOOL * pbReturnRecOK - ) + eFlmFuncs eFlmFuncId, + CURSOR * pCursor, + SUBQUERY * pSubQuery, + FLMUINT * puiSkipCount, + FLMUINT * puiCount, + FLMBOOL * pbReturnRecOK) { - RCODE rc = FERR_OK; - FLMBOOL bSavedInvisTrans; + RCODE rc = FERR_OK; + FLMBOOL bSavedInvisTrans; + F_DRNCompare * pDrnCompare = NULL; // At this point, we have a record that has passed all the selection // criteria in the query. If we have a record validator callback, @@ -163,22 +193,14 @@ FSTATIC RCODE flmCurRecValidate( if (pCursor->bEliminateDups) { - /* - Setup the result set - */ + // Setup the result set if( !pCursor->pDRNSet) { char szTmpDir[ F_PATH_MAX_SIZE]; szTmpDir[ 0] = 0; - - if ((pCursor->pDRNSet = f_new FDynSearchSet) == NULL) - { - rc = RC_SET( FERR_MEM); - goto Exit; - } - + if( gv_FlmSysData.bTempDirSet && gv_FlmSysData.szTempDir[ 0]) { if( RC_BAD( rc = flmGetTmpDir( szTmpDir))) @@ -189,19 +211,29 @@ FSTATIC RCODE flmCurRecValidate( if( !szTmpDir[ 0]) { - if( RC_BAD( rc = f_pathReduce( + if( RC_BAD( rc = gv_FlmSysData.pFileSystem->pathReduce( pCursor->pDb->pFile->pszDbPath, szTmpDir, NULL))) { goto Exit; } } - - if (RC_BAD( rc = pCursor->pDRNSet->setup( szTmpDir, sizeof( FLMUINT)))) + + if( RC_BAD( rc = FlmAllocResultSet( &pCursor->pDRNSet))) + { + goto Exit; + } + + if( (pDrnCompare = f_new F_DRNCompare) == NULL) + { + rc = RC_SET( FERR_MEM); + goto Exit; + } + + if( RC_BAD( rc = pCursor->pDRNSet->setupResultSet( szTmpDir, + pDrnCompare, sizeof( FLMUINT)))) { goto Exit; } - - pCursor->pDRNSet->setCompareFunc( DRNCompareFunc, (void *) 4); } if (RC_BAD( rc = pCursor->pDRNSet->addEntry( &pSubQuery->uiDrn))) @@ -249,7 +281,14 @@ FSTATIC RCODE flmCurRecValidate( // pass it back out to the caller. *pbReturnRecOK = TRUE; + Exit: + + if( pDrnCompare) + { + pDrnCompare->Release(); + } + return( rc); } @@ -317,7 +356,7 @@ FSTATIC RCODE flmCurSearchIndex( if (pCursor->fnStatus) { - FLM_SECS_TO_TIMER_UNITS( STATUS_CB_INTERVAL, uiCBTimer); + uiCBTimer = FLM_SECS_TO_TIMER_UNITS( STATUS_CB_INTERVAL); } // Set up initial search parameters. @@ -706,7 +745,7 @@ FSTATIC RCODE flmCurSearchPredicate( if (pCursor->fnStatus) { - FLM_SECS_TO_TIMER_UNITS( STATUS_CB_INTERVAL, uiCBTimer); + uiCBTimer = FLM_SECS_TO_TIMER_UNITS( STATUS_CB_INTERVAL); } // Set up initial search parameters. @@ -871,7 +910,7 @@ FSTATIC RCODE flmCurSearchContainer( if (pCursor->fnStatus) { - FLM_SECS_TO_TIMER_UNITS( STATUS_CB_INTERVAL, uiCBTimer); + uiCBTimer = FLM_SECS_TO_TIMER_UNITS( STATUS_CB_INTERVAL); } // Set up initial search parameters. diff --git a/flaim/src/fqstack.cpp b/flaim/src/fqstack.cpp index 2df4d42..a794fd4 100644 --- a/flaim/src/fqstack.cpp +++ b/flaim/src/fqstack.cpp @@ -544,7 +544,7 @@ Exit: Desc: Makes an FQNODE of a given type, and puts a value in it if necessary. ****************************************************************************/ RCODE flmCurMakeQNode( - POOL * pPool, + F_Pool * pPool, QTYPES eType, void * pVal, FLMUINT uiValLen, @@ -562,12 +562,12 @@ RCODE flmCurMakeQNode( FQNODE * pQNode; FQATOM * pQAtom; - if ((*ppQNode = pQNode = (FQNODE *)GedPoolCalloc( pPool, - sizeof( FQNODE))) == NULL) + if( RC_BAD( rc = pPool->poolCalloc( sizeof( FQNODE), (void **)&pQNode))) { - rc = RC_SET( FERR_MEM); goto Exit; } + + *ppQNode = pQNode; // Always set eOpType to the eType @@ -577,39 +577,52 @@ RCODE flmCurMakeQNode( pQNode->uiStatus = uiFlags; goto Exit; } - if ((pQNode->pQAtom = pQAtom = (FQATOM *)GedPoolCalloc( pPool, - sizeof( FQATOM))) == NULL) + + if( RC_BAD( rc = pPool->poolCalloc( sizeof( FQATOM), (void **)&pQAtom))) { - rc = RC_SET( FERR_MEM); goto Exit; } + + pQNode->pQAtom = pQAtom; pQAtom->uiFlags = uiFlags; switch (eType) { case FLM_TEXT_VAL: - if ((pTmpBuf = (FLMBYTE *)GedPoolCalloc( pPool, - (FLMUINT)(uiTmpLen + 1))) == NULL) + { + if( RC_BAD( rc = pPool->poolAlloc( uiTmpLen + 1, (void **)&pTmpBuf))) { - rc = RC_SET( FERR_MEM); goto Exit; } + f_memcpy( pTmpBuf, pVal, uiTmpLen); - pTmpBuf[ uiTmpLen ] = '\0'; // MUST BE NULL TERIMINATED! + pTmpBuf[ uiTmpLen ] = '\0'; pQAtom->val.pucBuf = pTmpBuf; - pQAtom->uiBufLen = uiTmpLen; // Must be actual length. + pQAtom->uiBufLen = uiTmpLen; break; + } + case FLM_BOOL_VAL: + { pQAtom->val.uiBool = *(FLMUINT *)pVal; break; + } + case FLM_INT32_VAL: + { pQAtom->val.iVal = *(FLMINT *)pVal; break; + } + case FLM_REC_PTR_VAL: case FLM_UINT32_VAL: + { pQAtom->val.uiVal = *(FLMUINT *)pVal; break; + } + case FLM_FLD_PATH: + { for (uiPathCnt = 0; ((FLMUINT *)pVal)[ uiPathCnt]; uiPathCnt++) @@ -620,14 +633,14 @@ RCODE flmCurMakeQNode( goto Exit; } } - - if ((puiTmpPath = (FLMUINT *)GedPoolCalloc( pPool, - (FLMUINT)((FLMUINT)(uiPathCnt + 1) * 2 * - (FLMUINT)sizeof( FLMUINT)))) == NULL) + + if( RC_BAD( rc = pPool->poolCalloc( + ((FLMUINT)(uiPathCnt + 1) * 2 * sizeof( FLMUINT)), + (void **)&puiTmpPath))) { - rc = RC_SET( FERR_MEM); goto Exit; } + puiPToCPath = &puiTmpPath [uiPathCnt + 1]; puiFldPath = (FLMUINT *)pVal; @@ -639,25 +652,37 @@ RCODE flmCurMakeQNode( pQAtom->val.QueryFld.puiFldPath = puiTmpPath; pQAtom->val.QueryFld.puiPToCPath = puiPToCPath; break; + } + case FLM_BINARY_VAL: - if ((pTmpBuf = (FLMBYTE *)GedPoolCalloc( pPool, uiTmpLen)) == NULL) + { + if( RC_BAD( rc = pPool->poolAlloc( uiTmpLen, (void **)&pTmpBuf))) { - rc = RC_SET( FERR_MEM); goto Exit; } + f_memcpy( pTmpBuf, pVal, uiTmpLen); pQAtom->val.pucBuf = pTmpBuf; pQAtom->uiBufLen = uiTmpLen; break; + } + case FLM_USER_PREDICATE: + { break; + } + default: + { rc = RC_SET( FERR_CURSOR_SYNTAX); goto Exit; + } } + pQAtom->eType = eType; Exit: + return( rc); } @@ -667,7 +692,7 @@ Desc: Grafts FQNODE onto a passed-in query tree as the right branch of a new Ret: ****************************************************************************/ RCODE flmCurGraftNode( - POOL * pPool, + F_Pool * pPool, FQNODE * pQNode, QTYPES eGraftOp, FQNODE * * ppQTree) @@ -710,8 +735,8 @@ FLMEXP RCODE FLMAPI FlmCursorAddValue( FLMUINT uiVal; void * pTmpVal = pVal; CURSOR * pCursor = (CURSOR *)hCursor; + F_Pool pool; FLMBOOL bPoolInitialized = FALSE; - POOL pool; if (!pCursor) { @@ -719,6 +744,7 @@ FLMEXP RCODE FLMAPI FlmCursorAddValue( rc = RC_SET( FERR_INVALID_PARM); goto Exit; } + if (RC_BAD( rc = pCursor->rc)) { goto Exit; @@ -752,7 +778,7 @@ FLMEXP RCODE FLMAPI FlmCursorAddValue( f_memset( &node, 0, sizeof(NODE)); - GedPoolInit( &pool, 512); + pool.poolInit( 512); bPoolInitialized = TRUE; rc = (eValType == FLM_UNICODE_VAL) @@ -842,6 +868,7 @@ FLMEXP RCODE FLMAPI FlmCursorAddValue( } Exit: + if (pCursor) { pCursor->rc = rc; @@ -849,8 +876,9 @@ Exit: if (bPoolInitialized) { - GedPoolFree( &pool); + pool.poolFree(); } + return( rc); } @@ -1038,14 +1066,15 @@ FLMEXP RCODE FLMAPI FlmCursorAddFieldCB( pQAtom->val.QueryFld.fnGetField = fnGetField; pQAtom->val.QueryFld.bValidateOnly = bValidateOnly; + if (pvUserData && uiUserDataLen) { - if ((pQAtom->val.QueryFld.pvUserData = - GedPoolAlloc( &pCursor->QueryPool, uiUserDataLen)) == NULL) + if( RC_BAD( rc = pCursor->QueryPool.poolAlloc( uiUserDataLen, + (void **)&pQAtom->val.QueryFld.pvUserData))) { - rc = RC_SET( FERR_MEM); goto Exit; } + f_memcpy( pQAtom->val.QueryFld.pvUserData, pvUserData, uiUserDataLen); pQAtom->val.QueryFld.uiUserDataLen = uiUserDataLen; diff --git a/flaim/src/fquery.h b/flaim/src/fquery.h index 92383e3..9934927 100644 --- a/flaim/src/fquery.h +++ b/flaim/src/fquery.h @@ -31,7 +31,6 @@ class FSIndexCursor; class FSDataCursor; -class FDynSearchSet; #define FLM_ALL_BOOL (FLM_TRUE | FLM_FALSE | FLM_UNK) @@ -324,7 +323,7 @@ typedef struct SUBQUERY FLMUINT uiNotEqualDrn; FLMBOOL bHaveDrnFlds; // Part of query involved DRN==x FLMUINT uiLanguage; - POOL OptPool; + F_Pool OptPool; FCURSOR_SUBQUERY_STATUS SQStatus; FlmRecord * pRec; @@ -362,12 +361,12 @@ typedef struct CURSOR FLMUINT uiLastPrcntOffs; FLMBOOL bUsePrcntPos; - FDynSearchSet * pDRNSet; + IF_ResultSet * pDRNSet; FLMBOOL bEliminateDups; QTINFO QTInfo; RCODE rc; - POOL SQPool; - POOL QueryPool; + F_Pool SQPool; + F_Pool QueryPool; void * pOptMark; FLMBOOL bOptimized; FLMBOOL bEmpty; @@ -427,7 +426,7 @@ RCODE flmInitCurCS( RCODE flmCurGetAtomVal( FlmRecord * pRecord, void * pField, - POOL * pPool, + F_Pool * pPool, QTYPES eFldType, FQATOM * pResult); @@ -502,7 +501,7 @@ FLMUINT flmTextMatch( RCODE flmCurMakeKeyFromRec( FDB * pDb, IXD * pIxd, - POOL * pPool, + F_Pool * pPool, FlmRecord * pRec, FLMBYTE ** ppucKeyBuffer, FLMUINT * puiKeyLen); @@ -515,7 +514,7 @@ RCODE flmCurCopyQNode( FQNODE * pSrcNode, QTINFO * pDestQTInfo, FQNODE * * ppDestNode, - POOL * pPool); + F_Pool * pPool); RCODE flmCurPrep( CURSOR * pCursor); @@ -564,7 +563,7 @@ RCODE flmPutValInAtom( FLMUINT uiFlags); RCODE flmCurMakeQNode( - POOL * pPool, + F_Pool * pPool, QTYPES eType, void * pVal, FLMUINT uiStrLen, @@ -572,7 +571,7 @@ RCODE flmCurMakeQNode( FQNODE * * ppQNode); RCODE flmCurGraftNode( - POOL * pPool, + F_Pool * pPool, FQNODE * pQNode, QTYPES eGraftOp, FQNODE * * ppQTree); diff --git a/flaim/src/frebuild.cpp b/flaim/src/frebuild.cpp index b817b72..15c59ea 100644 --- a/flaim/src/frebuild.cpp +++ b/flaim/src/frebuild.cpp @@ -42,10 +42,10 @@ typedef struct RECOV_DICT_REC RECOV_DICT_REC * pNext; } RECOV_DICT_REC; -typedef struct +typedef struct RECOV_DICT_INFO { RECOV_DICT_REC * pRecovRecs; - POOL pool; + F_Pool pool; } RECOV_DICT_INFO; FSTATIC RCODE bldAdjustNextDrn( @@ -110,7 +110,9 @@ FSTATIC RCODE bldDoDict( FLMBOOL * pbStartedTransRV); FSTATIC RCODE bldDetermineBlkSize( - F_SuperFileHdl * pSFileHdl, + const char * pszSourceDbPath, + const char * pszSourceDataDir, + FLMUINT uiDbVersion, FLMUINT uiMaxFileSize, FLMUINT * puiBlkSizeRV, STATUS_HOOK fnStatusFunc, @@ -433,7 +435,7 @@ FSTATIC RCODE bldAdjustNextDrn( // Find the element whose DRN is DRN_LAST_MARKER - flmUINT32ToBigEndian( (FLMUINT32)DRN_LAST_MARKER, DrnMarker); + f_UINT32ToBigEndian( (FLMUINT32)DRN_LAST_MARKER, DrnMarker); if( RC_BAD( rc = FSBtSearch( pDb, pLFile, &pStack, DrnMarker, DIN_KEY_SIZ, 0))) { @@ -502,7 +504,7 @@ FSTATIC RCODE bldRecovData( RECOV_DICT_INFO * pRecovDictInfo = NULL; FLMUINT uiFileNumber = 0; FLMUINT uiOffset = 0; - F_FileHdlImp * pFileHdl = NULL; + IF_FileHdl * pFileHdl = NULL; FLMUINT uiMaxFileSize = pRebuildState->uiMaxFileSize; FLMUINT uiDbVersion = pRebuildState->pHdrInfo->FileHdr.uiVersionNum; @@ -528,7 +530,7 @@ FSTATIC RCODE bldRecovData( break; } - if (RC_BAD( rc = pSFileHdl->GetFileHdl( + if (RC_BAD( rc = pSFileHdl->getFileHdl( uiFileNumber, FALSE, &pFileHdl))) { if (rc == FERR_IO_PATH_NOT_FOUND || @@ -543,7 +545,7 @@ FSTATIC RCODE bldRecovData( // Read the block into memory. - if (RC_BAD( rc = pFileHdl->SectorRead( uiOffset, uiBlockSize, + if (RC_BAD( rc = pFileHdl->sectorRead( uiOffset, uiBlockSize, pucBlk, &uiBytesRead))) { if (rc == FERR_IO_END_OF_FILE) @@ -1057,7 +1059,7 @@ FSTATIC RCODE bldExtractRecs( // Make sure the tempory memory is freed. // Eats up the memory during a rebuild. - GedPoolReset( &pDb->TempPool, NULL); + pDb->TempPool.poolReset(); if (!bRecovDictRecs) { pRebuildState->CallbackData.uiRecsRecov++; @@ -1105,7 +1107,7 @@ FSTATIC RCODE bldGetNextElm( *pbGotNewBlockRV = TRUE; uiBlkAddress = (FLMUINT)FB2UD( &pBlk [BH_NEXT_BLK]); - rc = pRebuildState->pSFileHdl->ReadBlock( uiBlkAddress, + rc = pRebuildState->pSFileHdl->readBlock( uiBlkAddress, pHdrInfo->FileHdr.uiBlockSize, pBlk, &uiBytesRead); if( uiBytesRead < pHdrInfo->FileHdr.uiBlockSize) @@ -1596,7 +1598,7 @@ FSTATIC RCODE bldSaveRecovDictRec( goto Exit; } - GedPoolInit( &pRecovDictInfo->pool, 512); + pRecovDictInfo->pool.poolInit( 512); *ppRecovDictInfoRV = pRecovDictInfo; } @@ -1748,11 +1750,10 @@ Remove_Rec: if( !pNewDictRec) { // All elements of pNewDictRec are initialized below. - - if( (pNewDictRec = (RECOV_DICT_REC *)GedPoolAlloc( - &pRecovDictInfo->pool, sizeof( RECOV_DICT_REC))) == NULL) + + if( RC_BAD( rc = pRecovDictInfo->pool.poolAlloc( + sizeof( RECOV_DICT_REC), (void **)&pNewDictRec))) { - rc = RC_SET( FERR_MEM); goto Exit; } @@ -1867,7 +1868,7 @@ FSTATIC void bldFreeRecovDictInfo( pDictRec = pDictRec->pNext; } - GedPoolFree( &pRecovDictInfo->pool); + pRecovDictInfo->pool.poolFree(); f_free( &pRecovDictInfo); } } @@ -2147,17 +2148,26 @@ FLMEXP RCODE FLMAPI FlmDbRebuild( HDR_INFO * pHdrInfo; CREATE_OPTS * pDefaultCreateOpts = NULL; FLMUINT uiTransID; - ServerLockObject * pWriteLockObj = NULL; - ServerLockObject * pFileLockObj = NULL; + IF_LockObject * pWriteLockObj = NULL; + IF_LockObject * pFileLockObj = NULL; FLMBOOL bMutexLocked = FALSE; - F_FileHdlImp * pLockFileHdl = NULL; - FLOCK_INFO LockInfo; + IF_FileHdl * pCFileHdl = NULL; + IF_FileHdl * pLockFileHdl = NULL; + eLockType currLockType; + FLMUINT uiLockThreadId; FLMUINT uiFileNumber; FLMUINT uiDbVersion = 0; FLMBOOL bUsedFFile = FALSE; FLMBOOL bBadHeader = FALSE; - FlmECache * pECacheMgr = NULL; + F_SEM hWaitSem = F_SEM_NULL; + // Allocate a semaphore + + if( RC_BAD( rc = f_semCreate( &hWaitSem))) + { + goto Exit; + } + f_mutexLock( gv_FlmSysData.hShareMutex); bMutexLocked = TRUE; @@ -2216,16 +2226,19 @@ FLMEXP RCODE FLMAPI FlmDbRebuild( // make sure there is no write lock. If there is, // we cannot do the rebuild right now. - pFile->pFileLockObj->GetLockInfo( (FLMINT)0, &LockInfo); - if (LockInfo.eCurrLockType == FLM_LOCK_EXCLUSIVE && - LockInfo.uiThreadId == f_threadId()) + pFile->pFileLockObj->getLockInfo( 0, &currLockType, + &uiLockThreadId, NULL); + + if (currLockType == FLM_LOCK_EXCLUSIVE && uiLockThreadId == f_threadId()) { // See if there is already a transaction going. - pFile->pWriteLockObj->GetLockInfo( (FLMINT)0, &LockInfo); - if ((LockInfo.eCurrLockType == FLM_LOCK_EXCLUSIVE) && - (LockInfo.uiThreadId == f_threadId())) + pFile->pWriteLockObj->getLockInfo( 0, &currLockType, + &uiLockThreadId, NULL); + + if (currLockType == FLM_LOCK_EXCLUSIVE && + uiLockThreadId == f_threadId()) { rc = RC_SET( FERR_TRANS_ACTIVE); goto Exit; @@ -2235,8 +2248,8 @@ FLMEXP RCODE FLMAPI FlmDbRebuild( { pFileLockObj = pFile->pFileLockObj; pFileLockObj->AddRef(); - if (RC_BAD( rc = pFileLockObj->Lock( TRUE, NULL, FALSE, TRUE, - FLM_NO_TIMEOUT, 0))) + if (RC_BAD( rc = pFileLockObj->lock( hWaitSem, + TRUE, FLM_NO_TIMEOUT, 0))) { goto Exit; } @@ -2252,11 +2265,12 @@ FLMEXP RCODE FLMAPI FlmDbRebuild( // Only contention here is with the checkpoint thread. // Wait forever for the checkpoint thread to give // up the lock. - - if (RC_BAD( rc = dbWriteLock( pFile))) + + if( RC_BAD( rc = pWriteLockObj->lock( hWaitSem, TRUE, FLM_NO_TIMEOUT, 0))) { goto Exit; } + bWriteLocked = TRUE; } @@ -2299,57 +2313,46 @@ FLMEXP RCODE FLMAPI FlmDbRebuild( pRebuildState->AppArg = pvStatusData; pRebuildState->fnStatusFunc = fnStatusFunc; pHdrInfo = pRebuildState->pHdrInfo; - - /* Open the corrupted database. */ - - if ((pSFileHdl = f_new F_SuperFileHdl) == NULL) - { - rc = RC_SET( FERR_MEM); - goto Exit; - } - - if( RC_BAD( rc = pSFileHdl->Setup( NULL, pszSourceDbPath, - pszSourceDataDir))) + + // Open the database file for reading header information + + if( RC_BAD( rc = gv_FlmSysData.pFileSystem->openFile( pszSourceDbPath, + FLM_IO_RDWR | FLM_IO_SH_DENYNONE | FLM_IO_DIRECT, &pCFileHdl))) { goto Exit; } + + rc = flmGetHdrInfo( pCFileHdl, &pHdrInfo->FileHdr, + &pHdrInfo->LogHdr, pRebuildState->pLogHdr); + + pCFileHdl->Release(); + pCFileHdl = NULL; - pRebuildState->pSFileHdl = pSFileHdl; - - /* - Check the header information to see if we were in the middle - of a previous copy. - */ - - if (RC_OK( rc = flmGetHdrInfo( pSFileHdl, - &pHdrInfo->FileHdr, - &pHdrInfo->LogHdr, - pRebuildState->pLogHdr))) + if( RC_OK( rc)) { - if (!pCreateOpts) { - flmGetCreateOpts( &pHdrInfo->FileHdr, - pRebuildState->pLogHdr, pDefaultCreateOpts); + flmGetCreateOpts( &pHdrInfo->FileHdr, pRebuildState->pLogHdr, + pDefaultCreateOpts); pCreateOpts = pDefaultCreateOpts; } + rc = FERR_OK; uiDbVersion = pHdrInfo->FileHdr.uiVersionNum; pRebuildState->uiMaxFileSize = flmGetMaxFileSize( uiDbVersion, pRebuildState->pLogHdr); } - else if ((rc == FERR_BLOCK_CHECKSUM) || - (rc == FERR_INCOMPLETE_LOG) || - (rc == FERR_DATA_ERROR) || - ((rc == FERR_UNSUPPORTED_VERSION) && - (pHdrInfo->FileHdr.uiVersionNum == 0))) + else if( rc == FERR_BLOCK_CHECKSUM || rc == FERR_INCOMPLETE_LOG || + rc == FERR_DATA_ERROR || + (rc == FERR_UNSUPPORTED_VERSION && pHdrInfo->FileHdr.uiVersionNum == 0)) { - if ((rc == FERR_BLOCK_CHECKSUM) || - (rc == FERR_DATA_ERROR)) + if( rc == FERR_BLOCK_CHECKSUM || rc == FERR_DATA_ERROR) { bBadHeader = TRUE; } + rc = FERR_OK; + if (!pCreateOpts) { flmGetCreateOpts( &pHdrInfo->FileHdr, @@ -2360,12 +2363,12 @@ FLMEXP RCODE FLMAPI FlmDbRebuild( pRebuildState->uiMaxFileSize = flmGetMaxFileSize( uiDbVersion, pRebuildState->pLogHdr); } - else if (rc == FERR_UNSUPPORTED_VERSION || rc == FERR_NEWER_FLAIM) + else if( rc == FERR_UNSUPPORTED_VERSION || rc == FERR_NEWER_FLAIM) { goto Exit; } - else if ((rc == FERR_NOT_FLAIM) || - (!VALID_BLOCK_SIZE( pHdrInfo->FileHdr.uiBlockSize))) + else if( rc == FERR_NOT_FLAIM || + !VALID_BLOCK_SIZE( pHdrInfo->FileHdr.uiBlockSize)) { FLMUINT uiSaveBlockSize; FLMUINT uiCalcBlockSize = 0; @@ -2374,7 +2377,7 @@ FLMEXP RCODE FLMAPI FlmDbRebuild( uiDbVersion = (FLMUINT)((rc != FERR_NOT_FLAIM) ? pHdrInfo->FileHdr.uiVersionNum : FLM_CUR_FILE_FORMAT_VER_NUM); - pSFileHdl->SetDbVersion( uiDbVersion); + pRebuildState->uiMaxFileSize = flmGetMaxFileSize( uiDbVersion, pRebuildState->pLogHdr); if (!pCreateOpts) @@ -2396,13 +2399,13 @@ FLMEXP RCODE FLMAPI FlmDbRebuild( pCreateOpts = pDefaultCreateOpts; } - /* Try to determine the correct block size. */ + // Try to determine the correct block size - if (RC_BAD( rc = bldDetermineBlkSize( pSFileHdl, - pRebuildState->uiMaxFileSize, - &uiCalcBlockSize, - fnStatusFunc, &pRebuildState->CallbackData, - pRebuildState->AppArg))) + if (RC_BAD( rc = bldDetermineBlkSize( + pszSourceDbPath, pszSourceDataDir, uiDbVersion, + pRebuildState->uiMaxFileSize, &uiCalcBlockSize, + fnStatusFunc, &pRebuildState->CallbackData, + pRebuildState->AppArg))) { goto Exit; } @@ -2414,40 +2417,25 @@ FLMEXP RCODE FLMAPI FlmDbRebuild( flmInitFileHdrInfo( pCreateOpts, &pHdrInfo->FileHdr, ucFileHdrBuf); - /* - Only use the passed-in block size (uiSaveBlockSize) if it - was non-zero. - */ + // Only use the passed-in block size (uiSaveBlockSize) if it + // was non-zero. if (uiSaveBlockSize) + { pCreateOpts->uiBlockSize = uiSaveBlockSize; + } } else { goto Exit; } - // Calculate the file size. - - pSFileHdl->SetDbVersion( uiDbVersion); - pRebuildState->CallbackData.ui64DatabaseSize = 0; - for (uiFileNumber = 1;;uiFileNumber++) - { - FLMUINT uiTmpSize; - - if (RC_BAD( pSFileHdl->GetFileSize( uiFileNumber, &uiTmpSize))) - { - break; - } - pRebuildState->CallbackData.ui64DatabaseSize += (FLMUINT64)uiTmpSize; - } - // Delete the destination database in case it already exists. - if (RC_BAD( rc = FlmDbRemove( pszDestDbPath, pszDestDataDir, + if( RC_BAD( rc = FlmDbRemove( pszDestDbPath, pszDestDataDir, pszDestRflDir, TRUE))) { - if (rc == FERR_IO_PATH_NOT_FOUND || rc == FERR_IO_INVALID_PATH) + if( rc == FERR_IO_PATH_NOT_FOUND || rc == FERR_IO_INVALID_PATH) { rc = FERR_OK; } @@ -2457,66 +2445,62 @@ FLMEXP RCODE FLMAPI FlmDbRebuild( } } - /* - If no block size has been specified or determined yet, use what we - read from the file header. - */ + // If no block size has been specified or determined yet, use what we + // read from the file header. if (!pCreateOpts->uiBlockSize) + { pCreateOpts->uiBlockSize = pHdrInfo->FileHdr.uiBlockSize; - - pSFileHdl->SetDbVersion( pHdrInfo->FileHdr.uiVersionNum); - pSFileHdl->SetBlockSize( pHdrInfo->FileHdr.uiBlockSize); - - /* - Set the ECache manger into the super file handle - */ - - if( pFile && pFile->pECacheMgr) - { - pSFileHdl->setECacheMgr( pFile->pECacheMgr); - } - else if( gv_FlmSysData.bOkToUseESM) - { - if( (pECacheMgr = f_new FlmECache) == NULL) - { - rc = RC_SET( FERR_MEM); - goto Exit; - } - - if( !pECacheMgr->setupECache( pHdrInfo->FileHdr.uiBlockSize, - pRebuildState->uiMaxFileSize)) - { - pECacheMgr->Release(); - pECacheMgr = NULL; - } - else - { - pSFileHdl->setECacheMgr( pECacheMgr); - } } - /* - When creating the new file, set the transaction ID to one greater than it - is in the corrupt file. However, don't let it get greater than about - 2 billion - want to leave room for 2 billion transactions in case they - were corrupted somehow in our old file. - */ + // Open the corrupted database - uiTransID = - ((FLMUINT)FB2UD( &pRebuildState->pLogHdr [LOG_CURR_TRANS_ID]) + 1) & 0x7FFFFFFF; + if ((pSFileHdl = f_new F_SuperFileHdl) == NULL) + { + rc = RC_SET( FERR_MEM); + goto Exit; + } + + if( RC_BAD( rc = pSFileHdl->setup( pszSourceDbPath, pszSourceDataDir, + pHdrInfo->FileHdr.uiVersionNum))) + { + goto Exit; + } + + pRebuildState->pSFileHdl = pSFileHdl; + + // Calculate the file size. + + pRebuildState->CallbackData.ui64DatabaseSize = 0; + for (uiFileNumber = 1;;uiFileNumber++) + { + FLMUINT64 ui64TmpSize; + + if (RC_BAD( pSFileHdl->getFileSize( uiFileNumber, &ui64TmpSize))) + { + break; + } + + pRebuildState->CallbackData.ui64DatabaseSize += ui64TmpSize; + } + + // When creating the new file, set the transaction ID to one greater than it + // is in the corrupt file. However, don't let it get greater than about + // 2 billion - want to leave room for 2 billion transactions in case they + // were corrupted somehow in our old file. + + uiTransID = ((FLMUINT)FB2UD( &pRebuildState->pLogHdr[ + LOG_CURR_TRANS_ID]) + 1) & 0x7FFFFFFF; if (RC_BAD( rc = flmCreateNewFile( pszDestDbPath, pszDestDataDir, - pszDestRflDir, - pszDictPath, NULL, - pCreateOpts, uiTransID, (FDB * *)&pRebuildState->hDb, - pRebuildState))) + pszDestRflDir, pszDictPath, NULL, pCreateOpts, + uiTransID, (FDB * *)&pRebuildState->hDb, pRebuildState))) { goto Exit; } pDb = (FDB *)pRebuildState->hDb; - /* Rebuild the database */ + // Rebuild the database if (RC_BAD( rc = flmDbRebuildFile( pRebuildState, bBadHeader))) { @@ -2525,7 +2509,7 @@ FLMEXP RCODE FLMAPI FlmDbRebuild( Exit: - /* Close the temporary database, if it is still open. */ + // Close the temporary database, if it is still open if (pDb) { @@ -2578,25 +2562,15 @@ Exit: bMutexLocked = FALSE; } - /* Unlock the file, if it is locked. */ - if (bWriteLocked) { - dbWriteUnlock( pFile); + pWriteLockObj->unlock(); bWriteLocked = FALSE; } if (bFileLocked) { - RCODE rc3; - - if (RC_BAD( rc3 = pFileLockObj->Unlock( TRUE, NULL))) - { - if (RC_OK( rc)) - { - rc = rc3; - } - } + pFileLockObj->unlock(); bFileLocked = FALSE; } @@ -2604,11 +2578,10 @@ Exit: { pSFileHdl->Release(); } - - if( pECacheMgr) + + if( pCFileHdl) { - pECacheMgr->Release(); - pECacheMgr = NULL; + pCFileHdl->Release(); } if (pWriteLockObj) @@ -2616,6 +2589,7 @@ Exit: pWriteLockObj->Release(); pWriteLockObj = NULL; } + if (pFileLockObj) { pFileLockObj->Release(); @@ -2624,7 +2598,6 @@ Exit: if (pLockFileHdl) { - (void)pLockFileHdl->Close(); pLockFileHdl->Release(); pLockFileHdl = NULL; } @@ -2693,6 +2666,11 @@ Exit: *puiRecsRecovRV = 0; } } + + if( hWaitSem != F_SEM_NULL) + { + f_semDestroy( &hWaitSem); + } return( rc); } @@ -2703,25 +2681,42 @@ Desc: This routine reads through a database and makes a best guess as to the true block size of the database. *****************************************************************************/ FSTATIC RCODE bldDetermineBlkSize( - F_SuperFileHdl * pSFileHdl, // Super file handle for database. + const char * pszSourceDbPath, + const char * pszSourceDataDir, + FLMUINT uiDbVersion, FLMUINT uiMaxFileSize, - FLMUINT * puiBlkSizeRV, // Calculated block size is returned here. - STATUS_HOOK fnStatusFunc, // Callback function. - REBUILD_INFO * pCallbackData, // Callback structure. - void * AppArg) // User data for callback. + FLMUINT * puiBlkSizeRV, + STATUS_HOOK fnStatusFunc, + REBUILD_INFO * pCallbackData, + void * AppArg) { - RCODE rc = FERR_OK; - FLMBYTE ucBlkHeader [BH_OVHD]; - FLMUINT uiBytesRead; - FLMUINT uiBlkAddress; - FLMUINT uiFileNumber = 0; - FLMUINT uiOffset = 0; - FLMUINT uiCount4K = 0; - FLMUINT uiCount8K = 0; - FLMUINT64 ui64BytesDone = 0; - F_FileHdlImp * pFileHdl = NULL; + RCODE rc = FERR_OK; + FLMBYTE ucBlkHeader [BH_OVHD]; + FLMUINT uiBytesRead; + FLMUINT uiBlkAddress; + FLMUINT uiFileNumber = 0; + FLMUINT uiOffset = 0; + FLMUINT uiCount4K = 0; + FLMUINT uiCount8K = 0; + FLMUINT64 ui64BytesDone = 0; + IF_FileHdl * pFileHdl = NULL; + F_SuperFileHdl * pSFileHdl = NULL; - /* Start from byte offset 0 in the first file. */ + // Open the corrupted database + + if( (pSFileHdl = f_new F_SuperFileHdl) == NULL) + { + rc = RC_SET( FERR_MEM); + goto Exit; + } + + if( RC_BAD( rc = pSFileHdl->setup( pszSourceDbPath, pszSourceDataDir, + uiDbVersion))) + { + goto Exit; + } + + // Start from byte offset 0 in the first file pCallbackData->iDoingFlag = REBUILD_GET_BLK_SIZ; pCallbackData->bStartFlag = TRUE; @@ -2731,7 +2726,7 @@ FSTATIC RCODE bldDetermineBlkSize( { uiOffset = 0; uiFileNumber++; - if (RC_BAD( rc = pSFileHdl->GetFileHdl( + if (RC_BAD( rc = pSFileHdl->getFileHdl( uiFileNumber, FALSE, &pFileHdl))) { if (rc == FERR_IO_PATH_NOT_FOUND) @@ -2743,7 +2738,7 @@ FSTATIC RCODE bldDetermineBlkSize( } } - if ((RC_OK(rc = pFileHdl->Read( uiOffset, BH_OVHD, ucBlkHeader, + if ((RC_OK(rc = pFileHdl->read( uiOffset, BH_OVHD, ucBlkHeader, &uiBytesRead))) || (rc == FERR_IO_END_OF_FILE)) { @@ -2760,10 +2755,16 @@ FSTATIC RCODE bldDetermineBlkSize( (FSGetFileOffset( uiBlkAddress) == uiOffset)) { if (uiOffset % 4096 == 0) + { uiCount4K++; + } + if (uiOffset % 8192 == 0) + { uiCount8K++; + } } + if (rc != FERR_OK || uiBytesRead < BH_OVHD) { @@ -2779,7 +2780,7 @@ FSTATIC RCODE bldDetermineBlkSize( uiOffset += MIN_BLOCK_SIZE; } - /* Call the callback function to report copy progress. */ + // Call the callback function to report copy progress if (fnStatusFunc != NULL) { @@ -2791,6 +2792,7 @@ FSTATIC RCODE bldDetermineBlkSize( { goto Exit; } + pCallbackData->bStartFlag = FALSE; } @@ -2801,8 +2803,11 @@ FSTATIC RCODE bldDetermineBlkSize( goto Exit; } } + if (rc == FERR_IO_END_OF_FILE) + { rc = FERR_OK; + } // If our count of 4K blocks is greater than 66% of the number // of 4K blocks that would fit in the database, we will use @@ -2818,6 +2823,13 @@ FSTATIC RCODE bldDetermineBlkSize( { *puiBlkSizeRV = 8192; } + Exit: + + if( pSFileHdl) + { + pSFileHdl->Release(); + } + return( rc); } diff --git a/flaim/src/frec.cpp b/flaim/src/frec.cpp index 503a0f3..1a09165 100644 --- a/flaim/src/frec.cpp +++ b/flaim/src/frec.cpp @@ -24,15 +24,8 @@ #include "flaimsys.h" -#if defined( FLM_NLM) && !defined( __MWERKS__) - // Disable "Warning! W549: col(XX) 'sizeof' operand contains - // compiler generated information" - - #pragma warning 549 9 -#endif - FSTATIC RCODE importTree( - F_FileHdl * pFileHdl, + IF_FileHdl * pFileHdl, char ** pBuf, FLMUINT uiBufSize, F_NameTable * pNameTable, @@ -120,8 +113,8 @@ FlmRecord * FlmRecord::copy( void) if( m_uiBufferSize) { if( RC_BAD( rc = gv_FlmSysData.RCacheMgr.pRecBufAlloc->allocBuf( - m_uiBufferSize, &pNewRec, sizeof( FlmRecord *), &pNewRec->m_pucBuffer, - &bHeapAlloc))) + NULL, m_uiBufferSize, &pNewRec, sizeof( FlmRecord *), + &pNewRec->m_pucBuffer, &bHeapAlloc))) { goto Exit; } @@ -141,9 +134,8 @@ FlmRecord * FlmRecord::copy( void) FLMUINT uiTableByteSize = fieldIdTableByteSize(); if( RC_BAD( rc = gv_FlmSysData.RCacheMgr.pRecBufAlloc->allocBuf( - uiTableByteSize, - &pNewRec, sizeof( FlmRecord *), &pNewRec->m_pucFieldIdTable, - &bHeapAlloc))) + NULL, uiTableByteSize, &pNewRec, sizeof( FlmRecord *), + &pNewRec->m_pucFieldIdTable, &bHeapAlloc))) { goto Exit; } @@ -1409,8 +1401,8 @@ RCODE FlmRecord::preallocSpace( if( m_uiBufferSize < uiNewSize || (m_uiBufferSize - uiNewSize) >= 32) { if( RC_BAD( rc = gv_FlmSysData.RCacheMgr.pRecBufAlloc->reallocBuf( - m_uiBufferSize, uiNewSize, &pThis, sizeof( FlmRecord *), &m_pucBuffer, - &bHeapAlloc))) + NULL, m_uiBufferSize, uiNewSize, &pThis, sizeof( FlmRecord *), + &m_pucBuffer, &bHeapAlloc))) { goto Exit; } @@ -1575,7 +1567,8 @@ RCODE FlmRecord::compressMemory( void) // Re-allocate the buffer if( RC_BAD( rc = gv_FlmSysData.RCacheMgr.pRecBufAlloc->allocBuf( - uiNewSize, &pThis, sizeof( FlmRecord *), &pucNewBuf, &bHeapAlloc))) + NULL, uiNewSize, &pThis, sizeof( FlmRecord *), + &pucNewBuf, &bHeapAlloc))) { goto Exit; } @@ -1785,7 +1778,7 @@ RCODE FlmRecord::compactMemory( void) // Temporarily increment the reference count so that we don't hit // debug asserts while processing - flmAtomicInc( &m_refCnt, gv_FlmSysData.RCacheMgr.hMutex, TRUE); + f_atomicInc( &m_refCnt); if( !m_uiBufferSize || (!m_bHolesInData && m_uiDataBufOffset == getDataBufSize())) @@ -1877,7 +1870,8 @@ RCODE FlmRecord::compactMemory( void) // Allocate a new buffer if( RC_BAD( rc = gv_FlmSysData.RCacheMgr.pRecBufAlloc->allocBuf( - uiNewSize, &pThis, sizeof( FlmRecord *), &pucNewBuf, &bHeapAlloc))) + NULL, uiNewSize, &pThis, sizeof( FlmRecord *), + &pucNewBuf, &bHeapAlloc))) { goto Exit; } @@ -1885,10 +1879,9 @@ RCODE FlmRecord::compactMemory( void) if (m_pucFieldIdTable) { uiFieldIdTableItemCount = getFieldIdTableItemCount( m_pucFieldIdTable); - if( RC_BAD( rc = gv_FlmSysData.RCacheMgr.pRecBufAlloc->allocBuf( - calcFieldIdTableByteSize( uiFieldIdTableItemCount), - &pThis, sizeof( FlmRecord *), &pucNewFieldIdTable, - &bFieldIdHeapAlloc))) + if( RC_BAD( rc = gv_FlmSysData.RCacheMgr.pRecBufAlloc->allocBuf( + NULL, calcFieldIdTableByteSize( uiFieldIdTableItemCount), &pThis, + sizeof( FlmRecord *), &pucNewFieldIdTable, &bFieldIdHeapAlloc))) { goto Exit; } @@ -2103,7 +2096,7 @@ Exit: &pucNewFieldIdTable); } - flmAtomicDec( &m_refCnt, gv_FlmSysData.RCacheMgr.hMutex, TRUE); + f_atomicDec( &m_refCnt); return( rc); } @@ -2151,7 +2144,7 @@ RCODE FlmRecord::createField( } if( RC_BAD( rc = gv_FlmSysData.RCacheMgr.pRecBufAlloc->reallocBuf( - m_uiBufferSize, uiNewSize, &pThis, sizeof( FlmRecord *), + NULL, m_uiBufferSize, uiNewSize, &pThis, sizeof( FlmRecord *), &m_pucBuffer, &bHeapAlloc))) { goto Exit; @@ -2421,8 +2414,8 @@ RCODE FlmRecord::getNewDataPtr( 32; if( RC_BAD( rc = gv_FlmSysData.RCacheMgr.pRecBufAlloc->reallocBuf( - m_uiBufferSize, uiNewSize, - &pThis, sizeof( FlmRecord *), &m_pucBuffer, &bHeapAlloc))) + NULL, m_uiBufferSize, uiNewSize, &pThis, + sizeof( FlmRecord *), &m_pucBuffer, &bHeapAlloc))) { goto Exit; } @@ -2481,7 +2474,7 @@ RCODE FlmRecord::getNewDataPtr( 32; if( RC_BAD( rc = gv_FlmSysData.RCacheMgr.pRecBufAlloc->reallocBuf( - m_uiBufferSize, uiNewSize, + NULL, m_uiBufferSize, uiNewSize, &pThis, sizeof( FlmRecord *), &m_pucBuffer, &bHeapAlloc))) { goto Exit; @@ -2637,7 +2630,7 @@ RCODE FlmRecord::getNewDataPtr( 32; if( RC_BAD( rc = gv_FlmSysData.RCacheMgr.pRecBufAlloc->reallocBuf( - m_uiBufferSize, uiNewSize, + NULL, m_uiBufferSize, uiNewSize, &pThis, sizeof( FlmRecord *), &m_pucBuffer, &bHeapAlloc))) { goto Exit; @@ -2770,7 +2763,7 @@ RCODE FlmRecord::getNewDataPtr( 32; if( RC_BAD( rc = gv_FlmSysData.RCacheMgr.pRecBufAlloc->reallocBuf( - m_uiBufferSize, uiNewSize, + NULL, m_uiBufferSize, uiNewSize, &pThis, sizeof( FlmRecord *), &m_pucBuffer, &bHeapAlloc))) { goto Exit; @@ -2859,12 +2852,11 @@ Exit: /***************************************************************************** Desc: Add a globally shared reference to this object. *****************************************************************************/ -FLMINT FlmRecord::AddRef( - FLMBOOL bMutexLocked) +FLMINT FLMAPI FlmRecord::AddRef( void) { FLMINT iRefCnt = 0; - iRefCnt = flmAtomicInc( &m_refCnt, gv_FlmSysData.RCacheMgr.hMutex, bMutexLocked); + iRefCnt = f_atomicInc( &m_refCnt); flmAssert( iRefCnt > 1); return( iRefCnt); @@ -2889,7 +2881,7 @@ FLMINT FlmRecord::Release( } } - iRefCnt = flmAtomicDec( &m_refCnt, gv_FlmSysData.RCacheMgr.hMutex, bMutexLocked); + iRefCnt = f_atomicDec( &m_refCnt); if( !iRefCnt) { @@ -3040,7 +3032,7 @@ void * FlmRecord::find( Desc: Import a record from a file *****************************************************************************/ RCODE FlmRecord::importRecord( - F_FileHdl * pFileHdl, + IF_FileHdl * pFileHdl, F_NameTable * pNameTable) { char ucBuffer[ 1024]; @@ -3074,7 +3066,7 @@ Desc : This function parses and builds one complete GEDCOM tree from a GEDCOM always start at zero. *****************************************************************************/ FSTATIC RCODE importTree( - F_FileHdl * pFileHdl, + IF_FileHdl * pFileHdl, char ** ppBuf, FLMUINT uiBufSize, F_NameTable * pNameTable, @@ -3087,7 +3079,7 @@ FSTATIC RCODE importTree( FLMBYTE nextChar; FLMBOOL bFirstFieldProcessed = FALSE; RCODE rc; - FLMUINT startPos; + FLMUINT64 ui64StartPos; gedStream.pFileHdl = pFileHdl; gedStream.pThis = *ppBuf; @@ -3100,10 +3092,10 @@ FSTATIC RCODE importTree( { // Find 1st starting file position - if( RC_OK( pFileHdl->Seek( 0L, F_IO_SEEK_CUR, &gedStream.uiFilePos))) + if( RC_OK( pFileHdl->seek( 0, FLM_IO_SEEK_CUR, &gedStream.ui64FilePos))) { gedStream.pLast = gedStream.pBuf; - gedReadChar( &gedStream, gedStream.uiFilePos); + gedReadChar( &gedStream, gedStream.ui64FilePos); } else return( RC_SET( FERR_FILE_ER)); @@ -3111,7 +3103,7 @@ FSTATIC RCODE importTree( else { gedStream.errorIO = 0; - gedStream.uiFilePos = 0; + gedStream.ui64FilePos = 0; gedStream.pLast = gedStream.pBuf + (uiBufSize - 1); gedStream.thisC = f_toascii( *gedStream.pBuf); } @@ -3119,7 +3111,7 @@ FSTATIC RCODE importTree( for(;;) { gedSkipBlankLines( &gedStream); - startPos = gedStream.uiFilePos; + ui64StartPos = gedStream.ui64FilePos; if( f_isdigit( gedStream.thisC)) { @@ -3183,9 +3175,9 @@ successful: if( pFileHdl == NULL) { *ppBuf = gedStream.pThis + - (FLMINT32)(startPos - gedStream.uiFilePos); + (FLMINT32)(ui64StartPos - gedStream.ui64FilePos); } - gedStream.uiFilePos = startPos; + gedStream.ui64FilePos = ui64StartPos; rc = FERR_OK; } else @@ -3211,8 +3203,8 @@ successful: if( pFileHdl) { - pFileHdl->Seek( gedStream.uiFilePos, - F_IO_SEEK_SET, &gedStream.uiFilePos); + pFileHdl->seek( gedStream.ui64FilePos, + FLM_IO_SEEK_SET, &gedStream.ui64FilePos); } return( rc); @@ -3228,7 +3220,7 @@ FSTATIC RCODE importField( F_NameTable * pNameTable, FlmRecord * pRec) { - FLMUINT startPos; + FLMUINT64 ui64StartPos; RCODE rc = FERR_OK; FLMUINT drn = 0; FLMUINT uiTagNum; @@ -3239,7 +3231,7 @@ FSTATIC RCODE importField( // Process optional xref-id - startPos = pGedStream->uiFilePos; + ui64StartPos = pGedStream->ui64FilePos; if( pGedStream->thisC == ASCII_AT) { int badDRN; @@ -3290,7 +3282,7 @@ FSTATIC RCODE importField( // Determine the Tag Number and insert a new field - startPos = pGedStream->uiFilePos; + ui64StartPos = pGedStream->ui64FilePos; if( !gedCopyTag( pGedStream, tagBuf)) { @@ -3325,7 +3317,7 @@ FSTATIC RCODE importField( // Alternate xref_ptr used instead of "value" - startPos = pGedStream->uiFilePos; + ui64StartPos = pGedStream->ui64FilePos; if( pGedStream->thisC == ASCII_AT) { for( drn = 0; gedNextChar( pGedStream) != ASCII_AT;) @@ -3358,8 +3350,8 @@ FSTATIC RCODE importField( } else { - FLMINT valLength; - FLMUINT tempPos = pGedStream->uiFilePos; + FLMINT valLength; + FLMUINT64 ui64TempPos = pGedStream->ui64FilePos; if( (valLength = gedCopyValue( pGedStream, NULL)) > 0) { @@ -3371,16 +3363,17 @@ FSTATIC RCODE importField( { goto Exit; } - gedReadChar( pGedStream, tempPos); + + gedReadChar( pGedStream, ui64TempPos); gedCopyValue( pGedStream, (char *)vp); } } - startPos = pGedStream->uiFilePos; + ui64StartPos = pGedStream->ui64FilePos; Exit: - gedReadChar( pGedStream, startPos); + gedReadChar( pGedStream, ui64StartPos); return( rc); } @@ -3445,7 +3438,7 @@ FLMINT gedCopyValue( FLMUINT valLength = 0; FLMUINT wsCount; FLMUINT lineLength = 0; - FLMUINT firstPos = 0; + FLMUINT64 ui64FirstPos = 0; FLMBYTE c; for(;;) @@ -3454,11 +3447,11 @@ FLMINT gedCopyValue( if( pGedStream->thisC == ASCII_DQUOTE) { gedNextChar( pGedStream); - firstPos = pGedStream->uiFilePos; + ui64FirstPos = pGedStream->ui64FilePos; } else { - firstPos = 0; + ui64FirstPos = 0; } for( lineLength = 0;;) @@ -3489,7 +3482,7 @@ FLMINT gedCopyValue( continue; default: - gedReadChar( pGedStream, pGedStream->uiFilePos - 1); + gedReadChar( pGedStream, pGedStream->ui64FilePos - 1); lineLength += wsCount; goto valid; } @@ -3508,7 +3501,7 @@ eol: if( lineLength) valLength += lineLength; if( dest) { - gedReadChar( pGedStream, firstPos); + gedReadChar( pGedStream, ui64FirstPos); while( lineLength--) { c = (FLMBYTE)pGedStream->thisC; @@ -3559,9 +3552,9 @@ valid: OEMcount += 1; } - if( !firstPos) + if( !ui64FirstPos) { - firstPos = pGedStream->uiFilePos; + ui64FirstPos = pGedStream->ui64FilePos; } lineLength++; gedNextChar( pGedStream); @@ -3634,7 +3627,7 @@ FLMINT gedNextChar( FLMUINT bytesRead; RCODE rc; - rc = pGedStream->pFileHdl->Read( F_IO_CURRENT_POS, + rc = pGedStream->pFileHdl->read( FLM_IO_CURRENT_POS, pGedStream->uiBufSize, pGedStream->pBuf, &bytesRead); if( rc == FERR_OK || (rc == FERR_IO_END_OF_FILE && bytesRead)) @@ -3642,7 +3635,7 @@ FLMINT gedNextChar( pGedStream->pThis = pGedStream->pBuf; pGedStream->pLast = pGedStream->pBuf + (bytesRead - 1); returnC: - pGedStream->uiFilePos++; + pGedStream->ui64FilePos++; return( pGedStream->thisC = f_toascii( *pGedStream->pThis)); } pGedStream->errorIO = rc != FERR_IO_END_OF_FILE; @@ -3655,7 +3648,7 @@ Desc: get an ASCII character at absolute file position and reset pointers *****************************************************************************/ FLMINT gedReadChar( GED_STREAM * pGedStream, - FLMUINT uiFilePos) + FLMUINT64 ui64FilePos) { RCODE rc = FERR_OK; @@ -3667,14 +3660,14 @@ FLMINT gedReadChar( char * pszTemp; pszTemp = pGedStream->pThis + - (FLMINT32)(uiFilePos - pGedStream->uiFilePos); + (FLMINT32)(ui64FilePos - pGedStream->ui64FilePos); if( pGedStream->pBuf == pGedStream->pLast || pszTemp > pGedStream->pLast || pszTemp < pGedStream->pBuf) { - if( RC_OK(rc = pGedStream->pFileHdl->Seek( uiFilePos, - F_IO_SEEK_SET, &pGedStream->uiFilePos)) && - (RC_OK( rc = pGedStream->pFileHdl->Read( F_IO_CURRENT_POS, + if( RC_OK(rc = pGedStream->pFileHdl->seek( ui64FilePos, + FLM_IO_SEEK_SET, &pGedStream->ui64FilePos)) && + (RC_OK( rc = pGedStream->pFileHdl->read( FLM_IO_CURRENT_POS, pGedStream->uiBufSize, pGedStream->pBuf, &bytesRead)) || (rc == FERR_IO_END_OF_FILE && bytesRead))) { @@ -3690,19 +3683,19 @@ FLMINT gedReadChar( } else { - pGedStream->uiFilePos = uiFilePos; + pGedStream->ui64FilePos = ui64FilePos; pGedStream->pThis = pszTemp; return( pGedStream->thisC = f_toascii( *pszTemp)); } } - if( (pGedStream->pBuf + uiFilePos) > pGedStream->pLast) + if( (pGedStream->pBuf + ui64FilePos) > pGedStream->pLast) { return( pGedStream->thisC = '\0'); } - pGedStream->pThis = pGedStream->pBuf + uiFilePos; - pGedStream->uiFilePos = uiFilePos; + pGedStream->pThis = pGedStream->pBuf + ui64FilePos; + pGedStream->ui64FilePos = ui64FilePos; return( pGedStream->thisC = f_toascii( *pGedStream->pThis)); } @@ -3805,7 +3798,7 @@ Desc: Export the record to GEDCOM *****************************************************************************/ RCODE FlmRecord::exportRecord( HFDB hDb, - POOL * pPool, + F_Pool * pPool, NODE ** ppRoot) { RCODE rc = FERR_OK; @@ -4655,22 +4648,16 @@ Desc: ****************************************************************************/ void * FlmRecord::operator new( FLMSIZET uiSize) -#ifndef FLM_NLM - throw() -#endif { F_UNREFERENCED_PARM( uiSize); flmAssert( gv_FlmSysData.RCacheMgr.pRecAlloc->getCellSize() >= uiSize); - return( gv_FlmSysData.RCacheMgr.pRecAlloc->allocCell( objectAllocInit)); + return( gv_FlmSysData.RCacheMgr.pRecAlloc->allocCell( NULL, objectAllocInit)); } /**************************************************************************** Desc: ****************************************************************************/ void * FlmRecord::operator new[]( FLMSIZET) -#ifndef FLM_NLM - throw() -#endif { flmAssert( 0); return( NULL); @@ -4684,12 +4671,9 @@ void * FlmRecord::operator new( FLMSIZET uiSize, const char *, int) -#ifndef FLM_NLM - throw() -#endif { flmAssert( gv_FlmSysData.RCacheMgr.pRecAlloc->getCellSize() >= uiSize); - return( gv_FlmSysData.RCacheMgr.pRecAlloc->allocCell( objectAllocInit)); + return( gv_FlmSysData.RCacheMgr.pRecAlloc->allocCell( NULL, objectAllocInit)); } #endif @@ -4701,9 +4685,6 @@ void * FlmRecord::operator new[]( FLMSIZET, // uiSize, const char *, // pszFile, int) // iLine) -#ifndef FLM_NLM - throw() -#endif { flmAssert( 0); return( NULL); @@ -5269,8 +5250,8 @@ RCODE FlmRecord::addToFieldIdTable( if (!uiItemCount) { if( RC_BAD( rc = gv_FlmSysData.RCacheMgr.pRecBufAlloc->allocBuf( - uiNewByteSize, &pThis, sizeof( FlmRecord *), &m_pucFieldIdTable, - &bHeapAlloc))) + NULL, uiNewByteSize, &pThis, sizeof( FlmRecord *), + &m_pucFieldIdTable, &bHeapAlloc))) { goto Exit; } @@ -5278,9 +5259,8 @@ RCODE FlmRecord::addToFieldIdTable( else { if( RC_BAD( rc = gv_FlmSysData.RCacheMgr.pRecBufAlloc->reallocBuf( - fieldIdTableByteSize(), - uiNewByteSize, &pThis, sizeof( FlmRecord *), - &m_pucFieldIdTable, &bHeapAlloc))) + NULL, fieldIdTableByteSize(), uiNewByteSize, &pThis, + sizeof( FlmRecord *), &m_pucFieldIdTable, &bHeapAlloc))) { goto Exit; } @@ -5352,9 +5332,8 @@ RCODE FlmRecord::removeFromFieldIdTable( if (uiTableSize > uiItemCount + 32) { if( RC_BAD( rc = gv_FlmSysData.RCacheMgr.pRecBufAlloc->reallocBuf( - fieldIdTableByteSize(), calcFieldIdTableByteSize( uiItemCount), - &pThis, sizeof( FlmRecord *), - &m_pucFieldIdTable, &bHeapAlloc))) + NULL, fieldIdTableByteSize(), calcFieldIdTableByteSize( uiItemCount), + &pThis, sizeof( FlmRecord *), &m_pucFieldIdTable, &bHeapAlloc))) { goto Exit; } @@ -5502,9 +5481,8 @@ RCODE FlmRecord::truncateFieldIdTable( void) FlmRecord * pThis = this; if( RC_BAD( rc = gv_FlmSysData.RCacheMgr.pRecBufAlloc->reallocBuf( - fieldIdTableByteSize(), calcFieldIdTableByteSize( uiItemCount), - &pThis, sizeof( FlmRecord *), - &m_pucFieldIdTable, &bHeapAlloc))) + NULL, fieldIdTableByteSize(), calcFieldIdTableByteSize( uiItemCount), + &pThis, sizeof( FlmRecord *), &m_pucFieldIdTable, &bHeapAlloc))) { goto Exit; } @@ -5527,7 +5505,7 @@ Exit: /**************************************************************************** Desc: ****************************************************************************/ -class RecCursor : public F_Base +class RecCursor : public F_Object { public: @@ -6216,4 +6194,3 @@ RCODE flmDecrField( return( rc); } - diff --git a/flaim/src/frset.cpp b/flaim/src/frset.cpp deleted file mode 100644 index 223ae3c..0000000 --- a/flaim/src/frset.cpp +++ /dev/null @@ -1,1517 +0,0 @@ -//------------------------------------------------------------------------- -// Desc: Result sets -// Tabs: 3 -// -// Copyright (c) 1996-2001,2003-2006 Novell, Inc. All Rights Reserved. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of version 2 of the GNU General Public -// License as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, contact Novell, Inc. -// -// To contact Novell about this file by physical or electronic mail, -// you may find current contact information at www.novell.com -// -// $Id: frset.cpp 12329 2006-01-20 17:49:30 -0700 (Fri, 20 Jan 2006) ahodgkinson $ -//------------------------------------------------------------------------- - -#include "flaimsys.h" - -/* -** Sorting Result Sets: -** - New algorithm 7/2/97. This is a good one! - Below are refinements to the existing result set code. - - 1) We now have two files that are used in the merge-sort process. - The first file is used to hold all of the blocks created when - adding entries into the result set. The second file is used for - the first and thereafter odd merge steps. The first file is then - truncated and used for each even merge step. At the end of the - merge one of the files will be deleted. Three buffers are used - during merge and only one will remain after the merge is done. - This is safer than the previous method and uses a little less - disk space. There are many small improvements that can be made. - - 2) The result set code now takes a buffer and a length and has no - knowledge of the data in the result set. In fact, the data may - be fixed length or variable length. We removed the record cache - from the result set and made a record cache manager. - - Future enhancements to consider: - 1) Do a 3, 4 or N-Way merge. - This will greatly increase memory allocations but save a lot of time - reading and writing when the number of entries is large. - 2) Use 3 buffers on the initial load. This is really doing the first - phase of the merge when adding entries. The algorithm would add - entries to two buffers, and when full merge to the third buffer and - write out two sorted buffer. - 3) Don't write out the last block - use it as the first block of the - merge when not complete. This will save a write and read on each - pass. In addition, the I/O cache may be helped out. - In addition, the last block of each phase should be used first - on the next phase. - - Old Notes: - Duplicate Entries: - Duplicate entries are very difficult for a general purpose sorter - to find. In some cases the user would want to compare only these - fields and not these to determine a duplicate. This result set - code lets the user pass in a callback routine to determine if - two entries are the same and if one should be dropped. The user - could pass in NULL to cause all duplicates to be retained. - Quick Sort Algorithm: - This algorithm, in FRSETBLK.CPP is a great algorithm that Scott - came up with. It will recurse only Log(base2)N times (number of - bits needed to represent N). This is a breakthrough because - all sorting algorithms I have seen will recurse N-1 times if - the data is in order or in reverse order. This will crash the - stack for a production quality sort. - Variable Length - This sorting engine (result set) supports variable length and - fixed length data. There is very low overhead for variable - length support. This sorting engine can be used for a variety - of tasks. - - Example: - - All numbers are logical block numbers. - - Adding Pass 1 Pass2 Pass3 Pass4 - Phase File 2 File 1 File 2 File 1 - File 1 (created) (truncated) (truncated) (truncated) - ========= ========= ========= =========== ==================== - 1 10 (1+2) 14 (10+11) 16 (14+15) 17 Final file (16+9) - 2 - 3 11 (3+4) 15 (12+13) 9 - 4 - 5 12 (5+6) 9 - 6 - 7 13 (7+8) - 8 - 9 9 -*/ - -/***************************************************************************** -***** -** Setup/Shutdown Routines -***** -*****************************************************************************/ - -FResultSet::FResultSet() -{ - // Let's just initialize all member variables. - - m_fnCompare = NULL; // Setup - m_UserValue = (void *) 0; // Setup - m_fnCallback = NULL; - m_CallbackInfo.UserValue = (void *)0; - m_CallbackInfo.ui64EstTotalUnits = 0; - m_CallbackInfo.ui64UnitsDone = 0; - - m_uiEntrySize = 0; - m_ui64TotalEntries = 0; - m_pCurRSBlk = m_pFirstRSBlk = m_pLastRSBlk = NULL; - - f_memset( m_szDefaultPath, 0, F_PATH_MAX_SIZE); - m_pBlockBuf1 = m_pBlockBuf2 = m_pBlockBuf3 = NULL; - m_uiBlockBuf1Len = 0; - m_bFile1Opened = m_bFile2Opened = FALSE; - m_pFileHdl641 = m_pFileHdl642 = NULL; - m_bOutput2ndFile = FALSE; - m_bInitialAdding = TRUE; - m_bFinalizeCalled = FALSE; - m_bSetupCalled = FALSE; -} - - -FResultSet::~FResultSet() -{ - FResultSetBlk *pCurRSBlk; - FResultSetBlk *pNextRSBlk; - - // Free up the result set block chain. - - for( pCurRSBlk = m_pFirstRSBlk; pCurRSBlk; pCurRSBlk = pNextRSBlk ) - { - FLMUINT uiCount; - - pNextRSBlk = pCurRSBlk->GetNext(); - uiCount = pCurRSBlk->Release(); - flmAssert( uiCount == 0); - } - // Set list to NULL for debugging in memory. - m_pFirstRSBlk = m_pLastRSBlk = m_pCurRSBlk = NULL; - - // Free up all of the block buffers in the list. - - f_free( &m_pBlockBuf1); - f_free( &m_pBlockBuf2); - f_free( &m_pBlockBuf3); - - // Close all opened files - - CloseFile( &m_pFileHdl641 ); - CloseFile( &m_pFileHdl642 ); -} - - -/**************************************************************************** -Public: reset -Desc: Reset the result set so it can be reused. -****************************************************************************/ -RCODE FResultSet::reset( void) -{ - RCODE rc = FERR_OK; - FResultSetBlk * pCurRSBlk; - FResultSetBlk * pNextRSBlk; - - // Free up the result set block chain - except for the first one. - - for( pCurRSBlk = m_pFirstRSBlk; pCurRSBlk; pCurRSBlk = pNextRSBlk ) - { - FLMUINT uiCount; - - pNextRSBlk = pCurRSBlk->GetNext(); - if (pCurRSBlk != m_pFirstRSBlk) - { - uiCount = pCurRSBlk->Release(); - flmAssert( uiCount == 0); - } - } - - // Free up all of the block buffers in the list, except for the first one. - - f_free( &m_pBlockBuf2); - f_free( &m_pBlockBuf3); - - // We want a buffer that is at least RSBLK_BLOCK_SIZE. - - if (!m_pBlockBuf1 || m_uiBlockBuf1Len < RSBLK_BLOCK_SIZE) - { - if (m_pBlockBuf1) - { - f_free( &m_pBlockBuf1); - } - if( RC_BAD( rc = f_calloc( RSBLK_BLOCK_SIZE, &m_pBlockBuf1))) - { - goto Exit; - } - m_uiBlockBuf1Len = RSBLK_BLOCK_SIZE; - } - - // Close all opened files - - CloseFile( &m_pFileHdl641 ); - CloseFile( &m_pFileHdl642 ); - m_bFile1Opened = m_bFile2Opened = FALSE; - m_pFileHdl641 = m_pFileHdl642 = NULL; - - // Reset some other variables - - m_fnCallback = NULL; - m_CallbackInfo.UserValue = (void *)0; - m_CallbackInfo.ui64EstTotalUnits = 0; - m_CallbackInfo.ui64UnitsDone = 0; - m_ui64TotalEntries = 0; - m_bOutput2ndFile = FALSE; - m_bInitialAdding = TRUE; - m_bEntriesInOrder = m_bAppAddsInOrder; - m_bFinalizeCalled = FALSE; - - // If we don't have a block, allocate it. Otherwise - // reset the one we have left. - - if (!m_pFirstRSBlk) - { - if ((m_pFirstRSBlk = f_new FResultSetBlk) == NULL) - { - rc = RC_SET( FERR_MEM); - goto Exit; - } - } - else - { - m_pFirstRSBlk->reset(); - } - m_pLastRSBlk = m_pCurRSBlk = m_pFirstRSBlk; - - (void)m_pFirstRSBlk->Setup( &m_pFileHdl641, m_fnCompare, m_UserValue, - m_uiEntrySize, RSBLK_IS_FIRST_IN_LIST, m_bDropDuplicates, - m_bEntriesInOrder); - (void) m_pFirstRSBlk->SetBuffer( m_pBlockBuf1, m_uiBlockBuf1Len); -Exit: - return( rc); -} - - -/**************************************************************************** -Public: Setup -Desc: Setup the result set with all of the needed input values. - This method must only be called once. -Ret: FERR_OK - Created FERR_OKfully - WERR_MEM - Allocation error -Notes: Handles all error conditions. -****************************************************************************/ - -RCODE FResultSet::Setup( - const char * pszIoPath, - RSET_COMPARE_FUNC_p fnCompare, - void * UserValue, - FLMUINT uiEntrySize, - FLMBOOL bDropDuplicates, - FLMBOOL bEntriesInOrder) -{ - RCODE rc = FERR_OK; - FLMBOOL bNewBlock = FALSE; - FLMBOOL bNewBuffer = FALSE; - - flmAssert( !m_bSetupCalled ); - flmAssert( uiEntrySize <= MAX_FIXED_ENTRY_SIZE ); - - // Perform all of the allocations first. - - m_pFirstRSBlk = m_pLastRSBlk = m_pCurRSBlk = f_new FResultSetBlk; - - // Allocation Error? - - if( ! m_pCurRSBlk ) - { - rc = RC_SET( FERR_MEM ); - goto Exit; - } - bNewBlock = TRUE; - m_pCurRSBlk->Setup( &m_pFileHdl641, fnCompare, UserValue, - uiEntrySize, RSBLK_IS_FIRST_IN_LIST, bDropDuplicates, bEntriesInOrder ); - - // Allocate only the first buffer - other buffers only used in merge. - - if( RC_BAD( rc = f_calloc( RSBLK_BLOCK_SIZE, &m_pBlockBuf1))) - goto Exit; - m_uiBlockBuf1Len = RSBLK_BLOCK_SIZE; - bNewBuffer = TRUE; - (void) m_pCurRSBlk->SetBuffer( m_pBlockBuf1); - - // Set the input variables. - - if( pszIoPath) - { - f_strcpy( m_szDefaultPath, pszIoPath); - } - - m_fnCompare = fnCompare; - m_UserValue = UserValue; - m_uiEntrySize = uiEntrySize; - m_bDropDuplicates = bDropDuplicates; - m_bEntriesInOrder = m_bAppAddsInOrder = bEntriesInOrder; - -Exit: - - // Free allocations on any error - - if( RC_BAD(rc)) - { - if( bNewBlock) - { - m_pCurRSBlk->Release(); - m_pFirstRSBlk = m_pLastRSBlk = m_pCurRSBlk = NULL; - } - if( bNewBuffer) - { - f_free( &m_pBlockBuf1); - m_uiBlockBuf1Len = 0; - } - } - else - { - m_bSetupCalled = TRUE; - } - return( rc); -} - - -/***************************************************************************** -***** -** Methods for Building a Result Set -***** -*****************************************************************************/ - -/**************************************************************************** -Public: AddEntry -Desc: Interface to add a variable length entry to the result set. -Ret: RCODE - I/O error -Notes: Public method used by application and by the internal sort - and merge steps during finalize. The user must never add an - entry that is larger than the block size. -****************************************************************************/ - -RCODE FResultSet::AddEntry( - void * pEntry, - FLMUINT uiEntryLength) // If zero then entry is fixed length -{ - RCODE rc; - - flmAssert( m_bSetupCalled ); - flmAssert( !m_bFinalizeCalled ); - - rc = m_pCurRSBlk->AddEntry( (FLMBYTE *) pEntry, uiEntryLength ); - - if( rc == FERR_EOF_HIT ) // Current block is full. - { - FResultSetBlk * pNextRSBlk; - F_64BitFileHandle ** ppFileHdl64; - - if( m_bInitialAdding && !m_bFile1Opened ) - { - // Need to create and open the output file? - // In a merge we may be working on the 2nd file and NOT the 1st. - // There just isn't a better place to open the 1st file. - - if( RC_BAD(rc = OpenFile( &m_pFileHdl641 ))) - goto Exit; - } - ppFileHdl64 = ( m_bOutput2ndFile ) ? &m_pFileHdl642 : &m_pFileHdl641; - - // Always flush to disk (TRUE) from here. - - if( RC_BAD( rc = m_pCurRSBlk->Flush( m_bInitialAdding, TRUE ))) - goto Exit; - (void) m_pCurRSBlk->SetBuffer( NULL ); - - // Adding the current block is complete so allocate a new - // block object and link it into the list. - // We must continue to use this same block buffer. - - // Allocate a new RSBlk and link into the result block list. - - pNextRSBlk = f_new FResultSetBlk; - if( ! pNextRSBlk ) - { - rc = RC_SET( FERR_MEM ); - goto Exit; - } - m_pCurRSBlk->SetNext( pNextRSBlk ); - pNextRSBlk->SetPrev( m_pCurRSBlk ); - m_pLastRSBlk = m_pCurRSBlk = pNextRSBlk; - m_pCurRSBlk->Setup( ppFileHdl64, m_fnCompare, - m_UserValue, m_uiEntrySize, m_bInitialAdding, m_bDropDuplicates, - !m_bInitialAdding ); - - // Reset all of the buffer pointers and values. - - (void) m_pCurRSBlk->SetBuffer( m_pBlockBuf1 ); - - // Make the callback only during the merge phase. - - if( !m_bInitialAdding && m_fnCallback ) - { - if( m_CallbackInfo.ui64EstTotalUnits <= - ++m_CallbackInfo.ui64UnitsDone ) - { - m_CallbackInfo.ui64EstTotalUnits = - m_CallbackInfo.ui64UnitsDone; - } - (void) m_fnCallback( &m_CallbackInfo ); - } - - // Add the entry again. This call should never fail because of space. - // If it does fail then the entry is larger than the buffer size. - - if( RC_BAD( rc = m_pCurRSBlk->AddEntry( (FLMBYTE *) pEntry, uiEntryLength ))) - { - if( rc == FERR_EOF_HIT ) - { - flmAssert( FALSE ); // Force assert for testing - rc = RC_SET( FERR_FAILURE ); - } - goto Exit; - } - } -Exit: - return( rc); -} - -/**************************************************************************** -Public: Finalize -Desc: Done adding entries. Sort all of the entries and perform a merge. -Ret: WERR_OK -Notes: This algorithm is tricky and there are many variations that we - could make to it. We have tried a lot of variations. In the - future this method may be replaced by CreateIterator(). -Caution: On any error the result set is in a bad state and should be dumped. -****************************************************************************/ - -RCODE FResultSet::Finalize( - FLMUINT64 * pui64TotalEntries) // (OUT) Returns total number of entries. -{ - RCODE rc = FERR_OK; - FLMBOOL bMergeSort; - - // Avoid being called more than once. - flmAssert( !m_bFinalizeCalled); - flmAssert( m_bSetupCalled ); - - // Not a bug - but for future possibilities just check - // if there is more than one block and if so then - // the while() loop merge sort needs to be called. - - bMergeSort = (m_pFirstRSBlk != m_pLastRSBlk) ? TRUE : FALSE; - - // Force the write to disk if bMergeSort is TRUE. - - if( RC_BAD(rc = m_pCurRSBlk->Finalize( bMergeSort ))) - goto Exit; - - m_bInitialAdding = FALSE; - - // If the entries are in order fixup the block chain and we are done. - if( m_bEntriesInOrder ) - { - FResultSetBlk * pBlk; - - if( NumberOfBlockChains() > (FLMUINT64)1 ) - { - // Entries already in order - need to fixup the blocks. - for( pBlk = m_pFirstRSBlk; pBlk; pBlk = pBlk->GetNext() ) - { - pBlk->SetFirstInChain( FALSE); - pBlk->SetLastInChain( FALSE ); - } - m_pFirstRSBlk->SetFirstInChain( TRUE ); - m_pLastRSBlk->SetLastInChain( TRUE ); - m_pCurRSBlk = NULL; - } - goto Exit; - } - - // Compute total number of blocks. - - if( m_fnCallback) - { - // Estimate total number of unit blocks to be written. - FLMUINT64 ui64Units = NumberOfBlockChains(); - FLMUINT64 ui64Loops; - - m_CallbackInfo.ui64EstTotalUnits = 0; - for( ui64Loops = ui64Units; ui64Loops > (FLMUINT64)1; - ui64Loops = (ui64Loops + (FLMUINT64)1) / (FLMUINT64)2 ) - { - m_CallbackInfo.ui64EstTotalUnits += ui64Units; - } - } - - // Do the merge sort. - // Keep looping until we have only one block in the result set list. - - while( NumberOfBlockChains() > (FLMUINT64)1) - { - // Allocate two more buffers. Merge will open the 2nd file. - // Exit will free these allocations and close one of the files. - - // Are the 2nd and 3rd buffers allocated? - - if( !m_pBlockBuf2) - { - if( RC_BAD( rc = f_calloc( RSBLK_BLOCK_SIZE, &m_pBlockBuf2))) - goto Exit; - } - if( !m_pBlockBuf3) - { - if( RC_BAD( rc = f_calloc( RSBLK_BLOCK_SIZE, &m_pBlockBuf3))) - goto Exit; - } - // Swap which file is selected as the output file. - - m_bOutput2ndFile = m_bOutput2ndFile ? FALSE : TRUE; - - // Here is the magical call that does all of the work! - - if( RC_BAD( rc = MergeSort())) - goto Exit; - } - -Exit: - - // If we did a merge sort of multiple blocks then - // free the first and second buffers and close one of the files. - - if( RC_BAD(rc)) - { - f_free( &m_pBlockBuf1); - m_uiBlockBuf1Len = 0; - } - f_free( &m_pBlockBuf2); - f_free( &m_pBlockBuf3); - - // Close the non-output opened file. Close both on error. - - // If m_bFile2Opened then we did a merge - close one file - - if( m_bFile2Opened || RC_BAD(rc)) - { - if( m_bOutput2ndFile || RC_BAD(rc) ) - { - if( m_bFile1Opened ) - { - m_pFileHdl641->Close( TRUE); - m_bFile1Opened = FALSE; - } - if (m_pFileHdl641) - { - m_pFileHdl641->Release(); - m_pFileHdl641 = NULL; - } - } - if( !m_bOutput2ndFile || RC_BAD(rc) ) - { - if( m_bFile2Opened ) - { - m_pFileHdl642->Close( TRUE); - m_bFile2Opened = FALSE; - } - - if (m_pFileHdl642) - { - m_pFileHdl642->Release(); - m_pFileHdl642 = NULL; - } - } - } - - if( RC_OK(rc)) - { - FLMUINT uiPos; - FResultSetBlk * pRSBlk; - - m_bFinalizeCalled = TRUE; // Used for asserts. - m_bEntriesInOrder = TRUE; - - m_ui64TotalEntries = GetTotalEntries(); - - // Set the return value for total entries. - - if( pui64TotalEntries) - { - *pui64TotalEntries = m_ui64TotalEntries; - } - - if( !m_ui64TotalEntries) - { - if( m_pCurRSBlk ) - m_pCurRSBlk->Release(); - m_pCurRSBlk = m_pFirstRSBlk = m_pLastRSBlk = NULL; - f_free( &m_pBlockBuf1); - m_uiBlockBuf1Len = 0; - } - - // Set the uiBlkEntryPosition values in each block. - - for( uiPos = 0, pRSBlk = m_pFirstRSBlk; - pRSBlk; - pRSBlk = pRSBlk->GetNext() ) - { - pRSBlk->SetInitialPosition( uiPos ); - uiPos += pRSBlk->GetNumberOfEntries(); - } - - // Resize the buffer to save space if only one block & in memory. - if( (m_pFirstRSBlk == m_pLastRSBlk) && m_pCurRSBlk ) - { - FLMBYTE * pNewBlk; - FLMUINT uiLen = m_pCurRSBlk->BytesUsedInBuffer(); - - if (uiLen != m_uiBlockBuf1Len) - { - rc = f_alloc( uiLen, &pNewBlk); - if( RC_OK(rc)) - { - f_memcpy( pNewBlk, m_pBlockBuf1, uiLen); - f_free( &m_pBlockBuf1); - m_pBlockBuf1 = pNewBlk; - m_uiBlockBuf1Len = uiLen; - } - } - - // Need to always do the SetBuffer, because it causes the - // result set to get positioned. - - if (RC_OK( rc)) - { - rc = m_pCurRSBlk->SetBuffer( m_pBlockBuf1, uiLen); - } - } - } - // else on error finalize leaves the block list in an awful state. - - return( rc); -} - -/**************************************************************************** -Desc: Perform a Merge Sort on a list of result set blocks. This new - algorithm uses two files for the sort. The end result may - be one of the two files. At the end of the sort all old result set - block objects will be freed and only one result set block object - will be left. This RSBlk object will be used for reading the - entries. At this point there are at least 'N' result set block - objects that will be merged into ('N'/2) block objects. -****************************************************************************/ -RCODE FResultSet::MergeSort() -{ - RCODE rc = FERR_OK; - FResultSetBlk * pBlkList = NULL, - * pTempBlk, - * pLeftBlk, - * pRightBlk; - F_64BitFileHandle ** ppFileHdl64; - - // Set output file and truncate it. - - // OpenFilex() Closes and creats a new file. - // This is prefered over truncating the file because - // if a database gets truncated we will be blamed. - - rc = (m_bOutput2ndFile) - ? OpenFile( &m_pFileHdl642) - : OpenFile( &m_pFileHdl641); - if( RC_BAD( rc)) - { - flmAssert( 0); - goto Exit; - } - - ppFileHdl64 = ( m_bOutput2ndFile ) ? &m_pFileHdl642 : &m_pFileHdl641; - - // Get the list to the RS blocks - pBlkList = m_pFirstRSBlk; - - // Form an empty list to build. - m_pFirstRSBlk = m_pLastRSBlk = m_pCurRSBlk = NULL; - - // Read and UNION one or two blocks at a time getting rid of duplicates. - // Reading the entries when performing a union of only one block - // is a lot of work for nothing - but it simplifies the code. - - pTempBlk = pBlkList; - while( pTempBlk ) - { - pLeftBlk = pTempBlk; - pRightBlk = pTempBlk->GetNext(); // May be NULL so watch out! - while( pRightBlk && (!pRightBlk->IsFirstInChain()) ) - { - pRightBlk = pRightBlk->GetNext(); - } - // Allocate a new result set block list and link into the new list. - - m_pCurRSBlk = f_new FResultSetBlk; - if( ! m_pCurRSBlk ) - { - rc = RC_SET( FERR_MEM ); - goto Exit; - } - if( ! m_pLastRSBlk ) // First Time? - { - m_pFirstRSBlk = m_pLastRSBlk = m_pCurRSBlk; - } - else - { - m_pLastRSBlk->SetNext( m_pCurRSBlk ); - m_pCurRSBlk->SetPrev( m_pLastRSBlk); - m_pLastRSBlk = m_pCurRSBlk; - } - m_pCurRSBlk->Setup( ppFileHdl64, m_fnCompare, m_UserValue, - m_uiEntrySize, RSBLK_IS_FIRST_IN_LIST, m_bDropDuplicates, - RSBLK_ENTRIES_IN_ORDER ); - - // Output to block buffer 1 - (void) m_pCurRSBlk->SetBuffer( m_pBlockBuf1 ); - if( RC_BAD( rc = pLeftBlk->SetBuffer( m_pBlockBuf2 ))) - goto Exit; - if( pRightBlk) - { - if( RC_BAD( rc = pRightBlk->SetBuffer( m_pBlockBuf3 ))) - goto Exit; - } - - // pRightBlk may be NULL - will move left block to output. - // Output leftBlk and rightBlk to the output block (m_pCurRSBlk) - - if( RC_BAD(rc = UnionBlkLists( pLeftBlk, pRightBlk ))) - goto Exit; - - // Setup for the next loop. - pTempBlk = pRightBlk ? pRightBlk->GetNext() : NULL; - while( pTempBlk && (!pTempBlk->IsFirstInChain()) ) - { - pTempBlk = pTempBlk->GetNext(); - } - } -Exit: - - // Free the working block list. - pTempBlk = pBlkList; - while( pTempBlk ) - { - FLMUINT uiTemp; - - pRightBlk = pTempBlk->GetNext(); - uiTemp = pTempBlk->Release(); - flmAssert( uiTemp == 0); - pTempBlk = pRightBlk; - } - - return( rc); -} - - -/***************************************************************************** -***** -** Reading Result Set Entries -***** -*****************************************************************************/ - - -/**************************************************************************** -Public: GetCurrent -Desc: Return the Current entry reference in the result set. -Ret: FERR_OK - Returned the current recRef[]. - FERR_CONV_DEST_OVERFLOW - buffer is not big enough for data - FERR_NOT_FOUND - Not positioned anywhere in the result set. - FERR_EOF_HIT - Positioned past the last entry - FERR_BOF_HIT - Positioned before the first entry. -****************************************************************************/ - -RCODE FResultSet::GetCurrent( - void * vpBuffer, - FLMUINT uiBufferLength, - FLMUINT * puiReturnLength) -{ - RCODE rc; - - flmAssert( m_bFinalizeCalled ); - - if( !m_pCurRSBlk ) - { - rc = RC_SET( FERR_NOT_FOUND ); - } - else - { - rc = m_pCurRSBlk->GetCurrent( (FLMBYTE *) vpBuffer, uiBufferLength, - puiReturnLength ); - } - return( rc); -} - -/**************************************************************************** -Public: GetNext -Desc: Return the next reference in the result set. If the result set - is not positioned then the first entry will be returned. - -Ret: FERR_OK - Returned the current recRef[]. - FERR_CONV_DEST_OVERFLOW - buffer is not big enough for data - FERR_EOF_HIT - Positioned past the last entry -****************************************************************************/ - -RCODE FResultSet::GetNext( - void * vpBuffer, - FLMUINT uiBufferLength, - FLMUINT * puiReturnLength) -{ - RCODE rc; - - flmAssert( m_bFinalizeCalled ); - - // Make sure we are positioned to a block. - if( ! m_pCurRSBlk ) - { - m_pCurRSBlk = m_pFirstRSBlk; - if( ! m_pCurRSBlk ) - { - rc = RC_SET( FERR_EOF_HIT ); - goto Exit; - } - if( RC_BAD( rc = m_pCurRSBlk->SetBuffer( m_pBlockBuf1 ))) - goto Exit; - } - - rc = m_pCurRSBlk->GetNext( (FLMBYTE *) vpBuffer, uiBufferLength, - puiReturnLength ); - - // Position to the next block? - if( rc == FERR_EOF_HIT ) - { - if( m_pCurRSBlk->GetNext() != NULL ) - { - m_pCurRSBlk->SetBuffer( NULL ); - m_pCurRSBlk = m_pCurRSBlk->GetNext(); - if( RC_BAD( rc= m_pCurRSBlk->SetBuffer( m_pBlockBuf1 ))) - goto Exit; - if( RC_BAD( rc = m_pCurRSBlk->GetNext( (FLMBYTE *) vpBuffer, uiBufferLength, - puiReturnLength ))) - goto Exit; - } - } -Exit: - return( rc); -} - -/**************************************************************************** -Public: GetPrev -Desc: Return the previous reference in the result set. If the result set - is not positioned then the last entry will be returned. - -Ret: FERR_OK - Returned the current recRef[]. - FERR_CONV_DEST_OVERFLOW - buffer is not big enough for data - FERR_BOF_HIT - Positioned before the first entry -****************************************************************************/ - -RCODE FResultSet::GetPrev( - void * vpBuffer, - FLMUINT uiBufferLength, - FLMUINT * puiReturnLength) -{ - RCODE rc; - - flmAssert( m_bFinalizeCalled ); - - // Make sure we are positioned to a block. - if( !m_pCurRSBlk ) - { - m_pCurRSBlk = m_pLastRSBlk; - if( ! m_pCurRSBlk ) - { - rc = RC_SET( FERR_BOF_HIT ); - goto Exit; - } - if( RC_BAD( rc = m_pCurRSBlk->SetBuffer( m_pBlockBuf1 ))) - goto Exit; - } - - rc = m_pCurRSBlk->GetPrev( (FLMBYTE *) vpBuffer, uiBufferLength, - puiReturnLength ); - - // Position to the previous block? - if( rc == FERR_BOF_HIT ) - { - if( m_pCurRSBlk->GetPrev() != NULL ) - { - m_pCurRSBlk->SetBuffer( NULL ); - m_pCurRSBlk = m_pCurRSBlk->GetPrev(); - if( RC_BAD( rc = m_pCurRSBlk->SetBuffer( m_pBlockBuf1 ))) - goto Exit; - rc = m_pCurRSBlk->GetPrev( (FLMBYTE *) vpBuffer, uiBufferLength, - puiReturnLength ); - if( RC_BAD(rc)) - goto Exit; - } - } -Exit: - return( rc); -} - -/**************************************************************************** -Public: GetFirst -Desc: Return the first reference in the result set. -Ret: FERR_OK - Returned the current recRef[]. - FERR_CONV_DEST_OVERFLOW - buffer is not big enough for data - FERR_NOT_FOUND - zero records in the result set. -****************************************************************************/ - -RCODE FResultSet::GetFirst( - void * vpBuffer, - FLMUINT uiBufferLength, - FLMUINT * puiReturnLength) -{ - RCODE rc; - - flmAssert( m_bFinalizeCalled ); - - if( m_pCurRSBlk != m_pFirstRSBlk ) - { - if( m_pCurRSBlk) - m_pCurRSBlk->SetBuffer( NULL ); - m_pCurRSBlk = m_pFirstRSBlk; - if( RC_BAD( rc = m_pCurRSBlk->SetBuffer( m_pBlockBuf1 ))) - goto Exit; - } - else if( ! m_pCurRSBlk ) - { - rc = RC_SET( FERR_NOT_FOUND ); - goto Exit; - } - - rc = m_pCurRSBlk->GetNext( (FLMBYTE *) vpBuffer, uiBufferLength, - puiReturnLength ); -Exit: - return( rc); -} - -/**************************************************************************** -Public: GetLast -Desc: Return the last reference in the result set. -Ret: FERR_OK - Returned the current recRef[]. - FERR_CONV_DEST_OVERFLOW - buffer is not big enough for data - FERR_NOT_FOUND - zero records in the result set. -****************************************************************************/ - -RCODE FResultSet::GetLast( - void * vpBuffer, - FLMUINT uiBufferLength, - FLMUINT * puiReturnLength) -{ - RCODE rc; - - flmAssert( m_bFinalizeCalled ); - - if( m_pCurRSBlk != m_pLastRSBlk ) - { - if( m_pCurRSBlk) - m_pCurRSBlk->SetBuffer( NULL ); - m_pCurRSBlk = m_pLastRSBlk; - if( RC_BAD(rc = m_pCurRSBlk->SetBuffer( m_pBlockBuf1 ))) - goto Exit; - } - else if( ! m_pCurRSBlk ) - { - rc = RC_SET( FERR_EOF_HIT ); - goto Exit; - } - - rc = m_pCurRSBlk->GetPrev( (FLMBYTE *) vpBuffer, uiBufferLength, - puiReturnLength ); -Exit: - return( rc); -} - -/**************************************************************************** -Public: FindMatch -Desc: Find the matching entry in the result set using the compare routine. - This does a binary search on the list of blocks. -Ret: FERR_OK - Returned OK - FERR_NOT_FOUND - match not found -****************************************************************************/ - -RCODE FResultSet::FindMatch( // Find and return an etnry that - // matches in the result set (variable). - void * vpMatchEntry, // Entry to match - FLMUINT uiMatchEntryLength, // Variable length of above entry - void * vpFoundEntry, // (out) Entry to return - FLMUINT * puiFoundEntryLength, // (out) Length of entry returned - RSET_COMPARE_FUNC_p // Record compare function. - fnCompare, // Returns (FLMINT) -1, 0 or 1 values. - void * UserValue) // UserValue for callback. -{ - RCODE rc; - FLMINT iBlkCompare; // RS_EQUALS if key is/would be in block. - FResultSetBlk *pLowBlk; // Used for locating block. - FResultSetBlk *pHighBlk; // Low and High are exclusive. - - flmAssert( m_bFinalizeCalled ); - - // If not positioned anywhere, position to the midpoint. - // Otherwise, start on the current block we are on. - if( ! m_pCurRSBlk ) - { - if( ! m_pFirstRSBlk ) // Will be null if no entries. - { - rc = RC_SET( FERR_NOT_FOUND ); - goto Exit; - } - if( m_pFirstRSBlk == m_pLastRSBlk ) - m_pCurRSBlk = m_pFirstRSBlk; - else - { - m_pCurRSBlk = SelectMidpoint( m_pFirstRSBlk, m_pLastRSBlk, FALSE ); - } - if( RC_BAD( rc = m_pCurRSBlk->SetBuffer( m_pBlockBuf1 ))) - goto Exit; - } - - // Set the exclusive low block and high block. - - pLowBlk = m_pFirstRSBlk; - pHighBlk = m_pLastRSBlk; - - // Loop until the correct block is found. - - for(;;) - { - // Two return value returned: rc and iBlkCompare. - // blk->FindMatch returns FERR_OK if the entry if found in the block. - // returns FERR_NOT_FOUND if not found in the block. - // uiCompare returns RS_EQUALS if entry would be within the block. - // otherwise RS_LESS_THAN if previous blocks should be checked - // and RS_GREATER_THAN if next blocks should be checked. - - rc = m_pCurRSBlk->FindMatch( - (FLMBYTE *) vpMatchEntry, uiMatchEntryLength, - (FLMBYTE *) vpFoundEntry, puiFoundEntryLength, - fnCompare, UserValue, - &iBlkCompare ); - // Found match or should key be within the block. - if( RC_OK(rc) || (RS_EQUALS == iBlkCompare )) - { - goto Exit; - } - if( RS_LESS_THAN == iBlkCompare ) - { - if( m_pCurRSBlk == pLowBlk ) // done if the low block - goto Exit; // keep FERR_NOT_FOUND value - - pHighBlk = m_pCurRSBlk->GetPrev();// Set the new high block - } - else // RS_GREATER_THAN == iBlkCompare - { - if( m_pCurRSBlk == pHighBlk ) // done if we are at the high block - goto Exit; // keep FERR_NOT_FOUND value - - pLowBlk = m_pCurRSBlk->GetNext(); - } - if( RC_BAD( rc = m_pCurRSBlk->SetBuffer( NULL ))) - goto Exit; - - m_pCurRSBlk = SelectMidpoint( pLowBlk, pHighBlk, FALSE ); - - // GWBUG 46817 - need to set the working buffer. - - if( RC_BAD( rc = m_pCurRSBlk->SetBuffer( m_pBlockBuf1 ))) - goto Exit; - } -Exit: - return( rc); -} - - -/**************************************************************************** -Desc: Select the midpoint between two different blocks in a list. - Entries should not be the same value. -****************************************************************************/ - -FResultSetBlk * FResultSet::SelectMidpoint( - FResultSetBlk *pLowBlk, - FResultSetBlk *pHighBlk, - FLMBOOL bPickHighIfNeighbors) -{ - int siCount; - FResultSetBlk *pTempBlk; - - // If the same then return. - - if( pLowBlk == pHighBlk ) - { - pTempBlk = pLowBlk; - goto Exit; - } - - // Check if neighbors and use the boolean flag. - - if( pLowBlk->GetNext() == pHighBlk) - { - if( bPickHighIfNeighbors ) - pTempBlk = pHighBlk; - else - pTempBlk = pLowBlk; - goto Exit; - } - - // Count the total blocks exclusive between low and high and add one. - // Check pTempBlk against null to not crash. - - for( pTempBlk = pLowBlk, siCount = 1; - pTempBlk && (pTempBlk != pHighBlk ); - siCount++ ) - { - pTempBlk = pTempBlk->GetNext(); - } - - // Check for implementation error - pTempBlk is NULL and handle. - - flmAssert( NULL != pTempBlk ); - if( ! pTempBlk ) // on error - { - pTempBlk = pLowBlk; // Just position to low block to be safe. - goto Exit; - } - - // Loop to the middle item. - siCount = siCount >> 1; // Divide by two. - for( pTempBlk = pLowBlk; siCount > 0; siCount-- ) - { - pTempBlk = pTempBlk->GetNext(); - } -Exit: - return pTempBlk; -} - -/**************************************************************************** -Public: SetPosition -Desc: Set the current entry position. -In: uiPosition - Zero based position value or RS_POSITION_NOT_SET - to set back to the beginning or end. -Ret: FERR_OK - Returned OK - FERR_EOF_HIT - Positioned to the end of the result set. -****************************************************************************/ - -RCODE FResultSet::SetPosition( - FLMUINT uiPosition) -{ - RCODE rc = FERR_OK; - FResultSetBlk * pInitialBlk = m_pCurRSBlk; - - flmAssert( m_bFinalizeCalled ); - - if( uiPosition == RS_POSITION_NOT_SET ) - { - // GWBUG 46817 - set out of focus. - if( m_pCurRSBlk ) - { - if( RC_BAD( rc = m_pCurRSBlk->SetBuffer( NULL ))) - goto Exit; - } - m_pCurRSBlk = NULL; - goto Exit; - } - // else position to the correct block that holds uiPosition. - - - if( !m_pCurRSBlk ) - { - m_pCurRSBlk = m_pFirstRSBlk; - } - // Check for empty result set. - if( !m_pCurRSBlk ) - { - rc = RC_SET( FERR_EOF_HIT ); - goto Exit; - } - - if( uiPosition < m_pCurRSBlk->GetInitialPosition() ) - { - // Go backwards looking for the correct block. - - do - { - m_pCurRSBlk = m_pCurRSBlk->GetPrev(); - flmAssert( NULL != m_pCurRSBlk ); - } - while( uiPosition < m_pCurRSBlk->GetInitialPosition() ); - } - else if( uiPosition >= - m_pCurRSBlk->GetInitialPosition() + m_pCurRSBlk->GetNumberOfEntries() ) - { - // Go forward looking for the correct block. - - do - { - if( ! m_pCurRSBlk->GetNext() ) - { - // Will set rc to EOF in SetPosition below. - break; - } - m_pCurRSBlk = m_pCurRSBlk->GetNext(); - } - while( uiPosition >= - m_pCurRSBlk->GetInitialPosition() + m_pCurRSBlk->GetNumberOfEntries() ); - } - - // GWBUG 46817 - need working buffer out of focus. - if( pInitialBlk != m_pCurRSBlk ) - { - if( pInitialBlk) - { - if( RC_BAD( rc = pInitialBlk->SetBuffer( NULL ))) - goto Exit; - } - - // GWBUG 46817 - need working buffer into focus. - if( RC_BAD( rc = m_pCurRSBlk->SetBuffer( m_pBlockBuf1 ))) - goto Exit; - } - // Now we are positioned to the correct block. - - rc = m_pCurRSBlk->SetPosition( uiPosition ); - -Exit: - return( rc); -} - -/**************************************************************************** -Desc: Return a pointer to the next entry in the list. -****************************************************************************/ -RCODE FResultSet::GetNextPtr( - FResultSetBlk ** ppCurBlk, - FLMBYTE ** ppBuffer, - FLMUINT * puiReturnLength) -{ - RCODE rc; - FResultSetBlk *pCurBlk = *ppCurBlk; - FResultSetBlk *pNextBlk; - FLMBYTE * pBuffer; - - flmAssert( NULL != pCurBlk ); - - while( RC_BAD( rc = pCurBlk->GetNextPtr( ppBuffer, puiReturnLength))) - { - if( rc == FERR_EOF_HIT ) - { - if( pCurBlk->GetNext()) - { - pNextBlk = pCurBlk->GetNext(); - if( !pNextBlk->IsFirstInChain() ) - { - pBuffer = pCurBlk->GetBuffer(); - pCurBlk->SetBuffer( NULL ); - pCurBlk = pNextBlk; - if( RC_BAD( rc = pCurBlk->SetBuffer( pBuffer ))) - goto Exit; - *ppCurBlk = pCurBlk; - continue; - } - } - } - goto Exit; - } -Exit: - return( rc); -} - -/**************************************************************************** -Desc: Union two block lists into a result output list. This may be - called to union two result sets or to perform the initial merge-sort - on a create result set. - - Performaing an N-way merge would be fast when we have over 10K - of entries. However, the code is more complex. -Notes: Intersection and cross product routines are very similar - to this routine. -****************************************************************************/ -RCODE FResultSet::UnionBlkLists( - FResultSetBlk *pLeftBlk, // (IN) Left block - FResultSetBlk *pRightBlk) // (IN) Right block - may be NULL -{ - RCODE rc = FERR_OK; - FLMBYTE * pLeftEntry, - * pRightEntry; - FLMUINT uiLeftLength, uiRightLength; - - // If no right block then copy all of the items from the left block - // to the output block. We could optimize this in the future. - - if( ! pRightBlk ) - { - rc = CopyRemainingItems( pLeftBlk ); - goto Exit; - } - - // Now the fun begins. Read entries from both lists and union - // while checking the order of the entries. - - - if( RC_BAD(rc = GetNextPtr( &pLeftBlk, &pLeftEntry, &uiLeftLength ))) - { - if( rc == FERR_EOF_HIT ) - { - rc = CopyRemainingItems( pRightBlk ); - } - goto Exit; - } - if( RC_BAD(rc = GetNextPtr( &pRightBlk, &pRightEntry, &uiRightLength ))) - { - if( rc == FERR_EOF_HIT ) - { - rc = CopyRemainingItems( pLeftBlk ); - } - goto Exit; - } - - for(;;) - { - FLMINT iCompare; - if( RC_BAD( rc = m_fnCompare( pLeftEntry, uiLeftLength, - pRightEntry, uiRightLength, - m_UserValue, &iCompare))) - { - goto Exit; - } - - if( iCompare == RS_LESS_THAN ) - { - // Take the left item. - - if( RC_BAD(rc = AddEntry( pLeftEntry, uiLeftLength ))) - goto Exit; - - if( RC_BAD(rc = GetNextPtr( &pLeftBlk, &pLeftEntry, &uiLeftLength ))) - { - if( rc != FERR_EOF_HIT ) - goto Exit; - - if( RC_BAD(rc = AddEntry( pRightEntry, uiRightLength ))) - goto Exit; - - // Left entries are done - read all of the right entries. - - rc = CopyRemainingItems( pRightBlk ); - goto Exit; - } - } - else - { - // If equals then drop the right item and continue comparing left. - // WARNING: Don't try to optimize for equals because when one - // list runs out the remaining duplicate entries must be dropped. - // Continuing to compare the duplicate item is the correct way. - - if( (iCompare == RS_GREATER_THAN) || !m_bDropDuplicates ) - { - // Take the right item. - - if( RC_BAD(rc = AddEntry( pRightEntry, uiRightLength ))) - goto Exit; - } - - if( RC_BAD(rc = GetNextPtr( &pRightBlk, &pRightEntry, &uiRightLength))) - { - if( rc != FERR_EOF_HIT ) - goto Exit; - - if( RC_BAD(rc = AddEntry( pLeftEntry, uiLeftLength ))) - goto Exit; - - // Right entries are done - read all of the left entries. - - rc = CopyRemainingItems( pLeftBlk ); - goto Exit; - } - } - } -Exit: - if( RC_OK(rc)) - { - // Flush out the output entries. - rc = m_pCurRSBlk->Finalize( TRUE ); - m_pCurRSBlk->SetBuffer( NULL ); - m_pCurRSBlk = NULL; - - if( m_fnCallback ) - { - ++m_CallbackInfo.ui64UnitsDone; - (void) m_fnCallback( &m_CallbackInfo ); - } - } - - return( rc); -} - - -/**************************************************************************** -Desc: Copy the remaining items from a block list to the output. -****************************************************************************/ -RCODE FResultSet::CopyRemainingItems( - FResultSetBlk * pCurBlk) -{ - RCODE rc; - FLMBYTE * pEntry; - FLMUINT uiLength; - - while( RC_OK(rc = GetNextPtr( &pCurBlk, &pEntry, &uiLength ))) - { - if( RC_BAD(rc = AddEntry( pEntry, uiLength ))) - goto Exit; - } - if( rc == FERR_EOF_HIT ) - { - rc = FERR_OK; - } -Exit: - return( rc); -} - - -/**************************************************************************** -Desc: Closes and deletes one of two files. -****************************************************************************/ -void FResultSet::CloseFile( - F_64BitFileHandle ** ppFileHdl64) -{ - if( ppFileHdl64 == &m_pFileHdl641) - { - if( m_bFile1Opened) - { - m_pFileHdl641->Close( TRUE); - m_bFile1Opened = FALSE; - } - if (m_pFileHdl641) - { - m_pFileHdl641->Release(); - m_pFileHdl641 = NULL; - } - } - else - { - if( m_bFile2Opened) - { - m_pFileHdl642->Close( TRUE); - m_bFile2Opened = FALSE; - } - if (m_pFileHdl642) - { - m_pFileHdl642->Release(); - m_pFileHdl642 = NULL; - } - } - return; -} - -/**************************************************************************** -Desc: Close the file if previously opened and creates the file. -****************************************************************************/ -RCODE FResultSet::OpenFile( - F_64BitFileHandle ** ppFileHdl64) -{ - RCODE rc = FERR_OK; - FLMBOOL * pbFileOpened; - char * pszIoPath; - - // Will close and delete if opened, else will do nothing. - - CloseFile( ppFileHdl64 ); - - if( ppFileHdl64 == &m_pFileHdl641 ) - { - pbFileOpened = &m_bFile1Opened; - pszIoPath = &m_szFilePath1[ 0]; - } - else - { - pbFileOpened = &m_bFile2Opened; - pszIoPath = &m_szFilePath2[ 0]; - } - - f_strcpy( pszIoPath, m_szDefaultPath); - - if( (*ppFileHdl64 = f_new F_64BitFileHandle) == NULL) - { - rc = RC_SET( FERR_MEM); - goto Exit; - } - - if( RC_BAD( rc = (*ppFileHdl64)->CreateUnique( pszIoPath, "frs"))) - { - (*ppFileHdl64)->Release(); - *ppFileHdl64 = NULL; - goto Exit; - } - - *pbFileOpened = TRUE; - -Exit: - - return( rc); -} diff --git a/flaim/src/frset.h b/flaim/src/frset.h deleted file mode 100644 index 5c42aa1..0000000 --- a/flaim/src/frset.h +++ /dev/null @@ -1,666 +0,0 @@ -//------------------------------------------------------------------------- -// Desc: Result sets - class definitions -// Tabs: 3 -// -// Copyright (c) 1996-2006 Novell, Inc. All Rights Reserved. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of version 2 of the GNU General Public -// License as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, contact Novell, Inc. -// -// To contact Novell about this file by physical or electronic mail, -// you may find current contact information at www.novell.com -// -// $Id: frset.h 12329 2006-01-20 17:49:30 -0700 (Fri, 20 Jan 2006) ahodgkinson $ -//------------------------------------------------------------------------- - -#ifndef FRSET_H -#define FRSET_H - -#include "fpackon.h" -// IMPORTANT NOTE: No other include files should follow this one except -// for fpackoff.h - -// Need forward declaration. - -class FResultSet; -class F_64BitFileHandle; - -/***************************************************************************** -***** -** Definitions -***** -*****************************************************************************/ - -// The default block size can be over 64K for 32-bit machines. -// We have tested a block size over 400K bytes (9/97). -// Three blocks are required during the merge phase if more than -// one block is used in the result set. The block may be resized at finalize. -// 0xE000 == 56K bytes -// 0x6000 = 24K bytes - -#define RSBLK_BLOCK_SIZE 0xE000 - -// Need to allocate on the stack the maximum fixed entry size -// in the recursive quicksort routine. - -#define MAX_FIXED_ENTRY_SIZE 64 - - -// Values to be used with the *piCompare variables in the compare routine. - -#define RS_LESS_THAN (-1) -#define RS_EQUALS (0) -#define RS_GREATER_THAN (1) - - -// Values for udPosition in GetPosition() and SetPosition(). - -#define RS_POSITION_NOT_SET ((FLMUINT)0xFFFFFFFF) - -/***************************************************************************** -***** -** Compare Routines -** The compare routine is used so that the user may specify how to -** sort the entries in the result set. If a non-zero RCODE is -** returned from the compare routine then the error will bubble up -** to the caller of the merge/finalize routine. -***** -*****************************************************************************/ - - -typedef RCODE (* RSET_COMPARE_FUNC_p)( - void * vpData1, - FLMUINT uiLength1, - void * vpData2, - FLMUINT uiLength2, - void * UserValue, - FLMINT * piCompare); - -RCODE FRSDefaultCompare( - void * vpData1, - FLMUINT uiLength1, - void * vpData2, - FLMUINT uiLength2, - void * UserValue, - FLMINT * piCompare); - -/***************************************************************************** -***** -** Callback Function - The callback function is used to callback the application - during the merge process. The merge process can take a long - time if there are millions of entries. The initial value of - udEstTotalUnits may be slightly less than the ending - result of udUnitsDone. -** -***** -*****************************************************************************/ - -typedef struct RSET_CB_INFO -{ - void * UserValue; - FLMUINT64 ui64EstTotalUnits; // Estimated total number of units to do. - FLMUINT64 ui64UnitsDone; // Units completed - -} RSET_CB_INFO; - -typedef FLMINT (* RSET_CB_FUNC_p)( RSET_CB_INFO *); - -/***************************************************************************** -***** -** Forward References -***** -*****************************************************************************/ - -class FResultSet; -class FResultSetBlk; - - -/***************************************************************************** -***** -** Result Set Block Definitions -***** -*****************************************************************************/ - - // Block Size Limits: - // 1) Allows over 64K entries per block providing (int) is 32 bits. - // 2) The block size cannot be over 64K for 16 bit applications. - // A 400K block size has been tested on WIN95(10/97). - // 3) Three blocks are allocated as a maximum during the merge phase. - // Two of these blocks are freed after the merge phase. - // - // Block Layout: - // Block Header Structure - // Variable Length Entries - // An array of [Offset][Length] entry items - // The variable length entries are stored from the end back to front. - // The length of a variable length entry must be less than the block size. - // Fixed Length Entries - // Each entry is stored from the first of the buffer to the last. - // - // - // BLKOFFSET_SIZE cannot be 4 for 16-bit code. Must be 4 if block size > 64K. - // The macros below are in mixed case because they may turn into methods - // if we would want to input the block size in the result set setup call. - // SEE RSBLK_BLOCK_SIZE in frset.h - - #if RSBLK_BLOCK_SIZE <= 0xFFFF - #define BLKOFFSET_SIZE 2 - typedef FLMUINT16 BLKOFFSET; - #define GetOffset(p) ( FB2UW( p)) - #define SetOffset(ofs,p) ( UW2FBA( ofs, p )) - #else - typedef FLMUINT32 BLKOFFSET; - #define BLKOFFSET_SIZE 4 - #define GetOffset(p) ( FB2UD( p)) - #define SetOffset(ofs,p) ( UD2FBA( ofs, p )) - #endif - - #define LENGTH_SIZE 2 - #define GetLength(p) ((FLMUINT)( FB2UW(&(p)[BLKOFFSET_SIZE]))) - #define SetLength(len,p) ( UW2FBA( ((FLMUINT16)len), &(p)[BLKOFFSET_SIZE] )) - - - // Write bytes used to write less than 64K at a time because - // Write and Read only support up to 64K size buffer. - - #define MAX_WRITE_BYTES 0x8000 - -/**************************************************************************** - - Block Header Definition - - Desc: Actually stored as the first section of each block. - We can write this structure because the same process will - read the block header i.e. portability is not a problem. -****************************************************************************/ - -typedef struct FBlockHeader -{ - FLMUINT64 ui64FilePos; // RSBLK_UNSET_FILE_POS or file position - FLMUINT uiEntryCount, // Number of entries in block - uiBlockSize; // Total Block size in memory or on disk - FLMBOOL bFirstBlock, // TRUE=first block in chain - bLastBlock; // TRUE=last block in chain -} FBlockHeader; - -#define RSBLK_UNSET_FILE_POS (~((FLMUINT64)0)) -#define RSBLK_IS_FIRST_IN_LIST TRUE -#define RSBLK_ENTRIES_IN_ORDER TRUE - -/**************************************************************************** -Desc: -****************************************************************************/ -class FResultSetBlk : public F_Base -{ -public: - - FResultSetBlk(); - - virtual ~FResultSetBlk() - { - if( m_pNext) - { - m_pNext->SetPrev( m_pPrev); - } - - if( m_pPrev) - { - m_pPrev->SetNext( m_pNext); - } - } - - void reset( void); - - void Setup( - F_64BitFileHandle ** ppFileHdl64, - RSET_COMPARE_FUNC_p fnCompare, - void * UserValue, - FLMUINT uiEntrySize, - FLMBOOL bFirstInList, - FLMBOOL bDropDuplicates, - FLMBOOL bEntriesInOrder); - - RCODE SetBuffer( - FLMBYTE * pBuffer, - FLMUINT uiBufferSize = RSBLK_BLOCK_SIZE); - - FINLINE FLMBYTE * GetBuffer( void) - { - return m_pBlockBuf; - } - - FINLINE FLMUINT BytesUsedInBuffer( void) - { - if( m_bEntriesInOrder) - { - return( m_BlockHeader.uiBlockSize); - } - else - { - return( m_BlockHeader.uiBlockSize - m_uiLengthRemaining); - } - } - - RCODE AddEntry( - FLMBYTE * pEntry, - FLMUINT uiEntryLength ); - - RCODE ModifyEntry( - FLMBYTE * pEntry, - FLMUINT uiEntryLength = 0); - - FINLINE FLMUINT GetNumberOfEntries( void) - { - return( m_BlockHeader.uiEntryCount); - } - - FINLINE RCODE Finalize( - FLMBOOL bForceWrite) - { - return( Flush( TRUE, bForceWrite)); - } - - RCODE Flush( - FLMBOOL bLastBlockInList, - FLMBOOL bForceWrite); - - FINLINE FResultSetBlk * GetNext( void) - { - return( m_pNext); - } - - FINLINE FResultSetBlk * GetPrev( void) - { - return( m_pPrev); - } - - FINLINE void SetNext( - FResultSetBlk * pRSBlk) - { - m_pNext = pRSBlk; - } - - FINLINE void SetPrev( - FResultSetBlk * pRSBlk ) - { - m_pPrev = pRSBlk; - } - - RCODE GetCurrent( - FLMBYTE * pBuffer, - FLMUINT uiBufferLength, - FLMUINT * puiReturnLength); - - FINLINE RCODE GetNext( - FLMBYTE * pBuffer, - FLMUINT uiBufferLength, - FLMUINT * puiReturnLength) - { - // Are we on the last entry or past the last entry? - - if( m_iEntryPos + 1 >= (FLMINT) m_BlockHeader.uiEntryCount ) - { - m_iEntryPos = (FLMINT) m_BlockHeader.uiEntryCount; - return( RC_SET( FERR_EOF_HIT)); - } - - m_iEntryPos++; - return( CopyCurrentEntry( pBuffer, uiBufferLength, puiReturnLength)); - } - - RCODE GetNextPtr( - FLMBYTE ** ppBuffer, - FLMUINT * puiReturnLength); - - RCODE GetPrev( - FLMBYTE * pBuffer, - FLMUINT uiBufferLength, - FLMUINT * puiReturnLength); - - FINLINE RCODE GetPosition( - FLMUINT * puiPosition) - { - if( !m_bPositioned || (m_iEntryPos == -1) || - (m_iEntryPos == (FLMINT) m_BlockHeader.uiEntryCount)) - { - *puiPosition = RS_POSITION_NOT_SET; - } - else if( puiPosition) - { - *puiPosition = m_uiBlkEntryPosition + m_iEntryPos; - } - - return( FERR_OK); - } - - RCODE SetPosition( - FLMUINT uiPosition); - - RCODE FindMatch( - FLMBYTE * pMatchEntry, - FLMUINT uiMatchEntryLength, - FLMBYTE * pFoundEntry, - FLMUINT * puiFoundEntryLength, - RSET_COMPARE_FUNC_p fnCompare, - void * UserValue, - FLMINT * piCompare); - - FINLINE FLMBOOL IsFirstInChain( void) - { - if( m_BlockHeader.bFirstBlock) - { - return( TRUE); - } - else - { - return( FALSE); - } - } - - FINLINE void SetFirstInChain( - FLMBOOL bIsFirstInChain) - { - m_BlockHeader.bFirstBlock = bIsFirstInChain; - } - - FINLINE void SetLastInChain( - FLMBOOL bIsLastInChain) - { - m_BlockHeader.bLastBlock = bIsLastInChain; - } - - FINLINE FLMUINT GetInitialPosition( void) - { - return( m_uiBlkEntryPosition); - } - - FINLINE void SetInitialPosition( - FLMUINT uiBlkEntryPosition) - { - m_uiBlkEntryPosition = uiBlkEntryPosition; - } - -private: - - RCODE AddEntry( - FLMBYTE * pEntry); - - void SqueezeSpace(); - - RCODE SortAndRemoveDups( void); - - void RemoveEntry( - FLMBYTE * pEntry); - - RCODE QuickSort( - FLMUINT uiLowerBounds, - FLMUINT uiUpperBounds); - - FINLINE RCODE EntryCompare( - FLMBYTE * pLeftEntry, - FLMBYTE * pRightEntry, - FLMINT * piCompare) - { - RCODE rc; - - if( m_bFixedEntrySize) - { - rc = m_fnCompare( pLeftEntry, m_uiEntrySize, - pRightEntry, m_uiEntrySize, m_UserValue, piCompare); - } - else - { - rc = m_fnCompare( m_pBlockBuf + GetOffset( pLeftEntry), - GetLength( pLeftEntry ), m_pBlockBuf + GetOffset( pRightEntry), - GetLength( pRightEntry ), m_UserValue, piCompare); - } - - if( *piCompare == RS_EQUALS) - { - m_bDuplicateFound = TRUE; - } - - return( rc); - } - - RCODE CopyCurrentEntry( - FLMBYTE * pBuffer, - FLMUINT uiBufferLength, - FLMUINT * puiReturnLength); - - RCODE CompareEntry( - FLMBYTE * pMatchEntry, - FLMUINT uiMatchEntryLength, - FLMUINT uiEntryPos, - RSET_COMPARE_FUNC_p fnCompare, - void * UserValue, - FLMINT * piCompare); - - RCODE Write( void); - - RCODE Read( void); - - FBlockHeader m_BlockHeader; - RSET_COMPARE_FUNC_p m_fnCompare; - void * m_UserValue; - FLMBYTE * m_pBlockBuf; - FLMBYTE * m_pNextEntryPtr; - FLMBYTE * m_pEndPoint; - FResultSetBlk * m_pNext; - FResultSetBlk * m_pPrev; - F_64BitFileHandle ** m_ppFileHdl64; - FLMUINT m_uiBlkEntryPosition; - FLMUINT m_uiLengthRemaining; - FLMINT m_iEntryPos; - FLMUINT m_uiEntrySize; - FLMBOOL m_bEntriesInOrder; - FLMBOOL m_bFixedEntrySize; - FLMBOOL m_bPositioned; - FLMBOOL m_bModifiedEntry; - FLMBOOL m_bDuplicateFound; - FLMBOOL m_bDropDuplicates; -}; - -/***************************************************************************** -Desc: -*****************************************************************************/ -class FResultSet : public F_Base -{ -public: - - FResultSet(); - - virtual ~FResultSet(); - - RCODE Setup( - const char * pIoPath, - RSET_COMPARE_FUNC_p fnCompare, - void * UserValue, - FLMUINT uiEntrySize, - FLMBOOL bDropDuplicates = TRUE, - FLMBOOL bEntriesInOrder = FALSE); - - FINLINE void SetCallback( - RSET_CB_FUNC_p fnCallback, - void * UserValue) - { - m_CallbackInfo.UserValue = UserValue; - m_fnCallback = fnCallback; - } - - FINLINE FLMUINT64 GetTotalEntries( void) - { - FResultSetBlk * pBlk = m_pFirstRSBlk; - FLMUINT64 ui64TotalEntries = 0; - - for( pBlk = m_pFirstRSBlk; pBlk; pBlk = pBlk->GetNext()) - { - ui64TotalEntries += pBlk->GetNumberOfEntries(); - } - - return( ui64TotalEntries); - } - - RCODE AddEntry( - void * vpEntry, - FLMUINT uiEntryLength = 0); - - RCODE Finalize( - FLMUINT64 * pui64TotalEntries = NULL); - - FINLINE RCODE ModifyCurrent( - void * pEntry, - FLMUINT uiEntryLength) - { - return( m_pCurRSBlk->ModifyEntry( (FLMBYTE *) pEntry, uiEntryLength)); - } - - RCODE GetCurrent( - void * vpBuffer, - FLMUINT uiBufferLength = 0, - FLMUINT * puiReturnLength = NULL); - - RCODE GetNext( - void * vpBuffer, - FLMUINT uiBufferLength = 0, - FLMUINT * puiReturnLength = NULL); - - RCODE GetPrev( - void * vpBuffer, - FLMUINT uiBufferLength = 0, - FLMUINT * puiReturnLength = NULL); - - RCODE GetFirst( - void * vpBuffer, - FLMUINT uiBufferLength = 0, - FLMUINT * puiReturnLength = NULL); - - RCODE GetLast( - void * vpBuffer, - FLMUINT uiBufferLength = 0, - FLMUINT * puiReturnLength = NULL); - - RCODE FindMatch( - void * vpMatchEntry, - FLMUINT uiMatchEntryLength, - void * vpFoundEntry, - FLMUINT * puiFoundEntryLength, - RSET_COMPARE_FUNC_p fnCompare, - void * UserValue); - - FINLINE RCODE FindMatch( - void * vpMatchEntry, - void * vpFoundEntry, - RSET_COMPARE_FUNC_p fnCompare, - void * UserValue) - { - return( FindMatch( vpMatchEntry, (FLMUINT) m_uiEntrySize, - vpFoundEntry, NULL, fnCompare, UserValue)); - } - - FINLINE RCODE GetPosition( - FLMUINT * puiPosition) - { - if( !m_pCurRSBlk) - { - if( puiPosition) - { - *puiPosition = RS_POSITION_NOT_SET; - } - - return( FERR_OK); - } - - return( m_pCurRSBlk->GetPosition( puiPosition)); - } - - RCODE SetPosition( - FLMUINT uiPosition); - - RCODE reset( void); - -private: - - FINLINE FLMUINT64 NumberOfBlockChains( void) - { - FLMUINT64 ui64Count = 0; - FResultSetBlk * pBlk = m_pFirstRSBlk; - - for( ; pBlk ; pBlk = pBlk->GetNext()) - { - if( pBlk->IsFirstInChain()) - { - ui64Count++; - } - } - - return( ui64Count); - } - - RCODE MergeSort( void); - - RCODE GetNextPtr( - FResultSetBlk ** ppCurBlk, - FLMBYTE ** ppBuffer, - FLMUINT * puiReturnLength); - - RCODE UnionBlkLists( - FResultSetBlk * pLeftBlk, - FResultSetBlk * pRightBlk = NULL); - - RCODE CopyRemainingItems( - FResultSetBlk * pCurBlk); - - void CloseFile( - F_64BitFileHandle ** ppFileHdl64); - - RCODE OpenFile( - F_64BitFileHandle ** ppFileHdl64); - - FResultSetBlk * SelectMidpoint( - FResultSetBlk * pLowBlk, - FResultSetBlk * pHighBlk, - FLMBOOL bPickHighIfNeighbors); - - RSET_COMPARE_FUNC_p m_fnCompare; - void * m_UserValue; - RSET_CB_FUNC_p m_fnCallback; - RSET_CB_INFO m_CallbackInfo; - FLMUINT m_uiEntrySize; - FLMUINT64 m_ui64TotalEntries; - FResultSetBlk * m_pCurRSBlk; - FResultSetBlk * m_pFirstRSBlk; - FResultSetBlk * m_pLastRSBlk; - char m_szDefaultPath[ F_PATH_MAX_SIZE]; - char m_szFilePath1[ F_PATH_MAX_SIZE]; - char m_szFilePath2[ F_PATH_MAX_SIZE]; - F_64BitFileHandle * m_pFileHdl641; - F_64BitFileHandle * m_pFileHdl642; - FLMBYTE * m_pBlockBuf1; - FLMBYTE * m_pBlockBuf2; - FLMBYTE * m_pBlockBuf3; - FLMUINT m_uiBlockBuf1Len; - FLMBOOL m_bFile1Opened; - FLMBOOL m_bFile2Opened; - FLMBOOL m_bOutput2ndFile; - FLMBOOL m_bInitialAdding; - FLMBOOL m_bFinalizeCalled; - FLMBOOL m_bSetupCalled; - FLMBOOL m_bDropDuplicates; - FLMBOOL m_bAppAddsInOrder; - FLMBOOL m_bEntriesInOrder; -}; - -#include "fpackoff.h" - -#endif diff --git a/flaim/src/frsetblk.cpp b/flaim/src/frsetblk.cpp deleted file mode 100644 index 9390e73..0000000 --- a/flaim/src/frsetblk.cpp +++ /dev/null @@ -1,1339 +0,0 @@ -//------------------------------------------------------------------------- -// Desc: Result set blocks -// Tabs: 3 -// -// Copyright (c) 1996-2001,2003-2006 Novell, Inc. All Rights Reserved. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of version 2 of the GNU General Public -// License as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, contact Novell, Inc. -// -// To contact Novell about this file by physical or electronic mail, -// you may find current contact information at www.novell.com -// -// $Id: frsetblk.cpp 12320 2006-01-19 15:53:51 -0700 (Thu, 19 Jan 2006) dsanders $ -//------------------------------------------------------------------------- - -#include "flaimsys.h" - -/**************************************************************************** -Public: FResultSetBlk -Desc: Constructor -Notes: -****************************************************************************/ - -FResultSetBlk::FResultSetBlk() -{ - m_pNext = m_pPrev = NULL; - reset(); -} - - -/**************************************************************************** -Public: reset -Desc: Reset a block so it can be reused. -****************************************************************************/ -void FResultSetBlk::reset( void) -{ - flmAssert( !m_pNext && !m_pPrev); - - // Initialize all of the member variables - // between this constructor, SetBuffer() and Setup(). - - m_BlockHeader.ui64FilePos = RSBLK_UNSET_FILE_POS; - m_BlockHeader.uiEntryCount = 0; - // m_BlockHeader.uiBlockSize = RSBLK_BLOCK_SIZE; set in Setup() - //m_BlockHeader.FirstBlock = ?; set in Setup(). - //m_BlockHeader.LastBlock = ?; set in Setup(). - - m_ppFileHdl64 = NULL; - m_uiBlkEntryPosition = RS_POSITION_NOT_SET; - m_iEntryPos = 0; - //m_uiEntrySize = set in Setup(). - //m_bEntriesInOrder = set in Setup(). - //m_bFixedEntrySize; set in Setup(). - m_bDuplicateFound = FALSE; - m_bPositioned = FALSE; - m_bModifiedEntry = FALSE; - m_pBlockBuf = NULL; -} - -/**************************************************************************** -Public: Setup -Desc: Setup the result set block - passing in needed member variables -Notes: Must be called. -****************************************************************************/ - -void FResultSetBlk::Setup( - F_64BitFileHandle ** - ppFileHdl64, // file handle to use for temp file. - RSET_COMPARE_FUNC_p // Zero or record compare function. - fnCompare, // Returns (FLMINT) -1, 0 or 1 values. - void * UserValue, // UserValue for callback. - FLMUINT uiEntrySize, - FLMBOOL bFirstInList, // Use RSBLK_IS_FIRST_IN_LIST for true. - FLMBOOL bDropDuplicates, // If TRUE drop duplicates - FLMBOOL bEntriesInOrder) // TRUE when entries are in order. -{ - flmAssert( ppFileHdl64 != NULL); - - m_ppFileHdl64 = ppFileHdl64; - m_fnCompare = fnCompare; - m_UserValue = UserValue; - m_uiEntrySize = uiEntrySize; - m_BlockHeader.bFirstBlock = bFirstInList; - m_BlockHeader.bLastBlock = FALSE; // Set for real in the flush call. - - m_bFixedEntrySize = m_uiEntrySize ? TRUE : FALSE; // Friend member - - if( !m_uiEntrySize ) - { - m_uiEntrySize = BLKOFFSET_SIZE + LENGTH_SIZE; - } - m_bDropDuplicates = bDropDuplicates; - m_bEntriesInOrder = bEntriesInOrder; - - // Other variables have been setup from the constructor call. -} - - -/**************************************************************************** -Public: SetBuffer -Desc: The buffer is NOT allocated the by the result set block object. - Setup the pBuffer and associated variables. Read in the data - for this block if necessary. If NULL is passed in as pBuffer - then this block is not the active block anymore. -Notes: Must be called before other methods below are called. -****************************************************************************/ - -RCODE FResultSetBlk::SetBuffer( - FLMBYTE * pBuffer, // Working buffer or NULL - FLMUINT uiBufferLength) // Default value is RSBLK_BLOCK_SIZE. -{ - RCODE rc = FERR_OK; - - // If a buffer is defined then read in the data from disk. - - f_yieldCPU(); - - if( pBuffer) - { - m_pBlockBuf = pBuffer; - // Is there data already in the block? - if( ! m_BlockHeader.uiEntryCount) - { - // uiBlockSize is the final block size after squeeze. - // uiLengthRemaining is working value of bytes available. - - m_BlockHeader.uiBlockSize = uiBufferLength; - m_uiLengthRemaining = uiBufferLength; - m_pNextEntryPtr = m_pBlockBuf; - if( m_bFixedEntrySize) - { - m_pEndPoint = m_pBlockBuf; - } - else // variable length entries - { - m_pEndPoint = m_pBlockBuf + uiBufferLength; - } - } - else - { - // Read in the data if necessary. - if( RC_BAD( rc = Read())) // Sets bPositioned to TRUE on success. - goto Exit; - } - // GWBUG: 46817 - // The block is now in focus - m_bPositioned = TRUE; - } - else // inactivating block so the buffer can be reused. - { - // Check if the block has been modified - - if( m_bModifiedEntry ) - { - // Is this a lone block? - if( !m_BlockHeader.bLastBlock || !m_BlockHeader.bFirstBlock ) - { - if( RC_BAD( rc = Write())) - goto Exit; - } - m_bModifiedEntry = FALSE; - } - // GWBUG: 46817 - // The block is now out of focus - - m_bPositioned = FALSE; - m_pNextEntryPtr = m_pEndPoint = m_pBlockBuf = NULL; - } -Exit: - return( rc); -} - - -/**************************************************************************** -Public: AddEntry -Desc: Add a variable length entry to the result set. If fixed length - entry then call AddEntry for fixed length entries. -Ret: RCODE - FERR_OK or FERR_EOF_HIT when full -Notes: -****************************************************************************/ - -RCODE FResultSetBlk::AddEntry( - FLMBYTE * pEntry, - FLMUINT uiEntryLength) -{ - RCODE rc = FERR_OK; - BLKOFFSET uEntryOffset; - FLMUINT uiAlignLength; // Length taking into account alignment. - - flmAssert( NULL != m_pBlockBuf ); - - // Was setup called for fixed length entries? - - if( m_bFixedEntrySize ) - { - rc = AddEntry( pEntry ); - goto Exit; - } - - uiAlignLength = (uiEntryLength + FLM_ALLOC_ALIGN) & (~FLM_ALLOC_ALIGN); - - // Check to see if the current buffer will overflow. - - if( m_uiLengthRemaining < uiAlignLength + BLKOFFSET_SIZE + LENGTH_SIZE ) - { - // Caller should call Flush and setup correctly what to do next. - - rc = RC_SET( FERR_EOF_HIT ); - goto Exit; - } - - // Copy entry and compute the offset value for pNextEntryPtr. - - m_pEndPoint -= uiAlignLength; - f_memcpy( m_pEndPoint, pEntry, uiEntryLength ); - - uEntryOffset = (BLKOFFSET) (m_pEndPoint - m_pBlockBuf); - SetOffset( uEntryOffset, m_pNextEntryPtr ); - SetLength( uiEntryLength, m_pNextEntryPtr ); - m_pNextEntryPtr += (BLKOFFSET_SIZE + LENGTH_SIZE); - - m_uiLengthRemaining -= (uiAlignLength + BLKOFFSET_SIZE + LENGTH_SIZE ); - m_BlockHeader.uiEntryCount++; - -Exit: - return( rc); -} - -/**************************************************************************** -Desc: Add an fixed length entry to the result set. -****************************************************************************/ - -RCODE FResultSetBlk::AddEntry( - FLMBYTE * pEntry) -{ - RCODE rc = FERR_OK; - FLMUINT uiEntrySize = m_uiEntrySize; // Optimization - - // Check that setup was called for fixed length entries. - - flmAssert( m_bFixedEntrySize ); - - // Check to see if the current buffer is full. - - if( m_uiLengthRemaining < uiEntrySize ) - { - // Caller should call Flush and setup correctly what to do next. - - rc = RC_SET( FERR_EOF_HIT ); - goto Exit; - } - - f_memcpy( m_pNextEntryPtr, pEntry, uiEntrySize ); - m_BlockHeader.uiEntryCount++; - m_pNextEntryPtr += uiEntrySize; - m_pEndPoint += uiEntrySize; - m_uiLengthRemaining -= uiEntrySize; - -Exit: - return( rc); -} - - -/**************************************************************************** -Public: ModifyEntry -Desc: Modify the current entry being references. -Ret: RCODE - FERR_OK always. Will assert on entry size mismatch. -Notes: The size of each block cannot be modified. This is to allow - writing to the same location on disk and not waste disk memory. -****************************************************************************/ - -RCODE FResultSetBlk::ModifyEntry( - FLMBYTE * pEntry, - FLMUINT uiEntryLength) -{ - RCODE rc = FERR_OK; - FLMBYTE * pCurEntry; - - F_UNREFERENCED_PARM( uiEntryLength); - - flmAssert( NULL != m_pBlockBuf ); - - // The incoming entry MUST be the same size. - - if( m_bFixedEntrySize ) - { - // Assert that the entry length must be zero. - // If not - still use m_uiEntrySize; - - flmAssert( 0 == uiEntryLength ); - - // Position to the current item. - - pCurEntry = &m_pBlockBuf[ m_iEntryPos * m_uiEntrySize ]; - f_memcpy( pCurEntry, pEntry, m_uiEntrySize ); - } - else - { - // Variable Length - FLMUINT uiCurEntryLength; // uiAlignLength; - - pCurEntry = &m_pBlockBuf[ m_iEntryPos * m_uiEntrySize ]; - uiCurEntryLength = GetLength( pCurEntry ); - - // We cannot support changing the entry size at this time. - - flmAssert( uiEntryLength == uiCurEntryLength ); - - pCurEntry = m_pBlockBuf + GetOffset( pCurEntry ); - - f_memcpy( pCurEntry, pEntry, uiCurEntryLength ); - } - - m_bModifiedEntry = TRUE; -//Exit: - return( rc); -} - - -/**************************************************************************** -Public: Flush -Desc: The block is full and need to flush the block to disk. If - bForceWrite is FALSE then will not write block to disk. -Ret: RCODE -Notes: -****************************************************************************/ - -RCODE FResultSetBlk::Flush( - FLMBOOL bLastBlockInList, // Last block in a block list. - FLMBOOL bForceWrite) // if TRUE write out to disk. -{ - RCODE rc = FERR_OK; - - flmAssert( NULL != m_pBlockBuf );// Insure SetBuffer was called. - - // Set the Block header information, sort, kill dups and flush - - SqueezeSpace(); // Squeeze out wasted space. - - if( !m_bEntriesInOrder) // Are entries NOT in order? - { - rc = SortAndRemoveDups(); // Remove duplicate entries - if( RC_BAD(rc)) - goto Exit; - } - m_bEntriesInOrder = TRUE; // Entries are now in order. - - m_BlockHeader.bLastBlock = bLastBlockInList; - - if( bForceWrite) - { - if( RC_BAD( rc = Write())) - goto Exit; - } - -Exit: - return( rc); -} - -/**************************************************************************** -Desc: If there is length remaining, squeeze out additional space. -****************************************************************************/ -void FResultSetBlk::SqueezeSpace() -{ - // Fixed Entry Size? - - if( m_bFixedEntrySize) - { - // Yes, no need to squeeze out any space. - goto Exit; - } - - // Is there room to shift things down? - // Don't do if no entries or if less than 64 bytes or no entries. - - if( (m_uiLengthRemaining >= 64 ) && m_BlockHeader.uiEntryCount ) - { - FLMUINT uiBytesToMoveUp; - FLMBYTE * pEntry; - - uiBytesToMoveUp = m_uiLengthRemaining; - m_uiLengthRemaining = 0; - - // Overlapping memory move call. - - flmAssert( (m_pBlockBuf + m_BlockHeader.uiBlockSize) > m_pEndPoint ); - flmAssert( uiBytesToMoveUp < m_BlockHeader.uiBlockSize ); - - f_memmove( m_pEndPoint - uiBytesToMoveUp, m_pEndPoint, - (FLMUINT) ((m_pBlockBuf + m_BlockHeader.uiBlockSize ) - m_pEndPoint )); - - m_BlockHeader.uiBlockSize -= uiBytesToMoveUp; - m_pEndPoint -= uiBytesToMoveUp; - - // Change all of the offsets for every entry. This is expensive. - - for( pEntry = m_pBlockBuf; - pEntry < m_pNextEntryPtr; - pEntry += BLKOFFSET_SIZE + LENGTH_SIZE ) - { - BLKOFFSET uEntryOffset; - - uEntryOffset = GetOffset( pEntry ) - ((BLKOFFSET) uiBytesToMoveUp); - SetOffset( uEntryOffset, pEntry ); - } - } -Exit: - return; -} - -/**************************************************************************** -Desc: Sort the current block and remove all duplicates. -****************************************************************************/ -RCODE FResultSetBlk::SortAndRemoveDups() -{ - RCODE rc = FERR_OK; - - // Nothing to do if one or zero entries in the block. - - if( (m_BlockHeader.uiEntryCount <= 1 ) || (! m_fnCompare )) - { - goto Exit; - } - - m_bDuplicateFound = FALSE; - if( RC_BAD( rc = QuickSort( 0, m_BlockHeader.uiEntryCount - 1 ))) - goto Exit; - - /* - Some users of result sets may not have any duplicates to remove - or may want the side effect of having duplicates to further - process the entries like for sorting tracker records. It is up - to the compare routine to never return RS_EQUALS in this case. - */ - /* - This algorithm is tuned for the case where there are zero or few - duplicate records. Removing duplicates is expensive in this design. - */ - - if( m_bDropDuplicates && m_bDuplicateFound ) - { - FLMUINT uiEntriesRemaining; - FLMBYTE * pBase; - FLMBYTE * pEntry; - FLMBYTE * pNextEntry; - FLMINT iCompare; - - pBase = pEntry = m_pBlockBuf; - - for( uiEntriesRemaining = m_BlockHeader.uiEntryCount - 1 - ; uiEntriesRemaining > 0 - ; uiEntriesRemaining-- ) - { - pNextEntry = pEntry + m_uiEntrySize; - - if( m_bFixedEntrySize) - { - rc = m_fnCompare( pEntry, m_uiEntrySize, - pNextEntry, m_uiEntrySize, - m_UserValue, &iCompare ); - } - else - { - rc = m_fnCompare( pBase + GetOffset( pEntry ), - GetLength( pEntry ), - pBase + GetOffset( pNextEntry), - GetLength( pNextEntry ), - m_UserValue, &iCompare ); - } - if( RC_BAD(rc)) - goto Exit; - - if( iCompare == RS_EQUALS ) - { - RemoveEntry( pEntry ); - - // Leave pEntry alone - everyone will scoot down - } - else - { - pEntry += m_uiEntrySize; - } - } - } - -Exit: - return( rc); -} - -/**************************************************************************** -Desc: Remove the current entry from the block. -****************************************************************************/ -void FResultSetBlk::RemoveEntry( - FLMBYTE * pEntry) -{ - if( m_bFixedEntrySize ) - { - // Don't like moving zero bytes - check first. - - if( pEntry + m_uiEntrySize < m_pEndPoint ) - { - // This is really easy - just memmove everyone down. - - f_memmove( pEntry, pEntry + m_uiEntrySize, - (FLMUINT) (m_pEndPoint - pEntry ) - m_uiEntrySize); - } - m_BlockHeader.uiEntryCount--; - m_BlockHeader.uiBlockSize -= m_uiEntrySize; - m_pEndPoint -= m_uiEntrySize; - } - else // Variable length - much harder - { - /* - Example - remove entry 3 below... - - [entryOfs1:len][entryOfs2:len][entryOfs3:len][entryOfs4:len] - [entryData1][entryData2][entryData3][entryData4] - - Need to reduce EntryOfs1 and entryOfs2 by m_uiEntrySize+entryLen3. - because these entries are stored AFTER entry 3 - entries are first - stored going from the back of the block to the front of the block. - Need to reduce Ofs4 by OFFSET_SIZE. - */ - BLKOFFSET uDeletedOffset = GetOffset( pEntry ); - BLKOFFSET uTempOffset; - FLMUINT uiDeletedLength = GetLength( pEntry ); - FLMBYTE * pCurEntry; - FLMUINT uiPos; - FLMUINT uiMoveBytes; - - flmAssert( m_BlockHeader.uiBlockSize >= - (uDeletedOffset + uiDeletedLength )); - - // Don't move zero bytes - don't know what will happen x-platform. - uiMoveBytes = (FLMUINT) - ( m_BlockHeader.uiBlockSize - (uDeletedOffset + uiDeletedLength )); - - if( uiMoveBytes) - { - // First move down the variable length entry data. - f_memmove( m_pBlockBuf + uDeletedOffset, - m_pBlockBuf + uDeletedOffset + uiDeletedLength, - uiMoveBytes ); - } - flmAssert( m_BlockHeader.uiBlockSize >= (FLMUINT) - ((pEntry + m_uiEntrySize) - m_pBlockBuf) ); - - uiMoveBytes = (FLMUINT) (m_BlockHeader.uiBlockSize - - ((pEntry + m_uiEntrySize) - m_pBlockBuf)); - if( uiMoveBytes ) - { - f_memmove( pEntry, pEntry + m_uiEntrySize, uiMoveBytes ); - } - m_BlockHeader.uiBlockSize -= uiDeletedLength + m_uiEntrySize; - - // Adjust the offset values. - - m_BlockHeader.uiEntryCount--; - for( uiPos = 0, pCurEntry = m_pBlockBuf - ; uiPos < m_BlockHeader.uiEntryCount - ; uiPos++, pCurEntry += m_uiEntrySize ) - { - // Assume that the offsets are NOT in descending order. - // This will help in the future additional adding and deleting - // to an existing result set. - - uTempOffset = GetOffset( pCurEntry ); - if( uTempOffset > uDeletedOffset) - { - uTempOffset -= (BLKOFFSET) uiDeletedLength; - } - uTempOffset -= (BLKOFFSET)m_uiEntrySize; - SetOffset( uTempOffset, pCurEntry ); - } - } - return; -} - -/**************************************************************************** -Desc: Quick sort an array of values. -Notes: Optimized the above quicksort algorithm. On page 559 the book - suggests that "The worst case can sometimes be avioded by choosing - more carefully the record for final placement at each state." - This algorithm picks a mid point for the compare value. Doing - this helps the worst case where the entries are in order. In Order - tests went from 101 seconds down to 6 seconds! - This helps the 'in order' sorts from worst case Order(N^^2)/2 with - the normal quickSort to Order(NLog2 N) for the worst case. - Also optimized the number of recursions to Log2 N from (N-2). - Will recurse the SMALLER side and will iterate to the top of - the routinefor the LARGER side. Follow comments below. -****************************************************************************/ -RCODE FResultSetBlk::QuickSort( - FLMUINT uiLowerBounds, - FLMUINT uiUpperBounds) -{ - FLMBYTE * pEntryTbl = m_pBlockBuf; - FLMBYTE * pCurEntry; - FLMUINT uiLBPos, uiUBPos, uiMIDPos; - FLMUINT uiLeftItems, uiRightItems; - FLMINT iCompare; - FLMUINT uiEntrySize = m_uiEntrySize; - RCODE rc = FERR_OK; // Set in case only one entry. - FLMBYTE ucaSwapBuffer[MAX_FIXED_ENTRY_SIZE]; -#define RECURSIVE_CALL - // The problem with using the non-recursive code is that - // for formula to compute the maximum number of levels - // is so complex we cannot guess on a value. -#ifndef RECURSIVE_CALL - FLMUINT uiaLowerStack[64]; - FLMUINT uiaUpperStack[64]; - FLMUINT uiStackPos; -#endif - -#define RS_SWAP(pTbl,pos1,pos2) { \ - f_memcpy( ucaSwapBuffer, &pTbl[pos2*uiEntrySize], uiEntrySize); \ - f_memcpy( &pTbl[ pos2 * uiEntrySize ], &pTbl[ pos1 * uiEntrySize ], uiEntrySize ); \ - f_memcpy( &pTbl[ pos1 * uiEntrySize ], ucaSwapBuffer, uiEntrySize ); } - -#ifndef RECURSIVE_CALL - // Setup the stack. - uiStackPos = 1; - uiaLowerStack[0] = uiLowerBounds; - uiaUpperStack[0] = uiUpperBounds; - - while( uiStackPos ) - { - uiStackPos--; - uiLowerBounds = uiaLowerStack[ uiStackPos ]; - uiUpperBounds = uiaUpperStack[ uiStackPos ]; -#endif - -Iterate_Larger_Half: - - uiUBPos = uiUpperBounds; - uiLBPos = uiLowerBounds; - uiMIDPos = (uiUpperBounds + uiLowerBounds + 1) / 2; - pCurEntry = &pEntryTbl[ uiMIDPos * uiEntrySize ]; - for( ;;) - { - while( (uiLBPos == uiMIDPos) // Don't compare with target - || (((rc = EntryCompare( &pEntryTbl[ uiLBPos * uiEntrySize ], - pCurEntry, - &iCompare )) == FERR_OK) - && (iCompare == RS_LESS_THAN ))) - { - if( uiLBPos >= uiUpperBounds) break; - uiLBPos++; - } - if(RC_BAD(rc)) // Check for error - goto Exit; - - while( (uiUBPos == uiMIDPos) // Don't compare with target - || (((rc = EntryCompare( pCurEntry, - &pEntryTbl[ uiUBPos * uiEntrySize ], - &iCompare )) == FERR_OK) - && (iCompare == RS_LESS_THAN ))) - { - if( uiUBPos == 0) // Check for underflow condition - { - break; - } - uiUBPos--; - } - if(RC_BAD(rc)) // Check for error - goto Exit; - - if( uiLBPos < uiUBPos ) // Interchange and continue loop. - { - /* Interchange [uiLBPos] with [uiUBPos]. */ - - RS_SWAP( pEntryTbl, uiLBPos, uiUBPos ); - uiLBPos++; // Scan from left to right. - uiUBPos--; // Scan from right to left. - } - else // Past each other - done - { - break; - } - } - /* 5 cases to check. - 1) UB < MID < LB - Don't need to do anything. - 2) MID < UB < LB - swap( UB, MID ) - 3) UB < LB < MID - swap( LB, MID ) - 4) UB = LB < MID - swap( LB, MID ) - At first position - 5) MID < UB = LB - swap( UB, MID ) - At last position - */ - - /* Check for swap( LB, MID ) - cases 3 and 4 */ - - if( uiLBPos < uiMIDPos ) - { - /* Interchange [uiLBPos] with [uiMIDPos] */ - - RS_SWAP( pEntryTbl, uiMIDPos, uiLBPos ); - uiMIDPos = uiLBPos; - } - else if( uiMIDPos < uiUBPos ) /* cases 2 and 5 */ - { - /* Interchange [uUBPos] with [uiMIDPos] */ - - RS_SWAP( pEntryTbl, uiMIDPos, uiUBPos ); - uiMIDPos = uiUBPos; - } - - /* To save stack space - recurse the SMALLER Piece. For the larger - piece goto the top of the routine. Worst case will be - (Log2 N) levels of recursion. - - Don't recurse in the following cases: - 1) We are at an end. Just loop to the top. - 2) There are two on one side. Compare and swap. Loop to the top. - Don't swap if the values are equal. There are many recursions - with one or two entries. This doesn't speed up any so it is - commented out. - */ - /* Check the left piece. */ - - uiLeftItems = (uiLowerBounds + 1 < uiMIDPos ) - ? uiMIDPos - uiLowerBounds // 2 or more - : 0; - uiRightItems = (uiMIDPos + 1 < uiUpperBounds ) - ? uiUpperBounds - uiMIDPos // 2 or more - : 0; - /* - A removed optimization was here. - If two left or right items then check and swap. - I didn't see any improvement in time using this code. - */ - - if( uiLeftItems < uiRightItems ) - { - /* Recurse on the LEFT side and goto the top on the RIGHT side. */ - - if( uiLeftItems ) - { -#ifdef RECURSIVE_CALL - // Recursive call. - if( RC_BAD( rc = QuickSort( uiLowerBounds, uiMIDPos - 1 ))) - goto Exit; -#else - uiaLowerStack[ uiStackPos ] = uiLowerBounds; - uiaUpperStack[ uiStackPos++ ] = uiMIDPos - 1; -#endif - } - uiLowerBounds = uiMIDPos + 1; - goto Iterate_Larger_Half; - } - else if( uiLeftItems ) // Compute a truth table to figure out this check. - { - /* Recurse on the RIGHT side and goto the top for the LEFT side. */ - - if( uiRightItems ) - { - // Recursive call. - -#ifdef RECURSIVE_CALL - if( RC_BAD( rc = QuickSort( uiMIDPos + 1, uiUpperBounds ))) - goto Exit; -#else - uiaLowerStack[ uiStackPos ] = uiMIDPos + 1; - uiaUpperStack[ uiStackPos++ ] = uiUpperBounds; -#endif - } - uiUpperBounds = uiMIDPos - 1; - goto Iterate_Larger_Half; - } -#ifndef RECURSIVE_CALL - } -#endif -Exit: - return( rc); -} - -/**************************************************************************** -Public: FRSDefaultCompare -Desc: Default compare that compares the data like memcmp() from left - to right and then by length where smaller is less than bigger. -Ret: *piCompare = -1 RS_LESS_THAN; 0 = RS_EQUALS; 1 RS_GREATER_THAN - RCODE = any code from user defined compare routine. - non-zero rcode will terminate sort/compare. -Notes: Do NOT make this routine static. This routine needs to be public. -****************************************************************************/ -RCODE FRSDefaultCompare( - void * pData1, - FLMUINT uiLength1, - void * pData2, - FLMUINT uiLength2, - void * UserValue, - FLMINT * piCompare) -{ - FLMUINT uiMinLength = f_min( uiLength1, uiLength2 ); - FLMINT iCompareValue; - int siMemcmpValue; - - F_UNREFERENCED_PARM( UserValue); - - if( (siMemcmpValue = f_memcmp( pData1, pData2, (FLMUINT) uiMinLength )) == 0) - { - // Both equal up to the minimum length. Is there additional data? - - if( uiLength1 != uiLength2 ) - { - iCompareValue = (uiLength1 < uiLength2) - ? RS_LESS_THAN : RS_GREATER_THAN; - } - else - { - iCompareValue = RS_EQUALS; - } - } - else - { - iCompareValue = (siMemcmpValue < 0) ? RS_LESS_THAN : RS_GREATER_THAN; - } - *piCompare = iCompareValue; - return FERR_OK; -} - -/**************************************************************************** -Desc: Write this block to disk. Adjust variables. -****************************************************************************/ -RCODE FResultSetBlk::Write() -{ - FLMUINT uiTotalBytesWritten; - FLMUINT64 ui64FilePos; - FLMUINT uiBytesToWrite, - uiBytesWritten; - RCODE rc; - - // By this time there better be something to write... - - // The file should be opened by default. - - if( m_BlockHeader.ui64FilePos == RSBLK_UNSET_FILE_POS ) - { - if( RC_BAD(rc = (*m_ppFileHdl64)->Size( &m_BlockHeader.ui64FilePos ))) - goto Exit; - } - - // Write out the block header definition. - - rc = (*m_ppFileHdl64)->Write( - m_BlockHeader.ui64FilePos, - sizeof( FBlockHeader), &m_BlockHeader, - &uiBytesWritten ); - if( RC_BAD( rc)) - goto Exit; - - ui64FilePos = m_BlockHeader.ui64FilePos + - (FLMUINT64)sizeof( FBlockHeader); - - for( uiTotalBytesWritten = 0 - ; uiTotalBytesWritten < m_BlockHeader.uiBlockSize - ; uiTotalBytesWritten += uiBytesWritten ) - { - if( uiTotalBytesWritten + (MAX_WRITE_BYTES) > m_BlockHeader.uiBlockSize) - { - uiBytesToWrite = m_BlockHeader.uiBlockSize - uiTotalBytesWritten; - } - else - { - uiBytesToWrite = MAX_WRITE_BYTES; - // Write at most 60K at a time. - } - rc = (*m_ppFileHdl64)->Write( - ui64FilePos, - uiBytesToWrite, - &m_pBlockBuf[ uiTotalBytesWritten ], - &uiBytesWritten ); - if( RC_BAD( rc)) - goto Exit; - ui64FilePos += uiBytesWritten; - } - -Exit: - return( rc); -} - -/**************************************************************************** -Desc: Read in the specified block into memory. -Ret: FERR_OK, FERR_EOF_HIT or I/O error -****************************************************************************/ -RCODE FResultSetBlk::Read() -{ - RCODE rc = FERR_OK; - FLMUINT uiBytesRead, uiBytesToRead; - FLMUINT uiTotalBytesRead; - FLMUINT64 ui64FilePos = m_BlockHeader.ui64FilePos; - FBlockHeader BlockHeader; - - // Nothing to do??? - - if( RSBLK_UNSET_FILE_POS == ui64FilePos) - goto Exit; - - // First read the block header in. - - rc = (*m_ppFileHdl64)->Read( ui64FilePos, sizeof( FBlockHeader ), - (void *) &BlockHeader, &uiBytesRead ); - if( RC_BAD(rc)) - goto Exit; - - // Verify that the block header data is the same. - // This is the best we can do to verify that the file handle - // is not junky. - - if( (BlockHeader.ui64FilePos != m_BlockHeader.ui64FilePos ) - || (BlockHeader.uiEntryCount != m_BlockHeader.uiEntryCount )) - { - // Returning data error because there is a big possibility - // that the file handles have become corrupt. - rc = RC_SET( FERR_FAILURE ); - goto Exit; - } - - ui64FilePos += sizeof( FBlockHeader ); - - for( uiTotalBytesRead = 0 - ; uiTotalBytesRead < m_BlockHeader.uiBlockSize - ; uiTotalBytesRead += uiBytesRead ) - { - if( uiTotalBytesRead + (MAX_WRITE_BYTES) > m_BlockHeader.uiBlockSize) - { - uiBytesToRead = m_BlockHeader.uiBlockSize - uiTotalBytesRead; - } - else - { - uiBytesToRead = MAX_WRITE_BYTES; - } - rc = (*m_ppFileHdl64)->Read( - ui64FilePos, - uiBytesToRead, - &m_pBlockBuf[ uiTotalBytesRead ], - &uiBytesRead ); - if( RC_BAD(rc)) - goto Exit; - ui64FilePos += (FLMUINT64)uiBytesRead; - } - -Exit: - if( RC_OK(rc)) - { - m_bPositioned = TRUE; - m_iEntryPos = -1; - } - return( rc); -} - -/**************************************************************************** -Desc: Copies the current entry into the user buffer. Checks for overflow. -****************************************************************************/ -RCODE FResultSetBlk::CopyCurrentEntry( - FLMBYTE * pBuffer, - FLMUINT uiBufferLength, - FLMUINT * puiReturnLength) -{ - RCODE rc = FERR_OK; // Must be initailized - FLMUINT uiEntrySize; - FLMBYTE * pEntry; - - flmAssert( NULL != pBuffer ); - - // Copy the current entry. This is a shared routine - // because the code to copy an entry is a little complicated. - - uiEntrySize = m_uiEntrySize; - pEntry = &m_pBlockBuf[ m_iEntryPos * uiEntrySize ]; - - if( !m_bFixedEntrySize ) - { - uiEntrySize = GetLength( pEntry ); - pEntry = m_pBlockBuf + GetOffset( pEntry ); - } - - if( uiBufferLength && (uiEntrySize > uiBufferLength)) - { - uiEntrySize = uiBufferLength; - rc = RC_SET( FERR_CONV_DEST_OVERFLOW ); - // Fall through into memcpy. - } - f_memcpy( pBuffer, pEntry, (FLMUINT) uiEntrySize ); - if( puiReturnLength) - { - *puiReturnLength = uiEntrySize; - } -//Exit: - return( rc); -} - -/**************************************************************************** -Public: GetCurrent -Desc: Return the Current entry reference in the result set. -Ret: FERR_OK - Returned the current recRef[]. - FERR_CONV_DEST_OVERFLOW - buffer is not big enough for data - FERR_NOT_FOUND - Not positioned anywhere in the result set. - FERR_EOF_HIT - Positioned past the last entry - FERR_BOF_HIT - Positioned before the first entry. -****************************************************************************/ -RCODE FResultSetBlk::GetCurrent( - FLMBYTE * pBuffer, - FLMUINT uiBufferLength, - FLMUINT * puiReturnLength) -{ - RCODE rc; - - flmAssert( NULL != m_pBlockBuf ); - if( !m_bPositioned ) - { - rc = RC_SET( FERR_NOT_FOUND ); - goto Exit; - } - - // Check for EOF and BOF conditions - otherwise return current. - - if( m_iEntryPos >= (FLMINT) m_BlockHeader.uiEntryCount ) - { - rc = RC_SET( FERR_EOF_HIT ); - goto Exit; - } - if( m_iEntryPos == -1) - { - rc = RC_SET( FERR_BOF_HIT ); - goto Exit; - } - rc = CopyCurrentEntry( pBuffer, uiBufferLength, puiReturnLength ); - -Exit: - return( rc); -} - -/**************************************************************************** -Public: GetNextPtr -Desc: Return a pointer to the next reference in the result set. - If the result set is not positioned then the first entry will - be returned. - -Ret: FERR_OK - Returned the current recRef[]. - FERR_CONV_DEST_OVERFLOW - buffer is not big enough for data - FERR_NOT_FOUND - zero records in the result set. - FERR_EOF_HIT - Positioned past the last entry -****************************************************************************/ -RCODE FResultSetBlk::GetNextPtr( - FLMBYTE ** ppBuffer, - FLMUINT * puiReturnLength) -{ - RCODE rc = FERR_OK; - FLMUINT uiEntrySize; - FLMBYTE * pEntry; - - flmAssert( ppBuffer != NULL ); - flmAssert( puiReturnLength != NULL ); - flmAssert( m_bPositioned ); - - // Are we on the last entry or past the last entry? - - if( m_iEntryPos + 1 >= (FLMINT) m_BlockHeader.uiEntryCount ) - { - m_iEntryPos = (FLMINT) m_BlockHeader.uiEntryCount; - rc = RC_SET( FERR_EOF_HIT ); - goto Exit; - } - m_iEntryPos++; // Else position to next entry - - uiEntrySize = m_uiEntrySize; - pEntry = &m_pBlockBuf[ m_iEntryPos * uiEntrySize ]; - - if( !m_bFixedEntrySize ) - { - uiEntrySize = GetLength( pEntry ); - pEntry = m_pBlockBuf + GetOffset( pEntry ); - } - - *ppBuffer = pEntry; - *puiReturnLength = uiEntrySize; - -Exit: - return( rc); -} - - -/**************************************************************************** -Public: GetPrev -Desc: Return the previous reference in the result set. If the result set - is not positioned then the last entry will be returned. -Ret: FERR_OK - Returned the current recRef[]. - FERR_CONV_DEST_OVERFLOW - buffer is not big enough for data - FERR_BOF_HIT - Positioned past the first entry -****************************************************************************/ -RCODE FResultSetBlk::GetPrev( - FLMBYTE * pBuffer, - FLMUINT uiBufferLength, - FLMUINT * puiReturnLength) -{ - RCODE rc = FERR_OK; - - flmAssert( m_bPositioned ); - - // If not positioned then position past last entry. - if( m_iEntryPos == -1) - { - m_iEntryPos = (FLMINT) m_BlockHeader.uiEntryCount; - } - // Are we on the first entry or before the first entry? - - if( m_iEntryPos == 0) - { - m_iEntryPos = -1; // Just set it - rc = RC_SET( FERR_BOF_HIT ); - goto Exit; - } - - m_iEntryPos--; // position to previous entry. - - rc = CopyCurrentEntry( pBuffer, uiBufferLength, puiReturnLength ); - -Exit: - return( rc); -} - -/**************************************************************************** -Public: SetPosition -Desc: Set the current entry position for this block. -In: uiPosition - Zero based position value for this block - or RS_POSITION_NOT_SET if invalid position (past the end). -Ret: FERR_OK - Returned OK - FERR_EOF_HIT - Positioned past the end of the block. -Note: The state must be that the data in the block has been - read in. Otherwise, will set position to first or last. -****************************************************************************/ - -RCODE FResultSetBlk::SetPosition( - FLMUINT uiPosition) -{ - RCODE rc= FERR_OK; - - // Buffer must be set or SetBuffer() will set iEntryPos back to -1. - flmAssert( m_bPositioned ); - - if( uiPosition == RS_POSITION_NOT_SET ) - { - m_iEntryPos = -1; - goto Exit; - } - flmAssert( uiPosition >= m_uiBlkEntryPosition ); - - // Convert to a zero based number relative to this block. - - if( uiPosition >= m_uiBlkEntryPosition ) - uiPosition -= m_uiBlkEntryPosition; - else - uiPosition = 0; // Handle if assert condition is not in debug. - - if( uiPosition >= m_BlockHeader.uiEntryCount) - { - rc = RC_SET( FERR_EOF_HIT ); - m_iEntryPos = m_BlockHeader.uiEntryCount; - } - else - { - m_iEntryPos = (FLMINT) uiPosition; - } - -Exit: - return( rc); -} - -/**************************************************************************** -Public: FindMatch -Desc: Find the matching entry within the block using the compare routine. - This does a binary search on entries. Watch the (out) variable. -Out: *piCompare = RS_EQUALS - match found OR entry would compare between - the low and high entries in the block. - = RS_GREATER_THAN - match entry is greater than - the highest entry in the block. - = RS_LESS_THAN - match entry is less than the - lowest entry in the block. -Ret: FERR_OK - Returned OK - FERR_NOT_FOUND - match not found -Notes: One side effect is that m_iEntryPos is set to the matched - entry or some random entry if not found is returned. -****************************************************************************/ - -RCODE FResultSetBlk::FindMatch( // Find and return an etnry that - // matches in this block. - FLMBYTE * pMatchEntry, // Entry to match - FLMUINT uiMatchEntryLength, // Variable length of above entry - FLMBYTE * pFoundEntry, // (out) Entry to return - FLMUINT * puiFoundEntryLength, // (out) Length of entry returned - RSET_COMPARE_FUNC_p // Record compare function. - fnCompare, // Returns (FLMINT) -1, 0 or 1 values. - void * UserValue, // UserValue for callback. - FLMINT * piCompare) // See comments above. -{ - RCODE rc = FERR_OK; - FLMINT iCompare; // Return from CompareEntry - FLMUINT uiLow, uiHigh, uiMid, uiLimit; - - uiLow = 0; - uiHigh = uiLimit = GetNumberOfEntries() - 1; - if( ! uiMatchEntryLength) // Set the match entry length. - uiMatchEntryLength = m_uiEntrySize; - - // Check the first and last entries in the block. - // Copy the current entry if found. - - if( RC_BAD( rc = CompareEntry( pMatchEntry, uiMatchEntryLength, uiLow, - fnCompare, UserValue, &iCompare ))) - goto Exit; - - if( iCompare != RS_GREATER_THAN ) - { - if( iCompare == RS_LESS_THAN ) - { - rc = RC_SET( FERR_NOT_FOUND ); - } - - *piCompare = iCompare; - goto Exit; - } - if( RC_BAD( rc = CompareEntry( pMatchEntry, uiMatchEntryLength, uiHigh, - fnCompare, UserValue, &iCompare ))) - goto Exit; - - if( iCompare != RS_LESS_THAN ) - { - if( iCompare == RS_GREATER_THAN ) - { - rc = RC_SET( FERR_NOT_FOUND ); - } - *piCompare = iCompare; - goto Exit; - } - - // Set the iCompare to equals because - // the match entry sorts within the block somewhere. - // Binary search the entries in the block. May still - // not find the matching entry. - - *piCompare = RS_EQUALS; - - for( ;; ) // Initialize low and high above. - { - uiMid = (uiLow + uiHigh) >> 1; // (uiLow + uiHigh) / 2 - - if( RC_BAD( rc = CompareEntry( pMatchEntry, uiMatchEntryLength, uiMid, - fnCompare, UserValue, &iCompare ))) - goto Exit; - if( iCompare == RS_EQUALS ) - { - // Found Match! All set up to return. - goto Exit; - } - // Check if we are done - where wLow equals uHigh. - - if( uiLow >= uiHigh) - break; // Done - item not found. - - if( iCompare == RS_LESS_THAN ) - { - if( uiMid == 0) // Way too high? - break; - uiHigh = uiMid - 1; // Too high - } - else - { - if( uiMid == uiLimit) // Done - Hit the top - break; - uiLow = uiMid + 1; // Too low - } - } - // On break set we did not find the matching entry. - - rc = RC_SET( FERR_NOT_FOUND ); - -Exit: - if( RC_OK(rc)) - { - rc = CopyCurrentEntry( pFoundEntry, 0, puiFoundEntryLength ); - } - return( rc); -} - - -/**************************************************************************** -Desc: Compare the buffer entry with entry identifies by - uiEntryPos. -Out: *piCompare = RS_EQUALS - match found OR entry value would compare - between the low and high entries. - = RS_GREATER_THAN - match entry is greater than - the highest entry in the block. - = RS_LESS_THAN - match entry is less than the - lowest entry in the block. -****************************************************************************/ - -RCODE FResultSetBlk::CompareEntry( // Compares match entry with entry - // identified by uiEntryPos. - FLMBYTE * pMatchEntry, // Entry to match - FLMUINT uiMatchEntryLength, // Variable length of pMatchEntry. - FLMUINT uiEntryPos, // Position of entry in block. - RSET_COMPARE_FUNC_p // Record compare function. - fnCompare, // Returns (FLMINT) -1, 0 or 1 values. - void * UserValue, // UserValue for callback. - FLMINT * piCompare) // Return from compare. -{ - RCODE rc; - FLMBYTE * pEntry; - FLMUINT uiEntrySize; - - F_UNREFERENCED_PARM( fnCompare); - F_UNREFERENCED_PARM( UserValue); - - // Position to the entry. - - m_iEntryPos = (FLMINT) uiEntryPos; - uiEntrySize = m_uiEntrySize; - pEntry = &m_pBlockBuf[ m_iEntryPos * uiEntrySize ]; - - if( !m_bFixedEntrySize ) - { - uiEntrySize = GetLength( pEntry ); - pEntry = m_pBlockBuf + GetOffset( pEntry ); - } - - rc = m_fnCompare( pMatchEntry, uiMatchEntryLength, - pEntry, uiEntrySize, - m_UserValue, piCompare ); - - return( rc); -} diff --git a/flaim/src/fsconvrt.cpp b/flaim/src/fsconvrt.cpp index 04aa765..43af9cc 100644 --- a/flaim/src/fsconvrt.cpp +++ b/flaim/src/fsconvrt.cpp @@ -90,7 +90,7 @@ RCODE FSVersionConversion40( FSInitStackCache( &stackBuf [0], BH_MAX_LEVELS); pStack = stackBuf; pStack->pKeyBuf = pKeyBuf; - flmUINT32ToBigEndian( 0, pDrnKey); + f_UINT32ToBigEndian( 0, pDrnKey); if( RC_BAD(rc = FSBtSearch( pDb, pLFile, &pStack, pDrnKey, DIN_KEY_SIZ,0))) goto Exit; @@ -144,7 +144,7 @@ FSTATIC RCODE FSConvertNonLeafTree( FLMUINT uiBlkAddr; FSInitStackCache( &stackBuf [0], BH_MAX_LEVELS); - flmUINT32ToBigEndian( 0, pDrnKey); + f_UINT32ToBigEndian( 0, pDrnKey); /* Free the b-tree blocks that are above this lowest non-leaf level. @@ -286,7 +286,7 @@ FSTATIC RCODE FSConvertNonLeafTree( // Do callback to report progress. if (fnStatusCallback) { - pDbConvertInfo->uiDrn = flmBigEndianToUINT32( pOldStack->pKeyBuf); + pDbConvertInfo->uiDrn = f_bigEndianToUINT32( pOldStack->pKeyBuf); if (RC_BAD( rc = (*fnStatusCallback)( FLM_DB_UPGRADE_STATUS, (void *) pDbConvertInfo, (void *)0, UserData))) @@ -334,7 +334,7 @@ FSTATIC void FSBuildNonLeafDataElement( // Check for last element marker. if( pOldElm[ BBE_PKC ] == 0 && pOldElm[ BBE_KL] == 0) { - flmUINT32ToBigEndian( (FLMUINT32)DRN_LAST_MARKER, pElement); + f_UINT32ToBigEndian( (FLMUINT32)DRN_LAST_MARKER, pElement); } else { diff --git a/flaim/src/fscursor.cpp b/flaim/src/fscursor.cpp index 6afddc0..4a54acb 100644 --- a/flaim/src/fscursor.cpp +++ b/flaim/src/fscursor.cpp @@ -1169,7 +1169,7 @@ VISIT: We may want to return BOF/EOF when positioned on an endpoint. ****************************************************************************/ RCODE FSIndexCursor::currentKeyBuf( FDB * pDb, - POOL * pPool, + F_Pool * pPool, FLMBYTE ** ppKeyBuf, FLMUINT * puiKeyLen, FLMUINT * puiRecordId, @@ -1219,10 +1219,9 @@ RCODE FSIndexCursor::currentKeyBuf( if( (*puiKeyLen = m_curKeyPos.uiKeyLen) != 0) { - if( (*ppKeyBuf = (FLMBYTE *) - GedPoolAlloc( pPool, m_curKeyPos.uiKeyLen)) == NULL) + if( RC_BAD( rc = pPool->poolAlloc( m_curKeyPos.uiKeyLen, + (void **)ppKeyBuf))) { - rc = RC_SET( FERR_MEM); goto Exit; } diff --git a/flaim/src/fscursor.h b/flaim/src/fscursor.h index c2df13e..5c88042 100644 --- a/flaim/src/fscursor.h +++ b/flaim/src/fscursor.h @@ -70,7 +70,7 @@ typedef struct KEYSET /**************************************************************************** Desc: File system implementation of a cursor for an index. ****************************************************************************/ -class FSIndexCursor : public F_Base +class FSIndexCursor : public F_Object { public: @@ -137,7 +137,7 @@ public: RCODE currentKeyBuf( FDB * pDb, - POOL * pPool, + F_Pool * pPool, FLMBYTE ** ppKeyBuf, FLMUINT * puiKeyLen, FLMUINT * puiRecordId, @@ -337,7 +337,7 @@ typedef struct RECSET /**************************************************************************** Desc: File system implementation of a cursor for a data container. ****************************************************************************/ -class FSDataCursor: public F_Base +class FSDataCursor: public F_Object { public: diff --git a/flaim/src/fsdatacu.cpp b/flaim/src/fsdatacu.cpp index 3f19545..0043563 100644 --- a/flaim/src/fsdatacu.cpp +++ b/flaim/src/fsdatacu.cpp @@ -668,7 +668,7 @@ FINLINE void setItemsFromBlock( RECPOS * pRecPos ) { - pRecPos->uiRecordId = flmBigEndianToUINT32( pRecPos->pKey); + pRecPos->uiRecordId = f_bigEndianToUINT32( pRecPos->pKey); pRecPos->uiBlockAddr = pRecPos->pStack->uiBlkAddr; pRecPos->uiBlockTransId = (pRecPos->uiBlockAddr != BT_END) ? FB2UD( &pRecPos->pStack->pBlk[ BH_TRANS_ID]) @@ -702,7 +702,7 @@ RCODE FSDataCursor::setRecPosition( pOutRecPos->pStack = pOutRecPos->Stack; pOutRecPos->Stack[0].pKeyBuf = pOutRecPos->pKey; uiRecordId = pInRecPos->uiRecordId; - flmUINT32ToBigEndian( (FLMUINT32)uiRecordId, buf); + f_UINT32ToBigEndian( (FLMUINT32)uiRecordId, buf); // All of the variables should be setup for the search. if( RC_BAD( rc = FSBtSearch( pDb, m_pLFile, &pOutRecPos->pStack, @@ -720,7 +720,7 @@ RCODE FSDataCursor::setRecPosition( if( bGoingForward) { if( pOutRecPos->pStack->uiCmpStatus == BT_END_OF_DATA || - flmBigEndianToUINT32( pOutRecPos->pKey) == DRN_LAST_MARKER) + f_bigEndianToUINT32( pOutRecPos->pKey) == DRN_LAST_MARKER) { rc = RC_SET( FERR_EOF_HIT); goto Exit; @@ -729,7 +729,7 @@ RCODE FSDataCursor::setRecPosition( else { if( (pOutRecPos->pStack->uiCmpStatus == BT_END_OF_DATA) || - (flmBigEndianToUINT32( pOutRecPos->pKey) > uiRecordId)) + (f_bigEndianToUINT32( pOutRecPos->pKey) > uiRecordId)) { // Went a little too far - go back to the previous record. // Need to position back one element. @@ -974,7 +974,7 @@ RCODE FSDataCursor::nextRec( goto Exit; } bRecordGone = TRUE; - if( flmBigEndianToUINT32( m_curRecPos.pKey) <= + if( f_bigEndianToUINT32( m_curRecPos.pKey) <= m_pCurSet->untilKey.uiRecordId) { setItemsFromBlock( &m_curRecPos); @@ -1120,7 +1120,7 @@ RCODE FSDataCursor::prevRec( pCurElm = CURRENT_ELM( pStack); } bRecordGone = TRUE; - if( flmBigEndianToUINT32( m_curRecPos.pKey) >= + if( f_bigEndianToUINT32( m_curRecPos.pKey) >= m_pCurSet->fromKey.uiRecordId) { setItemsFromBlock( &m_curRecPos); diff --git a/flaim/src/fslfileu.cpp b/flaim/src/fslfileu.cpp index 8ec5aa0..4803b3e 100644 --- a/flaim/src/fslfileu.cpp +++ b/flaim/src/fslfileu.cpp @@ -66,7 +66,7 @@ FSTATIC RCODE flmModifyTrackerRec( FlmRecord * pRecord); FSTATIC RCODE flmMaintThread( - F_Thread * pThread); + IF_Thread * pThread); FSTATIC RCODE fdictRemoveIndexes( FDB * pDb, @@ -764,43 +764,42 @@ RCODE flmIndexSetOfRecords( void * IxCallbackData, FINDEX_STATUS * pIndexStatus, FLMBOOL * pbHitEnd, - F_Thread * pThread, + IF_Thread * pThread, FlmRecord * pReusableRec) { - RCODE rc = FERR_OK; - FLMUINT uiDrn; - FLMUINT uiLastDrn = 0; - IXD * pIxd = NULL; - LFILE * pDataLFile; - FlmRecord * pRecord = NULL; - FlmRecord * pModRecord = NULL; - ServerLockObject * - pFileLockObj = pDb->pFile->pFileLockObj; - FLMBOOL bHitEnd = FALSE; - FLMBOOL bDataRecordRead; - FLMUINT uiCurrTime; - FLMUINT uiLastStatusTime = 0; - FLMUINT uiStartTime; - FLMUINT uiMinTU; - FLMUINT uiStatusIntervalTU; - FLMUINT uiRecsProcessed = 0; - FLMBOOL bUpdateTracker = FALSE; - FLMBOOL bHadUniqueKeys; - FLMBOOL bRelinquish = FALSE; - BTSK stackBuf [BH_MAX_LEVELS]; - BTSK * pStack = &stackBuf [0]; - FLMBYTE ucKeyBuf [DIN_KEY_SIZ]; - FLMBYTE ucSearchKey [DIN_KEY_SIZ]; - FLMBOOL bDoAllContainers = FALSE; - ITT * pItt; - POOL ReadPool; - void * pvTmpPoolMark = GedPoolMark( &pDb->TempPool); + RCODE rc = FERR_OK; + FLMUINT uiDrn; + FLMUINT uiLastDrn = 0; + IXD * pIxd = NULL; + LFILE * pDataLFile; + FlmRecord * pRecord = NULL; + FlmRecord * pModRecord = NULL; + IF_LockObject * pFileLockObj = pDb->pFile->pFileLockObj; + FLMBOOL bHitEnd = FALSE; + FLMBOOL bDataRecordRead; + FLMUINT uiCurrTime; + FLMUINT uiLastStatusTime = 0; + FLMUINT uiStartTime; + FLMUINT uiMinTU; + FLMUINT uiStatusIntervalTU; + FLMUINT uiRecsProcessed = 0; + FLMBOOL bUpdateTracker = FALSE; + FLMBOOL bHadUniqueKeys; + FLMBOOL bRelinquish = FALSE; + BTSK stackBuf [BH_MAX_LEVELS]; + BTSK * pStack = &stackBuf [0]; + FLMBYTE ucKeyBuf [DIN_KEY_SIZ]; + FLMBYTE ucSearchKey [DIN_KEY_SIZ]; + FLMBOOL bDoAllContainers = FALSE; + ITT * pItt; + F_Pool ReadPool; + void * pvTmpPoolMark = pDb->TempPool.poolMark(); - GedPoolInit( &ReadPool, 8192); + ReadPool.poolInit( 8192); FSInitStackCache( &stackBuf [0], BH_MAX_LEVELS); - FLM_MILLI_TO_TIMER_UNITS( 500, uiMinTU); - FLM_SECS_TO_TIMER_UNITS( 10, uiStatusIntervalTU); + uiMinTU = FLM_MILLI_TO_TIMER_UNITS( 500); + uiStatusIntervalTU = FLM_SECS_TO_TIMER_UNITS( 10); uiStartTime = FLM_GET_TIMER(); if( !pReusableRec) @@ -900,7 +899,7 @@ RCODE flmIndexSetOfRecords( uiLastDrn = 0; pStack->pKeyBuf = ucKeyBuf; - flmUINT32ToBigEndian( (FLMUINT32)uiStartDrn, ucSearchKey); + f_UINT32ToBigEndian( (FLMUINT32)uiStartDrn, ucSearchKey); if (RC_BAD( rc = FSBtSearch( pDb, pDataLFile, &pStack, ucSearchKey, 4, 0))) @@ -919,7 +918,7 @@ RCODE flmIndexSetOfRecords( for (;;) { - if ((uiDrn = flmBigEndianToUINT32( ucKeyBuf)) == DRN_LAST_MARKER) + if ((uiDrn = f_bigEndianToUINT32( ucKeyBuf)) == DRN_LAST_MARKER) { bHitEnd = TRUE; break; @@ -1016,7 +1015,7 @@ RCODE flmIndexSetOfRecords( // entries. Now that we are finished indexing the current record, // we need to reset the pool to free the CDL allocations. - GedPoolReset( &pDb->TempPool, pvTmpPoolMark); + pDb->TempPool.poolReset( pvTmpPoolMark); // See if there is an indexing callback @@ -1054,7 +1053,7 @@ RCODE flmIndexSetOfRecords( FSInitStackCache( &stackBuf [0], BH_MAX_LEVELS); pStack = stackBuf; pStack->pKeyBuf = ucKeyBuf; - flmUINT32ToBigEndian( (FLMUINT32)uiDrn, ucSearchKey); + f_UINT32ToBigEndian( (FLMUINT32)uiDrn, ucSearchKey); if (RC_BAD( rc = FSBtSearch( pDb, pDataLFile, &pStack, ucSearchKey, 4, 0))) { @@ -1098,7 +1097,7 @@ RCODE flmIndexSetOfRecords( break; } - if( pFileLockObj->ThreadWaitingLock()) + if( pFileLockObj->getWaiterCount()) { // See if our minimum run time has elapsed @@ -1134,7 +1133,7 @@ RCODE flmIndexSetOfRecords( if( FLM_ELAPSED_TIME( uiCurrTime, uiStartTime) > gv_FlmSysData.uiMaxCPInterval && - pDb->pFile->pWriteLockObj->ThreadWaitingLock()) + pDb->pFile->pWriteLockObj->getWaiterCount()) { bRelinquish = TRUE; break; @@ -1330,8 +1329,7 @@ Exit: FSReleaseStackCache( stackBuf, BH_MAX_LEVELS, FALSE); KrefCntrlFree( pDb); - GedPoolReset( &pDb->TempPool, pvTmpPoolMark); - GedPoolFree( &ReadPool); + pDb->TempPool.poolReset( pvTmpPoolMark); if( pReusableRec) { @@ -2658,7 +2656,8 @@ RCODE flmStartMaintThread( // Generate the thread name - if( RC_BAD( rc = f_pathReduce( pFile->pszDbPath, szThreadName, szBaseName))) + if( RC_BAD( rc = gv_FlmSysData.pFileSystem->pathReduce( + pFile->pszDbPath, szThreadName, szBaseName))) { goto Exit; } @@ -2674,7 +2673,7 @@ RCODE flmStartMaintThread( if( RC_BAD( rc = f_threadCreate( &pFile->pMaintThrd, flmMaintThread, szThreadName, - FLM_DEFAULT_THREAD_GROUP, 0, pFile, NULL, 32000))) + 0, 0, pFile, NULL, 32000))) { goto Exit; } @@ -2708,7 +2707,7 @@ FSTATIC RCODE flmRetrieveTrackerRec( FlmRecord ** ppRecord) { RCODE rc = FERR_OK; - POOL readPool; + F_Pool readPool; LFILE * pTrackerLFile; BTSK stackBuf[ BH_MAX_LEVELS]; BTSK * pStack = &stackBuf[ 0]; @@ -2718,7 +2717,7 @@ FSTATIC RCODE flmRetrieveTrackerRec( FLMUINT uiFoundDrn; FSInitStackCache( &stackBuf[ 0], BH_MAX_LEVELS); - GedPoolInit( &readPool, 8192); + readPool.poolInit( 8192); // Retrieve a tracker record for processing @@ -2729,7 +2728,7 @@ FSTATIC RCODE flmRetrieveTrackerRec( } pStack->pKeyBuf = ucKeyBuf; - flmUINT32ToBigEndian( (FLMUINT32)uiDrn, ucSearchKey); + f_UINT32ToBigEndian( (FLMUINT32)uiDrn, ucSearchKey); if( RC_BAD( rc = FSBtSearch( pDb, pTrackerLFile, &pStack, ucSearchKey, 4, 0))) @@ -2747,7 +2746,7 @@ FSTATIC RCODE flmRetrieveTrackerRec( // Stack points to leaf element - if( (uiFoundDrn = flmBigEndianToUINT32( ucKeyBuf)) == DRN_LAST_MARKER) + if( (uiFoundDrn = f_bigEndianToUINT32( ucKeyBuf)) == DRN_LAST_MARKER) { rc = RC_SET( FERR_EOF_HIT); goto Exit; @@ -2799,7 +2798,6 @@ Exit: } FSReleaseStackCache( stackBuf, BH_MAX_LEVELS, FALSE); - GedPoolFree( &readPool); return( rc); } @@ -2878,7 +2876,7 @@ Exit: Desc: *****************************************************************************/ FSTATIC RCODE flmMaintThread( - F_Thread * pThread) + IF_Thread * pThread) { RCODE rc = FERR_OK; FLMBOOL bStartedTrans = FALSE; @@ -2950,9 +2948,9 @@ FSTATIC RCODE flmMaintThread( pStatus->eDoing = FLM_MAINT_WAITING_FOR_LOCK; flmAssert( !(pDb->uiFlags & FDB_HAS_FILE_LOCK)); - if( RC_BAD( rc = pDb->pFile->pFileLockObj->Lock( TRUE, pDb, FALSE, + if( RC_BAD( rc = pDb->pFile->pFileLockObj->lock( pDb->hWaitSem, TRUE, FLM_NO_TIMEOUT, FLM_BACKGROUND_LOCK_PRIORITY, - pDb->pDbStats))) + pDb->pDbStats ? &pDb->pDbStats->LockStats : NULL))) { if( rc == FERR_IO_FILE_LOCK_ERR) { @@ -2978,7 +2976,7 @@ FSTATIC RCODE flmMaintThread( pDb->pFile->pFileLockObj->haveHigherPriorityWaiter( FLM_BACKGROUND_LOCK_PRIORITY)) { - if( RC_BAD( rc = pDb->pFile->pFileLockObj->Unlock( TRUE, pDb))) + if( RC_BAD( rc = pDb->pFile->pFileLockObj->unlock())) { goto Exit; } @@ -3091,7 +3089,7 @@ Exit: if( pDb && pDb->uiFlags & FDB_HAS_FILE_LOCK) { - (void)pDb->pFile->pFileLockObj->Unlock( TRUE, pDb); + pDb->pFile->pFileLockObj->unlock(); pDb->uiFlags &= ~(FDB_HAS_FILE_LOCK | FDB_FILE_LOCK_IMPLICIT); } diff --git a/flaim/src/fsrecget.cpp b/flaim/src/fsrecget.cpp index 0f06cb0..d7b996b 100644 --- a/flaim/src/fsrecget.cpp +++ b/flaim/src/fsrecget.cpp @@ -96,7 +96,7 @@ RCODE FSReadRecord( // Search the B-TREE for the record - flmUINT32ToBigEndian( (FLMUINT32)uiDrn, pDrnBuf); + f_UINT32ToBigEndian( (FLMUINT32)uiDrn, pDrnBuf); if (RC_OK( rc = FSBtSearch( pDb, pLFile, &pStack, pDrnBuf, 4, 0))) { rc = RC_SET( FERR_NOT_FOUND); @@ -117,7 +117,7 @@ Desc: Low-level routine to retrieve and build an internal tree record. ****************************************************************************/ RCODE FSReadElement( FDB * pDb, - POOL * pPool, + F_Pool * pPool, LFILE * pLFile, FLMUINT uiDrn, BTSK * pStack, @@ -129,7 +129,7 @@ RCODE FSReadElement( RCODE rc = FERR_OK; FlmRecord * pRecord = NULL; FLMBYTE * pCurElm; - void * pvPoolMark = GedPoolMark( pPool); + void * pvPoolMark = pPool->poolMark(); FLMUINT uiElmRecLen; FLMUINT uiFieldLen; FLMUINT uiLowestTransId; @@ -258,11 +258,10 @@ RCODE FSReadElement( uiFieldPos = 0; // Allocate the first field group from the pool. - - if ((pTempFldGroup = (FLDGROUP *) GedPoolAlloc( - pPool, sizeof( FLDGROUP))) == NULL) + + if( RC_BAD( rc = pPool->poolAlloc( + sizeof( FLDGROUP), (void **)&pTempFldGroup))) { - rc = RC_SET( FERR_MEM); goto Exit; } @@ -373,15 +372,14 @@ RCODE FSReadElement( if (RC_BAD( FSBlkNextElm( pStack))) { - LOCKED_BLOCK* pLastLockedBlock = pLockedBlock; + LOCKED_BLOCK * pLastLockedBlock = pLockedBlock; - if ((pLockedBlock = (LOCKED_BLOCK*) GedPoolAlloc( - pPool, sizeof( LOCKED_BLOCK))) == NULL) + if( RC_BAD( rc = pPool->poolAlloc( sizeof( LOCKED_BLOCK), + (void **)&pLockedBlock))) { - rc = RC_SET( FERR_MEM); goto Exit; } - + ScaHoldCache( pStack->pSCache); pLockedBlock->pSCache = pStack->pSCache; pLockedBlock->pNext = pLastLockedBlock; @@ -441,10 +439,9 @@ RCODE FSReadElement( fState.uiPosInElm += uiBytesToMove; uiDataPos += uiBytesToMove; - if ((pNextDataPiece = (DATAPIECE *) GedPoolAlloc( - pPool, sizeof( DATAPIECE))) == NULL) + if( RC_BAD( rc = pPool->poolAlloc( sizeof( DATAPIECE), + (void **)&pNextDataPiece))) { - rc = RC_SET( FERR_MEM); goto Exit; } @@ -466,12 +463,11 @@ RCODE FSReadElement( if (RC_BAD( FSBlkNextElm( pStack))) { - LOCKED_BLOCK* pLastLockedBlock = pLockedBlock; - - if ((pLockedBlock = (LOCKED_BLOCK *) GedPoolAlloc( - pPool, sizeof( LOCKED_BLOCK))) == NULL) + LOCKED_BLOCK * pLastLockedBlock = pLockedBlock; + + if( RC_BAD( rc = pPool->poolAlloc( sizeof( LOCKED_BLOCK), + (void **)&pLockedBlock))) { - rc = RC_SET( FERR_MEM); goto Exit; } @@ -625,7 +621,7 @@ Exit: pLockedBlock = pLockedBlock->pNext; } - GedPoolReset( pPool, pvPoolMark); + pPool->poolReset( pvPoolMark); if (pRecord) { diff --git a/flaim/src/fsrecupd.cpp b/flaim/src/fsrecupd.cpp index de3f615..b05ebbc 100644 --- a/flaim/src/fsrecupd.cpp +++ b/flaim/src/fsrecupd.cpp @@ -52,7 +52,7 @@ RCODE FSRecUpdate( FSInitStackCache( &stackBuf [0], BH_MAX_LEVELS); pStack->pKeyBuf = pKeyBuf; - flmUINT32ToBigEndian( (FLMUINT32)uiDrn, updCur.pKeyBuf); + f_UINT32ToBigEndian( (FLMUINT32)uiDrn, updCur.pKeyBuf); // Position to the element in the b-tree. @@ -121,7 +121,7 @@ RCODE FSRecUpdate( pElmBuf = updCur.pElmBuf; pElmBuf[ BBE_PKC] = BBE_FIRST_FLAG; pElmBuf[ BBE_KL] = DIN_KEY_SIZ; - flmUINT32ToBigEndian( (FLMUINT32)uiDrn, &pElmBuf[ BBE_KEY]); + f_UINT32ToBigEndian( (FLMUINT32)uiDrn, &pElmBuf[ BBE_KEY]); // BBE_RL is set in the flush routine diff --git a/flaim/src/fsrvlock.cpp b/flaim/src/fsrvlock.cpp deleted file mode 100644 index e9b4600..0000000 --- a/flaim/src/fsrvlock.cpp +++ /dev/null @@ -1,1282 +0,0 @@ -//------------------------------------------------------------------------- -// Desc: Database locking class. -// Tabs: 3 -// -// Copyright (c) 1998-2006 Novell, Inc. All Rights Reserved. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of version 2 of the GNU General Public -// License as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, contact Novell, Inc. -// -// To contact Novell about this file by physical or electronic mail, -// you may find current contact information at www.novell.com -// -// $Id: fsrvlock.cpp 12329 2006-01-20 17:49:30 -0700 (Fri, 20 Jan 2006) ahodgkinson $ -//------------------------------------------------------------------------- - -#include "flaimsys.h" - -#define LOCK_HASH_ENTRIES 256 - -/**************************************************************************** -Desc: -****************************************************************************/ -ServerLockManager::~ServerLockManager() -{ - // Signal all pending lock waiters. - - CheckLockTimeouts( TRUE); - - // Free everything in the avail lock list. This is where all - // of the lock objects should be at this point. - - while (m_pAvailLockList) - { - ServerLockObject_p pLockObject = m_pAvailLockList; - - UnlinkLockObject( pLockObject, FALSE, NULL); - - pLockObject->Release( NULL); - } - - // Free the hash table. - - f_free( &m_pHashTbl); - - return; -} - -/**************************************************************************** -Desc: Initializes the lock manager's hash table. -****************************************************************************/ -RCODE ServerLockManager::SetupHashTbl() -{ - return( flmAllocHashTbl( LOCK_HASH_ENTRIES, &m_pHashTbl)); -} - -/**************************************************************************** -Desc: Finds the lock object for the passed in item identifier. - If one is not found, one will be created. -****************************************************************************/ -ServerLockObject_p ServerLockManager::GetLockObject( - F_ItemId_p pItemId) -{ - F_MutexRef MutexRef( m_phMutex ); - FLMUINT uiBucket; - ServerLockObject_p pLockObject; - ServerLockObject_p pTmpLockObject; - - // Get the hash bucket. - - uiBucket = pItemId->GetHashBucket( m_pHashTbl, LOCK_HASH_ENTRIES); - - // See if the desired file is already in the hash bucket. - - MutexRef.Lock(); - - pLockObject = (ServerLockObject_p)m_pHashTbl [uiBucket].pFirstInBucket; - - // See if any of the objects match. - - while (pLockObject) - { - if (pItemId->IsEqual( pLockObject->GetItemIdPtr())) - goto Exit; - pLockObject = pLockObject->GetNext(); - } - - // If we didn't find a matching object, allocate an object and link it into - // the hash bucket. Check to see if we have any in the avail list - // first so that we don't have to allocate memory if we can avoid it. - - if ((pLockObject = m_pAvailLockList) != NULL) - { - UnlinkLockObject( pLockObject, FALSE, &MutexRef); - } - else - { - if ((pLockObject = f_new ServerLockObject) == NULL) - goto Exit; - } - - // Setup the new object and put it into the hash bucket. - - pLockObject->Setup( this, pItemId, uiBucket); - pTmpLockObject = - (ServerLockObject_p)m_pHashTbl [uiBucket].pFirstInBucket; - pLockObject->SetPrev( NULL); - pLockObject->SetNext( pTmpLockObject); - if (pTmpLockObject) - pTmpLockObject->SetPrev( pLockObject); - m_pHashTbl [uiBucket].pFirstInBucket = pLockObject; - -Exit: - - MutexRef.Unlock(); - return( pLockObject); -} - -/**************************************************************************** -Desc: Unlinks a lock object from whatever list it is in. -****************************************************************************/ -void ServerLockManager::UnlinkLockObject( - ServerLockObject * pLockObject, - FLMBOOL bPutInAvailList, - F_MutexRef * pMutexRef) -{ - ServerLockObject * pTmpLockObject; - FLMUINT uiBucket; - - if (pMutexRef) - pMutexRef->Lock(); - - /* - If hash bucket 0xFFFF, unlink from the avail list. Otherwise, - unlink from the hash bucket it is in. - */ - - if ((uiBucket = pLockObject->GetHashBucket()) == 0xFFFF) - { - if ((pTmpLockObject = pLockObject->GetPrev()) == NULL) - m_pAvailLockList = pLockObject->GetNext(); - else - pTmpLockObject->SetNext( pLockObject->GetNext()); - m_uiNumAvail--; - } - else - { - if ((pTmpLockObject = pLockObject->GetPrev()) == NULL) - m_pHashTbl [uiBucket].pFirstInBucket = pLockObject->GetNext(); - else - pTmpLockObject->SetNext( pLockObject->GetNext()); - } - if ((pTmpLockObject = pLockObject->GetNext()) != NULL) - pTmpLockObject->SetPrev( pLockObject->GetPrev()); - - if (bPutInAvailList) - { - if (m_uiNumAvail >= 50) - { - flmAssert( getRefCount() == 1); - pLockObject->Release( NULL); - } - else - { - pLockObject->Setup( this, NULL, 0xFFFF); - if (m_pAvailLockList) - m_pAvailLockList->SetPrev( pLockObject); - pLockObject->SetPrev( NULL); - pLockObject->SetNext( m_pAvailLockList); - m_pAvailLockList = pLockObject; - m_uiNumAvail++; - } - } - - if (pMutexRef) - pMutexRef->Unlock(); -} - -/**************************************************************************** -Desc: Checks for any pending lock requests that have timed out. -****************************************************************************/ -void ServerLockManager::CheckLockTimeouts( - F_MutexRef * pMutexRef, - FLMBOOL bTimeoutAll) -{ - FLMUINT uiCurrTime; - LOCK_WAITER * pLockWaiter; - - pMutexRef->Lock(); - uiCurrTime = (FLMUINT)FLM_GET_TIMER(); - - while ((m_pFirstLockWaiter) && - ((bTimeoutAll) || - ((m_pFirstLockWaiter->uiWaitTime) && - (FLM_ELAPSED_TIME( uiCurrTime, m_pFirstLockWaiter->uiWaitStartTime) >= - m_pFirstLockWaiter->uiWaitTime)))) - { - // Sanity check - - flmAssert( m_pFirstLockWaiter->pPrevGlobal == NULL); - - // Lock waiter has timed out. - - pLockWaiter = m_pFirstLockWaiter; - - // Remove from global list and lock object's list - - RemoveWaiter( pLockWaiter); - pLockWaiter->pLockObject->RemoveWaiter( pLockWaiter); - - /* Tell the waiter that it got a lock error. */ - - *(pLockWaiter->pRc) = RC_SET( FERR_IO_FILE_LOCK_ERR); - f_semSignal( pLockWaiter->hESem); - } - - pMutexRef->Unlock(); -} - -/**************************************************************************** -Desc: Signal a lock waiter that has a matching thread id. -****************************************************************************/ -void ServerLockManager::SignalLockWaiter( - FLMUINT uiThreadId) -{ - FLMUINT uiCurrTime; - LOCK_WAITER * pLockWaiter; - LOCK_WAITER * pNextWaiter; - F_MutexRef MutexRef( m_phMutex); - - - f_mutexLock( *m_phMutex); - uiCurrTime = (FLMUINT)FLM_GET_TIMER(); - - for( pLockWaiter = m_pFirstLockWaiter; - pLockWaiter; - pLockWaiter = pNextWaiter) - { - pNextWaiter = pLockWaiter->pNextGlobal; - - if( pLockWaiter->uiThreadId == uiThreadId) - { - // Remove from global list and lock object's list - - RemoveWaiter( pLockWaiter); - pLockWaiter->pLockObject->RemoveWaiter( pLockWaiter); - - /* Tell the waiter that it got a lock error. */ - - *(pLockWaiter->pRc) = RC_SET( FERR_IO_FILE_LOCK_ERR); - f_semSignal( pLockWaiter->hESem); - break; - } - } - - f_mutexUnlock( *m_phMutex); - return; -} - -/**************************************************************************** -Desc: Inserts a waiter into the global list of waiters, sorted by - its end wait time. - NOTE: This routine assumes that the lock manager's semaphore - is already locked. -****************************************************************************/ -void ServerLockManager::InsertWaiter( - LOCK_WAITER * pLockWaiter) -{ - LOCK_WAITER * pPrevLockWaiter; - - // Determine where in the list this lock waiter should go. - - if ((pPrevLockWaiter = m_pFirstLockWaiter) != NULL) - { - FLMUINT uiCurrTime = FLM_GET_TIMER(); - FLMUINT uiElapTime; - FLMUINT uiTimeLeft; - - while (pPrevLockWaiter) - { - // Waiters with zero wait time go to end of list. - // They never time out. - - if (!pPrevLockWaiter->uiWaitTime) - { - - // Should go BEFORE the first zero waiter. - - pPrevLockWaiter = pPrevLockWaiter->pPrevGlobal; - break; - } - else if (!pLockWaiter->uiWaitTime) - { - if (!pPrevLockWaiter->pNextGlobal) - { - break; - } - pPrevLockWaiter = pPrevLockWaiter->pNextGlobal; - } - else - { - // Determine how much time is left on the previous - // lock waiter's timer. If it is less than the - // new lock waiter's wait time, the new lock waiter - // should be inserted AFTER it. Otherwise, the - // new lock waiter should be inserted BEFORE it. - - uiElapTime = FLM_ELAPSED_TIME( uiCurrTime, - pPrevLockWaiter->uiWaitStartTime); - if (uiElapTime >= pPrevLockWaiter->uiWaitTime) - { - uiTimeLeft = 0; - } - else - { - uiTimeLeft = pPrevLockWaiter->uiWaitTime - uiElapTime; - } - - // New lock waiter will time out before previous lock - // waiter - insert it BEFORE the previous lock waiter. - - if (pLockWaiter->uiWaitTime < uiTimeLeft) - { - pPrevLockWaiter = pPrevLockWaiter->pPrevGlobal; - break; - } - else - { - if (!pPrevLockWaiter->pNextGlobal) - break; - pPrevLockWaiter = pPrevLockWaiter->pNextGlobal; - } - } - } - } - - // Insert into list AFTER pPrevLockWaiter. - - if ((pLockWaiter->pPrevGlobal = pPrevLockWaiter) != NULL) - { - if ((pLockWaiter->pNextGlobal = pPrevLockWaiter->pNextGlobal) != NULL) - { - pLockWaiter->pNextGlobal->pPrevGlobal = pLockWaiter; - } - pPrevLockWaiter->pNextGlobal = pLockWaiter; - } - else - { - if( (pLockWaiter->pNextGlobal = m_pFirstLockWaiter) != NULL) - { - m_pFirstLockWaiter->pPrevGlobal = pLockWaiter; - } - m_pFirstLockWaiter = pLockWaiter; - } -} - -/**************************************************************************** -Desc: See if this item ID is equal to another F_ItemId. -****************************************************************************/ -FLMBOOL FFileItemId::IsEqual( - F_ItemId_p pItemId) -{ - FFileItemId_p pFFileItemId; - RFileItemId_p pRFileItemId; - char szName1[ F_FILENAME_SIZE]; - char szName2[ F_FILENAME_SIZE]; - FLMUINT uiItemType = pItemId->GetItemType(); - - switch (uiItemType) - { - case FFILE_ITEM: - case FFILE_TRANS_ITEM: - { - if (m_uiItemType != uiItemType) - return( FALSE); - pFFileItemId = (FFileItemId_p)pItemId; - - /* First see if the FFILE pointers are the same. */ - - if (pFFileItemId->GetFilePtr() == this->GetFilePtr()) - return( TRUE); - - /* Next see if the file names are the same. */ - - this->GetFileName( szName1); - pFFileItemId->GetFileName( szName2); -#if !defined( FLM_UNIX) - if (f_stricmp( szName1, szName2) == 0) - return( TRUE); -#else - if (f_strcmp( szName1, szName2) == 0) - return( TRUE); -#endif - break; - } - - case RFILE_ITEM: - case RFILE_TRANS_ITEM: - { - if ((uiItemType == RFILE_ITEM && - m_uiItemType != FFILE_ITEM) || - (uiItemType == RFILE_TRANS_ITEM && - m_uiItemType != FFILE_TRANS_ITEM)) - { - return( FALSE); - } - pRFileItemId = (RFileItemId_p)pItemId; - - /* See if the file names are the same. */ - - this->GetFileName( szName1); - pRFileItemId->GetFileName( szName2); -#if !defined( FLM_UNIX) - if (f_stricmp( szName1, szName2) == 0) - return( TRUE); -#else - if (f_strcmp( szName1, szName2) == 0) - return( TRUE); -#endif - break; - } - - default: - { - break; - } - } - - return( FALSE); -} - -/**************************************************************************** -Desc: Get file name for this file item. -****************************************************************************/ -void FFileItemId::GetFileName( - char * pszFileName) -{ - char szTmpPath[ F_PATH_MAX_SIZE]; - - f_pathReduce( m_pFile->pszDbPath, szTmpPath, pszFileName); - -#if !defined( FLM_UNIX) - while( *pszFileName) - { - *pszFileName = f_toupper( *pszFileName); - pszFileName++; - } -#endif -} - -/**************************************************************************** -Desc: -****************************************************************************/ -RFileItemId::RFileItemId( - FLMBYTE * pszFileName, - FLMBOOL bTrans) -{ - char * pszTmp = &m_szFileName [0]; - - while( *pszFileName) - { -#if !defined( FLM_UNIX) - *pszFileName = f_toupper( *pszFileName); -#else - *pszTmp++ = *pszFileName; -#endif - pszFileName++; - } - - *pszTmp = 0; - m_uiItemType = (FLMUINT)((bTrans) - ? (FLMUINT)RFILE_TRANS_ITEM - : (FLMUINT)RFILE_ITEM); -} - -/**************************************************************************** -Desc: See if this item ID is equal to another F_ItemId. -****************************************************************************/ -FLMBOOL RFileItemId::IsEqual( - F_ItemId * pItemId) -{ - FFileItemId * pFFileItemId; - RFileItemId * pRFileItemId; - char szName1 [F_FILENAME_SIZE]; - char szName2 [F_FILENAME_SIZE]; - FLMUINT uiItemType = pItemId->GetItemType(); - - switch (uiItemType) - { - case FFILE_ITEM: - case FFILE_TRANS_ITEM: - if ((uiItemType == FFILE_ITEM && - m_uiItemType != RFILE_ITEM) || - (uiItemType == FFILE_TRANS_ITEM && - m_uiItemType != RFILE_TRANS_ITEM)) - { - return( FALSE); - } - pFFileItemId = (FFileItemId_p)pItemId; - - /* See if the file names are the same. */ - - this->GetFileName( szName1); - pFFileItemId->GetFileName( szName2); -#if !defined( FLM_UNIX) - if (f_stricmp( szName1, szName2) == 0) - return( TRUE); -#else - if (f_strcmp( szName1, szName2) == 0) - return( TRUE); -#endif - break; - case RFILE_ITEM: - case RFILE_TRANS_ITEM: - if (m_uiItemType != uiItemType) - return( FALSE); - pRFileItemId = (RFileItemId_p)pItemId; - - /* See if the file names are the same. */ - - this->GetFileName( szName1); - pRFileItemId->GetFileName( szName2); -#if !defined( FLM_UNIX) - if (f_stricmp( szName1, szName2) == 0) - return( TRUE); -#else - if (f_strcmp( szName1, szName2) == 0) - return( TRUE); -#endif - break; - default: - break; - } - return( FALSE); -} - -/**************************************************************************** -Desc: -****************************************************************************/ -ServerLockObject::ServerLockObject() -{ - m_pServerLockMgr = NULL; - m_pItemId = NULL; - m_uiLockThreadId = 0; - m_uiLockTime = 0; - m_uiLockCnt = 0; - m_pFirstLockWaiter = - m_pLastLockWaiter = NULL; - m_uiNumWaiters = 0; - m_pNext = m_pPrev = NULL; - m_uiSharedLockCnt = 0; - m_bExclLock = FALSE; - m_uiBucket = 0xFFFF; - m_bStartTimeSet = FALSE; -} - -/**************************************************************************** -Desc: -****************************************************************************/ -FLMINT ServerLockObject::Release( - F_MutexRef * pMutexRef) -{ - FLMINT iRefCnt = F_Base::Release(); - - if( !iRefCnt) - { - goto Exit; - } - - // When it is no longer pointed to from anything but the server lock - // manager, put it into the avail list. - - if (iRefCnt == 1) - { - LOCK_WAITER * pLockWaiter; - F_MutexRef TmpMutexRef( m_pServerLockMgr->GetSemPtr()); - - if( !pMutexRef) - { - pMutexRef = &TmpMutexRef; - } - - // Signal all waiters that they cannot get the lock. - - pMutexRef->Lock(); - while (m_pFirstLockWaiter) - { - pLockWaiter = m_pFirstLockWaiter; - - // Remove from global list and lock object's list - - RemoveWaiter( pLockWaiter); - m_pServerLockMgr->RemoveWaiter( pLockWaiter); - - // Tell the waiter that it got a lock error and signal - // the thread to wake it up. - - *(pLockWaiter->pRc) = RC_SET( FERR_IO_FILE_LOCK_ERR); - f_semSignal( pLockWaiter->hESem); - } - - m_pServerLockMgr->UnlinkLockObject( this, TRUE, NULL); - - pMutexRef->Unlock(); - } - -Exit: - - return( iRefCnt); -} - -/**************************************************************************** -Desc: Initialize some data for the lock object. -****************************************************************************/ -void ServerLockObject::Setup( - ServerLockManager_p pServerLockMgr, - F_ItemId_p pItemId, - FLMUINT uiBucket) -{ - m_pServerLockMgr = pServerLockMgr; - if (m_pItemId) - { - m_pItemId->Release(); - m_pItemId = NULL; - } - if ((m_pItemId = pItemId) != NULL) - { - m_pItemId->AddRef(); - } - m_uiBucket = uiBucket; -} - -/**************************************************************************** -Desc: Removes a waiter from the list of waiters on this object. - NOTE: This routine assumes that the lock manager's semaphore - is already locked. -****************************************************************************/ -void ServerLockObject::RemoveWaiter( - LOCK_WAITER * pLockWaiter) -{ - if (pLockWaiter->pNext) - pLockWaiter->pNext->pPrev = pLockWaiter->pPrev; - else - m_pLastLockWaiter = pLockWaiter->pPrev; - - if (pLockWaiter->pPrev) - pLockWaiter->pPrev->pNext = pLockWaiter->pNext; - else - m_pFirstLockWaiter = pLockWaiter->pNext; - flmAssert( m_uiNumWaiters > 0); - m_uiNumWaiters--; -} - -/**************************************************************************** -Desc: Lock this object. If object is locked, wait the specified - number of seconds. -****************************************************************************/ -RCODE ServerLockObject::Lock( - FLMBOOL bLogEvent, - FDB * pDb, // used for event callbacks. - FLMBOOL bSendSuspendEvent, // Send suspend event, as opposed to - // waiting event, when waiting. - FLMBOOL bExclReq, // Exclusive or shared lock? - FLMUINT uiMaxWaitSecs, // Maximum wait time in seconds. - FLMINT iPriority, // Lock priority - DB_STATS * pDbStats // Place to collect stats. - ) -{ - RCODE rc = FERR_OK; - RCODE TempRc; - LOCK_WAITER LockWait; - FLMBOOL bSemLocked = FALSE; - F_MutexRef MutexRef( m_pServerLockMgr->GetSemPtr()); - - MutexRef.Lock(); - bSemLocked = TRUE; - - if ((m_pFirstLockWaiter) || - (m_bExclLock) || - ((bExclReq) && (m_uiSharedLockCnt))) - { - - // Object is locked, wait to get lock. - - if (!uiMaxWaitSecs) - { - rc = RC_SET( FERR_IO_FILE_LOCK_ERR); - goto Exit; - } - - // Set up to wait for the lock. - - f_memset( &LockWait, 0, sizeof( LockWait)); - LockWait.pLockObject = this; - LockWait.hESem = F_SEM_NULL; - if (RC_BAD( f_semCreate( &LockWait.hESem))) - { - rc = RC_SET( FERR_IO_FILE_LOCK_ERR); - goto Exit; - } - - // Link into list of waiters on this object. - - if ((LockWait.pPrev = m_pLastLockWaiter) != NULL) - { - LockWait.pPrev->pNext = &LockWait; - } - else - { - m_pFirstLockWaiter = &LockWait; - } - m_pLastLockWaiter = &LockWait; - m_uiNumWaiters++; - - LockWait.uiThreadId = f_threadId(); - LockWait.pRc = &rc; - // Note: rc better be changed to success or lock error - // by the process that signals us. - rc = RC_SET( FERR_ACCESS_DENIED); - LockWait.bExclReq = bExclReq; - LockWait.iPriority = iPriority; - LockWait.uiWaitStartTime = (FLMUINT)FLM_GET_TIMER(); - if (bExclReq && pDbStats) - { - f_timeGetTimeStamp( &LockWait.StartTime); - LockWait.pDbStats = pDbStats; - } - if (uiMaxWaitSecs == FLM_NO_TIMEOUT) - { - LockWait.uiWaitTime = 0; - } - else - { - FLM_SECS_TO_TIMER_UNITS( uiMaxWaitSecs, - LockWait.uiWaitTime); - } - - // Link to list of global waiters - ordered by end time. - - m_pServerLockMgr->InsertWaiter( &LockWait); - - MutexRef.Unlock(); - bSemLocked = FALSE; - - // Do the event callback, if any registered. - - if (bLogEvent && - gv_FlmSysData.LockEvents.pEventCBList) - { - flmDoEventCallback( F_EVENT_LOCKS, - (FEventType)((bSendSuspendEvent) - ? F_EVENT_LOCK_SUSPENDED - : F_EVENT_LOCK_WAITING), - (void *)pDb, - (void *)LockWait.uiThreadId); - } - - // Now just wait to be signaled. - - if (RC_BAD( TempRc = f_semWait( LockWait.hESem, F_SEM_WAITFOREVER))) - { -#ifdef FLM_NLM - EnterDebugger(); -#else - flmAssert( 0); -#endif - rc = TempRc; - } - else - { - - // Process that signaled us better set the rc to something - // besides FERR_ACCESS_DENIED. - - if (rc == FERR_ACCESS_DENIED) - { -#ifdef FLM_NLM - EnterDebugger(); -#else - flmAssert( 0); -#endif - } - } - - // Do the event callback, if any registered. - - if (bLogEvent && - gv_FlmSysData.LockEvents.pEventCBList) - { - if (RC_BAD( rc)) - { - flmDoEventCallback( F_EVENT_LOCKS, - F_EVENT_LOCK_TIMEOUT, - (void *)pDb, - (void *)LockWait.uiThreadId); - } - else - { - flmDoEventCallback( F_EVENT_LOCKS, - (FEventType)((bSendSuspendEvent) - ? F_EVENT_LOCK_RESUMED - : F_EVENT_LOCK_GRANTED), - (void *)pDb, - (void *)LockWait.uiThreadId); - } - } - - /* Free the semaphore */ - - f_semDestroy( &LockWait.hESem); - } - else - { - - // Object is NOT locked in a conflicting mode. Grant the - // lock immediately. - - m_uiLockThreadId = f_threadId(); - m_bExclLock = bExclReq; - if (!bExclReq) - { - m_uiSharedLockCnt++; - } - else - { - m_uiLockTime = (FLMUINT)FLM_GET_TIMER(); - flmAssert( m_uiSharedLockCnt == 0); - - // Take care of statistics gathering. - - if (pDbStats) - { - - // If m_bStartTimeSet is TRUE, we started the - // clock the last time nobody had the exclusive - // lock, so we need to sum up idle time now. - - if (m_bStartTimeSet) - { - flmAddElapTime( &m_StartTime, &pDbStats->NoLocks.ui64ElapMilli); - pDbStats->NoLocks.ui64Count++; - } - - // Restart the clock for this locker. - - f_timeGetTimeStamp( &m_StartTime); - m_bStartTimeSet = TRUE; - } - else - { - m_bStartTimeSet = FALSE; - } - } - - // Do the event callback, if any registered. - - if (bLogEvent && - !bSendSuspendEvent && - gv_FlmSysData.LockEvents.pEventCBList) - { - MutexRef.Unlock(); - bSemLocked = FALSE; - flmDoEventCallback( F_EVENT_LOCKS, - F_EVENT_LOCK_GRANTED, - (void *)pDb, - (void *)m_uiLockThreadId); - } - } -Exit: - if (RC_OK( rc)) - { - m_uiLockCnt++; - } - if (bSemLocked) - { - MutexRef.Unlock(); - } - return( rc); -} - -/**************************************************************************** -Desc: Unlock this object. If there is a pending lock request, give - the lock to the next waiter. -****************************************************************************/ -RCODE ServerLockObject::Unlock( - FLMBOOL bLogEvent, - FDB * pDb, - FLMBOOL bRelease, - DB_STATS * pDbStats - ) -{ - RCODE rc = FERR_OK; - F_SEM hESem; - LOCK_WAITER * pLockWaiter; - F_MutexRef MutexRef( m_pServerLockMgr->GetSemPtr()); - - MutexRef.Lock(); - - if (m_bExclLock) - { - flmAssert( m_uiSharedLockCnt == 0); - m_bExclLock = FALSE; - - // Record how long the lock was held, if we were tracking - // it. - - if (pDbStats && m_bStartTimeSet) - { - flmAddElapTime( &m_StartTime, &pDbStats->HeldLock.ui64ElapMilli); - pDbStats->HeldLock.ui64Count++; - } - m_bStartTimeSet = FALSE; - } - else - { - flmAssert( m_uiSharedLockCnt > 0); - m_uiSharedLockCnt--; - } - - // Do the event callback, if any registered. - // NOTE: flmDoEventCallback locks the event semaphore. - // Since we are inside the lock manager's semaphore lock, - // the callback should not do ANYTHING that would cause - // us to end up in here again! - - if (bLogEvent && - gv_FlmSysData.LockEvents.pEventCBList) - { - flmDoEventCallback( F_EVENT_LOCKS, - F_EVENT_LOCK_RELEASED, - (void *)pDb, - (void *)m_uiLockThreadId); - } - - m_uiLockThreadId = 0; - - /* See if we need to signal the next set of waiters. */ - - if (m_pFirstLockWaiter && !m_uiSharedLockCnt) - { - m_bExclLock = m_pFirstLockWaiter->bExclReq; - while (m_pFirstLockWaiter) - { - if (!m_bExclLock) - { - m_uiSharedLockCnt++; - } - - - pLockWaiter = m_pFirstLockWaiter; - hESem = pLockWaiter->hESem; - - // Unlink the waiter from the list of waiters on this lock - // object and then from the global list of waiters. - // IMPORTANT NOTE: Do NOT signal the semaphore until AFTER - // doing this unlinking. This is because LOCK_WAITER - // structures exist only on the stack of the thread - // being signaled. If we tried to assign m_pFirstLockWaiter after - // signaling the semaphore, the LOCK_WAITER structure could - // disappear and m_pFirstLockWaiter would get garbage. - - RemoveWaiter( pLockWaiter); - m_pServerLockMgr->RemoveWaiter( pLockWaiter); - - // Update statistics for the waiter. - - if (pLockWaiter->pDbStats) - { - flmAddElapTime( &pLockWaiter->StartTime, - &pLockWaiter->pDbStats->WaitingForLock.ui64ElapMilli); - pLockWaiter->pDbStats->WaitingForLock.ui64Count++; - } - - // Grant the lock to this waiter and signal the thread - // to wake it up. - - m_uiLockThreadId = pLockWaiter->uiThreadId; - if (m_bExclLock) - { - m_uiLockTime = (FLMUINT)FLM_GET_TIMER(); - - // Restart the stats timer - - if (pDbStats) - { - m_bStartTimeSet = TRUE; - f_timeGetTimeStamp( &m_StartTime); - } - } - - *(pLockWaiter->pRc) = FERR_OK; - - f_semSignal( hESem); - - // If the next waiter is not a shared lock request or - // the lock that was granted was exclusive, we stop - // here. - - if (m_bExclLock || - (m_pFirstLockWaiter && m_pFirstLockWaiter->bExclReq)) - { - break; - } - } - } - else if (bRelease && - !m_pFirstLockWaiter && // No one is wating for the object - !m_uiSharedLockCnt) // No one has the object locked - { - // Release the object. If the reference count drops to 1, - // the object will be put in the avail list. The caller - // should have performed an AddRef() on the object at - // some point prior to calling this method. Once this routine - // returns the caller should not attempt further access of the object. - Release( &MutexRef); - bRelease = FALSE; - } - - // Start timer, if not already running. If the timer is not set at - // this point, it will be because nobody has been granted the exclusive - // lock. If someone was granted the exclusive lock, the timer would - // have been started above. We start it here so we can track idle - // time. - - if (pDbStats && !m_bStartTimeSet && !bRelease) - { - flmAssert( !m_bExclLock); - m_bStartTimeSet = TRUE; - f_timeGetTimeStamp( &m_StartTime); - } - - // If we get to this point and bRelease is still TRUE, someone was - // waiting to acquire the lock or there is still a shared lock - // count. - - if( bRelease) - { - // All lock waiters should have done an AddRef on the lock object. - // At this point we should still have our reference to the object, - // the lock manager's reference, and a reference from at least one - // waiter (that may have been granted above). - - flmAssert( getRefCount() >= 3); - F_Base::Release(); - } - - MutexRef.Unlock(); - return( rc); -} - -/**************************************************************************** -Desc: Returns information about the pending lock requests. -****************************************************************************/ -void ServerLockObject::GetLockInfo( - FLMINT iPriority, - FLOCK_INFO * pLockInfo - ) -{ - LOCK_WAITER * pLockWaiter; - F_MutexRef MutexRef( m_pServerLockMgr->GetSemPtr()); - - f_memset( pLockInfo, 0, sizeof( FLOCK_INFO)); - - MutexRef.Lock(); - - // Get the type of lock, if any. - - if (m_bExclLock) - { - pLockInfo->eCurrLockType = FLM_LOCK_EXCLUSIVE; - pLockInfo->uiThreadId = m_uiLockThreadId; - } - else if (m_uiSharedLockCnt) - { - pLockInfo->eCurrLockType = FLM_LOCK_SHARED; - pLockInfo->uiThreadId = 0; - } - else - { - pLockInfo->eCurrLockType = FLM_LOCK_NONE; - pLockInfo->uiThreadId = 0; - } - - // Get information on pending lock requests. - - pLockWaiter = m_pFirstLockWaiter; - for ( ; pLockWaiter; pLockWaiter = pLockWaiter->pNext ) - { - - // Count the number of exclusive and shared waiters. - - if (pLockWaiter->bExclReq) - { - pLockInfo->uiNumExclQueued++; - } - else - { - pLockInfo->uiNumSharedQueued++; - } - - // Count the number of waiters at or above input priority. - - if (pLockWaiter->iPriority >= iPriority) - { - pLockInfo->uiPriorityCount++; - } - } - - MutexRef.Unlock(); -} - -/**************************************************************************** -Desc: Return the lock waiters for this object. -****************************************************************************/ -RCODE ServerLockObject::GetLockInfo( - FLMBOOL bGetWaiters, - void * pvLockUsers - ) -{ - RCODE rc = FERR_OK; - F_MutexRef MutexRef( m_pServerLockMgr->GetSemPtr()); - LOCK_USER * pLockUser; - LOCK_WAITER * pLockWaiter; - FLMUINT uiCnt; - FLMUINT uiElapTime; - FLMUINT uiCurrTime; - - MutexRef.Lock(); - uiCurrTime = (FLMUINT)FLM_GET_TIMER(); - if (!bGetWaiters) - { - pLockUser = (LOCK_USER *)pvLockUsers; - pLockUser->uiThreadId = m_uiLockThreadId; - uiElapTime = FLM_ELAPSED_TIME( uiCurrTime, m_uiLockTime); - FLM_TIMER_UNITS_TO_MILLI( uiElapTime, pLockUser->uiTime); - } - else - { - if (!m_uiNumWaiters && !m_uiLockThreadId) - { - *((LOCK_USER **)pvLockUsers) = NULL; - goto Exit; - } - uiCnt = m_uiNumWaiters + 1; // Add one for lock holder. - - if( RC_BAD( rc = f_alloc( - sizeof( LOCK_USER) * (uiCnt + 1), &pLockUser))) - { - goto Exit; - } - - *((LOCK_USER **)pvLockUsers) = pLockUser; - - // Output the lock holder first. - - pLockUser->uiThreadId = m_uiLockThreadId; - uiElapTime = FLM_ELAPSED_TIME( uiCurrTime, m_uiLockTime); - FLM_TIMER_UNITS_TO_MILLI( uiElapTime, pLockUser->uiTime); - pLockUser++; - uiCnt--; - - // Output the lock waiters. - - pLockWaiter = m_pFirstLockWaiter; - while (pLockWaiter && uiCnt) - { - pLockUser->uiThreadId = pLockWaiter->uiThreadId; - uiElapTime = FLM_ELAPSED_TIME( uiCurrTime, - pLockWaiter->uiWaitStartTime); - FLM_TIMER_UNITS_TO_MILLI( uiElapTime, pLockUser->uiTime); - pLockWaiter = pLockWaiter->pNext; - pLockUser++; - uiCnt--; - } - flmAssert( pLockWaiter == NULL && uiCnt == 0); - - // zero out the last one. - - f_memset( pLockUser, 0, sizeof( LOCK_USER)); - } -Exit: - MutexRef.Unlock(); - return( rc); -} - -/**************************************************************************** -Desc: Return the lock waiters for this object. -****************************************************************************/ -RCODE ServerLockObject::GetLockInfo( - FlmLockInfo * pLockInfo) -{ - RCODE rc = FERR_OK; - F_MutexRef MutexRef( m_pServerLockMgr->GetSemPtr()); - LOCK_WAITER * pLockWaiter; - FLMUINT uiCnt; - FLMUINT uiElapTime; - FLMUINT uiCurrTime; - FLMUINT uiMilli; - - MutexRef.Lock(); - uiCurrTime = (FLMUINT)FLM_GET_TIMER(); - - if (!m_uiNumWaiters && !m_uiLockThreadId) - { - pLockInfo->setLockCount( 0); - goto Exit; - } - uiCnt = m_uiNumWaiters + 1; // Add one for lock holder. - if( pLockInfo->setLockCount( uiCnt) == FALSE) - { - goto Exit; - } - - // Output the lock holder first. - - uiElapTime = FLM_ELAPSED_TIME( uiCurrTime, m_uiLockTime); - FLM_TIMER_UNITS_TO_MILLI( uiElapTime, uiMilli); - if( pLockInfo->addLockInfo( 0, m_uiLockThreadId, uiMilli) == FALSE) - { - goto Exit; - } - uiCnt--; - - // Output the lock waiters. - - pLockWaiter = m_pFirstLockWaiter; - while( pLockWaiter && uiCnt) - { - uiElapTime = FLM_ELAPSED_TIME( uiCurrTime, pLockWaiter->uiWaitStartTime); - FLM_TIMER_UNITS_TO_MILLI( uiElapTime, uiMilli); - if( pLockInfo->addLockInfo( (m_uiNumWaiters - uiCnt) + 1, - pLockWaiter->uiThreadId, uiMilli) == FALSE) - { - goto Exit; - } - pLockWaiter = pLockWaiter->pNext; - uiCnt--; - } - flmAssert( pLockWaiter == NULL && uiCnt == 0); - -Exit: - - MutexRef.Unlock(); - return( rc); -} - -/**************************************************************************** -Desc: Returns TRUE if there are lock waiters with a priority > iPriority -****************************************************************************/ -FLMBOOL ServerLockObject::haveHigherPriorityWaiter( - FLMINT iPriority) -{ - LOCK_WAITER * pLockWaiter; - F_MutexRef MutexRef( m_pServerLockMgr->GetSemPtr()); - FLMBOOL bWaiters = FALSE; - - MutexRef.Lock(); - - pLockWaiter = m_pFirstLockWaiter; - for ( ; pLockWaiter; pLockWaiter = pLockWaiter->pNext ) - { - // If we find a waiter with a priority > the specified - // priority, we're done. - - if (pLockWaiter->iPriority > iPriority) - { - bWaiters = TRUE; - break; - } - } - - MutexRef.Unlock(); - return( bWaiters); -} diff --git a/flaim/src/fsrvlock.h b/flaim/src/fsrvlock.h deleted file mode 100644 index 9f98df0..0000000 --- a/flaim/src/fsrvlock.h +++ /dev/null @@ -1,427 +0,0 @@ -//------------------------------------------------------------------------- -// Desc: Database locking class - definitions. -// Tabs: 3 -// -// Copyright (c) 1998-2006 Novell, Inc. All Rights Reserved. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of version 2 of the GNU General Public -// License as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, contact Novell, Inc. -// -// To contact Novell about this file by physical or electronic mail, -// you may find current contact information at www.novell.com -// -// $Id: fsrvlock.h 12329 2006-01-20 17:49:30 -0700 (Fri, 20 Jan 2006) ahodgkinson $ -//------------------------------------------------------------------------- - -#ifndef FSRVLOCK_H -#define FSRVLOCK_H - -#include "fpackon.h" - -// IMPORTANT NOTE: No other include files should follow this one except -// for fpackoff.h - -class ServerLockManager; -class ServerLockObject; -class F_ItemId; -class FFileItemId; -class RFileItemId; - -typedef ServerLockManager * ServerLockManager_p; -typedef ServerLockObject * ServerLockObject_p; -typedef F_ItemId * F_ItemId_p; -typedef FFileItemId * FFileItemId_p; -typedef RFileItemId * RFileItemId_p; - -/************************************************************************** -Desc: This structure is used to keep track of threads waiting for a - lock. -**************************************************************************/ -typedef struct LOCK_WAITER -{ - ServerLockObject * pLockObject; // Pointer to lock object. - FLMUINT uiThreadId; // Thread of waiter - F_SEM hESem; // Semaphore to signal when lock is - // granted (or denied). - RCODE * pRc; // Pointer to return code that is to - // be set when lock is granted or - // denied. - FLMUINT uiWaitStartTime; - // Time we started waiting. - FLMUINT uiWaitTime; // Time pending lock request should - // wait before being timed out. - // Zero means should not be timed out. - FLMBOOL bExclReq; // TRUE if exclusive lock request. - FLMINT iPriority; // Priority of waiter. - F_TMSTAMP StartTime; // Time we started waiting (for stats) - DB_STATS * pDbStats; // Statistics to update. - LOCK_WAITER * pNext; // Next lock waiter in list. - LOCK_WAITER * pPrev; // Previous lock waiter in list. - LOCK_WAITER * pNextGlobal; // Next lock waiter in global list - // that is ordered according to - // udWaitEndTime. - LOCK_WAITER * pPrevGlobal; // Previous lock waiter in global list -} LOCK_WAITER; - -/**************************************************************************** -Desc: The ServerLockManager class manages ServerLockObject objects. -****************************************************************************/ -class ServerLockManager : public F_Base -{ -public: - - FINLINE ServerLockManager( - F_MUTEX * phMutex) - { - m_phMutex = phMutex; - m_pFirstLockWaiter = NULL; - m_pHashTbl = NULL; - m_uiNumAvail = 0; - m_pAvailLockList = NULL; - } - - virtual ~ServerLockManager(); - - FINLINE void SetMutexPtr( - F_MUTEX * phMutex) - { - m_phMutex = phMutex; - } - - RCODE SetupHashTbl( void); - - FINLINE void CheckLockTimeouts( - FLMBOOL bTimeoutAll) - { - F_MutexRef MutexRef( m_phMutex); - - CheckLockTimeouts( &MutexRef, bTimeoutAll); - } - - void InsertWaiter( - LOCK_WAITER * pLockWaiter); - - FINLINE void RemoveWaiter( - LOCK_WAITER * pLockWaiter) - { - if (pLockWaiter->pNextGlobal) - { - pLockWaiter->pNextGlobal->pPrevGlobal = pLockWaiter->pPrevGlobal; - } - - if (pLockWaiter->pPrevGlobal) - { - pLockWaiter->pPrevGlobal->pNextGlobal = pLockWaiter->pNextGlobal; - } - else - { - m_pFirstLockWaiter = pLockWaiter->pNextGlobal; - } - } - - ServerLockObject_p GetLockObject( - F_ItemId * pItemId); - - void SignalLockWaiter( - FLMUINT uiThreadId); - - FINLINE void UnlinkLockObject( - ServerLockObject * pLockObject, - FLMBOOL bPutInAvailList) - { - F_MutexRef MutexRef( m_phMutex); - - UnlinkLockObject( pLockObject, bPutInAvailList, &MutexRef); - } - - void UnlinkLockObject( - ServerLockObject_p pLockObject, - FLMBOOL bPutInAvailList, - F_MutexRef * pMutexRef); - - F_MUTEX * GetSemPtr( void) - { - return( m_phMutex); - } - -private: - - F_MUTEX * m_phMutex; - FBUCKET * m_pHashTbl; - LOCK_WAITER * m_pFirstLockWaiter; - FLMUINT m_uiNumAvail; - ServerLockObject * m_pAvailLockList; - - void CheckLockTimeouts( - F_MutexRef * pMutexRef, - FLMBOOL bTimeoutAll); - -friend class F_ServerLockMgrPage; -}; - -/**************************************************************************** -Desc: The item id that identifies a particular object. -****************************************************************************/ -class F_ItemId : public F_Base -{ -public: - - FINLINE F_ItemId() - { - m_uiItemType = 0; - } - - virtual ~F_ItemId() - { - } - - virtual FLMBOOL IsEqual( - F_ItemId * pItemId) = 0; - - virtual FLMUINT GetHashBucket( - FBUCKET * pHashTbl, - FLMUINT uiHashTblSize) = 0; - - FINLINE FLMUINT GetItemType( void) - { - return( m_uiItemType); - } - -protected: - - FLMUINT m_uiItemType; - -#define FFILE_ITEM 1 -#define RFILE_ITEM 2 -#define FFILE_TRANS_ITEM 3 -#define RFILE_TRANS_ITEM 4 -}; - -/**************************************************************************** -Desc: The item id that identifies an FFILE object. -****************************************************************************/ -class FFileItemId : public F_ItemId -{ -public: - - FINLINE FFileItemId( - FFILE * pFile, - FLMBOOL bTrans) - { - m_pFile = pFile; - m_uiItemType = (FLMUINT)((bTrans) - ? (FLMUINT)FFILE_TRANS_ITEM - : (FLMUINT)FFILE_ITEM); - } - - virtual ~FFileItemId() - { - } - - FLMBOOL IsEqual( - F_ItemId * pItemId); - - FINLINE FLMUINT GetHashBucket( - FBUCKET * pHashTbl, - FLMUINT uiHashTblSize) - { - char szFileName[ F_PATH_MAX_SIZE]; - - // Extract the file name - - this->GetFileName( szFileName); - - // Determine what hash bucket the file should be in - based on file name. - - return( flmStrHashBucket( szFileName, pHashTbl, uiHashTblSize)); - } - - FINLINE FFILE * GetFilePtr( void) - { - return( m_pFile); - } - - void GetFileName( - char * pszFileNameRV); - -private: - - FFILE * m_pFile; -}; - -/**************************************************************************** -Desc: The item id that identifies a file being used by rebuild. -****************************************************************************/ -class RFileItemId : public F_ItemId -{ -public: - RFileItemId( - FLMBYTE * pszFileName, - FLMBOOL bTrans = FALSE); - - virtual ~RFileItemId() - { - } - - FLMBOOL IsEqual( - F_ItemId * pItemId); - - FINLINE FLMUINT GetHashBucket( - FBUCKET * pHashTbl, - FLMUINT uiHashTblSize) - { - return( flmStrHashBucket( m_szFileName, pHashTbl, uiHashTblSize)); - } - - FINLINE void GetFileName( - char * pszFileNameRV) - { - f_strcpy( pszFileNameRV, m_szFileName); - } - -private: - - char m_szFileName[ F_PATH_MAX_SIZE]; -}; - -/**************************************************************************** -Desc: The ServerLockObject is used to lock and unlock a particular - object. -****************************************************************************/ -class ServerLockObject : public F_Base -{ -public: - - ServerLockObject(); - - virtual ~ServerLockObject() - { - if( m_pItemId) - { - m_pItemId->Release(); - } - } - - void Setup( - ServerLockManager * pServerLockMgr, - F_ItemId * pItemId, - FLMUINT uiBucket); - - RCODE Lock( - FLMBOOL bLogEvent, - FDB * pDb, - FLMBOOL bSendSuspendEvent, - FLMBOOL bExclLock, - FLMUINT uiMaxWaitSecs, - FLMINT iPriority, - DB_STATS * pDbStats = NULL); - - RCODE Unlock( - FLMBOOL bLogEvent, - FDB * pDb, - FLMBOOL bRelease = FALSE, - DB_STATS * pDbStats = NULL); - - FLMINT Release( - F_MutexRef * pMutexRef); - - FINLINE FLMINT Release( void) - { - return( Release( NULL)); - } - - FINLINE F_ItemId * GetItemIdPtr( void) - { - return( m_pItemId); - } - - FINLINE FLMUINT GetHashBucket( void) - { - return m_uiBucket; - } - - FINLINE ServerLockObject * GetNext( void) - { - return( m_pNext); - } - - FINLINE void SetNext( - ServerLockObject * pNext) - { - m_pNext = pNext; - } - - FINLINE ServerLockObject * GetPrev( void) - { - return( m_pPrev); - } - - FINLINE void SetPrev( - ServerLockObject * pPrev) - { - m_pPrev = pPrev; - } - - void RemoveWaiter( - LOCK_WAITER * pLockWaiter); - - FINLINE ServerLockManager * GetLockManager( void) - { - return( m_pServerLockMgr); - } - - FINLINE FLMBOOL ThreadWaitingLock( void) - { - return( ((m_pFirstLockWaiter) ? (FLMBOOL)TRUE : (FLMBOOL)FALSE) ); - } - - FINLINE FLMUINT LockCnt( void) - { - return( m_uiLockCnt); - } - - void GetLockInfo( - FLMINT iPriority, - FLOCK_INFO * pLockInfo); - - RCODE GetLockInfo( - FLMBOOL bGetWaiters, - void * pvLockUsers); - - RCODE GetLockInfo( - FlmLockInfo * pLockInfo); - - FLMBOOL haveHigherPriorityWaiter( - FLMINT iPriority); - -private: - - ServerLockManager * m_pServerLockMgr; - F_ItemId * m_pItemId; - FLMUINT m_uiLockThreadId; - FLMUINT m_uiLockTime; - FLMUINT m_uiLockCnt; - LOCK_WAITER * m_pFirstLockWaiter; - LOCK_WAITER * m_pLastLockWaiter; - FLMUINT m_uiNumWaiters; - ServerLockObject * m_pNext; - ServerLockObject * m_pPrev; - FLMUINT m_uiSharedLockCnt; - FLMBOOL m_bExclLock; - FLMUINT m_uiBucket; - F_TMSTAMP m_StartTime; - FLMBOOL m_bStartTimeSet; -}; - -#include "fpackoff.h" - -#endif diff --git a/flaim/src/fssearch.cpp b/flaim/src/fssearch.cpp index 4af3995..87143d1 100644 --- a/flaim/src/fssearch.cpp +++ b/flaim/src/fssearch.cpp @@ -80,7 +80,7 @@ RCODE FSBtSearch( rc = FSBtScanNonLeafData( pStack, keyLen == 1 ? (FLMUINT) *key - : (FLMUINT) flmBigEndianToUINT32( key)); + : (FLMUINT) f_bigEndianToUINT32( key)); } if (RC_BAD( rc)) @@ -144,7 +144,8 @@ RCODE FSBtSearchEnd( goto Exit; } - flmUINT32ToBigEndian( (FLMUINT32)uiDrn, key); + f_UINT32ToBigEndian( (FLMUINT32)uiDrn, key); + for (;;) { pStack->uiFlags = FULL_STACK; @@ -546,7 +547,7 @@ RCODE FSBtScanNonLeafData( { uiMid = (uiLow + uiHigh) >> 1; - uiCurDrn = flmBigEndianToUINT32( &pBlk[ BH_OVHD + (uiMid << 3)]); + uiCurDrn = f_bigEndianToUINT32( &pBlk[ BH_OVHD + (uiMid << 3)]); if (uiCurDrn == 0) { @@ -563,7 +564,7 @@ RCODE FSBtScanNonLeafData( while (uiMid) { - uiCurDrn = flmBigEndianToUINT32( + uiCurDrn = f_bigEndianToUINT32( &pBlk[ BH_OVHD + ((uiMid - 1) << 3)]); if (uiDrn != uiCurDrn) @@ -621,7 +622,7 @@ RCODE FSBtScanNonLeafData( // Set curElm and the key buffer. pStack->uiCurElm = BH_OVHD + (uiMid << 3); - flmUINT32ToBigEndian( (FLMUINT32)uiCurDrn, pStack->pKeyBuf); + f_UINT32ToBigEndian( (FLMUINT32)uiCurDrn, pStack->pKeyBuf); return (rc); } diff --git a/flaim/src/fstructs.h b/flaim/src/fstructs.h index cd3a60e..d6355ed 100644 --- a/flaim/src/fstructs.h +++ b/flaim/src/fstructs.h @@ -27,7 +27,6 @@ struct FFILE; struct FNOTIFY; -struct FBUCKET; struct QUERY_HDR; struct CDL; struct FDICT; @@ -41,19 +40,11 @@ struct IFD; // Typedefs for the http callback function and for the functions that register // and deregister the http callback function. -#if defined( FLM_WIN) - typedef HMODULE FLM_MODULE_HANDLE; -#elif defined( FLM_UNIX) - typedef void * FLM_MODULE_HANDLE; -#elif defined( FLM_NLM) - typedef void * FLM_MODULE_HANDLE; -#else - #error "Unsupported platform" -#endif +typedef void * FLM_MODULE_HANDLE; typedef int (* URLHandler)( - HRequest * pHRequest, - void * pvUserData); + HRequest * pHRequest, + void * pvUserData); typedef int (* REG_URL_HANDLER_FN)( FLM_MODULE_HANDLE hModule, @@ -68,10 +59,10 @@ typedef int (* DEREG_URL_HANDLER_FN)( URLHandler fnHandler); typedef const char * (* REQ_PATH_FN)( - HRequest * pHRequest); + HRequest * pHRequest); typedef const char * (* REQ_QUERY_FN)( - HRequest * pHRequest); + HRequest * pHRequest); typedef const char * (* REQ_HDR_VALUE_FN)( HRequest * pHRequest, @@ -88,83 +79,84 @@ typedef int (* PRINTF_FN)( ... ); typedef int (* EMIT_FN)( - HRequest * pHRequest); + HRequest * pHRequest); typedef void (* SET_NO_CACHE_FN)( HRequest * pHRequest, const char * pszHeader); typedef int (* SEND_HDR_FN)( - HRequest * pHRequest, - int iStatus); + HRequest * pHRequest, + int iStatus); typedef int (* SET_IO_MODE_FN)( - HRequest * pHRequest, - int bRaw, - int bOutput); + HRequest * pHRequest, + int bRaw, + int bOutput); typedef int (* SEND_BUFF_FN)( - HRequest * hRequest, + HRequest * hRequest, const void * pvBuf, - size_t bufsz); + FLMSIZET bufsz); typedef void * (* ACQUIRE_SESSION_FN)( HRequest * pHRequest); typedef void (* RELEASE_SESSION_FN)( - void * pvHSession); + void * pvHSession); typedef void * (* ACQUIRE_USER_FN)( - void * pvHSession, - HRequest * pHRequest); + void * pvHSession, + HRequest * pHRequest); typedef void (* RELEASE_USER_FN)( - void * pvHUser); + void * pvHUser); typedef int (* SET_SESSION_VALUE_FN)( - void * pvHSession, - const char * pcTag, - const void * pvData, - size_t uiSize); + void * pvHSession, + const char * pcTag, + const void * pvData, + FLMSIZET uiSize); typedef int (* GET_SESSION_VALUE_FN)( - void * pvHSession, - const char * pcTag, - void * pvData, - size_t * puiSize); + void * pvHSession, + const char * pcTag, + void * pvData, + FLMSIZET * puiSize); typedef int (* GET_GBL_VALUE_FN)( - const char * pcTag, - void * pvData, - size_t * puiSize); + const char * pcTag, + void * pvData, + FLMSIZET * puiSize); typedef int (* SET_GBL_VALUE_FN)( - const char * pcTag, - const void * pvData, - size_t uiSize); + const char * pcTag, + const void * pvData, + FLMSIZET uiSize); typedef int (* RECV_BUFFER_FN)( - HRequest * pHRequest, - void * pvBuf, - size_t * puiBufSize); + HRequest * pHRequest, + void * pvBuf, + FLMSIZET * puiBufSize); // These are flags that are passed to the http server during registration. // They're copied verbatum from John Calcote's code -/* Which protocol stack, CLEAR or TLS (secure) - the default is both.*/ + #define HR_STK_BOTH 0x0000 /* -- MUTUALLY EXCLUSIVE -- */ #define HR_STK_NOTLS 0x0001 /* register ONLY with CLEAR stack */ #define HR_STK_NOCLEAR 0x0002 /* register ONLY with TLS stack */ #define HR_STK_MASK 0x000F -/* Which level of authentication is required - the default is NONE. */ +// Which level of authentication is required - the default is NONE + #define HR_AUTH_NONE 0x0000 /* -- NOT MUTUALLY EXCLUSIVE -- */ #define HR_AUTH_USER 0x0010 /* user authentication required */ #define HR_AUTH_SADMIN 0x0020 /* SADMIN authentication required */ #define HR_AUTH_USERSA (HR_AUTH_USER|HR_AUTH_SADMIN) #define HR_AUTH_MASK 0x00F0 -/* Which authentication realm should be used - the default is none. -** A realm must be choosen if USER authentication level is specified.*/ +// Which authentication realm should be used - the default is none + #define HR_REALM_NONE 0x0000 /* -- MUTUALLY EXCLUSIVE -- */ #define HR_REALM_HFIO 0x0100 /* http file through .htaccess */ #define HR_REALM_NDS 0x0200 /* nds through dclient */ @@ -226,12 +218,12 @@ typedef int (* RECV_BUFFER_FN)( #define HTS_GATEWAY_TIMEOUT 504 /* 1.1 */ #define HTS_BAD_HTTP_VERSION 505 /* 1.1 */ -/* Authentication Levels - again, copied from John Calcote: httpdefs.h */ +// Authentication Levels - again, copied from John Calcote: httpdefs.h + #define HAL_NONE 0 #define HAL_USER 1 #define HAL_SADMIN 2 - // Flags for the uiQsortFlags parameter - used in sorting/indexing. #define KY_DUP_CHK_SRT 0x01 @@ -243,86 +235,14 @@ typedef int (* RECV_BUFFER_FN)( // Flags for the uiKrAction parameter - used in sorting/indexing. -#define KREF_DEL_KEYS 0x01 -#define KREF_ADD_KEYS 0x02 -#define KREF_INDEXING_ONLY 0x04 -#define KREF_IN_MODIFY 0x10 -#define KREF_MISSING_KEYS_OK 0x20 - -#if defined( FLM_NLM) - - #define FLM_GET_TIMER() (FLMUINT)GetCurrentTime() - - #define FLM_SECS_TO_TIMER_UNITS( uiSeconds, uiTU) \ - ConvertSecondsToTicks( (LONG)(uiSeconds), 0, (LONG *)(&(uiTU))) - - #define FLM_TIMER_UNITS_TO_SECS( uiTU, uiSeconds) \ - { \ - LONG udDummy; \ - ConvertTicksToSeconds( (LONG)(uiTU), (LONG *)(&(uiSeconds)), &udDummy); \ - } - - #define FLM_TIMER_UNITS_TO_MILLI( uiTU, uiMilli) \ - { \ - LONG udTenths; \ - LONG udSeconds; \ - ConvertTicksToSeconds( (LONG)(uiTU), (LONG *)(&(udSeconds)), &udTenths); \ - uiMilli = (FLMUINT)(udSeconds) * 1000 + (FLMUINT)udTenths * 100; \ - } - #define FLM_MILLI_TO_TIMER_UNITS( uiMilliSeconds, uiTU) \ - { \ - LONG udTenths, udSeconds; \ - udSeconds = ((LONG) uiMilliSeconds) / 1000; \ - udTenths = (((LONG) uiMilliSeconds) % 1000) / 100; \ - ConvertSecondsToTicks( udSeconds, udTenths, (LONG *)(&(uiTU))); \ - } - -#elif defined( FLM_UNIX) - - // gettimeofday() is actually 4 times faster than time() on - // Solaris. gethrtime() is even faster. On Linux time() is the - // fastest; gettimeofday() is 50% slower. clock() is the - // slowest on both Solaris and Linux. We use a new function for - // millisec resolution. The implementation is OS dependent. - - #define FLM_GET_TIMER() (FLMUINT) f_timeGetMilliTime() - #define FLM_SECS_TO_TIMER_UNITS( uiSeconds, uiTU) \ - ((uiTU) = ((uiSeconds) * 1000)) - #define FLM_TIMER_UNITS_TO_SECS( uiTU, uiSeconds) \ - ((uiSeconds) = ((uiTU) / 1000)) - #define FLM_TIMER_UNITS_TO_MILLI( uiTU, uiMilli) \ - ((uiMilli) = (uiTU)) - #define FLM_MILLI_TO_TIMER_UNITS( uiMilli, uiTU) \ - ((uiTU) = (uiMilli)) -#else /* FLM_WIN */ - - #define FLM_GET_TIMER() \ - (FLMUINT)GetTickCount() - - #define FLM_SECS_TO_TIMER_UNITS( uiSeconds, uiTU) \ - ((uiTU) = (uiSeconds) * 1000) - - #define FLM_TIMER_UNITS_TO_SECS( uiTU, uiSeconds) \ - ((uiSeconds) = (uiTU) / 1000) - - #define FLM_TIMER_UNITS_TO_MILLI( uiTU, uiMilli) \ - (uiMilli = (uiTU)) - - #define FLM_MILLI_TO_TIMER_UNITS( uiMilliSeconds, uiTU) \ - (uiTU = (uiMilliSeconds)) - -#endif - -// This macro for calculating elapsed time accounts for the -// possibility of the time wrapping - which it will for some -// of our counters (WIN is milliseconds and wraps in 49.7 days). - -#define FLM_ELAPSED_TIME(uiLaterTime,uiEarlierTime) \ - (FLMUINT)(((uiLaterTime) >= (uiEarlierTime)) \ - ? (FLMUINT)((uiLaterTime) - (uiEarlierTime)) \ - : (FLMUINT)((0xFFFFFFFF - (uiEarlierTime)) + (uiLaterTime))) +#define KREF_DEL_KEYS 0x01 +#define KREF_ADD_KEYS 0x02 +#define KREF_INDEXING_ONLY 0x04 +#define KREF_IN_MODIFY 0x10 +#define KREF_MISSING_KEYS_OK 0x20 #include "fpackon.h" + // IMPORTANT NOTE: No other include files should follow this one except // for fpackoff.h @@ -331,9 +251,9 @@ typedef int (* RECV_BUFFER_FN)( // C/S Address types -#define FLM_CS_NO_ADDR 0x00 -#define FLM_CS_IP_ADDR 0x01 -#define FLM_CS_STREAM_ADDR 0x02 +#define FLM_CS_NO_ADDR 0x00 +#define FLM_CS_IP_ADDR 0x01 +#define FLM_CS_STREAM_ADDR 0x02 // Define the overhead space required to manage encrypted fields. @@ -346,7 +266,7 @@ typedef int (* RECV_BUFFER_FN)( // C/S Address sizes -#define FLM_CS_MAX_ADDR_LEN 128 +#define FLM_CS_MAX_ADDR_LEN 128 typedef void * (* ALLOC_PAGE_FUNC)( FLMUINT uiSizeToAllocate); @@ -607,7 +527,7 @@ typedef struct SCACHE_MGR FLMUINT uiHashTblBits; // Number of bits that are significant // for the hash table size. - F_FixedAlloc * pAllocators[ 2]; + IF_FixedAlloc * pAllocators[ 2]; // Fixed size allocators for cache blocks // We only support 4K and 8K blocks @@ -767,10 +687,10 @@ typedef struct RCACHE_MGR // disk at the same time. F_MUTEX hMutex; // Mutex for controlling record // cache. - F_FixedAlloc * pRCacheAlloc; // RCACHE structure allocator - F_FixedAlloc * pRecAlloc; // Fixed size allocator for record + IF_FixedAlloc * pRCacheAlloc; // RCACHE structure allocator + IF_FixedAlloc * pRecAlloc; // Fixed size allocator for record // objects - F_BufferAlloc * pRecBufAlloc; // Record buffer allocator + IF_BufferAlloc * pRecBufAlloc; // Record buffer allocator #ifdef FLM_DEBUG FLMBOOL bDebug; // Debug mode? @@ -885,20 +805,14 @@ typedef struct FLMSYSDATA // Mutex for controlling access to // the server lock manager. - F_FileHdlMgr * pFileHdlMgr; // Used to Manage all FileHdl objects - - F_FileSystemImp * pFileSystem;// File system used to configure options + IF_FileSystem * pFileSystem;// File system used to configure options // for interacting with OS file system. FLMBOOL bTempDirSet; // TRUE if temporary directory has been set FLMBOOL bOkToDoAsyncWrites; // OK To do async writes, if available. - FLMBOOL bOkToUseESM; // OK to use Extended Server Memory, - // if available FLMBOOL bCheckCache; // Do extra checking of cache? - ServerLockManager * - pServerLockMgr;// Pointer to server lock manager. FLMUINT uiMaxCPInterval; // Maximum number of seconds to allow between // checkpoints @@ -935,7 +849,7 @@ typedef struct FLMSYSDATA FLMUINT uiMaxCache; // Maximum amount of record and block cache (in bytes) SCACHE_MGR SCacheMgr; // Shared cache manager RCACHE_MGR RCacheMgr; // Record cache manager - F_Thread * pMonitorThrd; // Monitor thread + IF_Thread * pMonitorThrd; // Monitor thread FLM_STATS Stats; // Statistics structure F_MUTEX hQueryMutex; // Mutex for managing query list @@ -966,77 +880,36 @@ typedef struct FLMSYSDATA FEVENT_HDR LockEvents; // Lock events FEVENT_HDR UpdateEvents; // Update events FEVENT_HDR SizeEvents; // Size threshold events - POOL KRefPool; // Memory Pool that is only used by + F_Pool KRefPool; // Memory Pool that is only used by // record updaters for key building HTTPCONFIGPARAMS HttpConfigParms; FLMUINT uiMaxFileSize; F_Logger * pLogger; - F_SlabManager * pSlabManager; + IF_SlabManager * pSlabManager; -#ifdef FLM_DEBUG - // Variables for memory allocation tracking. - - FLMBOOL bTrackLeaks; - FLMBOOL bLogLeaks; - FLMBOOL bStackWalk; - FLMBOOL bMemTrackingInitialized; - FLMUINT uiInitThreadId; - F_MUTEX hMemTrackingMutex; - void ** ppvMemTrackingPtrs; - FLMUINT uiMemTrackingPtrArraySize; - FLMUINT uiMemNumPtrs; - FLMUINT uiMemNextPtrSlotToUse; - FLMUINT uiAllocCnt; -#if defined( FLM_WIN) - HANDLE hMemProcess; -#endif - -#ifdef DEBUG_SIM_OUT_OF_MEM - FLMUINT uiOutOfMemSimEnabledFlag; - //we pick a random number for the flag so that it is hard to accidentally - //turn this flag on by writing memory out-of-bounds. -#define OUT_OF_MEM_SIM_ENABLED_FLAG 2149614134UL - f_randomGenerator memSimRandomGen; - FLMUINT uiSimOutOfMemFailTotal; - FLMUINT uiSimOutOfMemFailSequence; -#endif //#ifdef DEBUG_SIM_OUT_OF_MEM -#endif - - F_ThreadMgr * pThreadMgr; - F_SessionMgr * pSessionMgr; - F_MUTEX hHttpSessionMutex; + IF_ThreadMgr * pThreadMgr; + F_SessionMgr * pSessionMgr; + F_MUTEX hHttpSessionMutex; -#ifdef FLM_LINUX - FLMUINT uiLinuxMajorVer; - FLMUINT uiLinuxMinorVer; - FLMUINT uiLinuxRevision; -#endif - - FLMUINT uiMaxStratifyIterations; - FLMUINT uiMaxStratifyTime; + FLMUINT uiMaxStratifyIterations; + FLMUINT uiMaxStratifyTime; } FLMSYSDATA; #ifndef ALLOCATE_SYS_DATA extern FLMSYSDATA gv_FlmSysData; + extern FLMUINT gv_uiBackIxThrdGroup; + extern FLMUINT gv_uiCPThrdGrp; + extern FLMUINT gv_uiDbThrdGrp; #else FLMSYSDATA gv_FlmSysData; + FLMUINT gv_uiBackIxThrdGroup = F_INVALID_THREAD_GROUP; + FLMUINT gv_uiCPThrdGrp = F_INVALID_THREAD_GROUP; + FLMUINT gv_uiDbThrdGrp = F_INVALID_THREAD_GROUP; #endif -/*************************************************************************** -Desc: This is the hash bucket header structure. Each bucket header - points to a list of items that belong to the bucket. -***************************************************************************/ -typedef struct FBUCKET -{ - void * pFirstInBucket; // Pointer to first item in the bucket. - // The type of structure being pointed to - // depends on the usage of the hash bucket. - FLMUINT uiHashValue; // Hash value for this bucket. -} FBUCKET; - /**************************************************************************** Desc: This structure is used to sort keys before the keys are actually added to an index. @@ -1089,7 +962,7 @@ typedef struct KREF_CNTRL // transaction. It is used when doing // duplicate checking. FLMBOOL bKrefSetup; // True if the KRefCntrl has been initialized. - POOL * pPool; // GEDCOM pool to use + F_Pool * pPool; // GEDCOM pool to use FLMBOOL bReusePool; // Reuse pool instead of free it? FLMBOOL bHaveCompoundKey; // True if a compound key has been processed. void * pReset; // Used to reset pool for failed records. @@ -1148,7 +1021,7 @@ typedef struct CS_CONTEXT FLMUINT uiOpSeqNum; // Operation Sequence Number - // inremented for every operation that is // performed. - POOL pool; // Pool to pass into Wire objects. + F_Pool pool; // Pool to pass into Wire objects. char pucAddr[ FLM_CS_MAX_ADDR_LEN]; // Stream address. This is // aligned on a 4-byte boundary @@ -1378,7 +1251,7 @@ typedef struct FDB // killed. FLMUINT uiKilledTime; // Time transaction was killed, if // non-zero. - POOL tmpKrefPool; // GEDCOM KREF pool to be used during + F_Pool tmpKrefPool; // GEDCOM KREF pool to be used during // read transactions - only used when // checking indexes. // Misc. DB Info. @@ -1392,7 +1265,7 @@ typedef struct FDB FDIAG Diag; // Diagnostic information from the // last FLAIM operation. - POOL TempPool; // Temporary GEDCOM Memory Pool. It + F_Pool TempPool; // Temporary GEDCOM Memory Pool. It // is only used for the duration of // a FLAIM operation and then reset. // The first block in the pool is @@ -1430,6 +1303,9 @@ typedef struct FDB // the conclusion of the transaction. F_BKGND_IX * pIxStopList; // Indexing threads to stop at // the conclusion of the transaction. + F_SEM hWaitSem; // Semaphore used when waiting to + // acquire a file or write lock + // on the database #ifdef FLM_DEBUG //NOTE: Always set - no need to be part of memset. @@ -1579,7 +1455,7 @@ typedef struct FFILE // because of a critical error. RCODE rcMustClose; // Return code that caused bMustClose to // be set. - POOL krefPool; // GEDCOM Kref pool to be used during update + F_Pool krefPool; // GEDCOM Kref pool to be used during update // transactions. FILE_HDR FileHdr; // This structure contains the file // header information for the file. @@ -1644,24 +1520,21 @@ typedef struct FFILE #define FLM_MAX_DB_ENC_KEY_LEN 256 - F_FileIdList * pFileIdList; // List of unique IDs that have been - // assigned to the physical files that - // are mananaged by the FFILE. - F_IOBufferMgr * pBufferMgr; + IF_IOBufferMgr * pBufferMgr; #define MAX_WRITE_BUFFER_BYTES (4 * 1024 * 1024) #define MAX_PENDING_WRITES (MAX_WRITE_BUFFER_BYTES / 4096) #define MAX_LOG_BUFFER_SIZE (256 * 1024) - F_IOBuffer * pCurrLogBuffer; + IF_IOBuffer * pCurrLogBuffer; FLMUINT uiCurrLogWriteOffset;// Offset in current write buffer FLMUINT uiCurrLogBlkAddr; // Address of first block in the current // buffer. FLMBYTE * pucLogHdrWriteBuf; // Aligned buffer (on win) for writing // the log header. - ServerLockObject * pFileLockObj; // Object for locking the file. - ServerLockObject * pWriteLockObj; // Object for locking to do writing. - F_FileHdlImp * pLockFileHdl; // Lock file handle for 3.x databases. + IF_LockObject * pFileLockObj; // Object for locking the file. + IF_LockObject * pWriteLockObj; // Object for locking to do writing. + IF_FileHdl * pLockFileHdl; // Lock file handle for 3.x databases. FNOTIFY * pLockNotifies; // Pointer to a list of notifies to // perform when this file is finally // locked (points to a linked list of @@ -1684,8 +1557,8 @@ typedef struct FFILE FLMUINT uiLastCheckpointTime; // Last time we successfully completed a // checkpoint. - F_Thread * pMonitorThrd; // Database monitor thread - F_Thread * pCPThrd; // Checkpoint thread. + IF_Thread * pMonitorThrd; // Database monitor thread + IF_Thread * pCPThrd; // Checkpoint thread. CP_INFO * pCPInfo; // Pointer to checkpoint thread's // information buffer - used for // communicating information to the @@ -1703,7 +1576,6 @@ typedef struct FFILE #define DBF_BEING_CLOSED 0x04 // Database is being closed - cannot open. FLMBOOL bBackupActive; // Backup is currently being run against the // database. - FlmECache * pECacheMgr; // Extended cache manager F_CCS * pDbWrappingKey; // Master Wrapping Key FLMBOOL bInLimitedMode; // Set to true if we're running // in limited mode. @@ -1712,7 +1584,7 @@ typedef struct FFILE // want to override the bAllowLimitedMode parameter on the open. If // the version of flaim supports encryption, but the database was not // built with encryption, we will set the database into limited mode. - F_Thread * pMaintThrd; // Processes background jobs queued in + IF_Thread * pMaintThrd; // Processes background jobs queued in // the tracker (except indexing) F_SEM hMaintSem; // Used to signal the maintenance thread // that there may be some work to do @@ -1850,9 +1722,9 @@ Desc: ****************************************************************************/ typedef struct GED_STREAM { - F_FileHdl * pFileHdl; + IF_FileHdl * pFileHdl; FLMUINT uiBufSize; - FLMUINT uiFilePos; + FLMUINT64 ui64FilePos; char * pBuf; char * pThis; char * pLast; @@ -1877,14 +1749,14 @@ Desc: ****************************************************************************/ typedef struct EXP_IMP_INFO { - F_FileHdl * pFileHdl; - FLMBYTE * pBuf; - FLMUINT uiBufSize; - FLMUINT uiBufUsed; - FLMUINT uiCurrBuffOffset; - FLMUINT uiFilePos; - FLMBOOL bDictRecords; - FLMBOOL bBufDirty; + IF_FileHdl * pFileHdl; + FLMBYTE * pBuf; + FLMUINT uiBufSize; + FLMUINT uiBufUsed; + FLMUINT uiCurrBuffOffset; + FLMUINT64 ui64FilePos; + FLMBOOL bDictRecords; + FLMBOOL bBufDirty; } EXP_IMP_INFO; /**************************************************************************** @@ -1920,7 +1792,7 @@ typedef enum /**************************************************************************** Desc: FLAIM object base class ****************************************************************************/ -class F_HashObject : public F_Base +class F_HashObject : public F_Object { public: @@ -2073,24 +1945,14 @@ public: FFILE * pFile, F_NameTable ** ppNameTable); - FINLINE F_XMLImport * getXmlImport( void) - { - return( m_pXmlImport); - } - - FINLINE F_XMLExport * getXmlExport( void) - { - return( m_pXmlExport); - } - FLMUINT getNextToken( void); void * getKey( FLMUINT * puiKeyLen = NULL); - FLMINT AddRef(); + FLMINT FLMAPI AddRef(); - FLMINT Release(); + FLMINT FLMAPI Release(); FINLINE eHashObjType objectType( void) { @@ -2118,8 +1980,6 @@ private: FNOTIFY * m_pNotifyList; F_NameTable * m_pNameTable; FLMUINT m_uiDictSeqNum; - F_XMLImport * m_pXmlImport; - F_XMLExport * m_pXmlExport; FLMUINT m_uiNameTableFFileId; FLMUINT m_uiNextToken; F_HashTable * m_pDbTable; @@ -2132,7 +1992,7 @@ friend class F_SessionMgr; /**************************************************************************** Desc: FLAIM session manager object ****************************************************************************/ -class F_SessionMgr : public F_Base +class F_SessionMgr : public F_Object { public: @@ -2140,7 +2000,6 @@ public: { m_hMutex = F_MUTEX_NULL; m_pSessionTable = NULL; - m_pCRCTable = NULL; m_uiNextId = 1; f_timeGetSeconds( &m_uiNextToken); } @@ -2180,16 +2039,10 @@ public: return( uiToken); } - FINLINE FLMUINT32 * getCRCTable( void) - { - return( m_pCRCTable); - } - private: F_MUTEX m_hMutex; FLMUINT m_uiNextId; - FLMUINT32 * m_pCRCTable; F_HashTable * m_pSessionTable; FLMUINT m_uiNextToken; }; @@ -2197,7 +2050,7 @@ private: /**************************************************************************** Desc: FLAIM hash table ****************************************************************************/ -class F_HashTable : public F_Base +class F_HashTable : public F_Object { public: @@ -2207,8 +2060,7 @@ public: RCODE setupHashTable( FLMBOOL bMultithreaded, - FLMUINT uiNumBuckets, - FLMUINT32 * pCRCTable); + FLMUINT uiNumBuckets); RCODE addObject( F_HashObject * pObject); @@ -2248,14 +2100,10 @@ private: FLMUINT uiKeyLen, F_HashObject ** ppObject); - // Data - F_MUTEX m_hMutex; F_HashObject * m_pGlobalList; F_HashObject ** m_ppHashTable; FLMUINT m_uiBuckets; - FLMUINT32 * m_pCRCTable; - FLMBOOL m_bOwnCRCTable; }; #include "fpackoff.h" diff --git a/flaim/src/fsuperfl.cpp b/flaim/src/fsuperfl.cpp index 9c83689..e944d23 100644 --- a/flaim/src/fsuperfl.cpp +++ b/flaim/src/fsuperfl.cpp @@ -24,127 +24,16 @@ #include "flaimsys.h" -FSTATIC FLMBYTE base24ToDigit( - FLMUINT uiBaseValue); - /**************************************************************************** -Public: F_FileIdList -Desc: Constructor -****************************************************************************/ -F_FileIdList::F_FileIdList() -{ - m_hMutex = F_MUTEX_NULL; - m_uiFileIdTblSize = 0; - m_puiFileIdTbl = NULL; -} - -/**************************************************************************** -Public: ~F_FileIdList -Desc: Destructor -****************************************************************************/ -F_FileIdList::~F_FileIdList() -{ - if( m_hMutex != F_MUTEX_NULL) - { - f_mutexDestroy( &m_hMutex); - } - - if( m_puiFileIdTbl) - { - for( FLMUINT uiLoop = 0; uiLoop < m_uiFileIdTblSize; uiLoop++) - { - if( m_puiFileIdTbl[ uiLoop]) - { - (void)gv_FlmSysData.pFileHdlMgr->Remove( - m_puiFileIdTbl[ uiLoop]); - } - } - - f_free( &m_puiFileIdTbl); - } -} - -/**************************************************************************** -Public: setup -Desc: Allocates the mutex used by the file ID list object -****************************************************************************/ -RCODE F_FileIdList::setup( void) -{ - RCODE rc = FERR_OK; - - flmAssert( m_hMutex == F_MUTEX_NULL); - - if( RC_BAD( rc = f_mutexCreate( &m_hMutex))) - { - goto Exit; - } - -Exit: - - return( rc); -} - -/**************************************************************************** -Public: getFileId -Desc: Translates a database file number into a file ID. -****************************************************************************/ -RCODE F_FileIdList::getFileId( - FLMUINT uiFileNumber, - FLMUINT * puiFileId) -{ - RCODE rc = FERR_OK; - FLMBOOL bMutexLocked = TRUE; - FLMUINT uiLoop = 0; - - f_mutexLock( m_hMutex); - bMutexLocked = TRUE; - - if( uiFileNumber >= m_uiFileIdTblSize) - { - FLMUINT uiOldTableSize = m_uiFileIdTblSize; - - /* - Re-size the table - */ - - if( RC_BAD( rc = f_recalloc( (uiFileNumber + 1) * sizeof( FLMUINT), - &m_puiFileIdTbl))) - { - goto Exit; - } - m_uiFileIdTblSize = uiFileNumber + 1; - - for( uiLoop = uiOldTableSize; uiLoop < m_uiFileIdTblSize; uiLoop++) - { - m_puiFileIdTbl[ uiLoop] = gv_FlmSysData.pFileHdlMgr->GetUniqueId(); - } - } - - *puiFileId = m_puiFileIdTbl[ uiFileNumber]; - -Exit: - - if( bMutexLocked) - { - f_mutexUnlock( m_hMutex); - } - - return( rc); -} - -/**************************************************************************** -Public: F_SuperFileHdl -Desc: Constructor +Desc: ****************************************************************************/ F_SuperFileHdl::F_SuperFileHdl( void) { - m_pFileIdList = NULL; m_pszDbFileName = NULL; m_pszDataFileNameBase = NULL; f_memset( &m_CheckedOutFileHdls[ 0], 0, sizeof( m_CheckedOutFileHdls)); m_pCheckedOutFileHdls = &m_CheckedOutFileHdls [0]; m_uiCkoArraySize = MAX_CHECKED_OUT_FILE_HDLS + 1; - m_uiBlockSize = 0; m_uiExtendSize = DEFAULT_FILE_EXTEND_SIZE; m_uiMaxAutoExtendSize = gv_FlmSysData.uiMaxFileSize; m_uiDbVersion = 0; @@ -152,33 +41,18 @@ F_SuperFileHdl::F_SuperFileHdl( void) m_uiHighestDirtySlot = 0; m_uiHighestUsedSlot = 0; m_uiHighestFileNumber = 0; - m_pECacheMgr = NULL; m_bMinimizeFlushes = FALSE; m_bSetupCalled = FALSE; } /**************************************************************************** -Public: F_SuperFileHdl -Desc: Destructor +Desc: ****************************************************************************/ F_SuperFileHdl::~F_SuperFileHdl() { - /* - Release any file handles still being held and close the files. - */ - if( m_bSetupCalled) { - (void)ReleaseFiles( TRUE); - } - - /* - Release the ID list - */ - - if( m_pFileIdList) - { - m_pFileIdList->Release(); + (void)releaseFiles( TRUE); } if (m_pszDbFileName) @@ -188,61 +62,38 @@ F_SuperFileHdl::~F_SuperFileHdl() } /**************************************************************************** -Public: Setup -Desc: Configures the super file object +Desc: Configures the super file object ****************************************************************************/ -RCODE F_SuperFileHdl::Setup( - F_FileIdList * pFileIdList, +RCODE F_SuperFileHdl::setup( const char * pszDbFileName, - const char * pszDataDir) + const char * pszDataDir, + FLMUINT uiDbVersion) { - RCODE rc = FERR_OK; + RCODE rc = NE_FLM_OK; FLMUINT uiNameLen; FLMUINT uiDataNameLen; - char szDir[ F_PATH_MAX_SIZE]; - char szBaseName[ F_FILENAME_SIZE]; + char szDir [F_PATH_MAX_SIZE]; + char szBaseName [F_FILENAME_SIZE]; flmAssert( !m_bSetupCalled); if( !pszDbFileName && *pszDbFileName == 0) { - rc = RC_SET( FERR_IO_INVALID_PATH); + rc = RC_SET( NE_FLM_IO_INVALID_FILENAME); goto Exit; } - if( !pFileIdList) - { - if( (m_pFileIdList = f_new F_FileIdList) == NULL) - { - rc = RC_SET( FERR_MEM); - goto Exit; - } - - if( RC_BAD( rc = m_pFileIdList->setup())) - { - FLMINT iRefCnt; - - iRefCnt = m_pFileIdList->Release(); - flmAssert( !iRefCnt); - m_pFileIdList = NULL; - goto Exit; - } - } - else - { - pFileIdList->AddRef(); - m_pFileIdList = pFileIdList; - } - uiNameLen = f_strlen( pszDbFileName); if (pszDataDir && *pszDataDir) { - if (RC_BAD( rc = f_pathReduce( pszDbFileName, szDir, szBaseName))) + if (RC_BAD( rc = gv_FlmSysData.pFileSystem->pathReduce( + pszDbFileName, szDir, szBaseName))) { goto Exit; } f_strcpy( szDir, pszDataDir); - if (RC_BAD( rc = f_pathAppend( szDir, szBaseName))) + if (RC_BAD( rc = gv_FlmSysData.pFileSystem->pathAppend( + szDir, szBaseName))) { goto Exit; } @@ -273,6 +124,7 @@ RCODE F_SuperFileHdl::Setup( m_uiExtOffset = m_uiDataExtOffset; } + m_uiDbVersion = uiDbVersion; m_bSetupCalled = TRUE; Exit: @@ -281,80 +133,48 @@ Exit: } /**************************************************************************** -Public: CreateFile -Desc: Creates a file +Desc: Creates a file ****************************************************************************/ -RCODE F_SuperFileHdl::CreateFile( +RCODE F_SuperFileHdl::createFile( FLMUINT uiFileNumber) { - RCODE rc = FERR_OK; - char szFilePath[ F_PATH_MAX_SIZE]; - F_FileHdlImp * pFileHdl = NULL; - FLMUINT uiFileId; + RCODE rc = NE_FLM_OK; + char szFilePath[ F_PATH_MAX_SIZE]; + IF_FileHdl * pFileHdl = NULL; - flmAssert( m_bSetupCalled && m_uiDbVersion && m_uiBlockSize); - flmAssert( uiFileNumber <= MAX_LOG_BLOCK_FILE_NUMBER ( m_uiDbVersion)); + // Sanity checks + + flmAssert( m_bSetupCalled && m_uiDbVersion); + flmAssert( uiFileNumber <= MAX_LOG_BLOCK_FILE_NUMBER( m_uiDbVersion)); // See if we already have an open file handle (or if we can open the file). // If so, truncate the file and use it. - if( RC_OK( rc = GetFileHdl( uiFileNumber, TRUE, &pFileHdl))) + if( RC_OK( rc = getFileHdl( uiFileNumber, TRUE, &pFileHdl))) { - rc = pFileHdl->Truncate( 0); + rc = pFileHdl->truncate( 0); pFileHdl = NULL; goto Exit; } - else if( rc != FERR_IO_PATH_NOT_FOUND) - { - goto Exit; - } - - // The file was not found above. Allocate a new file handle. - - if( (pFileHdl = f_new F_FileHdlImp) == NULL) - { - rc = RC_SET( FERR_MEM); - goto Exit; - } - -#ifdef FLM_WIN - pFileHdl->SetBlockSize( m_uiBlockSize); -#endif - - // Configure the file handle. - - if( RC_BAD( rc = m_pFileIdList->getFileId( uiFileNumber, &uiFileId))) - { - goto Exit; - } - - flmAssert( uiFileId); // File ID should always be non-zero - - if( RC_BAD( rc = pFileHdl->Setup( uiFileId))) + else if( rc != NE_FLM_IO_PATH_NOT_FOUND) { goto Exit; } // Build the file path - if( RC_BAD( rc = GetFilePath( uiFileNumber, szFilePath))) + if( RC_BAD( rc = getFilePath( uiFileNumber, szFilePath))) { goto Exit; } - if( RC_BAD( rc = pFileHdl->Create( szFilePath, - F_IO_RDWR | F_IO_EXCL | F_IO_SH_DENYNONE | F_IO_DIRECT))) + if( RC_BAD( rc = gv_FlmSysData.pFileSystem->createFile( + szFilePath, FLM_IO_RDWR | FLM_IO_EXCL | FLM_IO_DIRECT | FLM_IO_SH_DENYNONE, + &pFileHdl))) { goto Exit; } - - // Insert into the file handle manager - - if( RC_BAD( rc = gv_FlmSysData.pFileHdlMgr->InsertNew( pFileHdl))) - { - goto Exit; - } - + Exit: if( pFileHdl) @@ -366,170 +186,116 @@ Exit: } /**************************************************************************** -Public: ReadBlock -Desc: Reads a database block into a buffer +Desc: Reads a database block into a buffer ****************************************************************************/ -RCODE F_SuperFileHdl::ReadBlock( +RCODE F_SuperFileHdl::readBlock( FLMUINT uiBlkAddress, FLMUINT uiBytesToRead, void * pvBuffer, FLMUINT * puiBytesRead) { - RCODE rc = FERR_OK; - F_FileHdlImp * pFileHdl = NULL; + IF_FileHdl * pFileHdl = NULL; + RCODE rc = NE_FLM_OK; - flmAssert( m_bSetupCalled && m_uiDbVersion && m_uiBlockSize); + flmAssert( m_bSetupCalled && m_uiDbVersion); - if( m_pECacheMgr) - { - flmAssert( uiBytesToRead <= m_uiBlockSize); - - if( RC_OK( rc = m_pECacheMgr->getBlock( uiBlkAddress, - (FLMBYTE *)pvBuffer, uiBytesToRead))) - { - if( puiBytesRead) - { - *puiBytesRead = uiBytesToRead; - } - goto Exit; - } - else if( rc != FERR_NOT_FOUND) - { - goto Exit; - } - else - { - // Drop through and read the block from disk. - rc = FERR_OK; - } - } - - if( RC_BAD( rc = GetFileHdl( + if( RC_BAD( rc = getFileHdl( FSGetFileNumber( uiBlkAddress), FALSE, &pFileHdl))) { goto Exit; } - if( RC_BAD( rc = pFileHdl->SectorRead( + if( RC_BAD( rc = pFileHdl->sectorRead( FSGetFileOffset( uiBlkAddress), uiBytesToRead, pvBuffer, puiBytesRead))) { - if (rc != FERR_IO_END_OF_FILE && rc != FERR_MEM) + if (rc != NE_FLM_IO_END_OF_FILE && rc != NE_FLM_MEM) { - ReleaseFile( FSGetFileNumber( uiBlkAddress), TRUE); + releaseFile( FSGetFileNumber( uiBlkAddress), TRUE); } goto Exit; } - if( m_pECacheMgr) - { - m_pECacheMgr->putBlock( uiBlkAddress, (FLMBYTE *)pvBuffer); - } - Exit: return( rc); } /**************************************************************************** -Public: WriteBlock -Desc: Writes a block to the database +Desc: Writes a block to the database ****************************************************************************/ -RCODE F_SuperFileHdl::WriteBlock( +RCODE F_SuperFileHdl::writeBlock( FLMUINT uiBlkAddress, FLMUINT uiBytesToWrite, - void * pvBuffer, + const void * pvBuffer, FLMUINT uiBufferSize, - F_IOBuffer * pIOBuffer, + IF_IOBuffer * pIOBuffer, FLMUINT * puiBytesWritten) { - RCODE rc = FERR_OK; - FLMUINT uiLoop; - F_FileHdlImp * pFileHdl = NULL; - FLMBYTE * pucBlk; + IF_FileHdl * pFileHdl = NULL; + RCODE rc = NE_FLM_OK; - flmAssert( m_bSetupCalled && m_uiDbVersion && m_uiBlockSize); + flmAssert( m_bSetupCalled && m_uiDbVersion); - if( RC_BAD( rc = GetFileHdl( +Get_Handle: + if( RC_BAD( rc = getFileHdl( FSGetFileNumber( uiBlkAddress), TRUE, &pFileHdl))) { + if (rc == NE_FLM_IO_PATH_NOT_FOUND) + { + if (RC_BAD( rc = createFile( FSGetFileNumber( uiBlkAddress)))) + { + goto Exit; + } + else + { + goto Get_Handle; + } + } goto Exit; } pFileHdl->setExtendSize( m_uiExtendSize); pFileHdl->setMaxAutoExtendSize( m_uiMaxAutoExtendSize); - if( RC_BAD( rc = pFileHdl->SectorWrite( + if( RC_BAD( rc = pFileHdl->sectorWrite( FSGetFileOffset( uiBlkAddress), uiBytesToWrite, pvBuffer, uiBufferSize, pIOBuffer, puiBytesWritten))) { - if (rc != FERR_IO_DISK_FULL && rc != FERR_MEM) + if (rc != NE_FLM_IO_DISK_FULL && rc != NE_FLM_MEM) { - ReleaseFile( FSGetFileNumber( uiBlkAddress), TRUE); + releaseFile( FSGetFileNumber( uiBlkAddress), TRUE); } goto Exit; } Exit: - if( m_pECacheMgr) - { - if( RC_OK( rc) && !pIOBuffer) - { - for( uiLoop = 0; uiLoop < uiBytesToWrite; uiLoop += m_uiBlockSize) - { - pucBlk = &(((FLMBYTE *)pvBuffer)[ uiLoop]); - m_pECacheMgr->putBlock( uiBlkAddress + uiLoop, pucBlk); - } - } - else - { - for( uiLoop = 0; uiLoop < uiBytesToWrite; uiLoop += m_uiBlockSize) - { - (void)m_pECacheMgr->invalidateBlock( uiBlkAddress + uiLoop); - } - } - } - return( rc); } /**************************************************************************** -Public: ReadHeader -Desc: Reads data from the database header +Desc: Reads data from the database header ****************************************************************************/ -RCODE F_SuperFileHdl::ReadHeader( +RCODE F_SuperFileHdl::readHeader( FLMUINT uiOffset, FLMUINT uiBytesToRead, void * pvBuffer, FLMUINT * puiBytesRead) { - RCODE rc = FERR_OK; - F_FileHdlImp * pFileHdl; + RCODE rc = NE_FLM_OK; + IF_FileHdl * pFileHdl; -#ifdef FLM_DEBUG - if( m_uiBlockSize) - { - /* - Note: Block size may not be set because we are in the process of - opening the file for the first time and we don't know the block - size until after the header has been read. - */ - - flmAssert( (FLMUINT)(uiOffset + uiBytesToRead) <= m_uiBlockSize); - } -#endif - - if( RC_BAD( rc = GetFileHdl( 0, TRUE, &pFileHdl))) + if( RC_BAD( rc = getFileHdl( 0, TRUE, &pFileHdl))) { goto Exit; } - if( RC_BAD( rc = pFileHdl->Read( uiOffset, + if( RC_BAD( rc = pFileHdl->read( uiOffset, uiBytesToRead, pvBuffer, puiBytesRead))) { - if (rc != FERR_IO_END_OF_FILE && rc != FERR_MEM) + if (rc != NE_FLM_IO_END_OF_FILE && rc != NE_FLM_MEM) { - ReleaseFile( (FLMUINT)0, TRUE); + releaseFile( (FLMUINT)0, TRUE); } goto Exit; } @@ -540,36 +306,28 @@ Exit: } /**************************************************************************** -Public: WriteHeader -Desc: Writes data to the database header +Desc: Writes data to the database header ****************************************************************************/ -RCODE F_SuperFileHdl::WriteHeader( +RCODE F_SuperFileHdl::writeHeader( FLMUINT uiOffset, FLMUINT uiBytesToWrite, - void * pvBuffer, + const void * pvBuffer, FLMUINT * puiBytesWritten) { - RCODE rc = FERR_OK; - F_FileHdlImp * pFileHdl; + RCODE rc = NE_FLM_OK; + IF_FileHdl * pFileHdl; -#ifdef FLM_DEBUG - if( m_uiBlockSize) - { - flmAssert( (FLMUINT)(uiOffset + uiBytesToWrite) <= m_uiBlockSize); - } -#endif - - if( RC_BAD( rc = GetFileHdl( 0, TRUE, &pFileHdl))) + if( RC_BAD( rc = getFileHdl( 0, TRUE, &pFileHdl))) { goto Exit; } - if( RC_BAD( rc = pFileHdl->Write( uiOffset, + if( RC_BAD( rc = pFileHdl->write( uiOffset, uiBytesToWrite, pvBuffer, puiBytesWritten))) { - if (rc != FERR_IO_DISK_FULL && rc != FERR_MEM) + if (rc != NE_FLM_IO_DISK_FULL && rc != NE_FLM_MEM) { - ReleaseFile( (FLMUINT)0, TRUE); + releaseFile( (FLMUINT)0, TRUE); } goto Exit; } @@ -580,21 +338,20 @@ Exit: } /**************************************************************************** -Public: ReleaseFile -Desc: Releases all file handle objects and optionally closes the files +Desc: Releases all file handle objects and optionally closes the files ****************************************************************************/ -RCODE F_SuperFileHdl::ReleaseFile( +RCODE F_SuperFileHdl::releaseFile( FLMUINT uiFileNum, FLMBOOL bCloseFile) { - RCODE rc = FERR_OK; + RCODE rc = NE_FLM_OK; CHECKED_OUT_FILE_HDL * pCkoFileHdl; FLMUINT uiSlot; pCkoFileHdl = getCkoFileHdlPtr( uiFileNum, &uiSlot); if( pCkoFileHdl->uiFileNumber == uiFileNum) { - if( RC_BAD( rc = ReleaseFile( pCkoFileHdl, bCloseFile))) + if( RC_BAD( rc = releaseFile( pCkoFileHdl, bCloseFile))) { goto Exit; } @@ -606,20 +363,19 @@ Exit: } /**************************************************************************** -Public: ReleaseFiles -Desc: Releases all file handle objects and optionally closes the files +Desc: Releases all file handle objects and optionally closes the files ****************************************************************************/ -RCODE F_SuperFileHdl::ReleaseFiles( +RCODE F_SuperFileHdl::releaseFiles( FLMBOOL bCloseFiles) { - RCODE rc = FERR_OK; + RCODE rc = NE_FLM_OK; FLMUINT uiLoop; flmAssert( m_bSetupCalled); for( uiLoop = 0; uiLoop <= m_uiHighestUsedSlot; uiLoop++) { - if( RC_BAD( rc = ReleaseFile( + if( RC_BAD( rc = releaseFile( &m_CheckedOutFileHdls[ uiLoop], bCloseFiles))) { goto Exit; @@ -632,50 +388,28 @@ Exit: } /**************************************************************************** -Public: ReleaseFile -Desc: Releases a file handle object +Desc: Releases a file handle object ****************************************************************************/ -RCODE F_SuperFileHdl::ReleaseFile( +RCODE F_SuperFileHdl::releaseFile( CHECKED_OUT_FILE_HDL * pCkoFileHdl, FLMBOOL bCloseFile) { - RCODE rc = FERR_OK; - F_FileHdlImp * pFileHdl = pCkoFileHdl->pFileHdl; + RCODE rc = NE_FLM_OK; + IF_FileHdl * pFileHdl = pCkoFileHdl->pFileHdl; if( pFileHdl) { - flmAssert( pFileHdl->GetFileId()); - if( pCkoFileHdl->bDirty) { - (void)pFileHdl->Flush(); + (void)pFileHdl->flush(); } if( bCloseFile) { - FLMINT iRefCnt; + FLMUINT uiRefCnt; - /* - We must remove this handle from all lists and release - the file handle. - */ - - rc = gv_FlmSysData.pFileHdlMgr->Remove( pFileHdl); - iRefCnt = pFileHdl->Release(); - flmAssert( iRefCnt == 0); // pFileHdl should have been freed. - } - else - { - /* - Link out of the used list and move to the available list. - */ - - rc = gv_FlmSysData.pFileHdlMgr->MakeAvailAndRelease( pFileHdl); - - /* - NOTE: MakeAvailAndRelease will perform a release on the - file handle object for the caller. - */ + uiRefCnt = pFileHdl->Release(); + flmAssert( uiRefCnt == 0); } clearCkoFileHdl( pCkoFileHdl); @@ -689,8 +423,7 @@ Desc: Copy one CKO array into another. ****************************************************************************/ void F_SuperFileHdl::copyCkoFileHdls( CHECKED_OUT_FILE_HDL * pSrcCkoArray, - FLMUINT uiSrcHighestUsedSlot - ) + FLMUINT uiSrcHighestUsedSlot) { FLMUINT uiNewSlot; FLMUINT uiSrcSlot; @@ -725,7 +458,7 @@ void F_SuperFileHdl::copyCkoFileHdls( { if (m_pCheckedOutFileHdls [uiNewSlot].uiFileNumber) { - ReleaseFile( &m_pCheckedOutFileHdls [uiNewSlot], FALSE); + releaseFile( &m_pCheckedOutFileHdls [uiNewSlot], FALSE); } f_memcpy( &m_pCheckedOutFileHdls [uiNewSlot], pSrcCkoArray, sizeof( CHECKED_OUT_FILE_HDL)); @@ -757,7 +490,7 @@ void F_SuperFileHdl::copyCkoFileHdls( } else { - ReleaseFile( pSrcCkoArray, FALSE); + releaseFile( pSrcCkoArray, FALSE); } } } @@ -789,9 +522,9 @@ void F_SuperFileHdl::disableFlushMinimize( void) /**************************************************************************** Desc: Flush dirty files to disk. ****************************************************************************/ -RCODE F_SuperFileHdl::Flush( void) +RCODE F_SuperFileHdl::flush( void) { - RCODE rc = FERR_OK; + RCODE rc = NE_FLM_OK; FLMUINT uiLoop; // Flush all dirty files @@ -805,10 +538,10 @@ RCODE F_SuperFileHdl::Flush( void) RCODE tmpRc; if (RC_BAD( tmpRc = - m_pCheckedOutFileHdls[ uiLoop].pFileHdl->Flush())) + m_pCheckedOutFileHdls[ uiLoop].pFileHdl->flush())) { rc = tmpRc; - ReleaseFile( &m_pCheckedOutFileHdls [uiLoop], TRUE); + releaseFile( &m_pCheckedOutFileHdls [uiLoop], TRUE); } m_pCheckedOutFileHdls[ uiLoop].bDirty = FALSE; } @@ -819,52 +552,47 @@ RCODE F_SuperFileHdl::Flush( void) } /**************************************************************************** -Public: TruncateFile -Desc: Truncates back to an end of file block address. - This may only be called from reduce() because there cannot - be any other cases to reduce a 3x block file. +Desc: Truncates back to an end of file block address. + This may only be called from reduce() because there cannot + be any other cases to reduce a 3x block file. ****************************************************************************/ -RCODE F_SuperFileHdl::TruncateFile( +RCODE F_SuperFileHdl::truncateFile( FLMUINT uiEOFBlkAddress) { - RCODE rc = FERR_OK; - FLMUINT uiFileNumber = (FLMUINT)FSGetFileNumber( uiEOFBlkAddress); - FLMUINT uiBlockOffset = (FLMUINT)FSGetFileOffset( uiEOFBlkAddress); - F_FileHdlImp * pFileHdl; + RCODE rc = NE_FLM_OK; + FLMUINT uiFileNumber = (FLMUINT)FSGetFileNumber( uiEOFBlkAddress); + FLMUINT uiBlockOffset = (FLMUINT)FSGetFileOffset( uiEOFBlkAddress); + IF_FileHdl * pFileHdl; - /* - Truncate the current block file. - */ + // Truncate the current block file. - if( RC_BAD( rc = GetFileHdl( uiFileNumber, TRUE, &pFileHdl))) + if( RC_BAD( rc = getFileHdl( uiFileNumber, TRUE, &pFileHdl))) { goto Exit; } - if( RC_BAD( rc = pFileHdl->Truncate( uiBlockOffset))) + if( RC_BAD( rc = pFileHdl->truncate( uiBlockOffset))) { - ReleaseFile( uiFileNumber, TRUE); + releaseFile( uiFileNumber, TRUE); goto Exit; } - /* - Visit the rest of the high block files until a NULL file hdl is hit. - */ + // Visit the rest of the high block files until a NULL file hdl is hit. for( ;;) { - if( RC_BAD( GetFileHdl( ++uiFileNumber, TRUE, &pFileHdl))) + if( RC_BAD( getFileHdl( ++uiFileNumber, TRUE, &pFileHdl))) { break; } - if( RC_BAD( rc = pFileHdl->Truncate( (FLMUINT)0 ))) + if( RC_BAD( rc = pFileHdl->truncate( (FLMUINT)0 ))) { - ReleaseFile( uiFileNumber, TRUE); + releaseFile( uiFileNumber, TRUE); goto Exit; } - if( RC_BAD( rc = ReleaseFile( uiFileNumber, TRUE))) + if( RC_BAD( rc = releaseFile( uiFileNumber, TRUE))) { goto Exit; } @@ -876,61 +604,53 @@ Exit: } /**************************************************************************** -Public: TruncateFiles -Desc: Truncate to zero length any files between the specified start - and end files. +Desc: Truncate to zero length any files between the specified start + and end files. ****************************************************************************/ -void F_SuperFileHdl::TruncateFiles( +void F_SuperFileHdl::truncateFiles( FLMUINT uiStartFileNum, FLMUINT uiEndFileNum) { FLMUINT uiFileNumber; - F_FileHdlImp * pFileHdl; + IF_FileHdl * pFileHdl; for( uiFileNumber = uiStartFileNum; uiFileNumber <= uiEndFileNum; uiFileNumber++ ) { - if( RC_OK( GetFileHdl( uiFileNumber, TRUE, &pFileHdl ))) + if( RC_OK( getFileHdl( uiFileNumber, TRUE, &pFileHdl ))) { - (void)pFileHdl->Truncate( (FLMUINT)0 ); - (void)ReleaseFile( uiFileNumber, TRUE); + (void)pFileHdl->truncate( (FLMUINT)0 ); + (void)releaseFile( uiFileNumber, TRUE); } } } /**************************************************************************** -Public: GetFileSize -Desc: Returns the physical size of a file +Desc: Returns the physical size of a file ****************************************************************************/ -RCODE F_SuperFileHdl::GetFileSize( - FLMUINT uiFileNumber, - FLMUINT * puiFileSize) +RCODE F_SuperFileHdl::getFileSize( + FLMUINT uiFileNumber, + FLMUINT64 * pui64FileSize) { - F_FileHdlImp * pFileHdl = NULL; - RCODE rc = FERR_OK; + IF_FileHdl * pFileHdl = NULL; + RCODE rc = NE_FLM_OK; flmAssert( m_bSetupCalled); - flmAssert( puiFileSize); + flmAssert( pui64FileSize); - /* - Initialize the size to zero. - */ + *pui64FileSize = 0; - *puiFileSize = 0; + // Get the file handle. - /* - Get the file handle. - */ - - if( RC_BAD( rc = GetFileHdl( uiFileNumber, FALSE, &pFileHdl))) + if( RC_BAD( rc = getFileHdl( uiFileNumber, FALSE, &pFileHdl))) { goto Exit; } - if( RC_BAD( rc = pFileHdl->Size( puiFileSize))) + if( RC_BAD( rc = pFileHdl->size( pui64FileSize))) { - ReleaseFile( uiFileNumber, TRUE); + releaseFile( uiFileNumber, TRUE); goto Exit; } @@ -940,14 +660,13 @@ Exit: } /**************************************************************************** -Public: GetFilePath -Desc: Returns the path of a file given its file number +Desc: Returns the path of a file given its file number ****************************************************************************/ -RCODE F_SuperFileHdl::GetFilePath( - FLMUINT uiFileNumber, - char * pszIoPath) +RCODE F_SuperFileHdl::getFilePath( + FLMUINT uiFileNumber, + char * pszIoPath) { - RCODE rc = FERR_OK; + RCODE rc = NE_FLM_OK; FLMUINT uiExtOffset; // Sanity checks @@ -990,7 +709,7 @@ RCODE F_SuperFileHdl::reallocCkoArray( FLMUINT uiFileNum ) { - RCODE rc = FERR_OK; + RCODE rc = NE_FLM_OK; FLMUINT uiNewSize; CHECKED_OUT_FILE_HDL * pNewCkoArray; CHECKED_OUT_FILE_HDL * pOldCkoArray; @@ -1042,23 +761,19 @@ Exit: } /**************************************************************************** -Public: GetFileHdl -Desc: Returns a file handle given the file's number +Desc: Returns a file handle given the file's number ****************************************************************************/ -RCODE F_SuperFileHdl::GetFileHdl( - FLMUINT uiFileNum, - FLMBOOL bGetForUpdate, - F_FileHdlImp ** ppFileHdl) +RCODE F_SuperFileHdl::getFileHdl( + FLMUINT uiFileNum, + FLMBOOL bGetForUpdate, + IF_FileHdl ** ppFileHdl) { - RCODE rc = FERR_OK; - F_FileHdlImp * pFileHdl = NULL; - FLMUINT uiFileId; + RCODE rc = NE_FLM_OK; + IF_FileHdl * pFileHdl = NULL; CHECKED_OUT_FILE_HDL * pCkoFileHdl; char szFilePath[ F_PATH_MAX_SIZE]; FLMUINT uiSlot; - // Get the file handle - pCkoFileHdl = getCkoFileHdlPtr( uiFileNum, &uiSlot); if( pCkoFileHdl->uiFileNumber != uiFileNum && pCkoFileHdl->pFileHdl) @@ -1080,7 +795,7 @@ RCODE F_SuperFileHdl::GetFileHdl( } else { - if( RC_BAD( rc = ReleaseFile( pCkoFileHdl, FALSE))) + if( RC_BAD( rc = releaseFile( pCkoFileHdl, FALSE))) { goto Exit; } @@ -1089,71 +804,30 @@ RCODE F_SuperFileHdl::GetFileHdl( if( !pCkoFileHdl->pFileHdl) { - // Get the file ID - - if( RC_BAD( rc = m_pFileIdList->getFileId( uiFileNum, &uiFileId))) + if (!pFileHdl) { - goto Exit; - } - - // Look for an available file handle if not opening exclusive. - // NOTE: AddRef() performed for caller by FindAvail if a file - // handle is found. - - if( RC_BAD( gv_FlmSysData.pFileHdlMgr->FindAvail( - uiFileId, FALSE, &pFileHdl))) - { - // Allocate a new file handle, open the file and - // link into the used directory. - - if( (pFileHdl = f_new F_FileHdlImp) == NULL) - { - rc = RC_SET( FERR_MEM); - goto Exit; - } - -#ifdef FLM_WIN - /* - If m_uiBlockSize is 0, direct I/O will not be used - */ - - pFileHdl->SetBlockSize( m_uiBlockSize); -#endif - - flmAssert( uiFileId); // File ID must be non-zero - - if( RC_BAD( rc = pFileHdl->Setup( uiFileId))) - { - goto Exit; - } - // Build the file path - if( RC_BAD( rc = GetFilePath( uiFileNum, szFilePath))) + if( RC_BAD( rc = getFilePath( uiFileNum, szFilePath))) { goto Exit; } // Open the file - if( RC_BAD( rc = pFileHdl->Open( szFilePath, - F_IO_RDWR | F_IO_SH_DENYNONE | F_IO_DIRECT))) - { - goto Exit; - } - - // Insert into the manager - - if( RC_BAD( rc = gv_FlmSysData.pFileHdlMgr->InsertNew( pFileHdl))) + if( RC_BAD( rc = gv_FlmSysData.pFileSystem->openFile( + szFilePath, FLM_IO_RDWR | FLM_IO_SH_DENYNONE | FLM_IO_DIRECT, + &pFileHdl))) { goto Exit; } } pCkoFileHdl->pFileHdl = pFileHdl; - pFileHdl = NULL; // Set to NULL so the handle won't be released below + pFileHdl = NULL; pCkoFileHdl->uiFileNumber = uiFileNum; pCkoFileHdl->bDirty = FALSE; + if( m_uiHighestUsedSlot < uiSlot) { m_uiHighestUsedSlot = uiSlot; @@ -1207,7 +881,7 @@ void bldSuperFileExtension( { FLMBYTE ucLetter; - flmAssert( uiDbVersion); // Make sure the database version is valid + flmAssert( uiDbVersion); if (uiDbVersion >= FLM_FILE_FORMAT_VER_4_3) { @@ -1215,36 +889,43 @@ void bldSuperFileExtension( { // No additional letter - File numbers 1 to 511 // This is just like pre-4.3 numbering. + ucLetter = 0; } else if (uiFileNum <= MAX_DATA_FILE_NUM_VER43 - 1024) { // File numbers 512 to 1023 + ucLetter = 'r'; } else if (uiFileNum <= MAX_DATA_FILE_NUM_VER43 - 512) { // File numbers 1024 to 1535 + ucLetter = 's'; } else if (uiFileNum <= MAX_DATA_FILE_NUM_VER43) { // File numbers 1536 to 2047 + ucLetter = 't'; } else if (uiFileNum <= MAX_LOG_FILE_NUM_VER43 - 1536) { // File numbers 2048 to 2559 + ucLetter = 'v'; } else if (uiFileNum <= MAX_LOG_FILE_NUM_VER43 - 1024) { // File numbers 2560 to 3071 + ucLetter = 'w'; } else if (uiFileNum <= MAX_LOG_FILE_NUM_VER43 - 512) { // File numbers 3072 to 3583 + ucLetter = 'x'; } else @@ -1252,15 +933,17 @@ void bldSuperFileExtension( flmAssert( uiFileNum <= MAX_LOG_FILE_NUM_VER43); // File numbers 3584 to 4095 + ucLetter = 'z'; } } - else // Pre-4.3 versions + else { if (uiFileNum <= MAX_DATA_FILE_NUM_VER40) { // No additional letter - File numbers 1 to 511 // This is just like pre-4.3 numbering. + ucLetter = 0; } else @@ -1268,58 +951,14 @@ void bldSuperFileExtension( flmAssert( uiFileNum <= MAX_LOG_FILE_NUM_VER40); // File numbers 512 to 1023 + ucLetter = 'x'; } } *pszFileExtension++ = '.'; - *pszFileExtension++ = base24ToDigit( (uiFileNum & 511) / 24); - *pszFileExtension++ = base24ToDigit( (uiFileNum & 511) % 24); + *pszFileExtension++ = f_getBase24DigitChar( (FLMBYTE)((uiFileNum & 511) / 24)); + *pszFileExtension++ = f_getBase24DigitChar( (FLMBYTE)((uiFileNum & 511) % 24)); *pszFileExtension++ = ucLetter; *pszFileExtension = 0; } - -/**************************************************************************** -Desc: Turn a base 24 value into a native alphanumeric value. -Notes: This is a base 24 alphanumeric value where - {a, b, c, d, e, f, i, l, o, r, u, v } values are removed. -****************************************************************************/ -FSTATIC FLMBYTE base24ToDigit( - FLMUINT uiValue) -{ - flmAssert( uiValue <= 23); - - if( uiValue <= 9) - { - uiValue += (FLMUINT) NATIVE_ZERO; - } - else - { - uiValue = f_toascii(uiValue) - 10 + (FLMUINT)f_toascii('g'); - if( uiValue >= (FLMUINT)'i') - { - uiValue++; - if( uiValue >= (FLMUINT)'l') - { - uiValue++; - if( uiValue >= (FLMUINT)'o') - { - uiValue++; - if( uiValue >= (FLMUINT)'r') - { - uiValue++; - if( uiValue >= (FLMUINT)'u') - { - uiValue++; - if( uiValue >= (FLMUINT)'v') - { - uiValue++; - } - } - } - } - } - } - } - return (FLMBYTE)uiValue; -} diff --git a/flaim/src/fsuperfl.h b/flaim/src/fsuperfl.h index 2a2173a..972bd0c 100644 --- a/flaim/src/fsuperfl.h +++ b/flaim/src/fsuperfl.h @@ -25,153 +25,95 @@ #ifndef FSUPERFL_H #define FSUPERFL_H -#include "fpackon.h" -// IMPORTANT NOTE: No other include files should follow this one except -// for fpackoff.h - #define MAX_CHECKED_OUT_FILE_HDLS 8 -class F_SuperFileHdl; -class F_FileIdList; +void bldSuperFileExtension( + FLMUINT uiDbVersion, + FLMUINT uiFileNum, + char * pszFileExtension); -/**************************************************************************** -Desc: -****************************************************************************/ -typedef struct CHECKED_OUT_FILE_HDL +typedef struct { - F_FileHdlImp * pFileHdl; + IF_FileHdl * pFileHdl; FLMUINT uiFileNumber; FLMBOOL bDirty; } CHECKED_OUT_FILE_HDL; -void bldSuperFileExtension( - FLMUINT uiDbVersion, - FLMUINT uiFileNum, - char * pszFileExtension); - -/**************************************************************************** -Desc: This class keeps a list of file IDs for file numbers in a database. - It does not know the use of the file IDs, and it is not limited in - the number of file IDs it can keep track of, but it will generally - be as follows: - - FileNumber - 0 This is the database file (xxx.db) - 1-4095 These are the data files (xxx_data.nnn) - 4096-8192 These are the rollback files (xxx_rb.nnn). In this - case, the caller will map the file number in and - out of this range. -****************************************************************************/ -class F_FileIdList : public F_Base -{ -public: - F_FileIdList(); - - virtual ~F_FileIdList(); - - RCODE setup( void); - - RCODE getFileId( - FLMUINT uiFileNumber, - FLMUINT * puiFileId); - -private: - - F_MUTEX m_hMutex; - FLMUINT m_uiFileIdTblSize; - FLMUINT * m_puiFileIdTbl; -}; - /**************************************************************************** Desc: The F_SuperFileHdl object manages the control and block files associated with a FLAIM Super File. This class also provides backward compatibility with prior file formats. +Note: ****************************************************************************/ -class F_SuperFileHdl : public F_Base +class F_SuperFileHdl : public F_Object { public: F_SuperFileHdl(); - virtual ~F_SuperFileHdl(); + ~F_SuperFileHdl(); - RCODE Setup( // Configures the object. Should - // be called exactly once. - F_FileIdList * pFileIdList, + RCODE setup( const char * pszDbFileName, - const char * pszDataDir); + const char * pszDataDir, + FLMUINT uiDbVersion); - FINLINE void setECacheMgr( // Sets the ECacheMgr to be used by - // the super file. - FlmECache * pECacheMgr) - { - m_pECacheMgr = pECacheMgr; - } - - RCODE CreateFile( // Create a block file (>= 3.0 only) - FLMUINT uiFileNumber); // File number to create + RCODE createFile( + FLMUINT uiFileNumber); - RCODE ReadBlock( // Reads a block from a block file or - // the log - FLMUINT uiBlkAddress, // Block address - FLMUINT uiBytesToRead, // Number of bytes to read from block - void * pvBuffer, // Buffer to place read bytes into - FLMUINT * puiBytesRead); // [out] number of bytes read + RCODE readBlock( + FLMUINT uiBlkAddress, + FLMUINT uiBytesToRead, + void * pvBuffer, + FLMUINT * puiBytesRead); - RCODE WriteBlock( // Writes a block to a block file or - // the log - FLMUINT uiBlkAddress, // Block address - FLMUINT uiBytesToWrite, // Number of bytes to write - void * pvBuffer, // Buffer to write bytes from - FLMUINT uiBufferSize, // Actual size of buffer - F_IOBuffer * pIOBuffer, // If non-NULL, contains info for - // doing an async write. - FLMUINT * puiBytesWritten); // [out] number of bytes written + RCODE writeBlock( + FLMUINT uiBlkAddress, + FLMUINT uiBytesToWrite, + const void * pvBuffer, + FLMUINT uiBufferSize, + IF_IOBuffer * pIOBuffer, + FLMUINT * puiBytesWritten); - RCODE ReadHeader( // Reads data from the DB header - FLMUINT uiOffset, - FLMUINT uiBytesToRead, - void * pvBuffer, - FLMUINT * puiBytesRead); + RCODE readHeader( + FLMUINT uiOffset, + FLMUINT uiBytesToRead, + void * pvBuffer, + FLMUINT * puiBytesRead); - RCODE WriteHeader( // Writes data to the DB header - FLMUINT uiOffset, - FLMUINT uiBytesToWrite, - void * pvBuffer, - FLMUINT * puiBytesWritten); + RCODE writeHeader( + FLMUINT uiOffset, + FLMUINT uiBytesToWrite, + const void * pvBuffer, + FLMUINT * puiBytesWritten); - RCODE GetFilePath( // Generates a block file's path - FLMUINT uiFileNumber, // File number - char * pIoPath); // Returned path + RCODE getFilePath( + FLMUINT uiFileNumber, + char * pszPath); - RCODE GetFileHdl( // Returns a file's handle given - // the file's number + RCODE getFileHdl( FLMUINT uiFileNumber, FLMBOOL bGetForUpdate, - F_FileHdlImp ** ppFileHdlRV); + IF_FileHdl ** ppFileHdlRV); - RCODE GetFileSize( // Returns the physical size of - // a file - FLMUINT uiFileNumber, // File number - FLMUINT * puiFileSize); // File size return value + RCODE getFileSize( + FLMUINT uiFileNumber, + FLMUINT64 * pui64FileSize); - RCODE ReleaseFile( // Release a single file - FLMUINT uiFileNum, - FLMBOOL bCloseFile); + RCODE releaseFile( + FLMUINT uiFileNum, + FLMBOOL bCloseFile); - RCODE ReleaseFiles( // Releases all file handles and - // returns them to the file handle - // manager. This is called at - // the end of a transaction. - FLMBOOL bCloseFiles); // Should files be closed? + RCODE releaseFiles( + FLMBOOL bCloseFiles); - RCODE TruncateFile( // Truncate the file(s) to given address. - FLMUINT uiEOFBlkAddress); // End of file block address. + RCODE truncateFile( + FLMUINT uiEOFBlkAddress); - void TruncateFiles( // Truncate the files specified by the - FLMUINT uiStartFileNum, // start and end file numbers. - FLMUINT uiEndFileNum); + void truncateFiles( + FLMUINT uiStartFileNum, + FLMUINT uiEndFileNum); - RCODE ReleaseFile( // Release a single file + RCODE releaseFile( CHECKED_OUT_FILE_HDL * pChkFileHdl, FLMBOOL bCloseFile); @@ -182,19 +124,7 @@ public: void disableFlushMinimize( void); - RCODE Flush( void); - - FINLINE void SetBlockSize( - FLMUINT uiBlockSize) - { - m_uiBlockSize = uiBlockSize; - } - - FINLINE void SetDbVersion( - FLMUINT uiDbVersion) - { - m_uiDbVersion = uiDbVersion; - } + RCODE flush( void); FINLINE void setExtendSize( FLMUINT uiExtendSize) @@ -208,19 +138,19 @@ public: m_uiMaxAutoExtendSize = uiMaxAutoExtendSize; } - FINLINE FLMBOOL CanDoAsync( void) + FINLINE FLMBOOL canDoAsync( void) { - if( m_pCheckedOutFileHdls[ 0].pFileHdl) + if (m_pCheckedOutFileHdls[ 0].pFileHdl) { - return( m_pCheckedOutFileHdls[ 0].pFileHdl->CanDoAsync()); + return( m_pCheckedOutFileHdls[ 0].pFileHdl->canDoAsync()); } else { - F_FileHdlImp * pFileHdl; + IF_FileHdl * pFileHdl; - if( RC_OK( GetFileHdl( 0, FALSE, &pFileHdl))) + if( RC_OK( getFileHdl( 0, FALSE, &pFileHdl))) { - return( pFileHdl->CanDoAsync()); + return( pFileHdl->canDoAsync()); } } @@ -233,7 +163,7 @@ private: FLMUINT uiFileNum, FLMUINT * puiSlot) { - *puiSlot = (uiFileNum + *puiSlot = (uiFileNum ? (uiFileNum % (m_uiCkoArraySize - 1)) + 1 : 0); @@ -259,12 +189,10 @@ private: char * m_pszDataFileNameBase; FLMUINT m_uiExtOffset; FLMUINT m_uiDataExtOffset; - F_FileIdList * m_pFileIdList; CHECKED_OUT_FILE_HDL m_CheckedOutFileHdls[ MAX_CHECKED_OUT_FILE_HDLS + 1]; CHECKED_OUT_FILE_HDL * m_pCheckedOutFileHdls; FLMUINT m_uiCkoArraySize; - FLMUINT m_uiBlockSize; FLMUINT m_uiExtendSize; FLMUINT m_uiMaxAutoExtendSize; FLMUINT m_uiDbVersion; @@ -272,11 +200,8 @@ private: FLMUINT m_uiHighestDirtySlot; FLMUINT m_uiHighestUsedSlot; FLMUINT m_uiHighestFileNumber; - FlmECache * m_pECacheMgr; FLMBOOL m_bMinimizeFlushes; FLMBOOL m_bSetupCalled; }; -#include "fpackoff.h" - #endif diff --git a/flaim/src/fsv.cpp b/flaim/src/fsv.cpp index ff5db74..d70122c 100644 --- a/flaim/src/fsv.cpp +++ b/flaim/src/fsv.cpp @@ -26,19 +26,19 @@ FSTATIC RCODE fsvIteratorParse( FSV_WIRE * pWire, - POOL * pPool); + F_Pool * pPool); FSTATIC RCODE fsvIteratorWhereParse( FSV_WIRE * pWire, - POOL * pPool); + F_Pool * pPool); FSTATIC RCODE fsvIteratorFromParse( FSV_WIRE * pWire, - POOL * pPool); + F_Pool * pPool); FSTATIC RCODE fsvIteratorSelectParse( FSV_WIRE * pWire, - POOL * pPool); + F_Pool * pPool); FSTATIC RCODE fsvDbGetBlocks( HFDB hDb, @@ -48,30 +48,13 @@ FSTATIC RCODE fsvDbGetBlocks( FLMUINT * puiBlocksExamined, FLMUINT * puiNextBlkAddr, FLMUINT uiFlags, - POOL * pPool, + F_Pool * pPool, FLMBYTE ** ppBlocks, FLMUINT * puiBytes); FSTATIC RCODE fsvGetHandles( FSV_WIRE * pWire); -RCODE fsvTcpListener( - F_Thread * pThread); - -RCODE fsvTcpClientHandler( - F_Thread * pThread); - -RCODE fsvTcpVulture( - F_Thread * pThread); - -RCODE fsvTcpAcceptConnection( - F_MUTEX * phHandlerSem, - FCS_TCP * pClient); - -FLMBOOL gv_bTcpAllowConnections = TRUE; -FLMBOOL gv_bTcpRunning = FALSE; -F_Thread * gv_TcpHandlers[ FSV_MAX_TCP_HANDLERS]; -F_Thread * gv_pTcpListenerThrd = NULL; FSV_SCTX * gv_pGlobalContext = NULL; /**************************************************************************** @@ -198,7 +181,7 @@ Desc: This is the function that processes FLAIM requests. RCODE fsvProcessRequest( FCS_DIS * pDataIStream, FCS_DOS * pDataOStream, - POOL * pScratchPool, + F_Pool * pScratchPool, FLMUINT * puiSessionIdRV) { void * pvMark = NULL; @@ -209,7 +192,7 @@ RCODE fsvProcessRequest( if (pScratchPool) { - pvMark = GedPoolMark( pScratchPool); + pvMark = pScratchPool->poolMark(); Wire.setPool( pScratchPool); } @@ -390,7 +373,7 @@ Exit: if (pScratchPool) { - GedPoolReset( pScratchPool, pvMark); + pScratchPool->poolReset( pvMark); } return (rc); @@ -511,7 +494,8 @@ RCODE fsvOpClassFile( goto OP_EXIT; } - if (RC_BAD( opRc = gv_FlmSysData.pFileSystem->Exists( szSourcePath))) + if (RC_BAD( opRc = gv_FlmSysData.pFileSystem->doesFileExist( + szSourcePath))) { goto OP_EXIT; } @@ -526,7 +510,8 @@ RCODE fsvOpClassFile( goto OP_EXIT; } - if (RC_BAD( opRc = gv_FlmSysData.pFileSystem->Delete( szSourcePath))) + if (RC_BAD( opRc = gv_FlmSysData.pFileSystem->deleteFile( + szSourcePath))) { goto OP_EXIT; } @@ -1296,7 +1281,7 @@ RCODE fsvOpClassDatabase( case FDB_GET_LOCK_HOLDER: { - LOCK_USER lockUser; + F_LOCK_USER lockUser; if (RC_BAD( opRc = FlmDbGetConfig( hDb, FDB_GET_LOCK_HOLDER, (void *) &lockUser))) @@ -1314,14 +1299,14 @@ RCODE fsvOpClassDatabase( case FDB_GET_LOCK_WAITERS: { - LOCK_USER * pLockUser = NULL; + F_LOCK_USER * pLockUser = NULL; if (RC_BAD( opRc = FlmDbGetConfig( hDb, FDB_GET_LOCK_WAITERS, (void *) &pLockUser))) { if (pLockUser) { - FlmFreeMem( &pLockUser); + f_free( &pLockUser); } goto OP_EXIT; @@ -1332,7 +1317,7 @@ RCODE fsvOpClassDatabase( { if (pLockUser) { - FlmFreeMem( &pLockUser); + f_free( &pLockUser); } goto OP_EXIT; @@ -1340,7 +1325,7 @@ RCODE fsvOpClassDatabase( if (pLockUser) { - FlmFreeMem( &pLockUser); + f_free( &pLockUser); } break; } @@ -1361,13 +1346,12 @@ RCODE fsvOpClassDatabase( { uiBinSize = F_SERIAL_NUM_SIZE; - if( (pBinary = (FLMBYTE *) GedPoolAlloc( - pWire->getPool(), uiBinSize)) == NULL) + if( RC_BAD( opRc = pWire->getPool()->poolAlloc( + uiBinSize, (void **)&pBinary))) { - opRc = RC_SET( FERR_MEM); goto OP_EXIT; } - + if (RC_BAD( opRc = FlmDbGetConfig( hDb, FDB_GET_SERIAL_NUMBER, (void *) pBinary))) { @@ -1434,8 +1418,8 @@ RCODE fsvOpClassDatabase( case FDB_RFL_DIR: { char * pszPath; - POOL * pPool = pWire->getPool(); - void * pvMark = GedPoolMark( pPool); + F_Pool * pPool = pWire->getPool(); + void * pvMark = pPool->poolMark(); if (RC_BAD( rc = fcsConvertUnicodeToNative( pPool, pWire->getFilePath(), &pszPath))) @@ -1451,7 +1435,7 @@ RCODE fsvOpClassDatabase( goto OP_EXIT; } - GedPoolReset( pPool, pvMark); + pPool->poolReset( pvMark); break; } @@ -1467,9 +1451,9 @@ RCODE fsvOpClassDatabase( case FCS_OP_DATABASE_LOCK: { if (RC_BAD( opRc = FlmDbLock( hDb, - (FLOCK_TYPE) (FLMUINT) pWire->getNumber1(), - (FLMINT) pWire->getSignedValue(), (FLMUINT) pWire->getFlags() - ))) + (eLockType) (FLMUINT) pWire->getNumber1(), + (FLMINT) pWire->getSignedValue(), + (FLMUINT) pWire->getFlags()))) { goto OP_EXIT; } @@ -2092,10 +2076,10 @@ RCODE fsvOpClassTransaction( if (pWire->getFlags() & FCS_TRANS_FLAG_GET_HEADER) { uiBlockSize = 2048; - if ((pBlock = (FLMBYTE *) GedPoolAlloc( - pWire->getPool(), uiBlockSize)) == NULL) + + if( RC_BAD( rc = pWire->getPool()->poolAlloc( uiBlockSize, + (void **)&pBlock))) { - rc = RC_SET( FERR_MEM); goto OP_EXIT; } } @@ -2227,13 +2211,13 @@ RCODE fsvOpClassMaintenance( { FSV_SESN * pSession; HFDB hDb; - POOL pool; + F_Pool pool; RCODE opRc = FERR_OK; RCODE rc = FERR_OK; // Initialize a temporary pool. - GedPoolInit( &pool, 1024); + pool.poolInit( 1024); // Service the request. @@ -2312,7 +2296,7 @@ RCODE fsvOpClassIndex( HFDB hDb = HFDB_NULL; FLMUINT uiIndex; FINDEX_STATUS indexStatus; - POOL * pTmpPool = pWire->getPool(); + F_Pool * pTmpPool = pWire->getPool(); RCODE opRc = FERR_OK; RCODE rc = FERR_OK; @@ -2508,9 +2492,9 @@ Desc: Configures an iterator based on from, where, select, and config ****************************************************************************/ FSTATIC RCODE fsvIteratorParse( FSV_WIRE * pWire, - POOL * pPool) + F_Pool * pPool) { - RCODE rc = FERR_OK; + RCODE rc = FERR_OK; // Parse the "from" clause. This contains record source information. @@ -2559,7 +2543,7 @@ Desc: Adds selection criteria to an iterator. ****************************************************************************/ FSTATIC RCODE fsvIteratorWhereParse( FSV_WIRE * pWire, - POOL * pPool) + F_Pool * pPool) { HFCURSOR hIterator = pWire->getIteratorHandle(); NODE * pWhere = pWire->getIteratorWhere(); @@ -2786,7 +2770,7 @@ FSTATIC RCODE fsvIteratorWhereParse( // Mark the pool. - pPoolMark = GedPoolMark( pPool); + pPoolMark = pPool->poolMark(); // Determine the length of the string. @@ -2798,9 +2782,8 @@ FSTATIC RCODE fsvIteratorWhereParse( // Allocate a temporary buffer. uiLen += 2; - if ((puzBuf = (FLMUNICODE *) GedPoolAlloc( pPool, uiLen)) == NULL) + if( RC_BAD( rc = pPool->poolAlloc( uiLen, (void **)&puzBuf))) { - rc = RC_SET( FERR_MEM); goto Exit; } @@ -2817,7 +2800,7 @@ FSTATIC RCODE fsvIteratorWhereParse( goto Exit; } - GedPoolReset( pPool, pPoolMark); + pPool->poolReset( pPoolMark); break; } @@ -2832,7 +2815,7 @@ FSTATIC RCODE fsvIteratorWhereParse( // Mark the pool. - pPoolMark = GedPoolMark( pPool); + pPoolMark = pPool->poolMark(); // Determine the length of the string. @@ -2852,9 +2835,8 @@ FSTATIC RCODE fsvIteratorWhereParse( // Allocate a temporary buffer. uiLen += 2; - if ((pucBuf = (FLMBYTE *) GedPoolAlloc( pPool, uiLen)) == NULL) + if( RC_BAD( rc = pPool->poolAlloc( uiLen, (void **)&pucBuf))) { - rc = RC_SET( FERR_MEM); goto Exit; } @@ -2875,7 +2857,7 @@ FSTATIC RCODE fsvIteratorWhereParse( } } - GedPoolReset( pPool, pPoolMark); + pPool->poolReset( pPoolMark); break; } @@ -2948,7 +2930,7 @@ Desc: Adds source information to an iterator. ****************************************************************************/ FSTATIC RCODE fsvIteratorFromParse( FSV_WIRE * pWire, - POOL * pPool) + F_Pool * pPool) { HFDB hDb = HFDB_NULL; HFCURSOR hIterator = pWire->getIteratorHandle(); @@ -3159,7 +3141,7 @@ Desc: Adds a view to an iterator ****************************************************************************/ FSTATIC RCODE fsvIteratorSelectParse( FSV_WIRE * pWire, - POOL * pPool) + F_Pool * pPool) { NODE * pSelect = pWire->getIteratorSelect(); NODE * pCurNode; @@ -3221,7 +3203,7 @@ FSTATIC RCODE fsvDbGetBlocks( FLMUINT * puiBlocksExamined, FLMUINT * puiNextBlkAddr, FLMUINT uiFlags, - POOL * pPool, + F_Pool * pPool, FLMBYTE ** ppBlocks, FLMUINT * puiBytes) { @@ -3307,9 +3289,8 @@ FSTATIC RCODE fsvDbGetBlocks( if (*puiCount) { *puiBytes = Wire.getBlockSize(); - if ((*ppBlocks = (FLMBYTE *) GedPoolAlloc( pPool, *puiBytes)) == NULL) + if( RC_BAD( rc = pPool->poolAlloc( *puiBytes, (void **)ppBlocks))) { - rc = RC_SET( FERR_MEM); goto Exit; } @@ -3337,11 +3318,10 @@ Transmission_Error: { goto Exit; } - - if ((*ppBlocks = (FLMBYTE *) GedPoolAlloc( - pPool, uiBlockSize * uiCount)) == NULL) + + if( RC_BAD( rc = pPool->poolAlloc( uiBlockSize * uiCount, + (void **)ppBlocks))) { - rc = RC_SET( FERR_MEM); goto Exit; } @@ -3566,11 +3546,11 @@ RCODE fsvPostStreamedRequest( FLMBOOL bLastPacket, FCS_BIOS * pSessionResponse) { - FLMBOOL bReleaseSession = FALSE; RCODE rc = FERR_OK; - POOL localPool; + FLMBOOL bReleaseSession = FALSE; + F_Pool localPool; - GedPoolInit( &localPool, 1024); + localPool.poolInit( 1024); if (!pSession && !bLastPacket) { @@ -3651,7 +3631,7 @@ RCODE fsvPostStreamedRequest( goto Exit; } - GedPoolReset( pSession->getWireScratchPool(), NULL); + pSession->getWireScratchPool()->poolReset(); if (RC_BAD( rc = fsvProcessRequest( &dataIStream, &dataOStream, pSession->getWireScratchPool(), NULL))) { @@ -3662,8 +3642,6 @@ RCODE fsvPostStreamedRequest( Exit: - GedPoolFree( &localPool); - if (bReleaseSession) { pSession->Release(); @@ -4143,11 +4121,11 @@ RCODE FSV_SCTX::BuildFilePath( FUrl Url; char * pucAsciiUrl; const char * pszFile; - POOL tmpPool; + F_Pool tmpPool; // Initialize a temporary pool. - GedPoolInit( &tmpPool, 256); + tmpPool.poolInit( 256); // Attempt to convert the UNICODE URL to a native string @@ -4176,7 +4154,8 @@ RCODE FSV_SCTX::BuildFilePath( // Build the database path. f_strcpy( pszFilePathRV, szBasePath); - if (RC_BAD( rc = f_pathAppend( pszFilePathRV, pszFile))) + if (RC_BAD( rc = gv_FlmSysData.pFileSystem->pathAppend( + pszFilePathRV, pszFile))) { goto Exit; } @@ -4191,7 +4170,6 @@ RCODE FSV_SCTX::BuildFilePath( Exit: - GedPoolFree( &tmpPool); return (rc); } @@ -4251,7 +4229,7 @@ FSV_SESN::FSV_SESN(void) m_pBOStream = NULL; m_bSetupCalled = FALSE; m_uiClientProtocolVersion = 0; - GedPoolInit( &m_wireScratchPool, 2048); + m_wireScratchPool.poolInit( 2048); } /**************************************************************************** @@ -4293,8 +4271,6 @@ FSV_SESN::~FSV_SESN(void) m_pBOStream->Release(); } } - - GedPoolFree( &m_wireScratchPool); } /**************************************************************************** @@ -4450,17 +4426,17 @@ RCODE FSV_SESN::CreateDatabase( FLMUNICODE * puzDictBuf, CREATE_OPTS * pCreateOpts) { - RCODE rc = FERR_OK; - POOL tmpPool; - char * pucDictBuf = NULL; - char * pszDbPath = NULL; - char * pszDataDir; - char * pszRflDir; - char * pszDictPath; + RCODE rc = FERR_OK; + F_Pool tmpPool; + char * pucDictBuf = NULL; + char * pszDbPath = NULL; + char * pszDataDir; + char * pszRflDir; + char * pszDictPath; // Initialize a temporary pool. - GedPoolInit( &tmpPool, 1024); + tmpPool.poolInit( 1024); // Make sure that setup has been called. @@ -4570,7 +4546,6 @@ Exit: } } - GedPoolFree( &tmpPool); return (rc); } @@ -4899,423 +4874,6 @@ Exit: return (rc); } -/**************************************************************************** -Desc: -****************************************************************************/ -RCODE fsvStartTcpListener( - FLMUINT uiPort) -{ - RCODE rc = FERR_OK; - - if (RC_BAD( rc = f_threadCreate( &gv_pTcpListenerThrd, fsvTcpListener, - "DB TCP Listener", FLM_DEFAULT_THREAD_GROUP, 0, - (void *) uiPort))) - { - goto Exit; - } - -Exit: - - return (rc); -} - -/**************************************************************************** -Desc: -****************************************************************************/ -void fsvShutdownTcpListener(void) -{ - f_threadDestroy( &gv_pTcpListenerThrd); -} - -/**************************************************************************** -Desc: -****************************************************************************/ -RCODE fsvTcpListener( - F_Thread * pThread) -{ - RCODE rc = FERR_OK; - FCS_TCP_SERVER * pServer; - FCS_TCP * pClient = NULL; - F_Thread * pVultureThread = NULL; - F_MUTEX hHandlerSem = F_MUTEX_NULL; - FLMUINT uiLoop; - FLMUINT uiPort = (FLMUINT) pThread->getParm1(); - - // Initialize TCP - - if ((pServer = f_new FCS_TCP_SERVER) == NULL) - { - rc = RC_SET( FERR_MEM); - goto Exit; - } - - if (RC_BAD( rc = pServer->bind( uiPort))) - { - gv_bTcpAllowConnections = FALSE; - goto Exit; - } - - for (uiLoop = 0; uiLoop < FSV_MAX_TCP_HANDLERS; uiLoop++) - { - gv_TcpHandlers[uiLoop] = NULL; - } - - if (RC_BAD( rc = f_mutexCreate( &hHandlerSem))) - { - goto Exit; - } - - if (RC_BAD( rc = f_threadCreate( &pVultureThread, fsvTcpVulture, - "DB TCP Vulture", FLM_DEFAULT_THREAD_GROUP, 0, - (void *) (&hHandlerSem)))) - { - goto Exit; - } - - gv_bTcpRunning = TRUE; - - for (;;) - { - if (pThread->getShutdownFlag()) - { - goto Exit; - } - - if (pClient == NULL) - { - if ((pClient = f_new FCS_TCP) == NULL) - { - f_sleep( 100); - continue; - } - } - - // See if a client is waiting to connect. - - if (RC_OK( rc = pServer->connectClient( pClient, 2, 1200))) - { - if (RC_BAD( fsvTcpAcceptConnection( &hHandlerSem, pClient))) - { - pClient->Release(); - } - - pClient = NULL; - } - else - { - if (rc != FERR_SVR_READ_TIMEOUT) - { - // Drop the current client. - - pClient->Release(); - pClient = NULL; - - // Re-initialize the listener. - - pServer->Release(); - pServer = f_new FCS_TCP_SERVER; - flmAssert( pServer != NULL); - - if (RC_BAD( rc = pServer->bind( uiPort))) - { - gv_bTcpAllowConnections = FALSE; - } - } - } - } - -Exit: - - // Shut down all threads and free any allocated resources - - f_threadDestroy( &pVultureThread); - - if (pClient) - { - pClient->Release(); - } - - if (pServer) - { - pServer->Release(); - } - - gv_bTcpRunning = FALSE; - return (rc); -} - -/**************************************************************************** -Desc: -****************************************************************************/ -RCODE fsvTcpVulture( - F_Thread * pThread) -{ - F_MUTEX * phHandlerMutex = (F_MUTEX *) pThread->getParm1(); - FLMUINT uiLoop; - FLMUINT uiActiveThreads; - FLMUINT uiRetry; - FLMBOOL bShutdown = FALSE; - - while (!bShutdown) - { - if (pThread->getShutdownFlag()) - { - bShutdown = TRUE; - break; - } - - f_mutexLock( *phHandlerMutex); - - uiActiveThreads = 0; - uiLoop = 0; - while (uiLoop < FSV_MAX_TCP_HANDLERS) - { - if (gv_TcpHandlers[uiLoop] != NULL) - { - if (!gv_TcpHandlers[uiLoop]->isThreadRunning()) - { - f_threadDestroy( &(gv_TcpHandlers[uiLoop])); - } - else - { - uiActiveThreads++; - } - } - - uiLoop++; - } - - f_mutexUnlock( *phHandlerMutex); - - for (uiLoop = 0; uiLoop < 100; uiLoop++) - { - if (pThread->getShutdownFlag()) - { - bShutdown = TRUE; - break; - } - - f_sleep( 100); - } - } - - uiRetry = 0; - while (uiRetry < 60) - { - uiActiveThreads = 0; - uiLoop = 0; - while (uiLoop < FSV_MAX_TCP_HANDLERS) - { - if (gv_TcpHandlers[uiLoop] != NULL) - { - if (!gv_TcpHandlers[uiLoop]->isThreadRunning()) - { - f_threadDestroy( &(gv_TcpHandlers[uiLoop])); - } - else - { - gv_TcpHandlers[uiLoop]->setShutdownFlag(); - uiActiveThreads++; - } - } - - uiLoop++; - } - - if (uiActiveThreads == 0) - { - break; - } - - f_sleep( 1000); - uiRetry++; - } - - return (FERR_OK); -} - -/**************************************************************************** -Desc: -****************************************************************************/ -RCODE fsvTcpAcceptConnection( - F_MUTEX * phHandlerMutex, - FCS_TCP * pClient) -{ - RCODE rc = FERR_OK; - FLMBOOL bMutexLocked = FALSE; - FLMUINT uiLoop; - F_Thread * pClientThrd; - - f_mutexLock( *phHandlerMutex); - bMutexLocked = TRUE; - - uiLoop = 0; - while (uiLoop < FSV_MAX_TCP_HANDLERS) - { - if (gv_TcpHandlers[uiLoop] == NULL) - { - break; - } - - uiLoop++; - } - - if (uiLoop < FSV_MAX_TCP_HANDLERS) - { - if (RC_BAD( rc = f_threadCreate( &pClientThrd, fsvTcpClientHandler, - "DB TCP Handler", FLM_DEFAULT_THREAD_GROUP, 0, pClient))) - { - goto Exit; - } - - gv_TcpHandlers[uiLoop] = pClientThrd; - } - else - { - rc = RC_SET( FERR_MEM); - goto Exit; - } - -Exit: - - if (bMutexLocked) - { - f_mutexUnlock( *phHandlerMutex); - } - - return (rc); -} - -/**************************************************************************** -Desc: -****************************************************************************/ -RCODE fsvTcpClientHandler( - F_Thread * pThread) -{ - RCODE rc = FERR_OK; - FCS_TCP * pClient = (FCS_TCP *) pThread->getParm1(); - FCS_IPIS * pIpIStream; - FCS_IPOS * pIpOStream = NULL; - FCS_DIS * pDataIStream = NULL; - FCS_DOS * pDataOStream = NULL; - FLMUINT uiSessionId = FCS_INVALID_ID; - POOL pool; - - // Initialize the scratch pool - - GedPoolInit( &pool, 2048); - - // Allocate required objects. - - if ((pIpIStream = f_new FCS_IPIS( pClient)) == NULL) - { - rc = RC_SET( FERR_MEM); - goto Exit; - } - - if ((pIpOStream = f_new FCS_IPOS( pClient)) == NULL) - { - rc = RC_SET( FERR_MEM); - goto Exit; - } - - if ((pDataIStream = f_new FCS_DIS) == NULL) - { - rc = RC_SET( FERR_MEM); - goto Exit; - } - - if ((pDataOStream = f_new FCS_DOS) == NULL) - { - rc = RC_SET( FERR_MEM); - goto Exit; - } - - for (;;) - { - if (pThread->getShutdownFlag()) - { - goto Exit; - } - - if (RC_BAD( rc = pClient->socketPeekRead( 5))) - { - if (rc != FERR_SVR_READ_TIMEOUT) - { - goto Exit; - } - } - else - { - - // Configure the data input stream. - - if (RC_BAD( rc = pDataIStream->setup( pIpIStream))) - { - goto Exit; - } - - // Configure the data output stream. - - if (RC_BAD( rc = pDataOStream->setup( pIpOStream))) - { - goto Exit; - } - - // Process the request. - - if (RC_BAD( rc = fsvProcessRequest( pDataIStream, pDataOStream, &pool, - &uiSessionId))) - { - goto Exit; - } - } - } - -Exit: - - if (pDataIStream) - { - pDataIStream->Release(); - } - - if (pDataOStream) - { - pDataOStream->Release(); - } - - if (pIpIStream) - { - pIpIStream->Release(); - } - - if (pIpOStream) - { - pIpOStream->Release(); - } - - if (pClient) - { - pClient->Release(); - } - - if (RC_BAD( rc) && uiSessionId != FCS_INVALID_ID) - { - FSV_SCTX * pServerContext = NULL; - - // Close the session and release any resources held by the client - // (open transactions, etc.) - - if (RC_OK( fsvGetGlobalContext( &pServerContext))) - { - pServerContext->CloseSession( uiSessionId); - } - } - - GedPoolFree( &pool); - return (rc); -} - /**************************************************************************** Desc: ****************************************************************************/ @@ -5416,7 +4974,8 @@ RCODE FSV_WIRE::read(void) case WIRE_VALUE_DICT_FILE_PATH: { - if (RC_BAD( rc = m_pDIStream->readUTF( m_pPool, &m_puzDictPath))) + if (RC_BAD( rc = m_pDIStream->readUTF( m_pPool, + &m_puzDictPath))) { goto Exit; } diff --git a/flaim/src/fsv.h b/flaim/src/fsv.h index 57501b4..53aea07 100644 --- a/flaim/src/fsv.h +++ b/flaim/src/fsv.h @@ -59,10 +59,6 @@ typedef struct FSV_RECORD_ID FLMUINT uiDrn; } FSV_RECORD_ID; -#ifdef FLM_NLM - typedef LONG (* FSV_NLM_UTILIZATION_FUNC)(void); -#endif - typedef void (* FSV_LOG_FUNC)( const char * pszMsg, RCODE rc, @@ -81,7 +77,7 @@ typedef FSV_SCTX * FSV_SCTX_p; /**************************************************************************** Desc: ****************************************************************************/ -class FSV_SCTX : public F_Base +class FSV_SCTX : public F_Object { public: @@ -151,7 +147,7 @@ typedef FSV_SESN * FSV_SESN_p; /**************************************************************************** Desc: ****************************************************************************/ -class FSV_SESN : public F_Base +class FSV_SESN : public F_Object { public: @@ -231,7 +227,7 @@ public: return( m_uiFlags); } - FINLINE POOL * getWireScratchPool( void) + FINLINE F_Pool * getWireScratchPool( void) { return &m_wireScratchPool; } @@ -255,7 +251,7 @@ private: FCS_BIOS * m_pBOStream; #define MAX_SESN_ITERATORS 10 HFCURSOR m_IteratorList[ MAX_SESN_ITERATORS]; - POOL m_wireScratchPool; + F_Pool m_wireScratchPool; }; /**************************************************************************** @@ -424,7 +420,7 @@ typedef FSV_BLOB * FSV_BLOB_p; /**************************************************************************** Desc: ****************************************************************************/ -class FSV_BLOB : public F_Base +class FSV_BLOB : public F_Object { private: @@ -466,7 +462,7 @@ RCODE fsvSetTempDir( RCODE fsvProcessRequest( FCS_DIS * pDataIStream, FCS_DOS * pDataOStream, - POOL * pScratchPool, + F_Pool * pScratchPool, FLMUINT * puiSessionIdRV); RCODE fsvOpClassDiag( diff --git a/flaim/src/fsysdata.cpp b/flaim/src/fsysdata.cpp index 22a8b85..04febcb 100644 --- a/flaim/src/fsysdata.cpp +++ b/flaim/src/fsysdata.cpp @@ -26,25 +26,6 @@ #include "flaimsys.h" -#ifdef FLM_AIX - #include -#endif -#ifdef FLM_HPUX - #include - #include - #include -#endif - -#if defined( FLM_WIN) || defined( FLM_NLM) - #define FLM_CAN_GET_PHYS_MEM -#elif defined( FLM_UNIX) - #if defined( _SC_AVPHYS_PAGES) || defined( FLM_HPUX) - #define FLM_CAN_GET_PHYS_MEM - #endif -#endif - -#define FLM_MIN_FREE_BYTES (2 * 1024 * 1024) - #ifdef FLM_32BIT #if defined( FLM_LINUX) @@ -61,34 +42,21 @@ #define FLM_MAX_CACHE_SIZE (~((FLMUINT)0)) #endif - FLMATOMIC gv_flmSysSpinLock = 0; FLMUINT gv_uiFlmSysStartupCount = 0; -FLMBOOL gv_bNetWareStartupCalled = FALSE; - -#ifdef FLM_NLM - extern "C" - { - void flmHttpConfig( - FLMBOOL bEnable, - const char * pszParams); - } -#endif FSTATIC void flmInitHashTbl( FBUCKET * pHashTable, - FLMUINT uiHashEntries, - f_randomGenerator * RandGen); + FLMUINT uiHashEntries); -#ifdef FLM_CAN_GET_PHYS_MEM -FSTATIC FLMUINT flmGetCacheBytes( +FSTATIC RCODE flmGetCacheBytes( FLMUINT uiPercent, FLMUINT uiMin, FLMUINT uiMax, FLMUINT uiMinToLeave, FLMBOOL bCalcOnAvailMem, - FLMUINT uiBytesCurrentlyInUse); -#endif + FLMUINT uiBytesCurrentlyInUse, + FLMUINT * puiCacheBytes); FSTATIC void flmLockSysData( void); @@ -117,7 +85,7 @@ FSTATIC void flmUnlinkFileFromBucket( FFILE * pFile); RCODE flmSystemMonitor( - F_Thread * pThread); + IF_Thread * pThread); FSTATIC RCODE flmRegisterHttpCallback( FLM_MODULE_HANDLE hModule, @@ -155,7 +123,7 @@ FINLINE RCODE flmSetTmpDir( { RCODE rc; - if( RC_BAD( rc = gv_FlmSysData.pFileSystem->Exists( pszTmpDir))) + if( RC_BAD( rc = gv_FlmSysData.pFileSystem->doesFileExist( pszTmpDir))) { goto Exit; } @@ -193,8 +161,7 @@ Desc: This routine initializes a hash table. ****************************************************************************/ FSTATIC void flmInitHashTbl( FBUCKET * pHashTable, - FLMUINT uiHashEntries, - f_randomGenerator * RandGen) + FLMUINT uiHashEntries) { FLMUINT uiCnt; FLMUINT uiRandVal; @@ -210,8 +177,8 @@ FSTATIC void flmInitHashTbl( { for (uiCnt = 0; uiCnt < uiHashEntries - 1; uiCnt++) { - uiRandVal = (FLMBYTE) f_randomChoice( RandGen, (FLMINT32)uiCnt, - (FLMINT32)(uiHashEntries - 1)); + uiRandVal = f_getRandomUINT32( uiCnt, uiHashEntries - 1); + if (uiRandVal != uiCnt) { uiTempVal = (FLMBYTE)pHashTable [uiCnt].uiHashValue; @@ -230,7 +197,6 @@ RCODE flmAllocHashTbl( FBUCKET ** ppHashTblRV) { RCODE rc = FERR_OK; - f_randomGenerator RandGen; FBUCKET * pHashTbl = NULL; // Allocate memory for the hash table @@ -243,8 +209,7 @@ RCODE flmAllocHashTbl( // Initialize the hash table - f_randomSetSeed( &RandGen, 1); - flmInitHashTbl( pHashTbl, uiHashTblSize, &RandGen); + flmInitHashTbl( pHashTbl, uiHashTblSize); Exit: @@ -261,225 +226,39 @@ Desc: This routine determines the number of cache bytes to use for caching on the available memory. Lower limit is 1 megabyte. ****************************************************************************/ -#ifdef FLM_CAN_GET_PHYS_MEM -FSTATIC FLMUINT flmGetCacheBytes( +FSTATIC RCODE flmGetCacheBytes( FLMUINT uiPercent, FLMUINT uiMin, FLMUINT uiMax, FLMUINT uiMinToLeave, FLMBOOL bCalcOnAvailMem, - FLMUINT uiBytesCurrentlyInUse - ) + FLMUINT uiBytesCurrentlyInUse, + FLMUINT * puiCacheBytes) { - FLMUINT uiMem; -#if defined( FLM_WIN) - MEMORYSTATUS MemStatus; -#elif defined( FLM_UNIX) - FLMUINT uiProcMemLimit = FLM_MAX_UINT; - FLMUINT uiProcVMemLimit = FLM_MAX_UINT; -#endif - -#if defined( FLM_WIN) - GlobalMemoryStatus( &MemStatus); + RCODE rc = NE_FLM_OK; + FLMUINT uiMem = 0; + FLMUINT64 ui64TotalPhysMem; + FLMUINT64 ui64AvailPhysMem; + + if( RC_BAD( rc = f_getMemoryInfo( &ui64TotalPhysMem, &ui64AvailPhysMem))) + { + goto Exit; + } + + if( ui64TotalPhysMem > FLM_MAX_UINT) + { + ui64TotalPhysMem = FLM_MAX_UINT; + } + + if( ui64AvailPhysMem > ui64TotalPhysMem) + { + ui64AvailPhysMem = ui64TotalPhysMem; + } + uiMem = (FLMUINT)((bCalcOnAvailMem) - ? (FLMUINT)MemStatus.dwAvailPhys - : (FLMUINT)MemStatus.dwTotalPhys); -#elif defined( FLM_UNIX) - { -#ifdef FLM_AIX - struct vminfo tmpvminfo; - #ifdef _SC_PAGESIZE - long iPageSize = sysconf(_SC_PAGESIZE); - #else - long iPageSize = 4096; - #endif - - if( iPageSize == -1) - { - // If sysconf returned an error, resort to using the default - // page size for the Power architecture. - - iPageSize = 4096; - } - - uiMem = FLM_MAX_UINT; - if( vmgetinfo( &tmpvminfo, VMINFO, sizeof( tmpvminfo)) != -1) - { - if( bCalcOnAvailMem) - { - if( tmpvminfo.numfrb < FLM_MAX_UINT) - { - uiMem = (FLMUINT)tmpvminfo.numfrb; - } - } - else - { - if( tmpvminfo.memsizepgs < FLM_MAX_UINT) - { - uiMem = (FLMUINT)tmpvminfo.memsizepgs; - } - } - } -#elif defined( FLM_HPUX) - long iPageSize; - struct pst_static pst; - - if (pstat_getstatic( &pst, sizeof( pst), (size_t)1, 0) == -1) - { - iPageSize = 4096; - } - else - { - iPageSize = pst.page_size; - } - if (bCalcOnAvailMem) - { - struct pst_dynamic dyn; - - if (pstat_getdynamic( &dyn, sizeof( dyn), 1, 0) != -1) - { - uiMem = (FLMUINT)dyn.psd_free; - } - else - { - uiMem = 0; - } - } - else - { - uiMem = (FLMUINT)pst.physical_memory; - } -#else - - long iPageSize = sysconf(_SC_PAGESIZE); - - // Get the amount of memory available to the system - - uiMem = (FLMUINT)((bCalcOnAvailMem) - ? (FLMUINT)sysconf(_SC_AVPHYS_PAGES) - : (FLMUINT)sysconf(_SC_PHYS_PAGES)); -#endif - - if (FLM_MAX_UINT / (FLMUINT)iPageSize >= uiMem) - { - uiMem *= (FLMUINT)iPageSize; - } - else - { - uiMem = FLM_MAX_UINT; - } - - #if defined( RLIMIT_VMEM) - // Bump the process soft virtual limit up to the hard limit - { - struct rlimit rlim; - - if( getrlimit( RLIMIT_VMEM, &rlim) == 0) - { - if( rlim.rlim_cur < rlim.rlim_max) - { - rlim.rlim_cur = rlim.rlim_max; - (void)setrlimit( RLIMIT_VMEM, &rlim); - if( getrlimit( RLIMIT_VMEM, &rlim) != 0) - { - rlim.rlim_cur = RLIM_INFINITY; - rlim.rlim_max = RLIM_INFINITY; - } - } - - if( rlim.rlim_cur != RLIM_INFINITY) - { - uiProcVMemLimit = (FLMUINT)rlim.rlim_cur; - } - } - } - #endif - - #if defined( RLIMIT_DATA) - - // Bump the process soft heap limit up to the hard limit - { - struct rlimit rlim; - - if( getrlimit( RLIMIT_DATA, &rlim) == 0) - { - if( rlim.rlim_cur < rlim.rlim_max) - { - rlim.rlim_cur = rlim.rlim_max; - (void)setrlimit( RLIMIT_DATA, &rlim); - if( getrlimit( RLIMIT_DATA, &rlim) != 0) - { - rlim.rlim_cur = RLIM_INFINITY; - rlim.rlim_max = RLIM_INFINITY; - } - } - - if( rlim.rlim_cur != RLIM_INFINITY) - { - uiProcMemLimit = (FLMUINT)rlim.rlim_cur; - } - } - } - - #endif - } -#elif defined( FLM_NLM) - { - FLMUINT uiCacheBufferSize = GetCacheBufferSize(); - - uiMem = (FLMUINT)((bCalcOnAvailMem) - ? (FLMUINT)GetCurrentNumberOfCacheBuffers() - : (FLMUINT)GetOriginalNumberOfCacheBuffers()); - - // Operating System will never give up last three hundred buffers. - - if (uiMem > 300) - { - uiMem -= 300; - } - else - { - uiMem = 0; - } - if (uiMem > FLM_MAX_UINT / uiCacheBufferSize) - { - uiMem = FLM_MAX_UINT; - } - else - { - uiMem *= uiCacheBufferSize; - } - - // Get available memory in local process pool - - if (bCalcOnAvailMem) - { - FLMUINT uiFreeBytes; - FLMUINT uiFreeNodes; - FLMUINT uiAllocatedBytes; - FLMUINT uiAllocatedNodes; - FLMUINT uiTotalMemory; - - if (GetNLMAllocMemoryCounts( f_getNLMHandle(), - &uiFreeBytes, &uiFreeNodes, - &uiAllocatedBytes, &uiAllocatedNodes, - &uiTotalMemory) == 0) - { - if (uiMem > FLM_MAX_UINT - uiFreeBytes) - { - uiMem = FLM_MAX_UINT; - } - else - { - uiMem += uiFreeBytes; - } - } - } - } -#else - #error Getting physical memory is not supported by this platform. -#endif - + ? (FLMUINT)ui64TotalPhysMem + : (FLMUINT)ui64AvailPhysMem); + // If we are basing the calculation on available physical memory, // take in to account what has already been allocated. @@ -495,38 +274,6 @@ FSTATIC FLMUINT flmGetCacheBytes( } } - // Determine if there are limits on the amount of memory the - // process can access and reset uiMem accordingly. There may - // be more available memory than the process is able to access. - -#ifdef FLM_WIN - - // There could be more physical memory in the system than we could - // actually allocate in our virtual address space. Thus, we need to - // make sure that we never exceed our total virtual address space. - - if (uiMem > (FLMUINT)MemStatus.dwTotalVirtual) - { - uiMem = (FLMUINT)MemStatus.dwTotalVirtual; - } - -#elif defined( FLM_UNIX) - - // The process might be limited in the amount of memory it - // can access. - - if ( uiMem > uiProcMemLimit) - { - uiMem = uiProcMemLimit; - } - - if( uiMem > uiProcVMemLimit) - { - uiMem = uiProcVMemLimit; - } - -#endif - // If uiMax is zero, use uiMinToLeave to calculate the maximum. if (!uiMax) @@ -564,9 +311,12 @@ FSTATIC FLMUINT flmGetCacheBytes( { uiMem = uiMin; } - return( uiMem); + +Exit: + + *puiCacheBytes = uiMem; + return( rc); } -#endif /*************************************************************************** Desc: Lock the system data structure for access - called only by startup @@ -575,19 +325,10 @@ Desc: Lock the system data structure for access - called only by startup ***************************************************************************/ FSTATIC void flmLockSysData( void) { -#ifdef FLM_HAVE_ATOMICS - while( _flmAtomicExchange( &gv_flmSysSpinLock, 1) == 1) + while( f_atomicExchange( &gv_flmSysSpinLock, 1) == 1) { f_sleep( 10); } -#else - while (gv_flmSysSpinLock) - { - f_sleep( 10); - } - - gv_flmSysSpinLock = 1; -#endif } /*************************************************************************** @@ -596,11 +337,7 @@ Desc: Unlock the system data structure for access - called only by startup ***************************************************************************/ FSTATIC void flmUnlockSysData( void) { -#ifdef FLM_HAVE_ATOMICS - _flmAtomicExchange( &gv_flmSysSpinLock, 0); -#else - gv_flmSysSpinLock = 0; -#endif + f_atomicExchange( &gv_flmSysSpinLock, 0); } /**************************************************************************** @@ -616,30 +353,6 @@ FLMEXP RCODE FLMAPI FlmStartup( void) FLMUINT uiCacheBytes; #ifdef FLM_USE_NICI int iHandle; -#endif - - // Before starting anything, make sure the atomic primitives return the - // correct values on this platform - -#if defined( FLM_DEBUG) - - #if !defined( FLM_HAVE_ATOMICS) && (defined( FLM_WIN) || defined( FLM_NLM)) - #error Something is wrong with the build environment! - #endif - - { - FLMATOMIC atomicVal = 10772; - FLMINT32 i32Tmp; - - flmAssert( flmAtomicInc( &atomicVal, (F_MUTEX)1, TRUE) == 10773); - flmAssert( flmAtomicDec( &atomicVal, (F_MUTEX)1, TRUE) == 10772); - - i32Tmp = flmAtomicExchange( &atomicVal, 10777, (F_MUTEX)1, TRUE); - - flmAssert( i32Tmp == 10772); - flmAssert( atomicVal == 10777); - } - #endif flmLockSysData(); @@ -647,63 +360,27 @@ FLMEXP RCODE FLMAPI FlmStartup( void) // See if FLAIM has already been started. If so, // we are done. - if (++gv_uiFlmSysStartupCount > 1) + if( ++gv_uiFlmSysStartupCount > 1) { goto Exit; } - -#ifdef FLM_NLM - gv_bNetWareStartupCalled = TRUE; - if( RC_BAD( rc = f_netwareStartup())) + + if( RC_BAD( rc = ftkStartup())) { goto Exit; } -#endif - - // Sanity check -- make sure we are using the correct - // byte-swap macros for this platform - - flmAssert( FB2UD( "\x0A\x0B\x0C\x0D") == 0x0D0C0B0A); - flmAssert( FB2UW( "\x0A\x0B") == 0x0B0A); // The memset needs to be first. f_memset( &gv_FlmSysData, 0, sizeof( FLMSYSDATA)); -#if defined( FLM_LINUX) - flmGetLinuxKernelVersion( &gv_FlmSysData.uiLinuxMajorVer, - &gv_FlmSysData.uiLinuxMinorVer, - &gv_FlmSysData.uiLinuxRevision); - gv_FlmSysData.uiMaxFileSize = flmGetLinuxMaxFileSize( sizeof( FLMUINT)); -#elif defined( FLM_AIX) - // Call set setrlimit to increase the max allowed file size. - // We don't have a good way to deal with any errors returned by - // setrlimit(), so we just hope that there aren't any... - struct rlimit rlim; - rlim.rlim_cur = RLIM_INFINITY; - rlim.rlim_max = RLIM_INFINITY; - setrlimit( RLIMIT_FSIZE, &rlim); - gv_FlmSysData.uiMaxFileSize = F_MAXIMUM_FILE_SIZE; -#else - gv_FlmSysData.uiMaxFileSize = F_MAXIMUM_FILE_SIZE; -#endif + gv_FlmSysData.uiMaxFileSize = f_getMaxFileSize(); flmAssert( gv_FlmSysData.uiMaxFileSize); // Initialize memory tracking variables - should be done before // call to f_memoryInit(). -#ifdef FLM_DEBUG - - // Variables for memory allocation tracking. - - gv_FlmSysData.bTrackLeaks = TRUE; - gv_FlmSysData.hMemTrackingMutex = F_MUTEX_NULL; -#ifdef DEBUG_SIM_OUT_OF_MEM - f_randomSetSeed( &gv_FlmSysData.memSimRandomGen, 1); -#endif -#endif - gv_FlmSysData.hShareMutex = F_MUTEX_NULL; gv_FlmSysData.hFileHdlMutex = F_MUTEX_NULL; gv_FlmSysData.uiMaxStratifyIterations = DEFAULT_MAX_STRATIFY_ITERATIONS; @@ -715,51 +392,46 @@ FLMEXP RCODE FLMAPI FlmStartup( void) gv_FlmSysData.LockEvents.hMutex = F_MUTEX_NULL; gv_FlmSysData.SizeEvents.hMutex = F_MUTEX_NULL; - // Memory initialization should be first. - - f_memoryInit(); - -#if defined( FLM_NLM) || (defined( FLM_WIN) && !defined( FLM_64BIT)) - InitFastBlockCheckSum(); -#endif - -#if defined( FLM_NLM) - if (RC_BAD( rc = nssInitialize())) - { - goto Exit; - } -#endif - #ifdef FLM_DBG_LOG flmDbgLogInit(); #endif - FLM_SECS_TO_TIMER_UNITS( DEFAULT_MAX_UNUSED_TIME, - gv_FlmSysData.uiMaxUnusedTime); - FLM_SECS_TO_TIMER_UNITS( DEFAULT_MAX_CP_INTERVAL, - gv_FlmSysData.uiMaxCPInterval); - FLM_SECS_TO_TIMER_UNITS( DEFAULT_MAX_TRANS_SECS, - gv_FlmSysData.uiMaxTransTime); - FLM_SECS_TO_TIMER_UNITS( DEFAULT_MAX_TRANS_INACTIVE_SECS, - gv_FlmSysData.uiMaxTransInactiveTime); + gv_FlmSysData.uiMaxUnusedTime = + FLM_SECS_TO_TIMER_UNITS( DEFAULT_MAX_UNUSED_TIME); + + gv_FlmSysData.uiMaxCPInterval = + FLM_SECS_TO_TIMER_UNITS( DEFAULT_MAX_CP_INTERVAL); + + gv_FlmSysData.uiMaxTransTime = + FLM_SECS_TO_TIMER_UNITS( DEFAULT_MAX_TRANS_SECS); + + gv_FlmSysData.uiMaxTransInactiveTime = + FLM_SECS_TO_TIMER_UNITS( DEFAULT_MAX_TRANS_INACTIVE_SECS); -#ifdef FLM_CAN_GET_PHYS_MEM - gv_FlmSysData.bDynamicCacheAdjust = TRUE; - gv_FlmSysData.uiCacheAdjustPercent = DEFAULT_CACHE_ADJUST_PERCENT; - gv_FlmSysData.uiCacheAdjustMin = DEFAULT_CACHE_ADJUST_MIN; - gv_FlmSysData.uiCacheAdjustMax = DEFAULT_CACHE_ADJUST_MAX; - gv_FlmSysData.uiCacheAdjustMinToLeave = DEFAULT_CACHE_ADJUST_MIN_TO_LEAVE; - FLM_SECS_TO_TIMER_UNITS( DEFAULT_CACHE_ADJUST_INTERVAL, - gv_FlmSysData.uiCacheAdjustInterval); - uiCacheBytes = flmGetCacheBytes( gv_FlmSysData.uiCacheAdjustPercent, - gv_FlmSysData.uiCacheAdjustMin, - gv_FlmSysData.uiCacheAdjustMax, - gv_FlmSysData.uiCacheAdjustMinToLeave, TRUE, 0); -#else - gv_FlmSysData.bDynamicCacheAdjust = FALSE; - gv_FlmSysData.uiCacheAdjustInterval = 0; - uiCacheBytes = DEFAULT_CACHE_ADJUST_MIN; -#endif + if( f_canGetMemoryInfo()) + { + gv_FlmSysData.bDynamicCacheAdjust = TRUE; + gv_FlmSysData.uiCacheAdjustPercent = DEFAULT_CACHE_ADJUST_PERCENT; + gv_FlmSysData.uiCacheAdjustMin = DEFAULT_CACHE_ADJUST_MIN; + gv_FlmSysData.uiCacheAdjustMax = DEFAULT_CACHE_ADJUST_MAX; + gv_FlmSysData.uiCacheAdjustMinToLeave = DEFAULT_CACHE_ADJUST_MIN_TO_LEAVE; + + gv_FlmSysData.uiCacheAdjustInterval = + FLM_SECS_TO_TIMER_UNITS( DEFAULT_CACHE_ADJUST_INTERVAL); + + if( RC_BAD( rc = flmGetCacheBytes( gv_FlmSysData.uiCacheAdjustPercent, + gv_FlmSysData.uiCacheAdjustMin, gv_FlmSysData.uiCacheAdjustMax, + gv_FlmSysData.uiCacheAdjustMinToLeave, TRUE, 0, &uiCacheBytes))) + { + goto Exit; + } + } + else + { + gv_FlmSysData.bDynamicCacheAdjust = FALSE; + gv_FlmSysData.uiCacheAdjustInterval = 0; + uiCacheBytes = DEFAULT_CACHE_ADJUST_MIN; + } if( uiCacheBytes > FLM_MAX_CACHE_SIZE) { @@ -768,39 +440,31 @@ FLMEXP RCODE FLMAPI FlmStartup( void) gv_FlmSysData.uiBlockCachePercentage = DEFAULT_BLOCK_CACHE_PERCENTAGE; - FLM_SECS_TO_TIMER_UNITS( DEFAULT_CACHE_CLEANUP_INTERVAL, - gv_FlmSysData.uiCacheCleanupInterval); - FLM_SECS_TO_TIMER_UNITS( DEFAULT_UNUSED_CLEANUP_INTERVAL, - gv_FlmSysData.uiUnusedCleanupInterval); - - // Initialize the thread manager - - if( (gv_FlmSysData.pThreadMgr = f_new F_ThreadMgr) == NULL) - { - rc = RC_SET( FERR_MEM); - goto Exit; - } - - if( RC_BAD( rc = gv_FlmSysData.pThreadMgr->setupThreadMgr())) - { - goto Exit; - } - - // Initialize the serial number generator - - if( RC_BAD( rc = f_initSerialNumberGenerator())) + gv_FlmSysData.uiCacheCleanupInterval = + FLM_SECS_TO_TIMER_UNITS( DEFAULT_CACHE_CLEANUP_INTERVAL); + gv_FlmSysData.uiUnusedCleanupInterval = + FLM_SECS_TO_TIMER_UNITS( DEFAULT_UNUSED_CLEANUP_INTERVAL); + + // Get a pointer to the thread manager + + if( RC_BAD( rc = FlmGetThreadMgr( &gv_FlmSysData.pThreadMgr))) { goto Exit; } + // Allocate thread group IDs + + gv_uiBackIxThrdGroup = gv_FlmSysData.pThreadMgr->allocGroupId(); + gv_uiCPThrdGrp = gv_FlmSysData.pThreadMgr->allocGroupId(); + gv_uiDbThrdGrp = gv_FlmSysData.pThreadMgr->allocGroupId(); + // Initialize the slab manager - if( (gv_FlmSysData.pSlabManager = f_new F_SlabManager) == NULL) + if( RC_BAD( rc = FlmAllocSlabManager( &gv_FlmSysData.pSlabManager))) { - rc = RC_SET( FERR_MEM); goto Exit; } - + if( !gv_FlmSysData.bDynamicCacheAdjust) { if( RC_BAD( rc = gv_FlmSysData.pSlabManager->setup( uiCacheBytes))) @@ -880,58 +544,14 @@ FLMEXP RCODE FLMAPI FlmStartup( void) gv_FlmSysData.uiNextFFileId = 1; - // Allocate and Initialize FLAIM Shared File Handle Manager - - if ((gv_FlmSysData.pFileHdlMgr = - new F_FileHdlMgr( &gv_FlmSysData.hFileHdlMutex)) == NULL) - { - rc = RC_SET( FERR_MEM); - goto Exit; - } - - if (RC_BAD( rc = gv_FlmSysData.pFileHdlMgr->Setup( DEFAULT_OPEN_THRESHOLD, - DEFAULT_MAX_UNUSED_TIME))) + // Get the file system object + + if( RC_BAD( rc = FlmGetFileSystem( &gv_FlmSysData.pFileSystem))) { goto Exit; } - - // Allocate and Initialize FLAIM Shared File System object - - if ((gv_FlmSysData.pFileSystem = f_new F_FileSystemImp) == NULL) - { - rc = RC_SET( FERR_MEM); - goto Exit; - } - -#if defined( FLM_WIN) - OSVERSIONINFO versionInfo; - - versionInfo.dwOSVersionInfoSize = sizeof( OSVERSIONINFO); - if( !GetVersionEx( &versionInfo)) - { - return( MapWinErrorToFlaim( GetLastError(), FERR_FAILURE)); - } - - // Async writes are not supported on Win32s (3.1) or - // Win95, 98, ME, etc. - - gv_FlmSysData.bOkToDoAsyncWrites = - (versionInfo.dwPlatformId != VER_PLATFORM_WIN32_WINDOWS && - versionInfo.dwPlatformId != VER_PLATFORM_WIN32s) - ? TRUE - : FALSE; -#else - gv_FlmSysData.bOkToDoAsyncWrites = TRUE; -#endif - - // Allocate and Initialize FLAIM Server Lock Manager - - if ((gv_FlmSysData.pServerLockMgr = - new ServerLockManager( &gv_FlmSysData.hServerLockMgrMutex)) == NULL) - { - rc = RC_SET( FERR_MEM); - goto Exit; - } + + gv_FlmSysData.bOkToDoAsyncWrites = gv_FlmSysData.pFileSystem->canDoAsync(); // Set up the session manager @@ -946,13 +566,6 @@ FLMEXP RCODE FLMAPI FlmStartup( void) goto Exit; } - // Set up hash table for lock manager. - - if (RC_BAD( rc = gv_FlmSysData.pServerLockMgr->SetupHashTbl())) - { - goto Exit; - } - // Set up mutexes for the event table. if (RC_BAD( rc = f_mutexCreate( @@ -1002,6 +615,7 @@ Exit: { flmCleanup(); } + flmUnlockSysData(); return( rc); } @@ -1098,81 +712,89 @@ FLMEXP RCODE FLMAPI FlmSetDynamicMemoryLimit( FLMUINT uiCacheAdjustPercent, FLMUINT uiCacheAdjustMin, FLMUINT uiCacheAdjustMax, - FLMUINT uiCacheAdjustMinToLeave - ) + FLMUINT uiCacheAdjustMinToLeave) { -#ifndef FLM_CAN_GET_PHYS_MEM - F_UNREFERENCED_PARM( uiCacheAdjustPercent); - F_UNREFERENCED_PARM( uiCacheAdjustMin); - F_UNREFERENCED_PARM( uiCacheAdjustMax); - F_UNREFERENCED_PARM( uiCacheAdjustMinToLeave); - return( RC_SET( FERR_NOT_IMPLEMENTED)); -#else - RCODE rc = FERR_OK; - FLMUINT uiCacheBytes; - - f_mutexLock( gv_FlmSysData.hShareMutex); - f_mutexLock( gv_FlmSysData.RCacheMgr.hMutex); - gv_FlmSysData.bDynamicCacheAdjust = TRUE; - flmAssert( uiCacheAdjustPercent > 0 && - uiCacheAdjustPercent <= 100); - gv_FlmSysData.uiCacheAdjustPercent = uiCacheAdjustPercent; - gv_FlmSysData.uiCacheAdjustMin = uiCacheAdjustMin; - gv_FlmSysData.uiCacheAdjustMax = uiCacheAdjustMax; - gv_FlmSysData.uiCacheAdjustMinToLeave = uiCacheAdjustMinToLeave; - uiCacheBytes = flmGetCacheBytes( gv_FlmSysData.uiCacheAdjustPercent, - gv_FlmSysData.uiCacheAdjustMin, - gv_FlmSysData.uiCacheAdjustMax, - gv_FlmSysData.uiCacheAdjustMinToLeave, TRUE, - gv_FlmSysData.SCacheMgr.Usage.uiTotalBytesAllocated + - gv_FlmSysData.RCacheMgr.pRCacheAlloc->getTotalBytesAllocated()); - rc = flmSetCacheLimits( uiCacheBytes, FALSE, FALSE); - f_mutexUnlock( gv_FlmSysData.RCacheMgr.hMutex); - f_mutexUnlock( gv_FlmSysData.hShareMutex); - return( rc); -#endif + if( !f_canGetMemoryInfo()) + { + return( RC_SET( FERR_NOT_IMPLEMENTED)); + } + else + { + RCODE rc = FERR_OK; + FLMUINT uiCacheBytes; + + f_mutexLock( gv_FlmSysData.hShareMutex); + f_mutexLock( gv_FlmSysData.RCacheMgr.hMutex); + gv_FlmSysData.bDynamicCacheAdjust = TRUE; + flmAssert( uiCacheAdjustPercent > 0 && + uiCacheAdjustPercent <= 100); + gv_FlmSysData.uiCacheAdjustPercent = uiCacheAdjustPercent; + gv_FlmSysData.uiCacheAdjustMin = uiCacheAdjustMin; + gv_FlmSysData.uiCacheAdjustMax = uiCacheAdjustMax; + gv_FlmSysData.uiCacheAdjustMinToLeave = uiCacheAdjustMinToLeave; + + if( RC_OK( rc = flmGetCacheBytes( gv_FlmSysData.uiCacheAdjustPercent, + gv_FlmSysData.uiCacheAdjustMin, gv_FlmSysData.uiCacheAdjustMax, + gv_FlmSysData.uiCacheAdjustMinToLeave, TRUE, + gv_FlmSysData.SCacheMgr.Usage.uiTotalBytesAllocated + + gv_FlmSysData.SCacheMgr.Usage.uiTotalBytesAllocated, + &uiCacheBytes))) + { + rc = flmSetCacheLimits( uiCacheBytes, FALSE, FALSE); + } + + f_mutexUnlock( gv_FlmSysData.RCacheMgr.hMutex); + f_mutexUnlock( gv_FlmSysData.hShareMutex); + return( rc); + } } /**************************************************************************** Desc : Sets a hard memory limit for cache. ****************************************************************************/ FLMEXP RCODE FLMAPI FlmSetHardMemoryLimit( - FLMUINT uiPercent, - FLMBOOL bPercentOfAvail, - FLMUINT uiMin, - FLMUINT uiMax, - FLMUINT uiMinToLeave, - FLMBOOL bPreallocate - ) + FLMUINT uiPercent, + FLMBOOL bPercentOfAvail, + FLMUINT uiMin, + FLMUINT uiMax, + FLMUINT uiMinToLeave, + FLMBOOL bPreallocate) { - RCODE rc = FERR_OK; + RCODE rc = FERR_OK; f_mutexLock( gv_FlmSysData.hShareMutex); f_mutexLock( gv_FlmSysData.RCacheMgr.hMutex); + gv_FlmSysData.bDynamicCacheAdjust = FALSE; + if (uiPercent) { -#ifndef FLM_CAN_GET_PHYS_MEM - F_UNREFERENCED_PARM( bPercentOfAvail); - F_UNREFERENCED_PARM( uiMin); - F_UNREFERENCED_PARM( uiMinToLeave); - rc = RC_SET( FERR_NOT_IMPLEMENTED); -#else - FLMUINT uiCacheBytes; - - uiCacheBytes = flmGetCacheBytes( uiPercent, uiMin, uiMax, uiMinToLeave, - bPercentOfAvail, - gv_FlmSysData.SCacheMgr.Usage.uiTotalBytesAllocated + - gv_FlmSysData.RCacheMgr.pRCacheAlloc->getTotalBytesAllocated()); - rc = flmSetCacheLimits( uiCacheBytes, FALSE, bPreallocate); -#endif + if( !f_canGetMemoryInfo()) + { + rc = RC_SET( FERR_NOT_IMPLEMENTED); + } + else + { + FLMUINT uiCacheBytes; + + if( RC_OK( rc = flmGetCacheBytes( + uiPercent, uiMin, uiMax, uiMinToLeave, + bPercentOfAvail, gv_FlmSysData.SCacheMgr.Usage.uiTotalBytesAllocated + + gv_FlmSysData.RCacheMgr.Usage.uiTotalBytesAllocated, + &uiCacheBytes))) + { + rc = flmSetCacheLimits( uiCacheBytes, FALSE, bPreallocate); + } + } } else { rc = flmSetCacheLimits( uiMax, TRUE, bPreallocate); } + f_mutexUnlock( gv_FlmSysData.RCacheMgr.hMutex); f_mutexUnlock( gv_FlmSysData.hShareMutex); + return( rc); } @@ -1218,11 +840,6 @@ FLMEXP void FLMAPI FlmGetMemoryInfo( { while( pFile) { - if( pFile->pECacheMgr) - { - pFile->pECacheMgr->getStats( &pMemInfo->ECache, TRUE); - } - if( pFile->uiDirtyCacheCount) { pMemInfo->uiDirtyBytes += @@ -1371,10 +988,6 @@ Retry: f_mutexUnlock( gv_FlmSysData.hShareMutex); bMutexLocked = FALSE; - // Clean up any unused file handles - - (void)gv_FlmSysData.pFileHdlMgr->CheckAgedItems( (FLMUINT)0); - Exit: if (bMutexLocked) @@ -1524,13 +1137,12 @@ FLMEXP RCODE FLMAPI FlmConfig( switch( eConfigType) { - - case FLM_OPEN_THRESHOLD: - uiValue = (FLMUINT) Value1; - rc = gv_FlmSysData.pFileHdlMgr->SetOpenThreshold( uiValue); - break; - - case FLM_CACHE_LIMIT: + case FLM_OPEN_THRESHOLD: + { + break; + } + + case FLM_CACHE_LIMIT: { f_mutexLock( gv_FlmSysData.hShareMutex); f_mutexLock( gv_FlmSysData.RCacheMgr.hMutex); @@ -1540,8 +1152,8 @@ FLMEXP RCODE FLMAPI FlmConfig( f_mutexUnlock( gv_FlmSysData.hShareMutex); break; } - - case FLM_BLOCK_CACHE_PERCENTAGE: + + case FLM_BLOCK_CACHE_PERCENTAGE: { f_mutexLock( gv_FlmSysData.hShareMutex); f_mutexLock( gv_FlmSysData.RCacheMgr.hMutex); @@ -1561,151 +1173,168 @@ FLMEXP RCODE FLMAPI FlmConfig( f_mutexUnlock( gv_FlmSysData.hShareMutex); break; } - - case FLM_SCACHE_DEBUG: - f_mutexLock( gv_FlmSysData.hShareMutex); - f_mutexLock( gv_FlmSysData.RCacheMgr.hMutex); - if (RC_OK( rc = ScaConfig( FLM_SCACHE_DEBUG, Value1, Value2))) + + case FLM_SCACHE_DEBUG: { - rc = flmRcaConfig( FLM_SCACHE_DEBUG, Value1, Value2); + f_mutexLock( gv_FlmSysData.hShareMutex); + f_mutexLock( gv_FlmSysData.RCacheMgr.hMutex); + if (RC_OK( rc = ScaConfig( FLM_SCACHE_DEBUG, Value1, Value2))) + { + rc = flmRcaConfig( FLM_SCACHE_DEBUG, Value1, Value2); + } + f_mutexUnlock( gv_FlmSysData.RCacheMgr.hMutex); + f_mutexUnlock( gv_FlmSysData.hShareMutex); + break; } - f_mutexUnlock( gv_FlmSysData.RCacheMgr.hMutex); - f_mutexUnlock( gv_FlmSysData.hShareMutex); - break; - - case FLM_CLOSE_UNUSED_FILES: - - // Timeout inactive sessions - - if( gv_FlmSysData.pSessionMgr) + + case FLM_CLOSE_UNUSED_FILES: { - gv_FlmSysData.pSessionMgr->timeoutInactiveSessions( - (FLMUINT)Value1, TRUE); + + // Timeout inactive sessions + + if( gv_FlmSysData.pSessionMgr) + { + gv_FlmSysData.pSessionMgr->timeoutInactiveSessions( + (FLMUINT)Value1, TRUE); + } + + // Convert seconds to timer units + + uiValue = FLM_SECS_TO_TIMER_UNITS( (FLMUINT) Value1); + + // Free any other unused structures that have not been used for the + // specified amount of time. + + uiCurrTime = (FLMUINT)FLM_GET_TIMER(); + f_mutexLock( gv_FlmSysData.hShareMutex); + + // Temporarily set the maximum unused seconds in the FLMSYSDATA structure + // to the value that was passed in to Value1. Restore it after + // calling flmCheckNUStructs. + + uiSave = gv_FlmSysData.uiMaxUnusedTime; + gv_FlmSysData.uiMaxUnusedTime = uiValue; + + // May unlock and re-lock the global mutex. + flmCheckNUStructs( uiCurrTime); + gv_FlmSysData.uiMaxUnusedTime = uiSave; + f_mutexUnlock( gv_FlmSysData.hShareMutex); + break; } - - // Convert seconds to timer units - - FLM_SECS_TO_TIMER_UNITS( (FLMUINT) Value1, uiValue); - rc = gv_FlmSysData.pFileHdlMgr->CheckAgedItems( uiValue); - - // Free any other unused structures that have not been used for the - // specified amount of time. - - uiCurrTime = (FLMUINT)FLM_GET_TIMER(); - f_mutexLock( gv_FlmSysData.hShareMutex); - - // Temporarily set the maximum unused seconds in the FLMSYSDATA structure - // to the value that was passed in to Value1. Restore it after - // calling flmCheckNUStructs. - - uiSave = gv_FlmSysData.uiMaxUnusedTime; - gv_FlmSysData.uiMaxUnusedTime = uiValue; - - // May unlock and re-lock the global mutex. - flmCheckNUStructs( uiCurrTime); - gv_FlmSysData.uiMaxUnusedTime = uiSave; - f_mutexUnlock( gv_FlmSysData.hShareMutex); - break; - - case FLM_CLOSE_ALL_FILES: - rc = flmCloseAllFiles(); - break; - - case FLM_START_STATS: - (void)flmStatStart( &gv_FlmSysData.Stats); - - // Start query statistics, if they have not - // already been started. - - f_mutexLock( gv_FlmSysData.hQueryMutex); - if (!gv_FlmSysData.uiMaxQueries) + + case FLM_CLOSE_ALL_FILES: { - gv_FlmSysData.uiMaxQueries = 20; - gv_FlmSysData.bNeedToUnsetMaxQueries = TRUE; + break; } - f_mutexUnlock( gv_FlmSysData.hQueryMutex); - break; - - case FLM_STOP_STATS: - (void)flmStatStop( &gv_FlmSysData.Stats); - - // Stop query statistics, if they were - // started by a call to FLM_START_STATS. - - f_mutexLock( gv_FlmSysData.hQueryMutex); - if (gv_FlmSysData.bNeedToUnsetMaxQueries) + + case FLM_START_STATS: { + (void)flmStatStart( &gv_FlmSysData.Stats); + + // Start query statistics, if they have not + // already been started. + + f_mutexLock( gv_FlmSysData.hQueryMutex); + if (!gv_FlmSysData.uiMaxQueries) + { + gv_FlmSysData.uiMaxQueries = 20; + gv_FlmSysData.bNeedToUnsetMaxQueries = TRUE; + } + f_mutexUnlock( gv_FlmSysData.hQueryMutex); + break; + } + + case FLM_STOP_STATS: + { + (void)flmStatStop( &gv_FlmSysData.Stats); + + // Stop query statistics, if they were + // started by a call to FLM_START_STATS. + + f_mutexLock( gv_FlmSysData.hQueryMutex); + if (gv_FlmSysData.bNeedToUnsetMaxQueries) + { + gv_FlmSysData.uiMaxQueries = 0; + flmFreeSavedQueries( TRUE); + // NOTE: flmFreeSavedQueries unlocks the mutex. + } + else + { + f_mutexUnlock( gv_FlmSysData.hQueryMutex); + } + + break; + } + + case FLM_RESET_STATS: + { + + // Lock the record cache manager's mutex + + f_mutexLock( gv_FlmSysData.hShareMutex); + f_mutexLock( gv_FlmSysData.RCacheMgr.hMutex); + + // Reset the record cache statistics + + gv_FlmSysData.RCacheMgr.uiIoWaits = 0; + gv_FlmSysData.RCacheMgr.Usage.uiCacheHits = 0; + gv_FlmSysData.RCacheMgr.Usage.uiCacheHitLooks = 0; + gv_FlmSysData.RCacheMgr.Usage.uiCacheFaults = 0; + gv_FlmSysData.RCacheMgr.Usage.uiCacheFaultLooks = 0; + + // Reset the block cache statistics. + + gv_FlmSysData.SCacheMgr.uiIoWaits = 0; + gv_FlmSysData.SCacheMgr.Usage.uiCacheHits = 0; + gv_FlmSysData.SCacheMgr.Usage.uiCacheHitLooks = 0; + gv_FlmSysData.SCacheMgr.Usage.uiCacheFaults = 0; + gv_FlmSysData.SCacheMgr.Usage.uiCacheFaultLooks = 0; + + // Unlock the cache manager's mutex + + f_mutexUnlock( gv_FlmSysData.RCacheMgr.hMutex); + f_mutexUnlock( gv_FlmSysData.hShareMutex); + + (void)flmStatReset( &gv_FlmSysData.Stats, FALSE, TRUE); + + f_mutexLock( gv_FlmSysData.hQueryMutex); + uiSaveMax = gv_FlmSysData.uiMaxQueries; gv_FlmSysData.uiMaxQueries = 0; flmFreeSavedQueries( TRUE); // NOTE: flmFreeSavedQueries unlocks the mutex. + + // Restore the old maximum + + if (uiSaveMax) + { + + // flmFreeSavedQueries unlocks the mutex, so we + // must relock it to restore the old maximum. + + f_mutexLock( gv_FlmSysData.hQueryMutex); + gv_FlmSysData.uiMaxQueries = uiSaveMax; + f_mutexUnlock( gv_FlmSysData.hQueryMutex); + } + + break; } - else + + case FLM_TMPDIR: { - f_mutexUnlock( gv_FlmSysData.hQueryMutex); + f_mutexLock( gv_FlmSysData.hShareMutex); + rc = flmSetTmpDir( (const char *)Value1); + f_mutexUnlock( gv_FlmSysData.hShareMutex); + break; } - break; - - case FLM_RESET_STATS: - - // Lock the record cache manager's mutex - - f_mutexLock( gv_FlmSysData.hShareMutex); - f_mutexLock( gv_FlmSysData.RCacheMgr.hMutex); - - // Reset the record cache statistics - - gv_FlmSysData.RCacheMgr.uiIoWaits = 0; - gv_FlmSysData.RCacheMgr.Usage.uiCacheHits = 0; - gv_FlmSysData.RCacheMgr.Usage.uiCacheHitLooks = 0; - gv_FlmSysData.RCacheMgr.Usage.uiCacheFaults = 0; - gv_FlmSysData.RCacheMgr.Usage.uiCacheFaultLooks = 0; - - // Reset the block cache statistics. - - gv_FlmSysData.SCacheMgr.uiIoWaits = 0; - gv_FlmSysData.SCacheMgr.Usage.uiCacheHits = 0; - gv_FlmSysData.SCacheMgr.Usage.uiCacheHitLooks = 0; - gv_FlmSysData.SCacheMgr.Usage.uiCacheFaults = 0; - gv_FlmSysData.SCacheMgr.Usage.uiCacheFaultLooks = 0; - - // Unlock the cache manager's mutex - - f_mutexUnlock( gv_FlmSysData.RCacheMgr.hMutex); - f_mutexUnlock( gv_FlmSysData.hShareMutex); - - (void)flmStatReset( &gv_FlmSysData.Stats, FALSE, TRUE); - - f_mutexLock( gv_FlmSysData.hQueryMutex); - uiSaveMax = gv_FlmSysData.uiMaxQueries; - gv_FlmSysData.uiMaxQueries = 0; - flmFreeSavedQueries( TRUE); - // NOTE: flmFreeSavedQueries unlocks the mutex. - - // Restore the old maximum - - if (uiSaveMax) + + case FLM_MAX_CP_INTERVAL: { - - // flmFreeSavedQueries unlocks the mutex, so we - // must relock it to restore the old maximum. - - f_mutexLock( gv_FlmSysData.hQueryMutex); - gv_FlmSysData.uiMaxQueries = uiSaveMax; - f_mutexUnlock( gv_FlmSysData.hQueryMutex); + gv_FlmSysData.uiMaxCPInterval = + FLM_SECS_TO_TIMER_UNITS( (FLMUINT) Value1); + break; } - break; - - case FLM_TMPDIR: - f_mutexLock( gv_FlmSysData.hShareMutex); - rc = flmSetTmpDir( (const char *)Value1); - f_mutexUnlock( gv_FlmSysData.hShareMutex); - break; - - case FLM_MAX_CP_INTERVAL: - FLM_SECS_TO_TIMER_UNITS( (FLMUINT) Value1, gv_FlmSysData.uiMaxCPInterval); - break; - - case FLM_BLOB_EXT: + + case FLM_BLOB_EXT: { const char * pszTmp = (const char *)Value1; @@ -1727,263 +1356,261 @@ FLMEXP RCODE FLMAPI FlmConfig( } gv_FlmSysData.ucBlobExt [iCnt] = 0; } + + break; } - break; - - case FLM_MAX_TRANS_SECS: - FLM_SECS_TO_TIMER_UNITS( (FLMUINT) Value1, - gv_FlmSysData.uiMaxTransTime); - break; - - case FLM_MAX_TRANS_INACTIVE_SECS: - FLM_SECS_TO_TIMER_UNITS( (FLMUINT) Value1, - gv_FlmSysData.uiMaxTransInactiveTime); - break; - - case FLM_CACHE_ADJUST_INTERVAL: - FLM_SECS_TO_TIMER_UNITS( (FLMUINT)Value1, - gv_FlmSysData.uiCacheAdjustInterval); - break; - - case FLM_CACHE_CLEANUP_INTERVAL: - FLM_SECS_TO_TIMER_UNITS( (FLMUINT)Value1, - gv_FlmSysData.uiCacheCleanupInterval); - break; - - case FLM_UNUSED_CLEANUP_INTERVAL: - FLM_SECS_TO_TIMER_UNITS( (FLMUINT)Value1, - gv_FlmSysData.uiUnusedCleanupInterval); - break; - - case FLM_MAX_UNUSED_TIME: - f_mutexLock( gv_FlmSysData.hShareMutex); - FLM_SECS_TO_TIMER_UNITS( (FLMUINT)Value1, - gv_FlmSysData.uiMaxUnusedTime); - f_mutexUnlock( gv_FlmSysData.hShareMutex); - break; - - case FLM_OUT_OF_MEM_SIMULATION: -#ifdef DEBUG_SIM_OUT_OF_MEM - gv_FlmSysData.uiOutOfMemSimEnabledFlag = - (FLMUINT)((Value1) ? OUT_OF_MEM_SIM_ENABLED_FLAG : 0); -#else - rc = RC_SET( FERR_NOT_IMPLEMENTED); -#endif - break; - - case FLM_CACHE_CHECK: - gv_FlmSysData.bCheckCache = (FLMBOOL)((Value1 != 0) - ? (FLMBOOL)TRUE - : (FLMBOOL)FALSE); - break; - - case FLM_CLOSE_FILE: - rc = flmCloseDbFile( (const char *)Value1, (const char *)Value2); - break; - - case FLM_LOGGER: - f_mutexLock( gv_FlmSysData.hShareMutex); - if( !gv_FlmSysData.pLogger && Value1) - { - gv_FlmSysData.pLogger = (F_Logger *)Value1; - gv_FlmSysData.pLogger->lockLogger(); - gv_FlmSysData.pLogger->AddRef(); - gv_FlmSysData.pLogger->unlockLogger(); - } - f_mutexUnlock( gv_FlmSysData.hShareMutex); - break; - - case FLM_USE_ESM: - gv_FlmSysData.bOkToUseESM = (FLMBOOL)((Value1 != 0) - ? (FLMBOOL)TRUE - : (FLMBOOL)FALSE); - break; - - case FLM_ASSIGN_HTTP_SYMS: - if( gv_FlmSysData.HttpConfigParms.fnReg || - gv_FlmSysData.HttpConfigParms.fnDereg || - gv_FlmSysData.HttpConfigParms.fnReqPath || - gv_FlmSysData.HttpConfigParms.fnReqQuery || - gv_FlmSysData.HttpConfigParms.fnReqHdrValue || - gv_FlmSysData.HttpConfigParms.fnSetHdrValue || - gv_FlmSysData.HttpConfigParms.fnPrintf || - gv_FlmSysData.HttpConfigParms.fnEmit || - gv_FlmSysData.HttpConfigParms.fnSetNoCache || - gv_FlmSysData.HttpConfigParms.fnSendHeader || - gv_FlmSysData.HttpConfigParms.fnSetIOMode || - gv_FlmSysData.HttpConfigParms.fnSendBuffer || - gv_FlmSysData.HttpConfigParms.fnAcquireSession || - gv_FlmSysData.HttpConfigParms.fnReleaseSession || - gv_FlmSysData.HttpConfigParms.fnAcquireUser || - gv_FlmSysData.HttpConfigParms.fnReleaseUser || - gv_FlmSysData.HttpConfigParms.fnSetSessionValue || - gv_FlmSysData.HttpConfigParms.fnGetSessionValue || - gv_FlmSysData.HttpConfigParms.fnGetGblValue || - gv_FlmSysData.HttpConfigParms.fnSetGblValue || - gv_FlmSysData.HttpConfigParms.fnRecvBuffer) - { - rc = RC_SET( FERR_HTTP_SYMS_EXIST); - goto Exit; - } - else - { - gv_FlmSysData.HttpConfigParms.fnReg = ((HTTPCONFIGPARAMS *)Value1)->fnReg; - gv_FlmSysData.HttpConfigParms.fnDereg = ((HTTPCONFIGPARAMS *)Value1)->fnDereg; - gv_FlmSysData.HttpConfigParms.fnReqPath = ((HTTPCONFIGPARAMS *)Value1)->fnReqPath; - gv_FlmSysData.HttpConfigParms.fnReqQuery = ((HTTPCONFIGPARAMS *)Value1)->fnReqQuery; - gv_FlmSysData.HttpConfigParms.fnReqHdrValue = ((HTTPCONFIGPARAMS *)Value1)->fnReqHdrValue; - gv_FlmSysData.HttpConfigParms.fnSetHdrValue = ((HTTPCONFIGPARAMS *)Value1)->fnSetHdrValue; - gv_FlmSysData.HttpConfigParms.fnPrintf = ((HTTPCONFIGPARAMS *)Value1)->fnPrintf; - gv_FlmSysData.HttpConfigParms.fnEmit = ((HTTPCONFIGPARAMS *)Value1)->fnEmit; - gv_FlmSysData.HttpConfigParms.fnSetNoCache = ((HTTPCONFIGPARAMS *)Value1)->fnSetNoCache; - gv_FlmSysData.HttpConfigParms.fnSendHeader = ((HTTPCONFIGPARAMS *)Value1)->fnSendHeader; - gv_FlmSysData.HttpConfigParms.fnSetIOMode = ((HTTPCONFIGPARAMS *)Value1)->fnSetIOMode; - gv_FlmSysData.HttpConfigParms.fnSendBuffer = ((HTTPCONFIGPARAMS *)Value1)->fnSendBuffer; - gv_FlmSysData.HttpConfigParms.fnAcquireSession = ((HTTPCONFIGPARAMS *)Value1)->fnAcquireSession; - gv_FlmSysData.HttpConfigParms.fnReleaseSession = ((HTTPCONFIGPARAMS *)Value1)->fnReleaseSession; - gv_FlmSysData.HttpConfigParms.fnAcquireUser = ((HTTPCONFIGPARAMS *)Value1)->fnAcquireUser; - gv_FlmSysData.HttpConfigParms.fnReleaseUser = ((HTTPCONFIGPARAMS *)Value1)->fnReleaseUser; - gv_FlmSysData.HttpConfigParms.fnSetSessionValue = ((HTTPCONFIGPARAMS *)Value1)->fnSetSessionValue; - gv_FlmSysData.HttpConfigParms.fnGetSessionValue = ((HTTPCONFIGPARAMS *)Value1)->fnGetSessionValue; - gv_FlmSysData.HttpConfigParms.fnGetGblValue = ((HTTPCONFIGPARAMS *)Value1)->fnGetGblValue; - gv_FlmSysData.HttpConfigParms.fnSetGblValue = ((HTTPCONFIGPARAMS *)Value1)->fnSetGblValue; - gv_FlmSysData.HttpConfigParms.fnRecvBuffer = ((HTTPCONFIGPARAMS *)Value1)->fnRecvBuffer; - } - break; - - case FLM_REGISTER_HTTP_URL: - // Value1: FLM_MODULE_HANDLE - // Value2: Url string - if ((Value1 == NULL) || (Value2 == NULL)) - { - rc = RC_SET( FERR_INVALID_PARM); - goto Exit; - } - - rc = flmRegisterHttpCallback((FLM_MODULE_HANDLE)Value1, (char *)Value2); - break; - - case FLM_DEREGISTER_HTTP_URL: - rc = flmDeregisterHttpCallback(); - break; - case FLM_UNASSIGN_HTTP_SYMS: - gv_FlmSysData.HttpConfigParms.fnReg = NULL; - gv_FlmSysData.HttpConfigParms.fnDereg = NULL; - gv_FlmSysData.HttpConfigParms.fnReqPath = NULL; - gv_FlmSysData.HttpConfigParms.fnReqQuery = NULL; - gv_FlmSysData.HttpConfigParms.fnReqHdrValue = NULL; - gv_FlmSysData.HttpConfigParms.fnSetHdrValue = NULL; - gv_FlmSysData.HttpConfigParms.fnPrintf = NULL; - gv_FlmSysData.HttpConfigParms.fnEmit = NULL; - gv_FlmSysData.HttpConfigParms.fnSetNoCache = NULL; - gv_FlmSysData.HttpConfigParms.fnSendHeader = NULL; - gv_FlmSysData.HttpConfigParms.fnSetIOMode = NULL; - gv_FlmSysData.HttpConfigParms.fnSendBuffer = NULL; - gv_FlmSysData.HttpConfigParms.fnAcquireSession = NULL; - gv_FlmSysData.HttpConfigParms.fnReleaseSession = NULL; - gv_FlmSysData.HttpConfigParms.fnAcquireUser = NULL; - gv_FlmSysData.HttpConfigParms.fnReleaseUser = NULL; - gv_FlmSysData.HttpConfigParms.fnSetSessionValue = NULL; - gv_FlmSysData.HttpConfigParms.fnGetSessionValue = NULL; - gv_FlmSysData.HttpConfigParms.fnGetGblValue = NULL; - gv_FlmSysData.HttpConfigParms.fnSetGblValue = NULL; - gv_FlmSysData.HttpConfigParms.fnRecvBuffer = NULL; - break; - - case FLM_KILL_DB_HANDLES: - { - FFILE * pTmpFile; - - f_mutexLock( gv_FlmSysData.hShareMutex); - if( Value1) + case FLM_MAX_TRANS_SECS: { - // Look up the file using flmFindFile to see if we have the - // file open. May unlock and re-lock the global mutex. - - if( RC_OK( flmFindFile( (const char *)Value1, - (const char *)Value2, &pTmpFile)) && pTmpFile) - { - flmSetMustCloseFlags( pTmpFile, FERR_OK, TRUE); - } + gv_FlmSysData.uiMaxTransTime = + FLM_SECS_TO_TIMER_UNITS( (FLMUINT) Value1); + break; } - else + + case FLM_MAX_TRANS_INACTIVE_SECS: { - if( gv_FlmSysData.pFileHashTbl) + gv_FlmSysData.uiMaxTransInactiveTime = + FLM_SECS_TO_TIMER_UNITS( (FLMUINT) Value1); + break; + } + + case FLM_CACHE_ADJUST_INTERVAL: + { + gv_FlmSysData.uiCacheAdjustInterval = + FLM_SECS_TO_TIMER_UNITS( (FLMUINT)Value1); + break; + } + + case FLM_CACHE_CLEANUP_INTERVAL: + { + gv_FlmSysData.uiCacheCleanupInterval = + FLM_SECS_TO_TIMER_UNITS( (FLMUINT)Value1); + break; + } + + case FLM_UNUSED_CLEANUP_INTERVAL: + { + gv_FlmSysData.uiUnusedCleanupInterval = + FLM_SECS_TO_TIMER_UNITS( (FLMUINT)Value1); + break; + } + + case FLM_MAX_UNUSED_TIME: + { + f_mutexLock( gv_FlmSysData.hShareMutex); + gv_FlmSysData.uiMaxUnusedTime = + FLM_SECS_TO_TIMER_UNITS( (FLMUINT)Value1); + f_mutexUnlock( gv_FlmSysData.hShareMutex); + break; + } + + case FLM_CACHE_CHECK: + gv_FlmSysData.bCheckCache = (FLMBOOL)((Value1 != 0) + ? (FLMBOOL)TRUE + : (FLMBOOL)FALSE); + break; + + case FLM_CLOSE_FILE: + rc = flmCloseDbFile( (const char *)Value1, (const char *)Value2); + break; + + case FLM_LOGGER: + f_mutexLock( gv_FlmSysData.hShareMutex); + if( !gv_FlmSysData.pLogger && Value1) { - FLMUINT uiLoop; - - for( uiLoop = 0; uiLoop < FILE_HASH_ENTRIES; uiLoop++) + gv_FlmSysData.pLogger = (F_Logger *)Value1; + gv_FlmSysData.pLogger->lockLogger(); + gv_FlmSysData.pLogger->AddRef(); + gv_FlmSysData.pLogger->unlockLogger(); + } + f_mutexUnlock( gv_FlmSysData.hShareMutex); + break; + + case FLM_ASSIGN_HTTP_SYMS: + if( gv_FlmSysData.HttpConfigParms.fnReg || + gv_FlmSysData.HttpConfigParms.fnDereg || + gv_FlmSysData.HttpConfigParms.fnReqPath || + gv_FlmSysData.HttpConfigParms.fnReqQuery || + gv_FlmSysData.HttpConfigParms.fnReqHdrValue || + gv_FlmSysData.HttpConfigParms.fnSetHdrValue || + gv_FlmSysData.HttpConfigParms.fnPrintf || + gv_FlmSysData.HttpConfigParms.fnEmit || + gv_FlmSysData.HttpConfigParms.fnSetNoCache || + gv_FlmSysData.HttpConfigParms.fnSendHeader || + gv_FlmSysData.HttpConfigParms.fnSetIOMode || + gv_FlmSysData.HttpConfigParms.fnSendBuffer || + gv_FlmSysData.HttpConfigParms.fnAcquireSession || + gv_FlmSysData.HttpConfigParms.fnReleaseSession || + gv_FlmSysData.HttpConfigParms.fnAcquireUser || + gv_FlmSysData.HttpConfigParms.fnReleaseUser || + gv_FlmSysData.HttpConfigParms.fnSetSessionValue || + gv_FlmSysData.HttpConfigParms.fnGetSessionValue || + gv_FlmSysData.HttpConfigParms.fnGetGblValue || + gv_FlmSysData.HttpConfigParms.fnSetGblValue || + gv_FlmSysData.HttpConfigParms.fnRecvBuffer) + { + rc = RC_SET( FERR_HTTP_SYMS_EXIST); + goto Exit; + } + else + { + gv_FlmSysData.HttpConfigParms.fnReg = ((HTTPCONFIGPARAMS *)Value1)->fnReg; + gv_FlmSysData.HttpConfigParms.fnDereg = ((HTTPCONFIGPARAMS *)Value1)->fnDereg; + gv_FlmSysData.HttpConfigParms.fnReqPath = ((HTTPCONFIGPARAMS *)Value1)->fnReqPath; + gv_FlmSysData.HttpConfigParms.fnReqQuery = ((HTTPCONFIGPARAMS *)Value1)->fnReqQuery; + gv_FlmSysData.HttpConfigParms.fnReqHdrValue = ((HTTPCONFIGPARAMS *)Value1)->fnReqHdrValue; + gv_FlmSysData.HttpConfigParms.fnSetHdrValue = ((HTTPCONFIGPARAMS *)Value1)->fnSetHdrValue; + gv_FlmSysData.HttpConfigParms.fnPrintf = ((HTTPCONFIGPARAMS *)Value1)->fnPrintf; + gv_FlmSysData.HttpConfigParms.fnEmit = ((HTTPCONFIGPARAMS *)Value1)->fnEmit; + gv_FlmSysData.HttpConfigParms.fnSetNoCache = ((HTTPCONFIGPARAMS *)Value1)->fnSetNoCache; + gv_FlmSysData.HttpConfigParms.fnSendHeader = ((HTTPCONFIGPARAMS *)Value1)->fnSendHeader; + gv_FlmSysData.HttpConfigParms.fnSetIOMode = ((HTTPCONFIGPARAMS *)Value1)->fnSetIOMode; + gv_FlmSysData.HttpConfigParms.fnSendBuffer = ((HTTPCONFIGPARAMS *)Value1)->fnSendBuffer; + gv_FlmSysData.HttpConfigParms.fnAcquireSession = ((HTTPCONFIGPARAMS *)Value1)->fnAcquireSession; + gv_FlmSysData.HttpConfigParms.fnReleaseSession = ((HTTPCONFIGPARAMS *)Value1)->fnReleaseSession; + gv_FlmSysData.HttpConfigParms.fnAcquireUser = ((HTTPCONFIGPARAMS *)Value1)->fnAcquireUser; + gv_FlmSysData.HttpConfigParms.fnReleaseUser = ((HTTPCONFIGPARAMS *)Value1)->fnReleaseUser; + gv_FlmSysData.HttpConfigParms.fnSetSessionValue = ((HTTPCONFIGPARAMS *)Value1)->fnSetSessionValue; + gv_FlmSysData.HttpConfigParms.fnGetSessionValue = ((HTTPCONFIGPARAMS *)Value1)->fnGetSessionValue; + gv_FlmSysData.HttpConfigParms.fnGetGblValue = ((HTTPCONFIGPARAMS *)Value1)->fnGetGblValue; + gv_FlmSysData.HttpConfigParms.fnSetGblValue = ((HTTPCONFIGPARAMS *)Value1)->fnSetGblValue; + gv_FlmSysData.HttpConfigParms.fnRecvBuffer = ((HTTPCONFIGPARAMS *)Value1)->fnRecvBuffer; + } + break; + + case FLM_REGISTER_HTTP_URL: + // Value1: FLM_MODULE_HANDLE + // Value2: Url string + if ((Value1 == NULL) || (Value2 == NULL)) + { + rc = RC_SET( FERR_INVALID_PARM); + goto Exit; + } + + rc = flmRegisterHttpCallback((FLM_MODULE_HANDLE)Value1, (char *)Value2); + break; + + case FLM_DEREGISTER_HTTP_URL: + rc = flmDeregisterHttpCallback(); + break; + + case FLM_UNASSIGN_HTTP_SYMS: + gv_FlmSysData.HttpConfigParms.fnReg = NULL; + gv_FlmSysData.HttpConfigParms.fnDereg = NULL; + gv_FlmSysData.HttpConfigParms.fnReqPath = NULL; + gv_FlmSysData.HttpConfigParms.fnReqQuery = NULL; + gv_FlmSysData.HttpConfigParms.fnReqHdrValue = NULL; + gv_FlmSysData.HttpConfigParms.fnSetHdrValue = NULL; + gv_FlmSysData.HttpConfigParms.fnPrintf = NULL; + gv_FlmSysData.HttpConfigParms.fnEmit = NULL; + gv_FlmSysData.HttpConfigParms.fnSetNoCache = NULL; + gv_FlmSysData.HttpConfigParms.fnSendHeader = NULL; + gv_FlmSysData.HttpConfigParms.fnSetIOMode = NULL; + gv_FlmSysData.HttpConfigParms.fnSendBuffer = NULL; + gv_FlmSysData.HttpConfigParms.fnAcquireSession = NULL; + gv_FlmSysData.HttpConfigParms.fnReleaseSession = NULL; + gv_FlmSysData.HttpConfigParms.fnAcquireUser = NULL; + gv_FlmSysData.HttpConfigParms.fnReleaseUser = NULL; + gv_FlmSysData.HttpConfigParms.fnSetSessionValue = NULL; + gv_FlmSysData.HttpConfigParms.fnGetSessionValue = NULL; + gv_FlmSysData.HttpConfigParms.fnGetGblValue = NULL; + gv_FlmSysData.HttpConfigParms.fnSetGblValue = NULL; + gv_FlmSysData.HttpConfigParms.fnRecvBuffer = NULL; + break; + + case FLM_KILL_DB_HANDLES: + { + FFILE * pTmpFile; + + f_mutexLock( gv_FlmSysData.hShareMutex); + if( Value1) + { + // Look up the file using flmFindFile to see if we have the + // file open. May unlock and re-lock the global mutex. + + if( RC_OK( flmFindFile( (const char *)Value1, + (const char *)Value2, &pTmpFile)) && pTmpFile) { - pTmpFile = - (FFILE *)gv_FlmSysData.pFileHashTbl[ uiLoop].pFirstInBucket; - - while( pTmpFile) + flmSetMustCloseFlags( pTmpFile, FERR_OK, TRUE); + } + } + else + { + if( gv_FlmSysData.pFileHashTbl) + { + FLMUINT uiLoop; + + for( uiLoop = 0; uiLoop < FILE_HASH_ENTRIES; uiLoop++) { - flmSetMustCloseFlags( pTmpFile, FERR_OK, TRUE); - pTmpFile = pTmpFile->pNext; + pTmpFile = + (FFILE *)gv_FlmSysData.pFileHashTbl[ uiLoop].pFirstInBucket; + + while( pTmpFile) + { + flmSetMustCloseFlags( pTmpFile, FERR_OK, TRUE); + pTmpFile = pTmpFile->pNext; + } } } } - } - - f_mutexUnlock( gv_FlmSysData.hShareMutex); - - // Kill all sessions - - if( gv_FlmSysData.pSessionMgr) - { - gv_FlmSysData.pSessionMgr->shutdownSessions(); - } - - break; - } - case FLM_QUERY_MAX: - f_mutexLock( gv_FlmSysData.hQueryMutex); - gv_FlmSysData.uiMaxQueries = (FLMUINT)Value1; - gv_FlmSysData.bNeedToUnsetMaxQueries = FALSE; - flmFreeSavedQueries( TRUE); - - // flmFreeSavedQueries unlocks the mutex. - - break; - - case FLM_MAX_DIRTY_CACHE: - f_mutexLock( gv_FlmSysData.hShareMutex); - if (!Value1) - { - gv_FlmSysData.SCacheMgr.bAutoCalcMaxDirty = TRUE; - gv_FlmSysData.SCacheMgr.uiMaxDirtyCache = 0; - gv_FlmSysData.SCacheMgr.uiLowDirtyCache = 0; - } - else - { - gv_FlmSysData.SCacheMgr.bAutoCalcMaxDirty = FALSE; - gv_FlmSysData.SCacheMgr.uiMaxDirtyCache = (FLMUINT)Value1; - - // Low threshhold must be no higher than maximum! - - if ((gv_FlmSysData.SCacheMgr.uiLowDirtyCache = - (FLMUINT)Value2) > gv_FlmSysData.SCacheMgr.uiMaxDirtyCache) + f_mutexUnlock( gv_FlmSysData.hShareMutex); + + // Kill all sessions + + if( gv_FlmSysData.pSessionMgr) { - gv_FlmSysData.SCacheMgr.uiLowDirtyCache = - gv_FlmSysData.SCacheMgr.uiMaxDirtyCache; + gv_FlmSysData.pSessionMgr->shutdownSessions(); } + + break; } - f_mutexUnlock( gv_FlmSysData.hShareMutex); - break; - - case FLM_QUERY_STRATIFY_LIMITS: - f_mutexLock( gv_FlmSysData.hShareMutex); - gv_FlmSysData.uiMaxStratifyIterations = (FLMUINT)Value1; - gv_FlmSysData.uiMaxStratifyTime = (FLMUINT)Value2; - f_mutexUnlock( gv_FlmSysData.hShareMutex); - break; - - default: - rc = RC_SET( FERR_NOT_IMPLEMENTED); - break; + + case FLM_QUERY_MAX: + f_mutexLock( gv_FlmSysData.hQueryMutex); + gv_FlmSysData.uiMaxQueries = (FLMUINT)Value1; + gv_FlmSysData.bNeedToUnsetMaxQueries = FALSE; + flmFreeSavedQueries( TRUE); + + // flmFreeSavedQueries unlocks the mutex. + + break; + + case FLM_MAX_DIRTY_CACHE: + f_mutexLock( gv_FlmSysData.hShareMutex); + if (!Value1) + { + gv_FlmSysData.SCacheMgr.bAutoCalcMaxDirty = TRUE; + gv_FlmSysData.SCacheMgr.uiMaxDirtyCache = 0; + gv_FlmSysData.SCacheMgr.uiLowDirtyCache = 0; + } + else + { + gv_FlmSysData.SCacheMgr.bAutoCalcMaxDirty = FALSE; + gv_FlmSysData.SCacheMgr.uiMaxDirtyCache = (FLMUINT)Value1; + + // Low threshhold must be no higher than maximum! + + if ((gv_FlmSysData.SCacheMgr.uiLowDirtyCache = + (FLMUINT)Value2) > gv_FlmSysData.SCacheMgr.uiMaxDirtyCache) + { + gv_FlmSysData.SCacheMgr.uiLowDirtyCache = + gv_FlmSysData.SCacheMgr.uiMaxDirtyCache; + } + } + f_mutexUnlock( gv_FlmSysData.hShareMutex); + break; + + case FLM_QUERY_STRATIFY_LIMITS: + f_mutexLock( gv_FlmSysData.hShareMutex); + gv_FlmSysData.uiMaxStratifyIterations = (FLMUINT)Value1; + gv_FlmSysData.uiMaxStratifyTime = (FLMUINT)Value2; + f_mutexUnlock( gv_FlmSysData.hShareMutex); + break; + + default: + rc = RC_SET( FERR_NOT_IMPLEMENTED); + break; } Exit: @@ -1999,153 +1626,137 @@ FLMEXP RCODE FLMAPI FlmGetConfig( ) { RCODE rc = FERR_OK; - FLMUINT uiTmp; switch( eConfigType) { - case FLM_CACHE_LIMIT: - f_mutexLock( gv_FlmSysData.hShareMutex); - f_mutexLock( gv_FlmSysData.RCacheMgr.hMutex); - *((FLMUINT *)Value1) = gv_FlmSysData.SCacheMgr.Usage.uiMaxBytes + - gv_FlmSysData.RCacheMgr.Usage.uiMaxBytes; - f_mutexUnlock( gv_FlmSysData.RCacheMgr.hMutex); - f_mutexUnlock( gv_FlmSysData.hShareMutex); - break; - - case FLM_BLOCK_CACHE_PERCENTAGE: - f_mutexLock( gv_FlmSysData.hShareMutex); - *((FLMUINT *)Value1) = gv_FlmSysData.uiBlockCachePercentage; - f_mutexUnlock( gv_FlmSysData.hShareMutex); - break; - - case FLM_SCACHE_DEBUG: -#ifdef FLM_DEBUG - *((FLMBOOL *)Value1) = gv_FlmSysData.SCacheMgr.bDebug; -#else - *((FLMBOOL *)Value1) = FALSE; -#endif - break; - - case FLM_OPEN_FILES: - *((FLMUINT *)Value1) = gv_FlmSysData.pFileHdlMgr->GetOpenedFiles(); - break; - - case FLM_OPEN_THRESHOLD: - *((FLMUINT *)Value1) = gv_FlmSysData.pFileHdlMgr->GetOpenThreshold(); - break; - - case FLM_TMPDIR: - f_mutexLock( gv_FlmSysData.hShareMutex); - - if( !gv_FlmSysData.bTempDirSet ) - { - rc = RC_SET( FERR_IO_PATH_NOT_FOUND ); - - // Set the output to nulls on failure. - - *((char *)Value1) = 0; - } - else - { - f_strcpy( (char *)Value1, gv_FlmSysData.szTempDir); - } + case FLM_CACHE_LIMIT: + f_mutexLock( gv_FlmSysData.hShareMutex); + f_mutexLock( gv_FlmSysData.RCacheMgr.hMutex); + *((FLMUINT *)Value1) = gv_FlmSysData.SCacheMgr.Usage.uiMaxBytes + + gv_FlmSysData.RCacheMgr.Usage.uiMaxBytes; + f_mutexUnlock( gv_FlmSysData.RCacheMgr.hMutex); + f_mutexUnlock( gv_FlmSysData.hShareMutex); + break; - f_mutexUnlock( gv_FlmSysData.hShareMutex); - break; - - case FLM_MAX_CP_INTERVAL: - FLM_TIMER_UNITS_TO_SECS( gv_FlmSysData.uiMaxCPInterval, uiTmp); - *((FLMUINT *)Value1) = uiTmp; - break; - - case FLM_BLOB_EXT: - f_strcpy( (char *)Value1, (const char *)gv_FlmSysData.ucBlobExt); - break; - - case FLM_MAX_TRANS_SECS: - FLM_TIMER_UNITS_TO_SECS( gv_FlmSysData.uiMaxTransTime, uiTmp); - *((FLMUINT *)Value1) = uiTmp; - break; - - case FLM_MAX_TRANS_INACTIVE_SECS: - FLM_TIMER_UNITS_TO_SECS( gv_FlmSysData.uiMaxTransInactiveTime, uiTmp); - *((FLMUINT *)Value1) = (FLMUINT)uiTmp; - break; - - case FLM_CACHE_ADJUST_INTERVAL: - FLM_TIMER_UNITS_TO_SECS( gv_FlmSysData.uiCacheAdjustInterval, uiTmp); - *((FLMUINT *)Value1) = uiTmp; - break; - - case FLM_CACHE_CLEANUP_INTERVAL: - FLM_TIMER_UNITS_TO_SECS( gv_FlmSysData.uiCacheCleanupInterval, uiTmp); - *((FLMUINT *)Value1) = uiTmp; - break; - - case FLM_UNUSED_CLEANUP_INTERVAL: - FLM_TIMER_UNITS_TO_SECS( gv_FlmSysData.uiUnusedCleanupInterval, uiTmp); - *((FLMUINT *)Value1) = uiTmp; - break; - - case FLM_MAX_UNUSED_TIME: - f_mutexLock( gv_FlmSysData.hShareMutex); - FLM_TIMER_UNITS_TO_SECS( gv_FlmSysData.uiMaxUnusedTime, uiTmp); - f_mutexUnlock( gv_FlmSysData.hShareMutex); - *((FLMUINT *)Value1) = uiTmp; - break; - - case FLM_OUT_OF_MEM_SIMULATION: -#ifdef DEBUG_SIM_OUT_OF_MEM - *((FLMBOOL *)Value1) = - (gv_FlmSysData.uiOutOfMemSimEnabledFlag == - OUT_OF_MEM_SIM_ENABLED_FLAG) - ? TRUE - : FALSE; -#else - *((FLMBOOL *)Value1) = FALSE; -#endif - break; - - case FLM_CACHE_CHECK: - *((FLMBOOL *)Value1) = gv_FlmSysData.bCheckCache; - break; - - case FLM_USE_ESM: - *((FLMBOOL *)Value1) = gv_FlmSysData.bOkToUseESM; - break; - - case FLM_QUERY_MAX: - f_mutexLock( gv_FlmSysData.hQueryMutex); - *((FLMUINT *)Value1) = gv_FlmSysData.uiMaxQueries; - f_mutexUnlock( gv_FlmSysData.hQueryMutex); - break; - - case FLM_MAX_DIRTY_CACHE: - f_mutexLock( gv_FlmSysData.hShareMutex); - *((FLMUINT *)Value1) = gv_FlmSysData.SCacheMgr.uiMaxDirtyCache; - f_mutexUnlock( gv_FlmSysData.hShareMutex); - break; - - case FLM_DYNA_CACHE_SUPPORTED: -#ifdef FLM_CAN_GET_PHYS_MEM - *((FLMBOOL *)Value1) = TRUE; -#else - *((FLMBOOL *)Value1) = FALSE; -#endif - break; - - case FLM_QUERY_STRATIFY_LIMITS: - f_mutexLock( gv_FlmSysData.hShareMutex); - if (Value1) - { - *((FLMUINT *)Value1) = gv_FlmSysData.uiMaxStratifyIterations; - } - f_mutexUnlock( gv_FlmSysData.hShareMutex); - break; - - default: - rc = RC_SET( FERR_NOT_IMPLEMENTED); - break; + case FLM_BLOCK_CACHE_PERCENTAGE: + f_mutexLock( gv_FlmSysData.hShareMutex); + *((FLMUINT *)Value1) = gv_FlmSysData.uiBlockCachePercentage; + f_mutexUnlock( gv_FlmSysData.hShareMutex); + break; + + case FLM_SCACHE_DEBUG: + #ifdef FLM_DEBUG + *((FLMBOOL *)Value1) = gv_FlmSysData.SCacheMgr.bDebug; + #else + *((FLMBOOL *)Value1) = FALSE; + #endif + break; + + case FLM_OPEN_FILES: + break; + + case FLM_OPEN_THRESHOLD: + break; + + case FLM_TMPDIR: + f_mutexLock( gv_FlmSysData.hShareMutex); + + if( !gv_FlmSysData.bTempDirSet ) + { + rc = RC_SET( FERR_IO_PATH_NOT_FOUND ); + + // Set the output to nulls on failure. + + *((char *)Value1) = 0; + } + else + { + f_strcpy( (char *)Value1, gv_FlmSysData.szTempDir); + } + + f_mutexUnlock( gv_FlmSysData.hShareMutex); + break; + + case FLM_MAX_CP_INTERVAL: + *((FLMUINT *)Value1) = + FLM_TIMER_UNITS_TO_SECS( gv_FlmSysData.uiMaxCPInterval); + break; + + case FLM_BLOB_EXT: + f_strcpy( (char *)Value1, (const char *)gv_FlmSysData.ucBlobExt); + break; + + case FLM_MAX_TRANS_SECS: + *((FLMUINT *)Value1) = + FLM_TIMER_UNITS_TO_SECS( gv_FlmSysData.uiMaxTransTime); + break; + + case FLM_MAX_TRANS_INACTIVE_SECS: + *((FLMUINT *)Value1) = + FLM_TIMER_UNITS_TO_SECS( gv_FlmSysData.uiMaxTransInactiveTime); + break; + + case FLM_CACHE_ADJUST_INTERVAL: + *((FLMUINT *)Value1) = + FLM_TIMER_UNITS_TO_SECS( gv_FlmSysData.uiCacheAdjustInterval); + break; + + case FLM_CACHE_CLEANUP_INTERVAL: + *((FLMUINT *)Value1) = + FLM_TIMER_UNITS_TO_SECS( gv_FlmSysData.uiCacheCleanupInterval); + break; + + case FLM_UNUSED_CLEANUP_INTERVAL: + *((FLMUINT *)Value1) = + FLM_TIMER_UNITS_TO_SECS( gv_FlmSysData.uiUnusedCleanupInterval); + break; + + case FLM_MAX_UNUSED_TIME: + f_mutexLock( gv_FlmSysData.hShareMutex); + *((FLMUINT *)Value1) = + FLM_TIMER_UNITS_TO_SECS( gv_FlmSysData.uiMaxUnusedTime); + f_mutexUnlock( gv_FlmSysData.hShareMutex); + break; + + case FLM_CACHE_CHECK: + *((FLMBOOL *)Value1) = gv_FlmSysData.bCheckCache; + break; + + case FLM_QUERY_MAX: + f_mutexLock( gv_FlmSysData.hQueryMutex); + *((FLMUINT *)Value1) = gv_FlmSysData.uiMaxQueries; + f_mutexUnlock( gv_FlmSysData.hQueryMutex); + break; + + case FLM_MAX_DIRTY_CACHE: + f_mutexLock( gv_FlmSysData.hShareMutex); + *((FLMUINT *)Value1) = gv_FlmSysData.SCacheMgr.uiMaxDirtyCache; + f_mutexUnlock( gv_FlmSysData.hShareMutex); + break; + + case FLM_DYNA_CACHE_SUPPORTED: + if( f_canGetMemoryInfo()) + { + *((FLMBOOL *)Value1) = TRUE; + } + else + { + *((FLMBOOL *)Value1) = FALSE; + } + break; + + case FLM_QUERY_STRATIFY_LIMITS: + f_mutexLock( gv_FlmSysData.hShareMutex); + if (Value1) + { + *((FLMUINT *)Value1) = gv_FlmSysData.uiMaxStratifyIterations; + } + f_mutexUnlock( gv_FlmSysData.hShareMutex); + break; + + default: + rc = RC_SET( FERR_NOT_IMPLEMENTED); + break; } //Exit: @@ -2156,7 +1767,7 @@ FLMEXP RCODE FLMAPI FlmGetConfig( Desc: ****************************************************************************/ FLMEXP RCODE FLMAPI FlmGetThreadInfo( - POOL * pPool, + F_Pool * pPool, F_THREAD_INFO ** ppThreadInfo, FLMUINT * puiNumThreads, const char * pszUrl) @@ -2279,7 +1890,7 @@ FSTATIC void flmShutdownDbThreads( RCODE rc = FERR_OK; F_BKGND_IX * pBackgroundIx; FDB * pDb; - F_Thread * pThread; + IF_Thread * pThread; FLMUINT uiThreadId; FLMUINT uiThreadCount; FLMBOOL bMutexLocked = TRUE; @@ -2322,7 +1933,7 @@ FSTATIC void flmShutdownDbThreads( for( ;;) { if( RC_BAD( rc = gv_FlmSysData.pThreadMgr->getNextGroupThread( - &pThread, FLM_BACKGROUND_INDEXING_THREAD_GROUP, &uiThreadId))) + &pThread, gv_uiBackIxThrdGroup, &uiThreadId))) { if( rc == FERR_NOT_FOUND) { @@ -2350,13 +1961,13 @@ FSTATIC void flmShutdownDbThreads( } } - // Shut down all threads in the FLM_DB_THREAD_GROUP. + // Shut down all threads in the database thread group uiThreadId = 0; for( ;;) { if( RC_BAD( rc = gv_FlmSysData.pThreadMgr->getNextGroupThread( - &pThread, FLM_DB_THREAD_GROUP, &uiThreadId))) + &pThread, gv_uiDbThrdGrp, &uiThreadId))) { if( rc == FERR_NOT_FOUND) { @@ -2527,18 +2138,6 @@ void flmFreeFile( flmRcaFreeFileRecs( pFile); - // Free the file ID list. This will also remove all file handles - // associated with this file. - - if( pFile->pFileIdList) - { - FLMINT iRefCnt; - - iRefCnt = pFile->pFileIdList->Release(); - flmAssert( !iRefCnt); - pFile->pFileIdList = NULL; - } - // Release the lock objects. if( pFile->pWriteLockObj) @@ -2557,7 +2156,6 @@ void flmFreeFile( if( pFile->pLockFileHdl) { - (void)pFile->pLockFileHdl->Close(); pFile->pLockFileHdl->Release(); pFile->pLockFileHdl = NULL; } @@ -2574,18 +2172,10 @@ void flmFreeFile( if( pFile->pucLogHdrWriteBuf) { -#ifdef FLM_WIN - (void)VirtualFree( pFile->pucLogHdrWriteBuf, 0, MEM_RELEASE); - pFile->pucLogHdrWriteBuf = NULL; -#elif defined( FLM_LINUX) || defined( FLM_SOLARIS) - free( pFile->pucLogHdrWriteBuf); - pFile->pucLogHdrWriteBuf = NULL; -#else - f_free( &pFile->pucLogHdrWriteBuf); -#endif + f_freeAlignedBuffer( (void **)&pFile->pucLogHdrWriteBuf); } - GedPoolFree( &pFile->krefPool); + pFile->krefPool.poolFree(); if( pFile->ppBlocksDone) { @@ -2593,12 +2183,6 @@ void flmFreeFile( pFile->uiBlocksDoneArraySize = 0; } - if( pFile->pECacheMgr) - { - pFile->pECacheMgr->Release(); - pFile->pECacheMgr = NULL; - } - // Free the maintenance thread's semaphore if( pFile->hMaintSem != F_SEM_NULL) @@ -2707,6 +2291,7 @@ FSTATIC void flmCleanup( void) // SMDIBHandle::exit). This code is here for the cases where we're // part of Flint or some other utility that doesn't necessarily use // SMI... + if (gv_FlmSysData.HttpConfigParms.fnDereg) { FlmConfig( FLM_DEREGISTER_HTTP_URL, NULL, NULL); @@ -2747,7 +2332,7 @@ FSTATIC void flmCleanup( void) gv_FlmSysData.pMrnuFile = NULL; gv_FlmSysData.pLrnuFile = NULL; - /* Free all of the files and associated structures. */ + // Free all of the files and associated structures if (gv_FlmSysData.pFileHashTbl) { @@ -2775,10 +2360,7 @@ FSTATIC void flmCleanup( void) pFileHashTbl->pFirstInBucket = NULL; } - // Unlock the global mutex f_mutexUnlock( gv_FlmSysData.hShareMutex); - - // Free the hash table f_free( &gv_FlmSysData.pFileHashTbl); } @@ -2790,51 +2372,6 @@ FSTATIC void flmCleanup( void) gv_FlmSysData.bStatsInitialized = FALSE; } - // Free (release) FLAIM's File Shared File Handles. - - if (gv_FlmSysData.pFileHdlMgr) - { - FLMINT iRefCnt = gv_FlmSysData.pFileHdlMgr->Release(); - - // No one else should have a reference to the file handle manager - // after this point. - -#ifdef FLM_DEBUG - flmAssert( !iRefCnt); -#else - // Quiet the compiler about the unused variable - (void)iRefCnt; -#endif - gv_FlmSysData.pFileHdlMgr = NULL; - } - - // Free (release) FLAIM's Server Lock Manager. - - if (gv_FlmSysData.pServerLockMgr) - { - FLMINT iRefCnt; - - // Release all locks. - - gv_FlmSysData.pServerLockMgr->CheckLockTimeouts( TRUE); - - // Release the lock manager. - - iRefCnt = gv_FlmSysData.pServerLockMgr->Release(); - - // No one else should have a reference to the server lock manager - // at this point, so lets trip a flmAssert if the object was really - // not deleted. - -#ifdef FLM_DEBUG - flmAssert( !iRefCnt); -#else - // Quiet the compiler about the unused variable - (void)iRefCnt; -#endif - gv_FlmSysData.pServerLockMgr = NULL; - } - // Free the resources of the shared cache manager. ScaExit(); @@ -2912,31 +2449,14 @@ FSTATIC void flmCleanup( void) if (gv_FlmSysData.pFileSystem) { - FLMINT iRefCnt = gv_FlmSysData.pFileSystem->Release(); - - // No one else should have a reference to the file system - // after this point. - -#ifdef FLM_DEBUG - flmAssert( !iRefCnt); -#else - // Quiet the compiler about the unused variable - (void)iRefCnt; -#endif + gv_FlmSysData.pFileSystem->Release(); gv_FlmSysData.pFileSystem = NULL; } + #ifdef FLM_DBG_LOG flmDbgLogExit(); #endif - // Free the serial number generator - - f_freeSerialNumberGenerator(); - -#if defined( FLM_NLM) - nssUninitialize(); -#endif - // Release the logger (if any) if( gv_FlmSysData.pLogger) @@ -2971,25 +2491,17 @@ FSTATIC void flmCleanup( void) CCS_Shutdown(); #endif - // Memory cleanup needs to be last. + // Shut down the toolkit - f_memoryCleanup(); - -#ifdef FLM_NLM - if( gv_bNetWareStartupCalled) - { - f_netwareShutdown(); - gv_bNetWareStartupCalled = FALSE; - } -#endif + ftkShutdown(); } /**************************************************************************** -Desc : Shuts down FLAIM. -Notes: Allows itself to be called multiple times and even before FlmStartup - is called, or even if FlmStartup fails. Warning: May not handle - race conditions very well on platforms that do not support atomic - exchange. +Desc: Shuts down FLAIM. +Notes: Allows itself to be called multiple times and even before FlmStartup + is called, or even if FlmStartup fails. Warning: May not handle + race conditions very well on platforms that do not support atomic + exchange. ****************************************************************************/ FLMEXP void FLMAPI FlmShutdown( void) { @@ -2998,59 +2510,6 @@ FLMEXP void FLMAPI FlmShutdown( void) flmUnlockSysData(); } -/**************************************************************************** -Desc: This routine determines the hash bucket for a string. -****************************************************************************/ -FLMUINT flmStrHashBucket( - const char * pszStr, - FBUCKET * pHashTbl, - FLMUINT uiNumBuckets) -{ - FLMUINT uiHashIndex; - - if ((uiHashIndex = (FLMUINT)*pszStr) >= uiNumBuckets) - { - uiHashIndex -= uiNumBuckets; - } - - while( *pszStr) - { - if ((uiHashIndex = - (FLMUINT)((pHashTbl [uiHashIndex].uiHashValue) ^ (FLMUINT)(*pszStr))) >= - uiNumBuckets) - uiHashIndex -= uiNumBuckets; - pszStr++; - } - return( uiHashIndex); -} - -/**************************************************************************** -Desc: This routine determines the hash bucket for a binary array of - characters. -****************************************************************************/ -FLMUINT flmBinHashBucket( - void * pBuf, - FLMUINT uiBufLen, - FBUCKET * pHashTbl, - FLMUINT uiNumBuckets) -{ - FLMUINT uiHashIndex; - FLMBYTE * ptr = (FLMBYTE *)pBuf; - - if ((uiHashIndex = (FLMUINT)*ptr) >= uiNumBuckets) - uiHashIndex -= uiNumBuckets; - while (uiBufLen) - { - if ((uiHashIndex = - (FLMUINT)((pHashTbl [uiHashIndex].uiHashValue) ^ (FLMUINT)(*ptr))) >= - uiNumBuckets) - uiHashIndex -= uiNumBuckets; - ptr++; - uiBufLen--; - } - return( uiHashIndex); -} - /**************************************************************************** Desc: This routine links a notify request into a notification list and then waits to be notified that the event has occurred. @@ -3060,30 +2519,26 @@ Notes: ****************************************************************************/ RCODE flmWaitNotifyReq( F_MUTEX hMutex, - FNOTIFY ** ppNotifyListRV, /* Pointer to the head of a notify - list where the new notify - request should be linked into. */ - void * UserData /* Other user data that the notifier - can use to pass other information - to the waiter. */ - ) + FNOTIFY ** ppNotifyListRV, + void * UserData) { FNOTIFY * pNotify = NULL; RCODE TempRc; RCODE rc = FERR_OK; F_SEM hSem; - /* First create a notify request and link it into the list. */ + // First create a notify request and link it into the list if (RC_OK( rc = f_calloc( (FLMUINT)(sizeof( FNOTIFY)), &pNotify))) { - /* Allocate a semaphore for the notify request. */ + // Allocate a semaphore for the notify request pNotify->uiThreadId = f_threadId(); pNotify->hSem = F_SEM_NULL; rc = f_semCreate( &pNotify->hSem); } + if (RC_BAD( rc)) { if (pNotify) @@ -3102,7 +2557,7 @@ RCODE flmWaitNotifyReq( *ppNotifyListRV = pNotify; hSem = pNotify->hSem; - /* Unlock the mutex and wait on the semaphore. */ + // Unlock the mutex and wait on the semaphore f_mutexUnlock( hMutex); if (RC_BAD( TempRc = f_semWait( hSem, F_SEM_WAITFOREVER))) @@ -3110,7 +2565,7 @@ RCODE flmWaitNotifyReq( rc = TempRc; } - /* Free the semaphore and the notify structure. */ + // Free the semaphore and the notify structure f_semDestroy( &hSem); f_free( &pNotify); @@ -3130,25 +2585,25 @@ Desc: This routine links an FFILE structure to its name hash bucket. locked. ****************************************************************************/ RCODE flmLinkFileToBucket( - FFILE * pFile /* File to be linked to its name hash bucket. */ - ) + FFILE * pFile) { RCODE rc = FERR_OK; FFILE * pTmpFile; FBUCKET * pBucket; FLMUINT uiBucket; - char szDbPathStr [F_PATH_MAX_SIZE]; + char szDbPathStr[ F_PATH_MAX_SIZE]; pBucket = gv_FlmSysData.pFileHashTbl; // Normalize the path to a string before hashing on it. - if (RC_BAD( rc = f_pathToStorageString( pFile->pszDbPath, szDbPathStr))) + if (RC_BAD( rc = gv_FlmSysData.pFileSystem->pathToStorageString( + pFile->pszDbPath, szDbPathStr))) { goto Exit; } - uiBucket = flmStrHashBucket( szDbPathStr, pBucket, FILE_HASH_ENTRIES); + uiBucket = f_strHashBucket( szDbPathStr, pBucket, FILE_HASH_ENTRIES); pBucket = &pBucket [uiBucket]; if (pBucket->pFirstInBucket) { @@ -3327,14 +2782,6 @@ void flmCheckNUStructs( break; } } - - // Look for unused file handles - - if( gv_FlmSysData.pFileHdlMgr) - { - gv_FlmSysData.pFileHdlMgr->CheckAgedItems( - gv_FlmSysData.pFileHdlMgr->GetMaxAvailTime()); - } } /**************************************************************************** @@ -3379,73 +2826,35 @@ Desc: This routine links an FDB structure to an FFILE structure. locked. ****************************************************************************/ RCODE flmLinkFdbToFile( - FDB * pDb, /* FDB that is to be linked to an FFILE - structure. */ - FFILE * pFile /* Pointer to FFILE structure the FDB is to be - linked to. */ - ) + FDB * pDb, + FFILE * pFile) { RCODE rc = FERR_OK; - /* - If the use count on the file used to be zero, unlink it from the - unused list. - */ + // If the use count on the file used to be zero, unlink it from the + // unused list. flmAssert( !pDb->pFile); + pDb->pPrevForFile = NULL; if ((pDb->pNextForFile = pFile->pFirstDb) != NULL) { pFile->pFirstDb->pPrevForFile = pDb; } + pFile->pFirstDb = pDb; pDb->pFile = pFile; + if (++pFile->uiUseCount == 1) { flmUnlinkFileFromNUList( pFile); } + if (pDb->uiFlags & FDB_INTERNAL_OPEN) { pFile->uiInternalUseCount++; } - /* - Allocate the super file object - */ - - if (!pDb->pSFileHdl) - { - if( (pDb->pSFileHdl = f_new F_SuperFileHdl) == NULL) - { - rc = RC_SET( FERR_MEM); - goto Exit; - } - - /* - Set up the super file - */ - - if( RC_BAD( rc = pDb->pSFileHdl->Setup( pFile->pFileIdList, - pFile->pszDbPath, - pFile->pszDataDir))) - { - goto Exit; - } - - if( pFile->pECacheMgr) - { - pDb->pSFileHdl->setECacheMgr( pFile->pECacheMgr); - } - - if( pFile->FileHdr.uiVersionNum) - { - pDb->pSFileHdl->SetBlockSize( pFile->FileHdr.uiBlockSize); - pDb->pSFileHdl->SetDbVersion( pFile->FileHdr.uiVersionNum); - } - } - -Exit: - return( rc); } @@ -3509,23 +2918,21 @@ Desc: This routine functions as a thread. It monitors open files and close time. ****************************************************************************/ RCODE flmSystemMonitor( - F_Thread * pThread) + IF_Thread * pThread) { - FLMUINT uiLastUnusedCleanupTime = 0; - FLMUINT uiLastRCacheCleanupTime = 0; - FLMUINT uiLastSCacheCleanupTime = 0; - FLMUINT uiCurrTime; - FLMUINT uiMaxLockTime; -#ifdef FLM_CAN_GET_PHYS_MEM - FLMUINT uiLastCacheAdjustTime = 0; -#endif + FLMUINT uiLastUnusedCleanupTime = 0; + FLMUINT uiLastRCacheCleanupTime = 0; + FLMUINT uiLastSCacheCleanupTime = 0; + FLMUINT uiCurrTime; + FLMUINT uiMaxLockTime; + FLMUINT uiLastCacheAdjustTime = 0; - FLM_MILLI_TO_TIMER_UNITS( 100, uiMaxLockTime); + uiMaxLockTime = FLM_MILLI_TO_TIMER_UNITS( 100); for (;;) { - /* See if we should shut down. */ + // See if we should shut down if( pThread->getShutdownFlag()) { @@ -3554,43 +2961,43 @@ RCODE flmSystemMonitor( uiCurrTime = uiLastUnusedCleanupTime = FLM_GET_TIMER(); } - // Call the lock manager to check timeouts. It is critial - // that this routine be called on a regular interval to - // timeout lock waiters that have expired. - - gv_FlmSysData.pServerLockMgr->CheckLockTimeouts( FALSE); - // Check the adjusting cache limit -#ifdef FLM_CAN_GET_PHYS_MEM - if ((gv_FlmSysData.bDynamicCacheAdjust) && - (FLM_ELAPSED_TIME( uiCurrTime, uiLastCacheAdjustTime) >= - gv_FlmSysData.uiCacheAdjustInterval)) + if( f_canGetMemoryInfo()) { - FLMUINT uiCacheBytes; - - f_mutexLock( gv_FlmSysData.hShareMutex); - f_mutexLock( gv_FlmSysData.RCacheMgr.hMutex); - - // Make sure the dynamic adjust flag is still set. - if ((gv_FlmSysData.bDynamicCacheAdjust) && (FLM_ELAPSED_TIME( uiCurrTime, uiLastCacheAdjustTime) >= - gv_FlmSysData.uiCacheAdjustInterval)) + gv_FlmSysData.uiCacheAdjustInterval)) { - uiCacheBytes = flmGetCacheBytes( gv_FlmSysData.uiCacheAdjustPercent, - gv_FlmSysData.uiCacheAdjustMin, - gv_FlmSysData.uiCacheAdjustMax, - gv_FlmSysData.uiCacheAdjustMinToLeave, TRUE, - gv_FlmSysData.SCacheMgr.Usage.uiTotalBytesAllocated + - gv_FlmSysData.RCacheMgr.pRCacheAlloc->getTotalBytesAllocated()); - (void)flmSetCacheLimits( uiCacheBytes, FALSE, FALSE); + FLMUINT uiCacheBytes; + + f_mutexLock( gv_FlmSysData.hShareMutex); + f_mutexLock( gv_FlmSysData.RCacheMgr.hMutex); + + // Make sure the dynamic adjust flag is still set. + + if ((gv_FlmSysData.bDynamicCacheAdjust) && + (FLM_ELAPSED_TIME( uiCurrTime, uiLastCacheAdjustTime) >= + gv_FlmSysData.uiCacheAdjustInterval)) + { + if( RC_OK( flmGetCacheBytes( + gv_FlmSysData.uiCacheAdjustPercent, + gv_FlmSysData.uiCacheAdjustMin, + gv_FlmSysData.uiCacheAdjustMax, + gv_FlmSysData.uiCacheAdjustMinToLeave, TRUE, + gv_FlmSysData.SCacheMgr.Usage.uiTotalBytesAllocated + + gv_FlmSysData.RCacheMgr.Usage.uiTotalBytesAllocated, + &uiCacheBytes))) + { + flmSetCacheLimits( uiCacheBytes, FALSE, FALSE); + } + } + + f_mutexUnlock( gv_FlmSysData.hShareMutex); + f_mutexUnlock( gv_FlmSysData.RCacheMgr.hMutex); + uiCurrTime = uiLastCacheAdjustTime = FLM_GET_TIMER(); } - f_mutexUnlock( gv_FlmSysData.hShareMutex); - f_mutexUnlock( gv_FlmSysData.RCacheMgr.hMutex); - uiCurrTime = uiLastCacheAdjustTime = FLM_GET_TIMER(); } -#endif // See if block cache should be cleaned up @@ -3881,8 +3288,6 @@ F_Session::F_Session() m_uiDictSeqNum = 0; m_uiLastUsed = FLM_GET_TIMER(); m_uiNextToken = FLM_GET_TIMER(); - m_pXmlImport = NULL; - m_pXmlExport = NULL; m_pDbTable = NULL; f_memset( m_ucKey, 0, sizeof( m_ucKey)); } @@ -3921,18 +3326,6 @@ F_Session::~F_Session() { m_pNameTable->Release(); } - - // Free XML import / export - - if( m_pXmlImport) - { - m_pXmlImport->Release(); - } - - if( m_pXmlExport) - { - m_pXmlExport->Release(); - } } /**************************************************************************** @@ -3987,38 +3380,13 @@ RCODE F_Session::setupSession( goto Exit; } - if( (m_pXmlImport = f_new F_XMLImport) == NULL) - { - rc = RC_SET( FERR_MEM); - goto Exit; - } - - if( RC_BAD( rc = m_pXmlImport->setup())) - { - goto Exit; - } - - if( (m_pXmlExport = f_new F_XMLExport) == NULL) - { - rc = RC_SET( FERR_MEM); - goto Exit; - } - - if( RC_BAD( rc = m_pXmlExport->setup())) - { - goto Exit; - } - - // Allocate the object table - if( (m_pDbTable = f_new F_HashTable) == NULL) { rc = RC_SET( FERR_MEM); goto Exit; } - if( RC_BAD( rc = m_pDbTable->setupHashTable( FALSE, 16, - pSessionMgr->getCRCTable()))) + if( RC_BAD( rc = m_pDbTable->setupHashTable( FALSE, 16))) { goto Exit; } @@ -4336,13 +3704,13 @@ Exit: /**************************************************************************** Desc: Releases a thread's lock on a session. ****************************************************************************/ -void F_Session::unlockSession() +void F_Session::unlockSession( void) { F_SEM hSem; flmAssert( getRefCount()); - f_mutexLock( m_hMutex); + if( m_uiThreadId != f_threadId()) { flmAssert( 0); @@ -4392,7 +3760,7 @@ FLMINT F_Session::AddRef( void) f_mutexLock( m_hMutex); flmAssert( getRefCount()); - iRefCnt = flmAtomicInc( &m_refCnt, m_hMutex, TRUE); + iRefCnt = ++m_refCnt; f_mutexUnlock( m_hMutex); return( iRefCnt); @@ -4408,14 +3776,14 @@ FLMINT F_Session::Release( void) flmAssert( getRefCount()); f_mutexLock( m_hMutex); - if( (iRefCnt = flmAtomicDec( &m_refCnt, m_hMutex, TRUE)) == 0) + if( (iRefCnt = --m_refCnt) == 0) { f_mutexUnlock( m_hMutex); delete this; return( iRefCnt); } + f_mutexUnlock( m_hMutex); - return( iRefCnt); } @@ -4434,11 +3802,6 @@ F_SessionMgr::~F_SessionMgr() { f_mutexDestroy( &m_hMutex); } - - if( m_pCRCTable) - { - f_freeCRCTable( &m_pCRCTable); - } } /**************************************************************************** @@ -4560,13 +3923,6 @@ RCODE F_SessionMgr::setupSessionMgr( void) goto Exit; } - // Initialize the CRC table - - if( RC_BAD( rc = f_initCRCTable( &m_pCRCTable))) - { - goto Exit; - } - // Create the session object table if( (m_pSessionTable = f_new F_HashTable) == NULL) @@ -4575,8 +3931,7 @@ RCODE F_SessionMgr::setupSessionMgr( void) goto Exit; } - if( RC_BAD( rc = m_pSessionTable->setupHashTable( FALSE, - 128, m_pCRCTable))) + if( RC_BAD( rc = m_pSessionTable->setupHashTable( FALSE, 128))) { goto Exit; } @@ -4756,7 +4111,7 @@ void F_SessionMgr::timeoutInactiveSessions( { uiCurrTime = FLM_GET_TIMER(); uiElapTime = FLM_ELAPSED_TIME( uiCurrTime, pSession->m_uiLastUsed); - FLM_TIMER_UNITS_TO_SECS( uiElapTime, uiElapSecs); + uiElapSecs = FLM_TIMER_UNITS_TO_SECS( uiElapTime); if( !uiInactiveSecs || uiElapSecs >= uiInactiveSecs) { @@ -4785,8 +4140,6 @@ F_HashTable::F_HashTable() m_pGlobalList = NULL; m_ppHashTable = NULL; m_uiBuckets = 0; - m_pCRCTable = NULL; - m_bOwnCRCTable = FALSE; } /**************************************************************************** @@ -4815,11 +4168,6 @@ F_HashTable::~F_HashTable() { f_mutexDestroy( &m_hMutex); } - - if( m_pCRCTable && m_bOwnCRCTable) - { - f_freeCRCTable( &m_pCRCTable); - } } /**************************************************************************** @@ -4827,8 +4175,7 @@ Desc: Configures the hash table prior to first use ****************************************************************************/ RCODE F_HashTable::setupHashTable( FLMBOOL bMultithreaded, - FLMUINT uiNumBuckets, - FLMUINT32 * pCRCTable) + FLMUINT uiNumBuckets) { RCODE rc = FERR_OK; @@ -4855,21 +4202,6 @@ RCODE F_HashTable::setupHashTable( } } - if( !pCRCTable) - { - // Initialize the CRC table - - if( RC_BAD( rc = f_initCRCTable( &m_pCRCTable))) - { - goto Exit; - } - m_bOwnCRCTable = TRUE; - } - else - { - m_pCRCTable = pCRCTable; - } - Exit: return( rc); @@ -5139,7 +4471,7 @@ FLMUINT F_HashTable::getHashBucket( { FLMUINT32 ui32CRC = 0; - f_updateCRC( m_pCRCTable, (FLMBYTE *)pvKey, uiLen, &ui32CRC); + f_updateCRC( (FLMBYTE *)pvKey, uiLen, &ui32CRC); if( pui32KeyCRC) { *pui32KeyCRC = ui32CRC; @@ -5298,69 +4630,6 @@ void * F_SessionDb::getKey( return( (void *)(&m_ucKey[ 0])); } -/**************************************************************************** -Desc: -****************************************************************************/ -FLMEXP RCODE FLMAPI FlmAllocFileSystem( - F_FileSystem ** ppFileSystem) -{ - RCODE rc = FERR_OK; - - flmAssert( ppFileSystem && *ppFileSystem == NULL); - - if( (*ppFileSystem = f_new F_FileSystemImp) == NULL) - { - rc = RC_SET( FERR_MEM); - goto Exit; - } - -Exit: - - return( rc); -} - -/**************************************************************************** -Desc: -****************************************************************************/ -FLMEXP RCODE FLMAPI FlmAllocDirHdl( - F_DirHdl ** ppDirHdl) -{ - RCODE rc = FERR_OK; - - flmAssert( ppDirHdl && *ppDirHdl == NULL); - - if( (*ppDirHdl = f_new F_DirHdlImp) == NULL) - { - rc = RC_SET( FERR_MEM); - goto Exit; - } - -Exit: - - return( rc); -} - -/**************************************************************************** -Desc: -****************************************************************************/ -FLMEXP RCODE FLMAPI FlmAllocFileHandle( - F_FileHdl ** ppFileHandle) -{ - RCODE rc = FERR_OK; - - flmAssert( ppFileHandle && *ppFileHandle == NULL); - - if( (*ppFileHandle = f_new F_FileHdlImp) == NULL) - { - rc = RC_SET( FERR_MEM); - goto Exit; - } - -Exit: - - return( rc); -} - /**************************************************************************** Desc: Deletes (releases) and F_CCS objected referenced in the ITT table. *****************************************************************************/ diff --git a/flaim/src/ftext.cpp b/flaim/src/ftext.cpp index 358e69a..47cbbfe 100644 --- a/flaim/src/ftext.cpp +++ b/flaim/src/ftext.cpp @@ -3522,72 +3522,6 @@ FINLINE FLMUINT flmCharTypeAnsi7( return (DELI_CHR); } -/**************************************************************************** -Desc: Compare two unicode strings. This comparison uses the collation - rules that are defined for the specified language. -****************************************************************************/ -FLMEXP FLMINT FLMAPI FlmStrCmp( - FLMUINT uiCompFlags, - FLMUINT byLang, - const FLMUNICODE * uzStr1, - const FLMUNICODE * uzStr2) -{ - RCODE rc; - FLMINT iCmp; - POOL Pool; - NODE * pNd1; - NODE * pNd2; - - GedPoolInit( &Pool, 256); - - if ((pNd1 = GedNodeMake( &Pool, 1, &rc)) == NULL || - (pNd2 = GedNodeMake( &Pool, 1, &rc)) == NULL) - { - flmAssert( 0); - iCmp = 1; - goto Exit; - } - - if (RC_BAD( rc = GedPutUNICODE( &Pool, pNd1, uzStr1))) - { - flmAssert( RC_OK( rc)); - iCmp = 1; - goto Exit; - } - - if (RC_BAD( rc = GedPutUNICODE( &Pool, pNd2, uzStr2))) - { - flmAssert( RC_OK( rc)); - iCmp = -1; - goto Exit; - } - - // Handle null string cases. - - if (GedValLen( pNd1) == 0) - { - iCmp = 1; - goto Exit; - } - else if (GedValLen( pNd2) == 0) - { - iCmp = -1; - goto Exit; - } - - // VISIT: need to add support for the IGNORE_DASH and IGNORE_SPACE - // options. - - iCmp = flmTextCompare( (FLMBYTE*) GedValPtr( pNd1), GedValLen( pNd1), - (FLMBYTE*) GedValPtr( pNd2), GedValLen( pNd2), - uiCompFlags, byLang); - -Exit: - - GedPoolFree( &Pool); - return (iCmp); -} - /**************************************************************************** Desc: Return the next WP or unicode character value and parsing type. ****************************************************************************/ @@ -3603,7 +3537,7 @@ FLMUINT flmTextGetCharType( FLMUNICODE uniValue; FLMUINT uiCharSet; - uiReturnLen = flmTextGetValue( pText, uiLen, NULL, FLM_MIN_SPACES, + uiReturnLen = flmTextGetValue( pText, uiLen, NULL, FLM_COMP_COMPRESS_WHITESPACE, pui16WPValue, puzUniValue); wpValue = *pui16WPValue; uniValue = *puzUniValue; @@ -3686,33 +3620,33 @@ Check_White_Space: // apply. if (ui16CurValue == (FLMUINT16) ASCII_UNDERSCORE && - (uiFlags & FLM_NO_UNDERSCORE)) + (uiFlags & FLM_COMP_NO_UNDERSCORES)) { ui16CurValue = (FLMUINT16) ASCII_SPACE; } if (ui16CurValue == (FLMUINT16) ASCII_SPACE) { - if (uiFlags & FLM_NO_SPACE) + if (uiFlags & FLM_COMP_NO_WHITESPACE) { ui16CurValue = 0; } - else if (uiFlags & FLM_MIN_SPACES) + else if (uiFlags & FLM_COMP_COMPRESS_WHITESPACE) { // Eat up the remaining spaces and underscores (if - // NO_UNDERSCORES). + // FLM_COMP_NO_UNDERSCORES). while ((pText[uiObjectLength] == ASCII_SPACE || (pText[uiObjectLength] == ASCII_UNDERSCORE && - (uiFlags & FLM_NO_UNDERSCORE))) && + (uiFlags & FLM_COMP_NO_UNDERSCORES))) && uiObjectLength < uiLen) { uiObjectLength++; } } } - else if (ui16CurValue == ASCII_DASH && (uiFlags & FLM_NO_DASH)) + else if (ui16CurValue == ASCII_DASH && (uiFlags & FLM_COMP_NO_DASHES)) { ui16CurValue = 0; } diff --git a/flaim/src/ftk.h b/flaim/src/ftk.h deleted file mode 100644 index 7048ed2..0000000 --- a/flaim/src/ftk.h +++ /dev/null @@ -1,1583 +0,0 @@ -//------------------------------------------------------------------------- -// Desc: Toolkit - cross platform APIs for system functionality. -// Tabs: 3 -// -// Copyright (c) 1991-2006 Novell, Inc. All Rights Reserved. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of version 2 of the GNU General Public -// License as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, contact Novell, Inc. -// -// To contact Novell about this file by physical or electronic mail, -// you may find current contact information at www.novell.com -// -// $Id: ftk.h 12334 2006-01-23 12:45:35 -0700 (Mon, 23 Jan 2006) dsanders $ -//------------------------------------------------------------------------- - -#ifndef FTK_H -#define FTK_H - - /**************************************************************************** - Desc: Internal return code macros - ****************************************************************************/ - #ifdef FLM_DEBUG - RCODE flmMakeErr( - RCODE rc, - const char * pszFile, - int iLine, - FLMBOOL bAssert); - - #define RC_SET( rc) \ - flmMakeErr( rc, __FILE__, __LINE__, FALSE) - - #define RC_SET_AND_ASSERT( rc) \ - flmMakeErr( rc, __FILE__, __LINE__, TRUE) - - #define RC_UNEXPECTED_ASSERT( rc) \ - flmMakeErr( rc, __FILE__, __LINE__, TRUE) - #else - #define RC_SET( rc) (rc) - #define RC_SET_AND_ASSERT( rc) (rc) - #define RC_UNEXPECTED_ASSERT( rc) - #endif - - #define F_SEM_WAITFOREVER 0xFFFFFFFF - - #ifdef FLM_NLM - #include "ftknlm.h" - #elif defined( FLM_WIN) - - #define FSTATIC static - - #ifndef WIN32_LEAN_AND_MEAN - #define WIN32_LEAN_AND_MEAN - #endif - - #ifndef WIN32_EXTRA_LEAN - #define WIN32_EXTRA_LEAN - #endif - - // This pragma is needed because FLAIM may be built with a - // packing other than 8-bytes on Win (such as 1-byte packing). - // Code in FLAIM that uses windows structures and system calls - // MUST use 8-byte packing (the packing used by the O/S). - // See Microsoft technical article Q117388. - - #pragma pack( push, enter_windows, 8) - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #pragma pack( pop, enter_windows) - - // Conversion from XXX to YYY, possible loss of data - - #pragma warning( disable : 4244) - - // Local variable XXX may be used without having been initialized - - #pragma warning( disable : 4701) - - // Function XXX not inlined - - #pragma warning( disable : 4710) - - #define f_stricmp( str1, str2) \ - _stricmp( (str1), (str2)) - - #define f_strnicmp( str1, str2, size) \ - _strnicmp( (str1), (str2),(size_t)(size)) - - #define f_memcpy( dest, src, size) \ - memcpy((void *)(dest), (void *)(src),(size_t)(size)) - - #define f_memmove( dest, src, length) \ - memmove((void *)(dest), (void *)(src),(size_t)(length)) - - #define f_memset( src, chr, size) \ - memset((void *)(src),(chr),(size_t)(size)) - - #define f_memcmp( str1, str2, length) \ - memcmp((void *)(str1), (void *)(str2),(size_t)(length)) - - #define f_strcat( dest, src) \ - strcat( (char*)(dest), (char*)(src)) - - #define f_strcmp( str1, str2) \ - strcmp( (char*)(str1), (char*)(str2)) - - #define f_strcpy( dest, src) \ - strcpy( (char*)(dest), (char*)(src)) - - #define f_strncpy( dest, src, length) \ - strncpy( (char*)(dest), (char*)(src), (size_t)(length)) - - #define f_strlen( str) \ - ((FLMUINT)strlen( (char*)(str))) - - #define f_strncmp( str1, str2, size) \ - strncmp( (char*)(str1), (char*)(str2), (size_t)(size)) - - #define f_strrchr( str, value ) \ - strrchr( (char*)(str), (int)value) - - #define f_strstr( str1, str2) \ - strstr( (char*)(str1), (char*)(str2)) - - #define f_strncat( str1, str2, n) \ - strncat( (str1), (str2), n) - - #define f_strupr( str) \ - _strupr( (str)) - - #define f_va_list va_list - #define f_va_start va_start - #define f_va_arg va_arg - #define f_va_end va_end - - #elif defined( FLM_UNIX) - - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - - #ifndef _POSIX_THREADS - #define _POSIX_THREADS - #endif - - #include - - #ifndef FLM_OSX - #include - #endif - - #ifdef FLM_AIX - #include - #endif - - #ifdef FLM_OSX - #include - #endif - - #define FSTATIC static - - #define f_stricmp(str1,str2) \ - strcasecmp( (str1), (str2)) - - #define f_strnicmp(str1,str2,size_t) \ - strncasecmp( (str1), (str2),size_t) - - #define f_memcpy( dest, src, size) \ - memcpy( (void*)(dest), (void*)(src), size) - - #define f_memmove( dest, src, len) \ - memmove( (void*)(dest), (void*)(src), len) - - #define f_memset( src, chr, size) \ - memset((void *)(src),(chr),(size_t)(size)) - - #define f_memcmp( str1, str2, length) \ - memcmp((void *)(str1), (void *)(str2),(size_t)(length)) - - #define f_strcat( dest, src) \ - strcat( (char*)(dest), (char*)(src)) - - #define f_strcmp( str1, str2) \ - strcmp( (char*)(str1), (char*)(str2)) - - #define f_strcpy( dest, src) \ - strcpy( (char*)(dest), (char*)(src)) - - #define f_strncpy( dest, src, length) \ - strncpy( (char*)(dest), (char*)(src), (size_t)(length)) - - #define f_strlen( str) \ - strlen( (char*)(str)) - - #define f_strncmp( str1, str2, size) \ - strncmp( (char*)(str1), (char*)(str2), (size_t)(size)) - - #define f_strrchr( str, value ) \ - strrchr( (char*)(str), (int)value) - - #define f_strstr( str1, str2) \ - strstr( (char*)(str1), (char*)(str2)) - - #define f_strncat( str1, str2, n) \ - strncat( (str1), (str2), n) - - char * f_strupr( - char * pszStr); - - #define f_strupr( str) \ - f_strupr( (str)) - - #define f_va_list va_list - #define f_va_start va_start - #define f_va_arg va_arg - #define f_va_end va_end - - #ifndef INVALID_SOCKET - #define INVALID_SOCKET (-1) - #endif - - #ifndef INADDR_NONE - #define INADDR_NONE (-1) - #endif - - #ifndef SOCKET - #define SOCKET int - #endif - - #endif - - /**************************************************************************** - CROSS PLATFORM DEFINITIONS - ****************************************************************************/ - - #define F_UNREFERENCED_PARM( parm) \ - (void)parm - - #if defined( __va_copy) - #define f_va_copy(to, from) \ - __va_copy(to, from) - #else - #define f_va_copy(to, from) \ - ((to) = (from)) - #endif - - #define shiftN(data,size,distance) \ - f_memmove((FLMBYTE *)(data) + (FLMINT)(distance), \ - (FLMBYTE *)(data), (unsigned)(size)) - - /**************************************************************************** - FLAIM's Assert Layer - ****************************************************************************/ - - #ifndef FLM_DEBUG - #define flmAssert( exp) - #else - #ifdef FLM_DBG_LOG - void flmDbgLogFlush( void); - #endif - - #if defined( FLM_WIN) - #ifdef FLM_DBG_LOG - #define flmAssert( exp) \ - (void)( (exp) || (flmDbgLogFlush(), DebugBreak(), 0)) - #else - #define flmAssert( exp) \ - (void)( (exp) || (DebugBreak(), 0)) - #endif - - #elif defined( FLM_NLM) - #ifdef FLM_DBG_LOG - #define flmAssert( exp) \ - (void)( (exp) || (flmDbgLogFlush(), EnterDebugger(), 0)) - #else - #define flmAssert( exp) \ - (void)( (exp) || ( EnterDebugger(), 0)) - #endif - - #elif defined( FLM_UNIX) - #include - - #ifdef FLM_DBG_LOG - #define flmAssert( exp) \ - (void)( (exp) || (flmDbgLogFlush(), assert(0), 0)) - #else - #define flmAssert( exp) \ - (void)( (exp) || (assert(0), 0)) - #endif - - #else - #define flmAssert( exp) - #endif - - #endif - - #ifdef FLM_DEBUG - #define flmReleaseAssert( exp) flmAssert( exp) - #else - #if defined( FLM_WIN) - #define flmReleaseAssert( exp) \ - (void)( (exp) || (DebugBreak(), 0)) - - #elif defined( FLM_NLM) - #define flmReleaseAssert( exp) \ - (void)( (exp) || ( EnterDebugger(), 0)) - - #elif defined( FLM_UNIX) - #include - #define flmReleaseAssert( exp) \ - (void)( (exp) || (abort(), 0)) - #else - #define flmReleaseAssert( exp) - #endif - #endif - - - #include "fpackon.h" - // IMPORTANT NOTE: No other include files should follow this one except - // for fpackoff.h - - FLMUINT f_breakpoint( - FLMUINT uiBreakFlag); - - /**************************************************************************** - Desc: ASCII Constants - ****************************************************************************/ - - #define ASCII_TAB 0x09 - #define ASCII_NEWLINE 0x0A - #define ASCII_CR 0x0D - #define ASCII_CTRLZ 0x1A - #define ASCII_SPACE 0x20 - #define ASCII_DQUOTE 0x22 - #define ASCII_POUND 0x23 - #define ASCII_DOLLAR 0x24 - #define ASCII_SQUOTE 0x27 - #define ASCII_WILDCARD 0x2A - #define ASCII_PLUS 0x2B - #define ASCII_COMMA 0x2C - #define ASCII_DASH 0x2D - #define ASCII_MINUS 0x2D - #define ASCII_DOT 0x2E - #define ASCII_SLASH 0x2F - #define ASCII_COLON 0x3A - #define ASCII_SEMICOLON 0x3B - #define ASCII_EQUAL 0x3D - #define ASCII_QUESTIONMARK 0x3F - #define ASCII_AT 0x40 - #define ASCII_BACKSLASH 0x5C - #define ASCII_CARAT 0x5E - #define ASCII_UNDERSCORE 0x5F - #define ASCII_TILDE 0x7E - #define ASCII_AMP 0x26 - - #define ASCII_UPPER_A 0x41 - #define ASCII_UPPER_B 0x42 - #define ASCII_UPPER_C 0x43 - #define ASCII_UPPER_D 0x44 - #define ASCII_UPPER_E 0x45 - #define ASCII_UPPER_F 0x46 - #define ASCII_UPPER_G 0x47 - #define ASCII_UPPER_H 0x48 - #define ASCII_UPPER_I 0x49 - #define ASCII_UPPER_J 0x4A - #define ASCII_UPPER_K 0x4B - #define ASCII_UPPER_L 0x4C - #define ASCII_UPPER_M 0x4D - #define ASCII_UPPER_N 0x4E - #define ASCII_UPPER_O 0x4F - #define ASCII_UPPER_P 0x50 - #define ASCII_UPPER_Q 0x51 - #define ASCII_UPPER_R 0x52 - #define ASCII_UPPER_S 0x53 - #define ASCII_UPPER_T 0x54 - #define ASCII_UPPER_U 0x55 - #define ASCII_UPPER_V 0x56 - #define ASCII_UPPER_W 0x57 - #define ASCII_UPPER_X 0x58 - #define ASCII_UPPER_Y 0x59 - #define ASCII_UPPER_Z 0x5A - - #define ASCII_LOWER_A 0x61 - #define ASCII_LOWER_B 0x62 - #define ASCII_LOWER_C 0x63 - #define ASCII_LOWER_D 0x64 - #define ASCII_LOWER_E 0x65 - #define ASCII_LOWER_F 0x66 - #define ASCII_LOWER_G 0x67 - #define ASCII_LOWER_H 0x68 - #define ASCII_LOWER_I 0x69 - #define ASCII_LOWER_J 0x6A - #define ASCII_LOWER_K 0x6B - #define ASCII_LOWER_L 0x6C - #define ASCII_LOWER_M 0x6D - #define ASCII_LOWER_N 0x6E - #define ASCII_LOWER_O 0x6F - #define ASCII_LOWER_P 0x70 - #define ASCII_LOWER_Q 0x71 - #define ASCII_LOWER_R 0x72 - #define ASCII_LOWER_S 0x73 - #define ASCII_LOWER_T 0x74 - #define ASCII_LOWER_U 0x75 - #define ASCII_LOWER_V 0x76 - #define ASCII_LOWER_W 0x77 - #define ASCII_LOWER_X 0x78 - #define ASCII_LOWER_Y 0x79 - #define ASCII_LOWER_Z 0x7A - - #define ASCII_ZERO 0x30 - #define ASCII_ONE 0x31 - #define ASCII_TWO 0x32 - #define ASCII_THREE 0x33 - #define ASCII_FOUR 0x34 - #define ASCII_FIVE 0x35 - #define ASCII_SIX 0x36 - #define ASCII_SEVEN 0x37 - #define ASCII_EIGHT 0x38 - #define ASCII_NINE 0x39 - - /**************************************************************************** - Desc: Native constants - ****************************************************************************/ - - #define NATIVE_SPACE ' ' - #define NATIVE_DOT '.' - #define NATIVE_PLUS '+' - #define NATIVE_MINUS '-' - #define NATIVE_WILDCARD '*' - #define NATIVE_QUESTIONMARK '?' - - #define NATIVE_UPPER_A 'A' - #define NATIVE_UPPER_F 'F' - #define NATIVE_UPPER_X 'X' - #define NATIVE_UPPER_Z 'Z' - #define NATIVE_LOWER_A 'a' - #define NATIVE_LOWER_F 'f' - #define NATIVE_LOWER_X 'x' - #define NATIVE_LOWER_Z 'z' - #define NATIVE_ZERO '0' - #define NATIVE_NINE '9' - - #define f_stringToAscii(str) - - #define f_toascii(native) \ - (native) - - #define f_tonative(ascii) \ - (ascii) - - #define f_toupper(native) \ - (((native) >= 'a' && (native) <= 'z') \ - ? (native) - 'a' + 'A' : (native)) - - #define f_tolower(native) \ - (((native) >= 'A' && (native) <= 'Z') \ - ? (native) - 'A' + 'a' : (native)) - - #define f_islower(native) \ - ((native) >= 'a' && (native) <= 'z') - - /**************************************************************************** - Desc: Unicode constants - ****************************************************************************/ - - #define FLM_UNICODE_LINEFEED ((FLMUNICODE)10) - #define FLM_UNICODE_SPACE ((FLMUNICODE)32) - #define FLM_UNICODE_BANG ((FLMUNICODE)33) - #define FLM_UNICODE_QUOTE ((FLMUNICODE)34) - #define FLM_UNICODE_POUND ((FLMUNICODE)35) - #define FLM_UNICODE_DOLLAR ((FLMUNICODE)36) - #define FLM_UNICODE_PERCENT ((FLMUNICODE)37) - #define FLM_UNICODE_AMP ((FLMUNICODE)38) - #define FLM_UNICODE_APOS ((FLMUNICODE)39) - #define FLM_UNICODE_LPAREN ((FLMUNICODE)40) - #define FLM_UNICODE_RPAREN ((FLMUNICODE)41) - #define FLM_UNICODE_ASTERISK ((FLMUNICODE)42) - #define FLM_UNICODE_PLUS ((FLMUNICODE)43) - #define FLM_UNICODE_COMMA ((FLMUNICODE)44) - #define FLM_UNICODE_HYPHEN ((FLMUNICODE)45) - #define FLM_UNICODE_PERIOD ((FLMUNICODE)46) - #define FLM_UNICODE_FSLASH ((FLMUNICODE)47) - - #define FLM_UNICODE_0 ((FLMUNICODE)48) - #define FLM_UNICODE_1 ((FLMUNICODE)49) - #define FLM_UNICODE_2 ((FLMUNICODE)50) - #define FLM_UNICODE_3 ((FLMUNICODE)51) - #define FLM_UNICODE_4 ((FLMUNICODE)52) - #define FLM_UNICODE_5 ((FLMUNICODE)53) - #define FLM_UNICODE_6 ((FLMUNICODE)54) - #define FLM_UNICODE_7 ((FLMUNICODE)55) - #define FLM_UNICODE_8 ((FLMUNICODE)56) - #define FLM_UNICODE_9 ((FLMUNICODE)57) - - #define FLM_UNICODE_COLON ((FLMUNICODE)58) - #define FLM_UNICODE_SEMI ((FLMUNICODE)59) - #define FLM_UNICODE_LT ((FLMUNICODE)60) - #define FLM_UNICODE_EQ ((FLMUNICODE)61) - #define FLM_UNICODE_GT ((FLMUNICODE)62) - #define FLM_UNICODE_QUEST ((FLMUNICODE)63) - #define FLM_UNICODE_ATSIGN ((FLMUNICODE)64) - - #define FLM_UNICODE_A ((FLMUNICODE)65) - #define FLM_UNICODE_B ((FLMUNICODE)66) - #define FLM_UNICODE_C ((FLMUNICODE)67) - #define FLM_UNICODE_D ((FLMUNICODE)68) - #define FLM_UNICODE_E ((FLMUNICODE)69) - #define FLM_UNICODE_F ((FLMUNICODE)70) - #define FLM_UNICODE_G ((FLMUNICODE)71) - #define FLM_UNICODE_H ((FLMUNICODE)72) - #define FLM_UNICODE_I ((FLMUNICODE)73) - #define FLM_UNICODE_J ((FLMUNICODE)74) - #define FLM_UNICODE_K ((FLMUNICODE)75) - #define FLM_UNICODE_L ((FLMUNICODE)76) - #define FLM_UNICODE_M ((FLMUNICODE)77) - #define FLM_UNICODE_N ((FLMUNICODE)78) - #define FLM_UNICODE_O ((FLMUNICODE)79) - #define FLM_UNICODE_P ((FLMUNICODE)80) - #define FLM_UNICODE_Q ((FLMUNICODE)81) - #define FLM_UNICODE_R ((FLMUNICODE)82) - #define FLM_UNICODE_S ((FLMUNICODE)83) - #define FLM_UNICODE_T ((FLMUNICODE)84) - #define FLM_UNICODE_U ((FLMUNICODE)85) - #define FLM_UNICODE_V ((FLMUNICODE)86) - #define FLM_UNICODE_W ((FLMUNICODE)87) - #define FLM_UNICODE_X ((FLMUNICODE)88) - #define FLM_UNICODE_Y ((FLMUNICODE)89) - #define FLM_UNICODE_Z ((FLMUNICODE)90) - - #define FLM_UNICODE_LBRACKET ((FLMUNICODE)91) - #define FLM_UNICODE_BACKSLASH ((FLMUNICODE)92) - #define FLM_UNICODE_RBRACKET ((FLMUNICODE)93) - #define FLM_UNICODE_UNDERSCORE ((FLMUNICODE)95) - - #define FLM_UNICODE_a ((FLMUNICODE)97) - #define FLM_UNICODE_b ((FLMUNICODE)98) - #define FLM_UNICODE_c ((FLMUNICODE)99) - #define FLM_UNICODE_d ((FLMUNICODE)100) - #define FLM_UNICODE_e ((FLMUNICODE)101) - #define FLM_UNICODE_f ((FLMUNICODE)102) - #define FLM_UNICODE_g ((FLMUNICODE)103) - #define FLM_UNICODE_h ((FLMUNICODE)104) - #define FLM_UNICODE_i ((FLMUNICODE)105) - #define FLM_UNICODE_j ((FLMUNICODE)106) - #define FLM_UNICODE_k ((FLMUNICODE)107) - #define FLM_UNICODE_l ((FLMUNICODE)108) - #define FLM_UNICODE_m ((FLMUNICODE)109) - #define FLM_UNICODE_n ((FLMUNICODE)110) - #define FLM_UNICODE_o ((FLMUNICODE)111) - #define FLM_UNICODE_p ((FLMUNICODE)112) - #define FLM_UNICODE_q ((FLMUNICODE)113) - #define FLM_UNICODE_r ((FLMUNICODE)114) - #define FLM_UNICODE_s ((FLMUNICODE)115) - #define FLM_UNICODE_t ((FLMUNICODE)116) - #define FLM_UNICODE_u ((FLMUNICODE)117) - #define FLM_UNICODE_v ((FLMUNICODE)118) - #define FLM_UNICODE_w ((FLMUNICODE)119) - #define FLM_UNICODE_x ((FLMUNICODE)120) - #define FLM_UNICODE_y ((FLMUNICODE)121) - #define FLM_UNICODE_z ((FLMUNICODE)122) - - #define FLM_UNICODE_LBRACE ((FLMUNICODE)123) - #define FLM_UNICODE_PIPE ((FLMUNICODE)124) - #define FLM_UNICODE_RBRACE ((FLMUNICODE)125) - #define FLM_UNICODE_TILDE ((FLMUNICODE)126) - #define FLM_UNICODE_C_CEDILLA ((FLMUNICODE)199) - #define FLM_UNICODE_N_TILDE ((FLMUNICODE)209) - #define FLM_UNICODE_c_CEDILLA ((FLMUNICODE)231) - #define FLM_UNICODE_n_TILDE ((FLMUNICODE)241) - - /**************************************************************************** - Desc: Byte order macros - ****************************************************************************/ - - FINLINE FLMUINT16 flmBigEndianToUINT16( - FLMBYTE * pucBuf) - { - FLMUINT16 ui16Val = 0; - - ui16Val |= ((FLMUINT16)pucBuf[ 0]) << 8; - ui16Val |= ((FLMUINT16)pucBuf[ 1]); - - return( ui16Val); - } - - FINLINE FLMUINT32 flmBigEndianToUINT32( - FLMBYTE * pucBuf) - { - FLMUINT32 ui32Val = 0; - - ui32Val |= ((FLMUINT32)pucBuf[ 0]) << 24; - ui32Val |= ((FLMUINT32)pucBuf[ 1]) << 16; - ui32Val |= ((FLMUINT32)pucBuf[ 2]) << 8; - ui32Val |= ((FLMUINT32)pucBuf[ 3]); - - return( ui32Val); - } - - FINLINE FLMUINT64 flmBigEndianToUINT64( - FLMBYTE * pucBuf) - { - FLMUINT64 ui64Val = 0; - - ui64Val |= ((FLMUINT64)pucBuf[ 0]) << 56; - ui64Val |= ((FLMUINT64)pucBuf[ 1]) << 48; - ui64Val |= ((FLMUINT64)pucBuf[ 2]) << 40; - ui64Val |= ((FLMUINT64)pucBuf[ 3]) << 32; - ui64Val |= ((FLMUINT64)pucBuf[ 4]) << 24; - ui64Val |= ((FLMUINT64)pucBuf[ 5]) << 16; - ui64Val |= ((FLMUINT64)pucBuf[ 6]) << 8; - ui64Val |= ((FLMUINT64)pucBuf[ 7]); - - return( ui64Val); - } - - FINLINE FLMINT16 flmBigEndianToINT16( - FLMBYTE * pucBuf) - { - FLMINT16 i16Val = 0; - - i16Val |= ((FLMINT16)pucBuf[ 0]) << 8; - i16Val |= ((FLMINT16)pucBuf[ 1]); - - return( i16Val); - } - - FINLINE FLMINT32 flmBigEndianToINT32( - FLMBYTE * pucBuf) - { - FLMINT32 i32Val = 0; - - i32Val |= ((FLMINT32)pucBuf[ 0]) << 24; - i32Val |= ((FLMINT32)pucBuf[ 1]) << 16; - i32Val |= ((FLMINT32)pucBuf[ 2]) << 8; - i32Val |= ((FLMINT32)pucBuf[ 3]); - - return( i32Val); - } - - FINLINE FLMINT64 flmBigEndianToINT64( - FLMBYTE * pucBuf) - { - FLMINT64 i64Val = 0; - - i64Val |= ((FLMINT64)pucBuf[ 0]) << 56; - i64Val |= ((FLMINT64)pucBuf[ 1]) << 48; - i64Val |= ((FLMINT64)pucBuf[ 2]) << 40; - i64Val |= ((FLMINT64)pucBuf[ 3]) << 32; - i64Val |= ((FLMINT64)pucBuf[ 4]) << 24; - i64Val |= ((FLMINT64)pucBuf[ 5]) << 16; - i64Val |= ((FLMINT64)pucBuf[ 6]) << 8; - i64Val |= ((FLMINT64)pucBuf[ 7]); - - return( i64Val); - } - - FINLINE void flmUINT32ToBigEndian( - FLMUINT32 ui32Num, - FLMBYTE * pucBuf) - { - pucBuf[ 0] = (FLMBYTE) (ui32Num >> 24); - pucBuf[ 1] = (FLMBYTE) (ui32Num >> 16); - pucBuf[ 2] = (FLMBYTE) (ui32Num >> 8); - pucBuf[ 3] = (FLMBYTE) (ui32Num); - } - - FINLINE void flmINT32ToBigEndian( - FLMINT32 i32Num, - FLMBYTE * pucBuf) - { - pucBuf[ 0] = (FLMBYTE) (i32Num >> 24); - pucBuf[ 1] = (FLMBYTE) (i32Num >> 16); - pucBuf[ 2] = (FLMBYTE) (i32Num >> 8); - pucBuf[ 3] = (FLMBYTE) (i32Num); - } - - FINLINE void flmINT64ToBigEndian( - FLMINT64 i64Num, - FLMBYTE * pucBuf) - { - pucBuf[ 0] = (FLMBYTE) (i64Num >> 56); - pucBuf[ 1] = (FLMBYTE) (i64Num >> 48); - pucBuf[ 2] = (FLMBYTE) (i64Num >> 40); - pucBuf[ 3] = (FLMBYTE) (i64Num >> 32); - pucBuf[ 4] = (FLMBYTE) (i64Num >> 24); - pucBuf[ 5] = (FLMBYTE) (i64Num >> 16); - pucBuf[ 6] = (FLMBYTE) (i64Num >> 8); - pucBuf[ 7] = (FLMBYTE) (i64Num); - } - - FINLINE void flmUINT64ToBigEndian( - FLMUINT64 ui64Num, - FLMBYTE * pucBuf) - { - pucBuf[ 0] = (FLMBYTE) (ui64Num >> 56); - pucBuf[ 1] = (FLMBYTE) (ui64Num >> 48); - pucBuf[ 2] = (FLMBYTE) (ui64Num >> 40); - pucBuf[ 3] = (FLMBYTE) (ui64Num >> 32); - pucBuf[ 4] = (FLMBYTE) (ui64Num >> 24); - pucBuf[ 5] = (FLMBYTE) (ui64Num >> 16); - pucBuf[ 6] = (FLMBYTE) (ui64Num >> 8); - pucBuf[ 7] = (FLMBYTE) (ui64Num); - } - - FINLINE void flmINT16ToBigEndian( - FLMINT16 i16Num, - FLMBYTE * pucBuf) - { - pucBuf[ 0] = (FLMBYTE) (i16Num >> 8); - pucBuf[ 1] = (FLMBYTE) (i16Num); - } - - FINLINE void flmUINT16ToBigEndian( - FLMUINT16 ui16Num, - FLMBYTE * pucBuf) - { - pucBuf[ 0] = (FLMBYTE) (ui16Num >> 8); - pucBuf[ 1] = (FLMBYTE) (ui16Num); - } - - #ifndef FLM_BIG_ENDIAN - - #if defined( FLM_SPARC) || defined( FLM_PPC) - #error Wrong endian order selected - #endif - - #define LO(wrd) \ - (*(FLMUINT8 *)&wrd) - - #define HI(wrd) \ - (*((FLMUINT8 *)&wrd + 1)) - - #if( defined( FLM_UNIX) && defined( FLM_STRICT_ALIGNMENT)) - - #define FB2UW( bp) \ - ((FLMUINT16)((((FLMUINT16)(((FLMUINT8 *)(bp))[1]))<<8) | \ - (((FLMUINT16)(((FLMUINT8 *)(bp))[0]))))) - - #define FB2UD( bp) \ - ((FLMUINT32)( (((FLMUINT32)(((FLMUINT8 *)(bp))[3]))<<24) | \ - (((FLMUINT32)(((FLMUINT8 *)(bp))[2]))<<16) | \ - (((FLMUINT32)(((FLMUINT8 *)(bp))[1]))<< 8) | \ - (((FLMUINT32)(((FLMUINT8 *)(bp))[0]))))) - - #define UW2FBA( uw, bp) \ - (((FLMUINT8 *)(bp))[0] = ((FLMUINT8)(uw)), \ - ((FLMUINT8 *)(bp))[1] = ((FLMUINT8)((((uw) & 0xff00)>>8)))) - - #define UD2FBA( udw, bp) \ - (((FLMUINT8 *)(bp))[0] = ((FLMUINT8)((udw) & 0xff)), \ - ((FLMUINT8 *)(bp))[1] = ((FLMUINT8)(((udw) & 0xff00)>>8)), \ - ((FLMUINT8 *)(bp))[2] = ((FLMUINT8)(((udw) & 0xff0000)>>16)), \ - ((FLMUINT8 *)(bp))[3] = ((FLMUINT8)(((udw) & 0xff000000)>>24))) - - #else - - #define FB2UW( fbp) \ - (*((FLMUINT16 *)(fbp))) - - #define FB2UD( fbp) \ - (*((FLMUINT32 *)(fbp))) - - #define UW2FBA( uw, fbp) \ - (*((FLMUINT16 *)(fbp)) = ((FLMUINT16) (uw))) - - #define UD2FBA( uw, fbp) \ - (*((FLMUINT32 *)(fbp)) = ((FLMUINT32) (uw))) - - #endif - - #else - - #if defined( __i386__) - #error Wrong endian order selected - #endif - - #define LO(wrd) \ - (*((FLMUINT8 *)&wrd + 1)) - - #define HI(wrd) \ - (*(FLMUINT8 *)&wrd) - - #define FB2UW( bp) \ - ((FLMUINT16)((((FLMUINT16)(((FLMUINT8 *)(bp))[1])) << 8) | \ - (((FLMUINT16)(((FLMUINT8 *)(bp))[0])) ) )) - - #define FB2UD( bp) \ - ((FLMUINT32)((((FLMUINT32)(((FLMUINT8 *)(bp))[3])) << 24) | \ - (((FLMUINT32)(((FLMUINT8 *)(bp))[2])) << 16) | \ - (((FLMUINT32)(((FLMUINT8 *)(bp))[1])) << 8) | \ - (((FLMUINT32)(((FLMUINT8 *)(bp))[0])) ) )) - - #define UW2FBA( uw, bp) \ - (((FLMUINT8 *)(bp))[0] = ((FLMUINT8)(uw)), \ - ((FLMUINT8 *)(bp))[1] = ((FLMUINT8)((((uw) & 0xff00)>>8)))) - - #define UD2FBA( udw, bp) \ - (((FLMUINT8 *)(bp))[0] = ((FLMUINT8)((udw) & 0xff)), \ - ((FLMUINT8 *)(bp))[1] = ((FLMUINT8)(((udw) & 0xff00)>>8)), \ - ((FLMUINT8 *)(bp))[2] = ((FLMUINT8)(((udw) & 0xff0000)>>16)), \ - ((FLMUINT8 *)(bp))[3] = ((FLMUINT8)(((udw) & 0xff000000)>>24))) - #endif - - /**************************************************************************** - Desc: File Path Functions & Macros - ****************************************************************************/ - - #if defined( FLM_WIN) || defined( FLM_NLM) - #define FWSLASH '/' - #define SLASH '\\' - #define SSLASH "\\" - #define COLON ':' - #define PERIOD '.' - #define PARENT_DIR ".." - #define CURRENT_DIR "." - #else - #ifndef FWSLASH - #define FWSLASH '/' - #endif - - #ifndef SLASH - #define SLASH '/' - #endif - - #ifndef SSLASH - #define SSLASH "/" - #endif - - #ifndef COLON - #define COLON ':' - #endif - - #ifndef PERIOD - #define PERIOD '.' - #endif - - #ifndef PARENT_DIR - #define PARENT_DIR ".." - #endif - - #ifndef CURRENT_DIR - #define CURRENT_DIR "." - #endif - #endif - - /**************************************************************************** - Desc: CPU Release Functions - ****************************************************************************/ - - #ifdef FLM_NLM - #define f_yieldCPU() \ - NWYieldIfTime() - #else - #define f_yieldCPU() - #endif - - void f_sleep( - FLMUINT uiMilliseconds); - - #ifdef FLM_WIN - #define f_sleep( uiMilliseconds) \ - Sleep( (DWORD)uiMilliseconds) - #endif - - /**************************************************************************** - Desc: Mutexes - ****************************************************************************/ - - #if defined( FLM_WIN) - - RCODE f_mutexCreate( - F_MUTEX * phMutex); - - void f_mutexDestroy( - F_MUTEX * phMutex); - - FINLINE void f_mutexLock( - F_MUTEX hMutex) - { - (void)EnterCriticalSection( (CRITICAL_SECTION *)hMutex); - } - - FINLINE void f_mutexUnlock( - F_MUTEX hMutex) - { - (void)LeaveCriticalSection( (CRITICAL_SECTION *)hMutex); - } - - #elif defined( FLM_UNIX) - - RCODE f_mutexCreate( - F_MUTEX * phMutex); - - void f_mutexDestroy( - F_MUTEX * phMutex); - - void f_mutexLock( - F_MUTEX hMutex); - - void f_mutexUnlock( - F_MUTEX hMutex); - - #endif - - - /**************************************************************************** - Desc: Semaphores - ****************************************************************************/ - - #if defined( FLM_WIN) - - typedef HANDLE F_SEM; - typedef HANDLE * F_SEM_p; - #define F_SEM_NULL NULL - - #elif defined( FLM_UNIX) - - #if defined( FLM_AIX) || defined( FLM_OSX) - - typedef struct - { - pthread_mutex_t lock; - pthread_cond_t cond; - int count; - } sema_t; - - int sema_init( sema_t * sem); - - void sema_destroy( sema_t * sem); - - void p_operation_cleanup( void * arg); - - int sema_wait( sema_t * sem); - - int sema_timedwait( sema_t * sem, unsigned int uiTimeout); - - int sema_signal( sema_t * sem); - - #else - - #include - - #endif - - typedef F_SEM * F_SEM_p; - #define F_SEM_NULL NULL - - #elif !defined( FLM_NLM) - #error Unsupported platform - #endif - - #if defined( FLM_WIN) - - FINLINE RCODE f_semCreate( - F_SEM * phSem) - { - if( (*phSem = CreateSemaphore( (LPSECURITY_ATTRIBUTES)NULL, - 0, 10000, NULL )) == NULL) - { - return( RC_SET( FERR_MUTEX_OPERATION_FAILED)); - } - - return FERR_OK; - } - - FINLINE void f_semDestroy( - F_SEM * phSem) - { - if (*phSem != F_SEM_NULL) - { - CloseHandle( *phSem); - *phSem = F_SEM_NULL; - } - } - - FINLINE RCODE f_semWait( - F_SEM hSem, - FLMUINT uiTimeout) - { - if( WaitForSingleObject( hSem, uiTimeout ) == WAIT_OBJECT_0) - { - return( FERR_OK); - } - else - { - return( RC_SET( FERR_MUTEX_UNABLE_TO_LOCK)); - } - } - - FINLINE void f_semSignal( - F_SEM hSem) - { - (void)ReleaseSemaphore( hSem, 1, NULL); - } - - #elif defined( FLM_UNIX) - - void f_semDestroy( - F_SEM * phSem); - - RCODE f_semCreate( - F_SEM * phSem); - - RCODE f_semWait( - F_SEM hSem, - FLMUINT uiTimeout); - - FINLINE void f_semSignal( - F_SEM hSem) - { - #if defined( FLM_AIX) || defined( FLM_OSX) - (void)sema_signal( (sema_t *)hSem); - #else - (void)sem_post( (sem_t *)hSem); - #endif - } - #endif - - /********************************************************************** - Desc: Atomic Increment, Decrement, Exchange - Note: Some of this code is derived from the Ximian source code contained - in that Mono project's atomic.h file. - **********************************************************************/ - #ifndef FLM_HAVE_ATOMICS - #define FLM_HAVE_ATOMICS - #endif - - /********************************************************************** - Desc: - **********************************************************************/ - #if defined( FLM_SOLARIS) && defined( FLM_SPARC) && !defined( FLM_GNUC) - extern "C" FLMINT32 sparc_atomic_add_32( - volatile FLMINT32 * piTarget, - FLMINT32 iDelta); - #endif - - /********************************************************************** - Desc: - **********************************************************************/ - #if defined( FLM_SOLARIS) && defined( FLM_SPARC) && !defined( FLM_GNUC) - extern "C" FLMINT32 sparc_atomic_xchg_32( - volatile FLMINT32 * piTarget, - FLMINT32 iNewValue); - #endif - - /********************************************************************** - Desc: - **********************************************************************/ - #if defined( FLM_AIX) - FINLINE int aix_atomic_add( - volatile int * piTarget, - int iDelta) - { - return( fetch_and_add( (int *)piTarget, iDelta) + iDelta); - } - #endif - - /********************************************************************** - Desc: - **********************************************************************/ - FINLINE FLMINT32 _flmAtomicInc( - FLMATOMIC * piTarget) - { - #if defined( FLM_NLM) - { - return( (FLMINT32)nlm_AtomicIncrement( (volatile LONG *)piTarget)); - } - #elif defined( FLM_WIN) - { - return( (FLMINT32)InterlockedIncrement( (volatile LONG *)piTarget)); - } - #elif defined( FLM_AIX) - { - return( (FLMINT32)aix_atomic_add( piTarget, 1)); - } - #elif defined( FLM_OSX) - { - return( (FLMINT32)OSAtomicIncrement32( (int32_t *)piTarget)); - } - #elif defined( FLM_SOLARIS) && defined( FLM_SPARC) && !defined( FLM_GNUC) - { - return( sparc_atomic_add_32( piTarget, 1)); - } - #elif (defined( __i386__) || defined( __x86_64__)) && defined( FLM_GNUC) - { - FLMINT32 i32Tmp; - - __asm__ __volatile__ ( - "lock;" - "xaddl %0, %1" - : "=r" (i32Tmp), "=m" (*piTarget) - : "0" (1), "m" (*piTarget)); - - return( i32Tmp + 1); - } - #else - #ifdef FLM_HAVE_ATOMICS - #undef FLM_HAVE_ATOMICS - #endif - - F_UNREFERENCED_PARM( piTarget); - - flmAssert( 0); - return( 0); - #endif - } - - /********************************************************************** - Desc: - **********************************************************************/ - FINLINE FLMINT32 _flmAtomicDec( - FLMATOMIC * piTarget) - { - #if defined( FLM_NLM) - { - return( (FLMINT32)nlm_AtomicDecrement( (volatile LONG *)piTarget)); - } - #elif defined( FLM_WIN) - { - return( (FLMINT32)InterlockedDecrement( (volatile LONG *)piTarget)); - } - #elif defined( FLM_AIX) - { - return( (FLMINT32)aix_atomic_add( piTarget, -1)); - } - #elif defined( FLM_OSX) - { - return( (FLMINT32)OSAtomicDecrement32( (int32_t *)piTarget)); - } - #elif defined( FLM_SOLARIS) && defined( FLM_SPARC) && !defined( FLM_GNUC) - { - return( sparc_atomic_add_32( piTarget, -1)); - } - #elif (defined( __i386__) || defined( __x86_64__)) && defined( FLM_GNUC) - { - FLMINT32 i32Tmp; - - __asm__ __volatile__ ( - "lock;" - "xaddl %0, %1" - : "=r" (i32Tmp), "=m" (*piTarget) - : "0" (-1), "m" (*piTarget)); - - return( i32Tmp - 1); - } - #else - #ifdef FLM_HAVE_ATOMICS - #undef FLM_HAVE_ATOMICS - #endif - - F_UNREFERENCED_PARM( piTarget); - - flmAssert( 0); - return( 0); - #endif - } - - /********************************************************************** - Desc: - **********************************************************************/ - FINLINE FLMINT32 _flmAtomicExchange( - FLMATOMIC * piTarget, - FLMINT32 i32NewVal) - { - #if defined( FLM_NLM) - { - return( (FLMINT32)nlm_AtomicExchange( - (volatile LONG *)piTarget, i32NewVal)); - } - #elif defined( FLM_WIN) - { - return( (FLMINT32)InterlockedExchange( (volatile LONG *)piTarget, - i32NewVal)); - } - #elif defined( FLM_AIX) - { - int iOldVal; - - for( ;;) - { - iOldVal = (int)*piTarget; - - if( compare_and_swap( (int *)piTarget, &iOldVal, i32NewVal)) - { - break; - } - } - - return( (FLMINT32)iOldVal); - } - #elif defined( FLM_OSX) - { - int32_t iOldVal; - - for( ;;) - { - iOldVal = (int32_t)*piTarget; - - if( OSAtomicCompareAndSwap32( iOldVal, i32NewVal, - (int32_t *)piTarget)) - { - break; - } - } - - return( (FLMINT32)iOldVal); - } - #elif defined( FLM_SOLARIS) && defined( FLM_SPARC) && !defined( FLM_GNUC) - { - return( sparc_atomic_xchg_32( piTarget, i32NewVal)); - } - #elif (defined( __i386__) || defined( __x86_64__)) && defined( FLM_GNUC) - { - FLMINT32 i32OldVal; - - __asm__ __volatile__ ( - "1: lock;" - " cmpxchgl %2, %0;" - " jne 1b" - : "=m" (*piTarget), "=a" (i32OldVal) - : "r" (i32NewVal), "m" (*piTarget), "a" (*piTarget)); - - return( i32OldVal); - } - #else - #ifdef FLM_HAVE_ATOMICS - #undef FLM_HAVE_ATOMICS - #endif - - F_UNREFERENCED_PARM( piTarget); - F_UNREFERENCED_PARM( i32NewVal); - - flmAssert( 0); - return( 0); - #endif - } - - /********************************************************************** - Desc: - **********************************************************************/ - FINLINE FLMINT32 flmAtomicInc( - FLMATOMIC * piTarget, - F_MUTEX hMutex = F_MUTEX_NULL, - FLMBOOL bMutexAlreadyLocked = FALSE) - { - #ifdef FLM_HAVE_ATOMICS - { - F_UNREFERENCED_PARM( bMutexAlreadyLocked); - F_UNREFERENCED_PARM( hMutex); - - return( _flmAtomicInc( piTarget)); - } - #else - { - FLMINT32 i32NewVal; - - flmAssert( hMutex != F_MUTEX_NULL); - - if( !bMutexAlreadyLocked) - { - f_mutexLock( hMutex); - } - - i32NewVal = (FLMINT32)(++(*piTarget)); - - if( !bMutexAlreadyLocked) - { - f_mutexUnlock( hMutex); - } - - return( i32NewVal); - } - #endif - } - - /********************************************************************** - Desc: - **********************************************************************/ - FINLINE FLMINT32 flmAtomicDec( - FLMATOMIC * piTarget, - F_MUTEX hMutex = F_MUTEX_NULL, - FLMBOOL bMutexAlreadyLocked = FALSE) - { - #ifdef FLM_HAVE_ATOMICS - { - F_UNREFERENCED_PARM( bMutexAlreadyLocked); - F_UNREFERENCED_PARM( hMutex); - - return( _flmAtomicDec( piTarget)); - } - #else - { - FLMINT32 i32NewVal; - - flmAssert( hMutex != F_MUTEX_NULL); - - if( !bMutexAlreadyLocked) - { - f_mutexLock( hMutex); - } - - i32NewVal = (FLMINT32)(--(*piTarget)); - - if( !bMutexAlreadyLocked) - { - f_mutexUnlock( hMutex); - } - - return( i32NewVal); - } - #endif - } - - /********************************************************************** - Desc: - **********************************************************************/ - FINLINE FLMINT32 flmAtomicExchange( - FLMATOMIC * piTarget, - FLMINT32 i32NewVal, - F_MUTEX hMutex = F_MUTEX_NULL, - FLMBOOL bMutexAlreadyLocked = FALSE) - { - #ifdef FLM_HAVE_ATOMICS - { - F_UNREFERENCED_PARM( bMutexAlreadyLocked); - F_UNREFERENCED_PARM( hMutex); - - return( _flmAtomicExchange( piTarget, i32NewVal)); - } - #else - { - FLMINT32 i32OldVal; - - flmAssert( hMutex != F_MUTEX_NULL); - - if( !bMutexAlreadyLocked) - { - f_mutexLock( hMutex); - } - - i32OldVal = (FLMINT32)*piTarget; - *piTarget = i32NewVal; - - if( !bMutexAlreadyLocked) - { - f_mutexUnlock( hMutex); - } - - return( i32OldVal); - } - #endif - } - - /**************************************************************************** - Pseudo Serial Numbers - ****************************************************************************/ - - RCODE f_initSerialNumberGenerator( void); - - RCODE f_createSerialNumber( - FLMBYTE * pszGuid); - - void f_freeSerialNumberGenerator( void); - - /**************************************************************************** - CRC - ****************************************************************************/ - - RCODE f_initCRCTable( - FLMUINT32 ** ppui32CRCTbl); - - void f_updateCRC( - FLMUINT32 * pui32CRCTbl, - FLMBYTE * pucBlk, - FLMUINT uiBlkSize, - FLMUINT32 * pui32CRC); - - #define f_freeCRCTable( ppui32CRCTbl) \ - f_free( ppui32CRCTbl) - - /**************************************************************************** - Desc: Returns TRUE if the passed-in character is 0-9, a-f, or A-F - ****************************************************************************/ - FINLINE FLMBOOL f_isHexChar( - FLMBYTE ucChar) - { - if( (ucChar >= '0' && ucChar <= '9') || - (ucChar >= 'A' && ucChar <= 'F') || - (ucChar >= 'a' && ucChar <= 'f')) - { - return( TRUE); - } - - return( FALSE); - } - - /**************************************************************************** - Desc: Returns the base-10 equivalent of a hex character - ****************************************************************************/ - FINLINE FLMBYTE f_getHexVal( - FLMBYTE ucChar) - { - if( ucChar >= '0' && ucChar <= '9') - { - return( (FLMBYTE)(ucChar - '0')); - } - else if( ucChar >= 'A' && ucChar <= 'F') - { - return( (FLMBYTE)((ucChar - 'A') + 10)); - } - else if( ucChar >= 'a' && ucChar <= 'f') - { - return( (FLMBYTE)((ucChar - 'a') + 10)); - } - - return( 0); - } - - /*************************************************************************** - Desc: - ****************************************************************************/ - FINLINE FLMUINT64 flmRoundUp( - FLMUINT64 ui64ValueToRound, - FLMUINT64 ui64Boundary) - { - FLMUINT64 ui64RetVal; - - ui64RetVal = ((ui64ValueToRound / ui64Boundary) * ui64Boundary); - - if( ui64RetVal < ui64ValueToRound) - { - ui64RetVal += ui64Boundary; - } - - return( ui64RetVal); - } - - /**************************************************************************** - Desc: Process ID Functions - ****************************************************************************/ - - #if defined( FLM_WIN) - - FINLINE FLMUINT f_getpid() - { - return _getpid(); - } - - #elif defined( FLM_UNIX) - - pid_t getpid( void); - - FINLINE FLMUINT f_getpid() - { - return getpid(); - } - - #elif defined( FLM_NLM) - - FINLINE FLMUINT f_getpid() - { - return( f_getNLMHandle()); - } - - #endif - - typedef struct - { - char * pszDestStr; - } F_SPRINTF_INFO; - - void flmSprintfStringFormatter( - char ucFormatChar, - FLMUINT uiWidth, - FLMUINT uiPrecision, - FLMUINT uiFlags, - F_SPRINTF_INFO * pInfo, - f_va_list * args); - - FLMINT f_vsprintf( - char * pszDestStr, - const char * pszFormat, - f_va_list * args); - - typedef FLMINT (* F_SORT_COMPARE_FUNC)( - void * pvBuffer, - FLMUINT uiPos1, - FLMUINT uiPos2); - - typedef void (* F_SORT_SWAP_FUNC)( - void * pvBuffer, - FLMUINT uiPos1, - FLMUINT uiPos2); - - void f_qsort( - void * pvBuffer, - FLMUINT uiLowerBounds, - FLMUINT uiUpperBounds, - F_SORT_COMPARE_FUNC fnCompare, - F_SORT_SWAP_FUNC fnSwap); - - FLMINT flmQSortUINTCompare( - void * pvBuffer, - FLMUINT uiPos1, - FLMUINT uiPos2); - - void flmQSortUINTSwap( - void * pvBuffer, - FLMUINT uiPos1, - FLMUINT uiPos2); - - /**************************************************************************** - Desc: Module Load/Unload Functions - ****************************************************************************/ - - typedef void * FlmModHandle; - - RCODE FlmModLoad( - const char * pszName, - FlmModHandle * phMod); - - #ifndef FLM_NLM - RCODE FlmModUnload( - FlmModHandle * phMod); - #else - RCODE FlmModUnload( - const char * pszModPath); - #endif - - RCODE FlmSymLoad( - const char * pszName, - FlmModHandle hMod, - void ** ppvSym); - - RCODE FlmSymUnload( - const char * pszName); - - char * f_strchr( - const char * pszStr, - char c); - -#include "fpackoff.h" -#endif diff --git a/flaim/src/ftkdir.cpp b/flaim/src/ftkdir.cpp deleted file mode 100644 index 1cbb404..0000000 --- a/flaim/src/ftkdir.cpp +++ /dev/null @@ -1,974 +0,0 @@ -//------------------------------------------------------------------------- -// Desc: Class for accessing file system directory information. -// Tabs: 3 -// -// Copyright (c) 1998-2006 Novell, Inc. All Rights Reserved. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of version 2 of the GNU General Public -// License as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, contact Novell, Inc. -// -// To contact Novell about this file by physical or electronic mail, -// you may find current contact information at www.novell.com -// -// $Id: ftkdir.cpp 12334 2006-01-23 12:45:35 -0700 (Mon, 23 Jan 2006) dsanders $ -//------------------------------------------------------------------------- - -#include "flaimsys.h" - -#define ERR_NO_FILES_FOUND 0xFF -#define ERR_INVALID_PATH 0x9C - -#if defined( FLM_WIN) - - FSTATIC FLMBOOL f_fileMeetsFindCriteria( - F_IO_FIND_DATA * pFindData); - -#elif defined( FLM_UNIX) - - FSTATIC int Find1( - char * FindTemplate, - F_IO_FIND_DATA * DirInfo); - - - FSTATIC int Find2( - F_IO_FIND_DATA * pFindData); - - FSTATIC FLMBYTE flmReturnFileAttributes( - mode_t uiFileMode, - const char * pszFileName); - - FSTATIC int flmRetrieveFileStat( - const char * pszFilePath, - struct stat * pStatusRec); - -#elif !defined( FLM_NLM) - - #error Platform not supported - -#endif - -/**************************************************************************** -Desc: Get the next item in a directory -****************************************************************************/ -RCODE F_DirHdlImp::Next() -{ -#if defined( FLM_WIN) || defined( FLM_UNIX) - char szFoundPath[ F_PATH_MAX_SIZE]; - char szDummyPath[ F_PATH_MAX_SIZE]; - FLMUINT uiSearchAttributes; - FLMUINT uiFoundAttrib; - - if( RC_BAD( m_rc)) - { - goto Exit; - } - - uiSearchAttributes = - F_IO_FA_NORMAL | F_IO_FA_RDONLY | F_IO_FA_ARCHIVE | F_IO_FA_DIRECTORY; - - for( ;;) - { - if ( m_bFirstTime ) - { - m_bFirstTime = FALSE; - - if( RC_BAD( m_rc = f_fileFindFirst( m_DirectoryPath, uiSearchAttributes, - &m_FindData, szFoundPath, &uiFoundAttrib))) - { - goto Exit; - } - - m_bFindOpen = TRUE; - m_uiAttrib = uiFoundAttrib; - } - else - { - if( RC_BAD( m_rc = f_fileFindNext( &m_FindData, szFoundPath, - &uiFoundAttrib))) - { - goto Exit; - } - - m_uiAttrib = uiFoundAttrib; - } - - if( RC_BAD( m_rc = f_pathReduce( szFoundPath, szDummyPath, m_szFileName))) - { - goto Exit; - } - - if( f_doesFileMatch( m_szFileName, m_ucPattern)) - { - break; - } - } - -#elif defined( FLM_NLM) - - LONG lError = 0; - - if( RC_BAD( m_rc)) - { - goto Exit; - } - - for( ;;) - { - if( (lError = DirectorySearch( 0, m_lVolumeNumber, m_lDirectoryNumber, - LONGNameSpace, m_lCurrentEntryNumber, (BYTE *)"\x02\xFF*", - -1, &m_pCurrentItem, &m_lCurrentEntryNumber)) != 0) - { - if( (lError == ERR_NO_FILES_FOUND) || (lError == ERR_INVALID_PATH)) - { - m_rc = RC_SET( FERR_IO_NO_MORE_FILES); - } - else - { - m_rc = MapNWtoFlaimError(lError, FERR_READING_FILE); - } - - break; - } - - if( f_doesFileMatch( (const char *)m_pCurrentItem->DFileName, m_ucPattern)) - { - break; - } - } -#endif - -Exit: - - return( m_rc); -} - -/**************************************************************************** -Desc: Open a directory -****************************************************************************/ -RCODE F_DirHdlImp::OpenDir( - const char * pDirPath, - const char * pszPattern) -{ -#if defined( FLM_WIN) || defined( FLM_UNIX) - RCODE rc = FERR_OK; - - m_rc = FERR_OK; - m_bFirstTime = TRUE; - m_bFindOpen = FALSE; - m_uiAttrib = 0; - - f_strcpy( m_DirectoryPath, pDirPath); - - if( pszPattern) - { - if( f_strlen( pszPattern) >= sizeof( m_ucPattern)) - { - rc = RC_SET( FERR_MEM); - goto Exit; - } - - f_strcpy( m_ucPattern, pszPattern); - } - -Exit: - - return( rc); - -#elif defined( FLM_NLM) - - // Notes: - // 1. DOS file names, not long file names ! If we want to support long - // file names, then increase the size of the filename buffer and change - // the name space. - // 2. '*.*' doesn't work as a pattern. '*' seems to do the trick. - // 3. These Netware APIs are case sensitive. If you want to specify a - // a pattern like "*.db" make sure that the files you are looking for - // were created with lowercase "db" extensions. - // - // Also, the path needs to match the case also. For example, - // sys:\_netware won't work. SYS:\_NETWARE will. - // 4. Server names are not supported by ConvertPathString - // 'Connecting to remote servers' is not supported by this code. - - LONG unused; - FLMBYTE pseudoLNamePath[ F_PATH_MAX_SIZE + 1]; - FLMBYTE LNamePath[ F_PATH_MAX_SIZE]; - LONG lLNamePathCount; - LONG lError = 0; - - m_rc = FERR_OK; - m_lVolumeNumber = F_NW_DEFAULT_VOLUME_NUMBER; - m_lCurrentEntryNumber = 0xFFFFFFFFL; - f_memcpy( m_DirectoryPath, pDirPath, F_PATH_MAX_SIZE); - - LNamePath[0] = 0; - lLNamePathCount = 0; - - f_strcpy( (char *)&pseudoLNamePath[1], pDirPath); - pseudoLNamePath[0] = (FLMBYTE)f_strlen( (const char *)&pseudoLNamePath[1] ); - - if( (lError = ConvertPathString( 0, 0, pseudoLNamePath, &m_lVolumeNumber, - &unused, (BYTE *)LNamePath, &lLNamePathCount)) != 0) - { - goto Exit; - } - - // Remember the directory number (think of it as a NetWare directory ID) - - if( (lError = MapPathToDirectoryNumber( 0, m_lVolumeNumber, 0, - (BYTE *)LNamePath, lLNamePathCount, LONGNameSpace, &m_lDirectoryNumber, - &unused)) != 0) - { - goto Exit; - } - - // Save the pattern for later - - if( pszPattern) - { - f_strncpy( m_ucPattern, pszPattern, sizeof( m_ucPattern) - 1); - m_ucPattern[ sizeof( m_ucPattern) - 1] = 0; - } - else - { - m_ucPattern[ 0] = '\0'; - } - -Exit: - - if( lError != 0) - { - m_rc = MapNWtoFlaimError(lError, FERR_OPENING_FILE); - } - - return( m_rc); -#endif -} - -/**************************************************************************** -Desc: Find the first file that matches the supplied criteria -****************************************************************************/ -#if defined( FLM_WIN) || defined( FLM_UNIX) -RCODE f_fileFindFirst( - const char * pszSearchPath, - FLMUINT uiSearchAttrib, - F_IO_FIND_DATA * pFindData, - char * pszFoundPath, - FLMUINT * puiFoundAttrib) -{ -#ifdef FLM_WIN - RCODE rc = FERR_OK; - char szTmpPath[ F_PATH_MAX_SIZE]; - const char * pszWildCard = "*.*"; - - f_memset( pFindData, 0, sizeof( F_IO_FIND_DATA)); - pFindData->findHandle = INVALID_HANDLE_VALUE; - pFindData->uiSearchAttrib = uiSearchAttrib; - - if( !pszSearchPath) - { - rc = RC_SET( FERR_IO_PATH_NOT_FOUND); - goto Exit; - } - - f_strcpy( pFindData->szSearchPath, pszSearchPath); - - // As per MS-DOS specification. - - if( uiSearchAttrib & F_IO_FA_NORMAL ) - { - uiSearchAttrib |= F_IO_FA_ARCHIVE; - } - - f_strcpy( szTmpPath, pszSearchPath); - - if( RC_BAD( rc = f_pathAppend( szTmpPath, pszWildCard))) - { - goto Exit; - } - - if( (pFindData->findHandle = FindFirstFile( (LPTSTR)szTmpPath, - &(pFindData->findBuffer))) == INVALID_HANDLE_VALUE) - { - rc = MapWinErrorToFlaim( GetLastError(), FERR_OPENING_FILE); - goto Exit; - } - - // Loop until a file with correct attributes is found - - for( ;;) - { - if( f_fileMeetsFindCriteria( pFindData)) - { - break; - } - - if( FindNextFile( pFindData->findHandle, - &(pFindData->findBuffer)) == FALSE) - { - rc = MapWinErrorToFlaim( GetLastError(), FERR_READING_FILE); - goto Exit; - } - } - - // Append the file name to the path name - - f_strcpy( pszFoundPath, pFindData->szSearchPath); - if( RC_BAD( rc = f_pathAppend( pszFoundPath, - pFindData->findBuffer.cFileName))) - { - goto Exit; - } - - // Return the found file attribute - - *puiFoundAttrib = pFindData->findBuffer.dwFileAttributes; - -Exit: - - if( RC_BAD( rc) && pFindData && - pFindData->findHandle != INVALID_HANDLE_VALUE) - { - f_fileFindClose( pFindData); - } - - return( rc); - -#elif defined( FLM_UNIX) - RCODE rc = FERR_OK; - char szTmpPath[ F_PATH_MAX_SIZE]; - FSTATIC char pszWildCard[] = {'*',0}; - int iRetVal; - - if( !pszSearchPath) - { - rc = RC_SET( FERR_IO_PATH_NOT_FOUND); - goto Exit; - } - - f_strcpy( szTmpPath, pszSearchPath); - - if( RC_BAD( rc = f_pathAppend( szTmpPath, pszWildCard))) - { - goto Exit; - } - - f_memset( pFindData, 0, sizeof( F_IO_FIND_DATA)); - - if( uiSearchAttrib & F_IO_FA_DIRECTORY) - { - pFindData->mode_flag |= S_IFDIR; - } - - if( uiSearchAttrib & F_IO_FA_RDONLY) - { - pFindData->mode_flag |= S_IREAD; - } - - iRetVal = Find1( (char*)szTmpPath, pFindData); - - if( iRetVal != 0) - { - // If there were no more files found then return no more files - // instead of mapping to error path not found or io error. - // To return no more files ret_val is ENOENT (set in Find2) - // and errno is not set - - if( iRetVal == ENOENT && errno == 0) - { - rc = RC_SET( FERR_IO_NO_MORE_FILES); - } - else - { - rc = MapErrnoToFlaimErr( errno, FERR_READING_FILE); - } - - goto Exit; - } - - // filter out ".." (PARENT) and "." (CURRENT) directories - - if( uiSearchAttrib & F_IO_FA_DIRECTORY ) - { - while( (f_strcmp( pFindData->name, "..") == 0) || - (f_strcmp( pFindData->name, ".") == 0)) - { - if( (iRetVal = Find2( pFindData)) != 0) - { - // If there were no more files found then return no more files - // instead of mapping to error path not found or io error. - // To return no more files ret_val is ENOENT (set in Find2) - // and errno is not set - - if( iRetVal == ENOENT && errno == 0) - { - rc = RC_SET( FERR_IO_NO_MORE_FILES); - } - else - { - rc = MapErrnoToFlaimErr( errno, FERR_READING_FILE); - } - - goto Exit; - } - } - } - - // Append the file name to the path name - - f_strcpy( pszFoundPath, pszSearchPath); - - if( RC_BAD( rc = f_pathAppend( pszFoundPath, pFindData->name))) - { - goto Exit; - } - - *puiFoundAttrib = flmReturnFileAttributes( - pFindData->FileStat.st_mode, pszFoundPath); - - // Save the search path in the FERR_IO_FIND_DATA struct for a find next call - - f_strcpy( pFindData->search_path, pszSearchPath); - -Exit: - - return( rc); - -#endif -} -#endif - -/**************************************************************************** -Desc: Find the next file that matches the supplied criteria -****************************************************************************/ -#if defined( FLM_WIN) || defined( FLM_UNIX) -RCODE f_fileFindNext( - F_IO_FIND_DATA * pFindData, - char * pszFoundPath, - FLMUINT * puiFoundAttrib) -{ - RCODE rc = FERR_OK; - -#ifdef FLM_WIN - - if( FindNextFile( pFindData->findHandle, - &(pFindData->findBuffer)) == FALSE) - { - rc = MapWinErrorToFlaim( GetLastError(), FERR_READING_FILE); - goto Exit; - } - - // Loop until a file with correct attributes is found - - for( ;;) - { - if( f_fileMeetsFindCriteria( pFindData)) - { - break; - } - - if( FindNextFile( pFindData->findHandle, - &(pFindData->findBuffer)) == FALSE) - { - rc = MapWinErrorToFlaim( GetLastError(), FERR_READING_FILE); - goto Exit; - } - } - - // Append the file name to the path name - - f_strcpy( pszFoundPath, pFindData->szSearchPath); - if( RC_BAD( rc = f_pathAppend( pszFoundPath, - pFindData->findBuffer.cFileName))) - { - goto Exit; - } - - // Return the found file attribute - - *puiFoundAttrib = pFindData->findBuffer.dwFileAttributes; - -#elif defined( FLM_UNIX) - int iRetVal; - - if( (iRetVal = Find2( pFindData)) != 0) - { - // If there were no more files found then return no more files - // instead of mapping to error path not found or io error. - // To return no more files ret_val is ENOENT (set in Find2) - // and errno is not set - - if( iRetVal == ENOENT && errno == 0) - { - return( RC_SET( FERR_IO_NO_MORE_FILES)); - } - - return( MapErrnoToFlaimErr( errno, FERR_READING_FILE)); - } - - // Append the file name to the path name - - f_strcpy( pszFoundPath, pFindData->search_path); - - if( RC_BAD( rc = f_pathAppend( pszFoundPath, pFindData->name))) - { - goto Exit; - } - - *puiFoundAttrib = flmReturnFileAttributes( - pFindData->FileStat.st_mode, pszFoundPath); -#else - rc = RC_SET( FERR_NOT_IMPLEMENTED); - goto Exit; -#endif - -Exit: - - return( rc); -} -#endif - -/**************************************************************************** -Desc: Releases any memory allocated to an F_IO_FIND_DATA structure -****************************************************************************/ -#if defined( FLM_WIN) || defined( FLM_UNIX) -void f_fileFindClose( - F_IO_FIND_DATA * pFindData) -{ -#ifdef FLM_WIN - - // Don't call it on an already closed or invalid handle. - - if( pFindData->findHandle != INVALID_HANDLE_VALUE) - { - FindClose( pFindData->findHandle ); - pFindData->findHandle = INVALID_HANDLE_VALUE; - } -#elif defined( FLM_UNIX) - if( pFindData->globbuf.gl_pathv) - { - pFindData->globbuf.gl_offs = 0; - globfree( &pFindData->globbuf); - pFindData->globbuf.gl_pathv = 0; - } -#endif -} -#endif - -/**************************************************************************** -Desc: Find the next file that matches the supplied criteria -****************************************************************************/ -#ifdef FLM_WIN -FSTATIC FLMBOOL f_fileMeetsFindCriteria( - F_IO_FIND_DATA * pFindData) -{ - // Fail ".." (PARENT) and "." (CURRENT) directories. Then, - // if the file found possesses any of the search attributes, it's - // a match. - - if( !((f_strcmp( pFindData->findBuffer.cFileName, "..") == 0) || - (f_strcmp( pFindData->findBuffer.cFileName, ".") == 0) || - (!(pFindData->uiSearchAttrib & F_IO_FA_DIRECTORY) && - (pFindData->findBuffer.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)))) - { - if( (pFindData->findBuffer.dwFileAttributes & - pFindData->uiSearchAttrib) || - ((pFindData->uiSearchAttrib & F_IO_FA_NORMAL) && - (pFindData->findBuffer.dwFileAttributes == 0))) - { - return( TRUE); - } - } - - return( FALSE); -} -#endif - -/**************************************************************************** -Desc: Search for file names matching FindTemplate (UNIX) -****************************************************************************/ -#ifdef FLM_UNIX -FSTATIC int Find1( - char * pszFindTemplate, - F_IO_FIND_DATA * DirInfo) -{ - char szMask[ F_PATH_MAX_SIZE]; - char * pszPathSeparator; - FLMUINT uiLen; - - // If supplied template is illegal, return immediately - - if( (pszFindTemplate == NULL) || ! f_strlen( pszFindTemplate)) - { - return( EINVAL ); - } - - // Now separate the template into a PATH and a template MASK - // If no separating slash character found, use current directory - // as path! - - (void) f_strcpy( DirInfo->full_path, pszFindTemplate ); - - if( (pszPathSeparator = strrchr( DirInfo->full_path, '/')) == NULL) - { - getcwd( DirInfo->full_path, F_PATH_MAX_SIZE); - uiLen = f_strlen( DirInfo->full_path ); - DirInfo->full_path[ uiLen] = '/'; - DirInfo->full_path[ uiLen+1] = '\0'; - f_strcat( DirInfo->full_path, pszFindTemplate ); - pszPathSeparator = strrchr( DirInfo->full_path, '/'); - } - - // Copy the template MASK, and null terminate the PATH - - f_strcpy( szMask, pszPathSeparator + 1); - - if( !f_strlen( szMask)) - { - f_strcpy( szMask, "*"); - } - - *pszPathSeparator = '\0'; - - // Use ROOT directory if PATH is empty - - if( !f_strlen( DirInfo->full_path)) - { - f_strcpy( DirInfo->full_path, "/"); - } - - f_strcpy( DirInfo->dirpath, DirInfo->full_path); - - // Open the specified directory. Return immediately if error detected! - - errno = 0; - DirInfo->globbuf.gl_pathv = 0; - - if( glob( pszFindTemplate, GLOB_NOSORT, 0, &DirInfo->globbuf) != 0 && - !DirInfo->globbuf.gl_pathc) - { - globfree(&DirInfo->globbuf); - DirInfo->globbuf.gl_pathv = 0; - return ENOENT; - } - - // Call Find2 to get the 1st matching file - - return( Find2( DirInfo)); - -} -#endif - -/**************************************************************************** -Desc: Search for file names matching pszFindTemplate (UNIX) -****************************************************************************/ -#ifdef FLM_UNIX -FSTATIC int Find2( - F_IO_FIND_DATA * pFindData) -{ - int stat; - glob_t * pglob = &pFindData->globbuf; - char * pszTmp; - char * pszLastSlash; - - errno = 0; - - for( ;;) - { - if( pglob->gl_offs == pglob->gl_pathc) - { - pglob->gl_offs = 0; - globfree(pglob); - pglob->gl_pathv = 0; - return( ENOENT); - } - - // Get status of file - - f_strcpy( pFindData->full_path, pglob->gl_pathv[pglob->gl_offs++]); - - if( (stat = flmRetrieveFileStat( - pFindData->full_path, &pFindData->FileStat)) != 0) - { - // If file name just read from directory is NO longer there - // (deleted by another process) then just advance to the next file in - // the directory - - if( stat == ENOENT) - { - continue; - } - else - { - break; - } - } - - // If we don't want directories, and current entry is a directory, - // then skip it - - if( (!S_ISDIR( pFindData->mode_flag)) && - S_ISDIR( pFindData->FileStat.st_mode)) - { - continue; - } - - // If we only want regular files and file is NOT regular, then skip it. - // This means there is no way to retrieve named pipes, sockets, or links. - - if( (pFindData->mode_flag == F_IO_FA_NORMAL) && - (!S_ISREG( pFindData->FileStat.st_mode))) - { - continue; - } - - pszTmp = &pFindData->full_path[ 0]; - pszLastSlash = NULL; - - while( *pszTmp) - { - if( *pszTmp == '/') - { - pszLastSlash = pszTmp; - } - - pszTmp++; - } - - if( pszLastSlash) - { - f_strcpy( pFindData->name, &pszLastSlash[ 1]); - } - else - { - f_strcpy( pFindData->name, pFindData->full_path); - } - - stat = 0; - break; - } - - return( stat); -} -#endif - -/**************************************************************************** -Desc: Return file's attributes (UNIX) -****************************************************************************/ -#ifdef FLM_UNIX -FSTATIC FLMBYTE flmReturnFileAttributes( - mode_t uiFileMode, - const char * pszFileName) -{ - FLMBYTE ucIOmode = 0; - - // Return the found file attribute - - if( S_ISDIR( uiFileMode )) - { - ucIOmode |= F_IO_FA_DIRECTORY; - } - else - { - if( access( (char *)pszFileName, (int)(R_OK | W_OK)) == 0) - { - ucIOmode |= F_IO_FA_NORMAL; - } - else if( access( (char *)pszFileName, (int)R_OK) == 0) - { - ucIOmode |= F_IO_FA_RDONLY; - } - } - - return( ucIOmode); -} -#endif - -/**************************************************************************** -Desc: Return file's attributes (UNIX) -****************************************************************************/ -#ifdef FLM_UNIX -FSTATIC int flmRetrieveFileStat( - const char * pszFilePath, - struct stat * pStatusRec) -{ - // Get status of last file read from directory, using the standard - // UNIX stat call - - errno = 0; - - if( stat( pszFilePath, pStatusRec) == -1) - { - if( errno == ENOENT || errno == ELOOP) - { - // Get status of symbolic link rather than referenced file - - errno = 0; - - if( lstat( pszFilePath, pStatusRec ) == -1) - { - return( errno); - } - } - else - { - return( errno); - } - } - - return( 0); -} -#endif - -/**************************************************************************** -Desc: NetWare implementation to create a directory -Input: pPathToDirectory = fully-qualified path to the directory to be created - Examples: - In this example, the directory 'myDir' would be created: - sys:\system\myDir - - Note that ConvertPathString doesn't support server names. So - it returns an error on paths like: - server-name/volume:\directory_1 -****************************************************************************/ -#ifdef FLM_NLM -RCODE F_DirHdlImp::_CreateDir( - const char * pszPathToDirectory) -{ - RCODE rc = FERR_OK; - FLMBYTE pucPseudoLNamePath[ F_PATH_MAX_SIZE + 1]; - FLMBYTE pucLNamePath[ F_PATH_MAX_SIZE]; - LONG lVolumeID; - LONG lPathID; - LONG lLNamePathCount; - LONG lNewDirectoryID; - void *pNotUsed; - LONG lErrorCode; - - f_strcpy( (char *)&pucPseudoLNamePath[1], pszPathToDirectory); - pucPseudoLNamePath[0] = (FLMBYTE)f_strlen( pszPathToDirectory); - - if( (lErrorCode = ConvertPathString( 0, 0, pucPseudoLNamePath, &lVolumeID, - &lPathID, pucLNamePath, &lLNamePathCount)) != 0) - { - goto Exit; - } - - if( (lErrorCode = CreateDirectory( 0, lVolumeID, lPathID, pucLNamePath, - lLNamePathCount, LONGNameSpace, MaximumDirectoryAccessBits, - &lNewDirectoryID, &pNotUsed)) != 0) - { - goto Exit; - } - -Exit: - - if( lErrorCode) - { - rc = MapNWtoFlaimError( lErrorCode, FERR_CREATING_FILE); - } - - return( rc); -} -#endif - -/**************************************************************************** -Desc: Return the current item's name -****************************************************************************/ -const char * F_DirHdlImp::CurrentItemName( void) -{ -#if defined( FLM_WIN) || defined( FLM_UNIX) - const char * pszName = NULL; - - if( RC_OK( m_rc)) - { - pszName = m_szFileName; - } - - return( pszName); - -#elif defined( FLM_NLM) - - FLMUINT uiLength; - char * pszName = NULL; - - if( RC_BAD( m_rc)) - { - goto Exit; - } - - if( !m_pCurrentItem) - { - goto Exit; - } - - uiLength = sizeof( m_ucTempBuffer) - 1; - - if( m_pCurrentItem->DFileNameLength < uiLength) - { - uiLength = m_pCurrentItem->DFileNameLength; - } - - f_strncpy( (char *)m_ucTempBuffer, (const char *)m_pCurrentItem->DFileName, uiLength); - pszName = m_ucTempBuffer; - pszName[ uiLength] = 0; - -Exit: - - return( pszName); -#endif -} - -/**************************************************************************** -Desc: Return the current item's size -****************************************************************************/ -FLMUINT F_DirHdlImp::CurrentItemSize() -{ - FLMUINT uiSize = 0; - - if( RC_OK( m_rc)) - { -#if defined( FLM_WIN) - uiSize = (FLMUINT)m_FindData.findBuffer.nFileSizeLow; -#elif defined( FLM_UNIX) - uiSize = (FLMUINT)m_FindData.FileStat.st_size; -#elif defined( FLM_NLM) - if( m_pCurrentItem != NULL ) - { - uiSize = (FLMUINT)m_pCurrentItem->DFileSize; - } -#endif - } - - return( uiSize); -} - -/**************************************************************************** -Desc: Returns whether or not current item is a directory. -****************************************************************************/ -FLMBOOL F_DirHdlImp::CurrentItemIsDir() -{ -#if defined( FLM_WIN) || defined( FLM_UNIX) - return( ((m_uiAttrib & F_IO_FA_DIRECTORY) - ? TRUE - : FALSE)); -#elif defined( FLM_NLM) - if( !m_pCurrentItem) - { - return( FALSE); - } - - return( (m_pCurrentItem->DFileAttributes & SUBDIRECTORY_BIT) - ? TRUE - : FALSE); -#endif -} diff --git a/flaim/src/ftkmem.h b/flaim/src/ftkmem.h deleted file mode 100644 index fb279dd..0000000 --- a/flaim/src/ftkmem.h +++ /dev/null @@ -1,99 +0,0 @@ -//------------------------------------------------------------------------- -// Desc: Memory allocation - definitions. -// Tabs: 3 -// -// Copyright (c) 2000-2006 Novell, Inc. All Rights Reserved. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of version 2 of the GNU General Public -// License as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, contact Novell, Inc. -// -// To contact Novell about this file by physical or electronic mail, -// you may find current contact information at www.novell.com -// -// $Id: ftkmem.h 12299 2006-01-19 15:01:23 -0700 (Thu, 19 Jan 2006) dsanders $ -//------------------------------------------------------------------------- - -#ifndef FTKMEM_H -#define FTKMEM_H - -#include "fpackon.h" -// IMPORTANT NOTE: No other include files should follow this one except -// for fpackoff.h - - RCODE f_alloc( - FLMUINT uiSize, - void ** ppvPtr, - const char * pszFile, - int iLine); - - #define f_alloc( uiSize, ppvPtr) \ - f_alloc( (uiSize), (void **)(ppvPtr), __FILE__, __LINE__) - - RCODE f_calloc( - FLMUINT uiSize, - void ** ppvPtr, - const char * pszFile, - int iLine); - - #define f_calloc( uiSize, ppvPtr) \ - f_calloc( (uiSize), (void **)(ppvPtr), __FILE__, __LINE__) - - RCODE f_realloc( - FLMUINT uiSize, - void ** ppvPtr, - const char * pszFile, - int iLine); - - #define f_realloc( uiSize, ppvPtr) \ - f_realloc( (uiSize), (void **)(ppvPtr), __FILE__, __LINE__) - - RCODE f_recalloc( - FLMUINT uiSize, - void ** ppvPtr, - const char * pszFile, - int iLine); - - #define f_recalloc( uiSize, ppvPtr) \ - f_recalloc( (uiSize), (void **)(ppvPtr), __FILE__, __LINE__) - - void f_free( - void ** ppvPtr); - - #define f_free( ppvPtr) \ - f_free( (void **)ppvPtr) - - FLMUINT f_msize( - void * pvPtr); - - FLMUINT * memWalkStack( void); - - typedef struct F_MEM_HDR - { - FLMUINT uiDataSize; - #ifdef FLM_DEBUG - const char * pszFileName; - FLMINT iLineNumber; - FLMUINT uiAllocationId; - FLMUINT uiAllocCnt; - FLMUINT * puiStack; - #endif - #if !defined( FLM_DEBUG) && FLM_ALIGN_SIZE == 8 - FLMUINT uiDummy; - #endif - } F_MEM_HDR; - - void logMemLeak( - F_MEM_HDR * pHdr); - -#include "fpackoff.h" - -#endif diff --git a/flaim/src/ftkmisc.cpp b/flaim/src/ftkmisc.cpp deleted file mode 100644 index 08c1a6e..0000000 --- a/flaim/src/ftkmisc.cpp +++ /dev/null @@ -1,784 +0,0 @@ -//------------------------------------------------------------------------- -// Desc: Miscellaneous toolkit functions. -// Tabs: 3 -// -// Copyright (c) 2000-2003,2005-2006 Novell, Inc. All Rights Reserved. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of version 2 of the GNU General Public -// License as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, contact Novell, Inc. -// -// To contact Novell about this file by physical or electronic mail, -// you may find current contact information at www.novell.com -// -// $Id: ftkmisc.cpp 12329 2006-01-20 17:49:30 -0700 (Fri, 20 Jan 2006) ahodgkinson $ -//------------------------------------------------------------------------- - -#include "flaimsys.h" - -FLMUINT gv_uiSerialInitCount = 0; -f_randomGenerator gv_uiSerialRandom; -F_MUTEX gv_hSerialMutex = F_MUTEX_NULL; - -#if defined( FLM_NLM) - - #pragma pack(push,1) - - extern "C" - { - LONG gv_lMyModuleHandle = 0; - LONG gv_lFlmTimerTag = 0; - LONG gv_lAllocRTag = 0; - static f_randomGenerator gv_flmRandGenerator; - static SEMAPHORE gv_lFlmRandSemaphore = F_SEM_NULL; - static LONG gv_lFlmStartTicks = 0; - static FLMATOMIC gv_NetWareStartupCount = 0; - } - - #pragma pack(pop) - - void f_sleep( - FLMUINT uiMilliseconds) - { - if( ! uiMilliseconds ) - { - kYieldThread(); - } - else - { - kDelayThread( uiMilliseconds); - } - } - -#endif - - -#if defined( FLM_UNIX) - - #ifdef FLM_AIX - #ifndef nsleep - extern "C" - { - extern int nsleep( struct timestruc_t *, struct timestruc_t *); - } - #endif - #endif - -/**************************************************************************** -Desc: This routine causes the calling process to delay the given number - of milliseconds. Due to the nature of the call, the actual sleep - time is almost guaranteed to be different from requested sleep time. -In: milliseconds - the number of milliseconds to delay -****************************************************************************/ -void f_sleep( - FLMUINT uiMilliseconds) -{ -#ifdef FLM_AIX - struct timestruc_t timeout; - struct timestruc_t remain; -#else - struct timespec timeout; -#endif - - timeout.tv_sec = (uiMilliseconds / 1000); - timeout.tv_nsec = (uiMilliseconds % 1000) * 1000000; - -#ifdef FLM_AIX - nsleep(&timeout, &remain); -#else - nanosleep(&timeout, 0); -#endif -} -#endif - -#ifdef FLM_UNIX -/*************************************************************************** -Desc: Map POSIX errno to Flaim IO errors. -***************************************************************************/ -RCODE MapErrnoToFlaimErr( - int err, - RCODE defaultRc) -{ - /* Switch on passed in error code value */ - - switch (err) - { - case 0: - return( FERR_OK); - - case ENOENT: - return( RC_SET( FERR_IO_PATH_NOT_FOUND)); - - case EACCES: - case EEXIST: - return( RC_SET( FERR_IO_ACCESS_DENIED)); - - case EINVAL: - flmAssert( 0); - return( RC_SET( FERR_INVALID_PARM)); - - case EIO: - return( RC_SET( FERR_IO_DISK_FULL)); - - case ENOTDIR: - return( RC_SET( FERR_IO_MODIFY_ERR)); - -#ifdef EBADFD - case EBADFD: - return( RC_SET( FERR_IO_BAD_FILE_HANDLE)); -#endif - - case EOF: - return( RC_SET( FERR_IO_END_OF_FILE)); - - case EMFILE: - return( RC_SET( FERR_IO_NO_MORE_FILES)); - - default: - return( RC_SET( defaultRc)); - } -} -#endif - -/**************************************************************************** -Desc: This routine initializes the serial number generator. If the O/S - does not provide support for GUID generation or if the GUID - routines fail for some reason, a pseudo-GUID will be generated. -Notes: This routine should only be called once by the process. -****************************************************************************/ -RCODE f_initSerialNumberGenerator( void) -{ - FLMUINT uiTime; - RCODE rc = FERR_OK; - - if (++gv_uiSerialInitCount > 1) - { - goto Exit; - } - - if( RC_BAD( rc = f_mutexCreate( &gv_hSerialMutex))) - { - goto Exit; - } - - f_timeGetSeconds( &uiTime ); - -#if defined( FLM_WIN) - f_randomSetSeed( &gv_uiSerialRandom, - (FLMUINT32)(uiTime ^ (FLMUINT)_getpid())); -#elif defined( FLM_NLM) - f_randomSetSeed( &gv_uiSerialRandom, - (FLMUINT32)(uiTime ^ (FLMUINT)GetRunningProcess())); -#elif defined( FLM_UNIX) - f_randomSetSeed( &gv_uiSerialRandom, - (FLMUINT32)(uiTime ^ (FLMUINT)getpid())); -#else - f_randomSetSeed( &gv_uiSerialRandom, (FLMUINT32)uiTime); -#endif - -Exit: - - return( rc); -} - -/**************************************************************************** -Desc: This routine will use the operating system calls to generate a - "globally unique" identifier. Typically, this is based on the - MAC address of an ethernet card installed in the machine. If the - machine does not have an ethernet card, or if the OS does not - support generating GUIDs, this routine will generate a pseudo-GUID - using a random number generator. A serial number is 16-bytes. -****************************************************************************/ -RCODE f_createSerialNumber( - FLMBYTE * pszSerialNum) -{ - RCODE rc = FERR_OK; - -#if defined( FLM_WIN) - - UUID uuidVal; - RPC_STATUS err = UuidCreate( &uuidVal); - - if (err == RPC_S_OK || err == RPC_S_UUID_LOCAL_ONLY) - { - UD2FBA( (FLMUINT32)uuidVal.Data1, &pszSerialNum[ 0]); - UW2FBA( (FLMUINT16)uuidVal.Data2, &pszSerialNum[ 4]); - UW2FBA( (FLMUINT16)uuidVal.Data3, &pszSerialNum[ 6]); - f_memcpy( &pszSerialNum[ 8], (FLMBYTE *)uuidVal.Data4, 8); - goto Exit; - } - -#elif defined( FLM_NLM) - - NWGUID guidVal; - int err = SGUIDCreate( &guidVal); - - if( !err || err == 1) // NOTE: 1 == SGUID_WARN_RANDOM_NODE - { - UD2FBA( guidVal.time_low, &pszSerialNum[ 0]); - UW2FBA( guidVal.time_mid, &pszSerialNum[ 4]); - UW2FBA( guidVal.time_hi_and_version, &pszSerialNum[ 6]); - pszSerialNum[ 8] = guidVal.clk_seq_hi_res; - pszSerialNum[ 9] = guidVal.clk_seq_low; - f_memcpy( &pszSerialNum[ 10], (FLMBYTE *)guidVal.node, 6); - goto Exit; - } - -#endif - - /* - Generate a pseudo GUID value - */ - - flmAssert( gv_hSerialMutex != F_MUTEX_NULL); - - f_mutexLock( gv_hSerialMutex); - - UD2FBA( (FLMUINT32)f_randomLong( - &gv_uiSerialRandom), &pszSerialNum[ 0]); - UD2FBA( (FLMUINT32)f_randomLong( - &gv_uiSerialRandom), &pszSerialNum[ 4]); - UD2FBA( (FLMUINT32)f_randomLong( - &gv_uiSerialRandom), &pszSerialNum[ 8]); - UD2FBA( (FLMUINT32)f_randomLong( - &gv_uiSerialRandom), &pszSerialNum[ 12]); - - f_mutexUnlock( gv_hSerialMutex); - -#if defined( FLM_WIN) || defined( FLM_NLM) -Exit: -#endif - - return( rc); -} - -/**************************************************************************** -Notes: This routine should only be called once by the process. -****************************************************************************/ -void f_freeSerialNumberGenerator( void) -{ - if( (--gv_uiSerialInitCount) > 0) - { - return; - } - - if( gv_hSerialMutex != F_MUTEX_NULL) - { - f_mutexDestroy( &gv_hSerialMutex); - } -} - - -/**************************************************************************** -Desc: Generates a table of remainders for each 8-bit byte. The resulting - table is used by flmUpdateCRC to calculate a CRC value. The table - must be freed via a call to f_freeCRCTable. -*****************************************************************************/ -RCODE f_initCRCTable( - FLMUINT32 ** ppui32CRCTbl) -{ - FLMUINT32 * pTable; - FLMUINT32 ui32Val; - FLMUINT32 ui32Loop; - FLMUINT32 ui32SubLoop; - RCODE rc = FERR_OK; - - // Use the standard degree-32 polynomial used by - // Ethernet, PKZIP, etc. for computing the CRC of - // a data stream. This is the little-endian - // representation of the polynomial. The big-endian - // representation is 0x04C11DB7. - -#define CRC_POLYNOMIAL ((FLMUINT32)0xEDB88320) - - *ppui32CRCTbl = NULL; - - if( RC_BAD( rc = f_alloc( 256 * sizeof( FLMUINT32), &pTable))) - { - goto Exit; - } - - for( ui32Loop = 0; ui32Loop < 256; ui32Loop++) - { - ui32Val = ui32Loop; - for( ui32SubLoop = 0; ui32SubLoop < 8; ui32SubLoop++) - { - if( ui32Val & 0x00000001) - { - ui32Val = CRC_POLYNOMIAL ^ (ui32Val >> 1); - } - else - { - ui32Val >>= 1; - } - } - - pTable[ ui32Loop] = ui32Val; - } - - *ppui32CRCTbl = pTable; - pTable = NULL; - -Exit: - - if( pTable) - { - f_free( &pTable); - } - - return( rc); -} - -/**************************************************************************** -Desc: Computes the CRC of the passed-in data buffer. Multiple calls can - be made to this routine to build a CRC over multiple data buffers. - On the first call, *pui32CRC must be initialized to something - (0, etc.). For generating CRCs that are compatible with PKZIP, - *pui32CRC should be initialized to 0xFFFFFFFF and the ones complement - of the resulting CRC should be computed. -*****************************************************************************/ -void f_updateCRC( - FLMUINT32 * pui32CRCTbl, - FLMBYTE * pucBlk, - FLMUINT uiBlkSize, - FLMUINT32 * pui32CRC) -{ - FLMUINT32 ui32CRC = *pui32CRC; - FLMUINT uiLoop; - - for( uiLoop = 0; uiLoop < uiBlkSize; uiLoop++) - { - ui32CRC = (ui32CRC >> 8) ^ pui32CRCTbl[ - ((FLMBYTE)(ui32CRC & 0x000000FF)) ^ pucBlk[ uiLoop]]; - } - - *pui32CRC = ui32CRC; -} - -/**************************************************************************** -Desc: -****************************************************************************/ -FLMUINT f_breakpoint( - FLMUINT uiBreakFlag) -{ - if( uiBreakFlag) - { -#ifdef FLM_NLM - EnterDebugger(); -#else - flmAssert( 0); -#endif - } - - return( 0); -} - -/**************************************************************************** -Desc: Function that must be called within a NLM's startup routine. -****************************************************************************/ -#ifdef FLM_NLM -RCODE f_netwareStartup( void) -{ - RCODE rc = FERR_OK; - - if( flmAtomicInc( &gv_NetWareStartupCount) != 1) - { - goto Exit; - } - - gv_lMyModuleHandle = CFindLoadModuleHandle( (void *)f_netwareShutdown); - - // Allocate the needed resource tags - - if( (gv_lAllocRTag = AllocateResourceTag( - gv_lMyModuleHandle, - (BYTE *)"NOVDB Memory", AllocSignature)) == NULL) - { - rc = RC_SET( FERR_MEM); - goto Exit; - } - - if( (gv_lFlmTimerTag = AllocateResourceTag( - gv_lMyModuleHandle, - (BYTE *)"NOVDB Timer", TimerSignature)) == NULL) - { - rc = RC_SET( FERR_MEM); - goto Exit; - } - - gv_lFlmStartTicks = GetCurrentTime(); - - // Random Generator initialization - - if( (gv_lFlmRandSemaphore = kSemaphoreAlloc( - (BYTE *)"NOVDB", 1)) == F_SEM_NULL) - { - rc = RC_SET( FERR_MEM); - goto Exit; - } - - f_randomSetSeed( &gv_flmRandGenerator, 1); - -Exit: - - if( RC_BAD( rc)) - { - f_netwareShutdown(); - } - - return( rc); -} -#endif - -/**************************************************************************** -Desc: Closes (Frees) any resources used by FLAIM's clib patches layer. -****************************************************************************/ -#ifdef FLM_NLM -void f_netwareShutdown( void) -{ - // Call exit function. - - if( flmAtomicDec( &gv_NetWareStartupCount) != 0) - { - goto Exit; - } - - if( gv_lAllocRTag) - { - ReturnResourceTag( gv_lAllocRTag, 1); - gv_lAllocRTag = 0; - } - - if( gv_lFlmTimerTag) - { - ReturnResourceTag( gv_lFlmTimerTag, 1); - gv_lFlmTimerTag = 0; - } - - if( gv_lFlmRandSemaphore) - { - kSemaphoreFree( gv_lFlmRandSemaphore); - gv_lFlmRandSemaphore = 0; - } - - gv_lFlmStartTicks = 0; - gv_lMyModuleHandle = 0; - -Exit: - - return; -} -#endif - -/**************************************************************************** -Desc: -****************************************************************************/ -#ifdef FLM_NLM -FLMUINT f_getNLMHandle( void) -{ - return( (FLMUINT)gv_lMyModuleHandle); -} -#endif - -/**************************************************************************** -Desc: This routine is required to work around known bugs or inefficiencies - in various incarnations of clib. -****************************************************************************/ -#undef f_memset -void * f_memset( - void * pvMem, - FLMBYTE ucByte, - FLMUINT uiSize) -{ -#ifndef FLM_NLM - return( memset( pvMem, ucByte, uiSize)); -#else - char * cp = (char *)pvMem; - unsigned dwordLength; - unsigned long dwordVal; - - dwordVal = ((unsigned long)ucByte << 24) | - ((unsigned long)ucByte << 16) | - ((unsigned long)ucByte << 8) | - (unsigned long)ucByte; - - while( uiSize && ((long)cp & 3L)) - { - *cp++ = (char)ucByte; - uiSize--; - } - - dwordLength = uiSize >> 2; - if( dwordLength != 0) - { - CSetD( dwordVal, (void *)cp, dwordLength); - cp += (dwordLength << 2); - uiSize -= (dwordLength << 2); - } - - while( uiSize) - { - *cp++ = (char)ucByte; - uiSize--; - } - - return( pvMem); -#endif -} - -/**************************************************************************** -Desc: This routine is required to work around known bugs or inefficiencies - in various incarnations of clib. -****************************************************************************/ -#undef f_memmove -void * f_memmove( - void * pvDest, - const void * pvSrc, - FLMUINT uiSize) -{ -#ifndef FLM_NLM - return( memmove( pvDest, pvSrc, uiSize)); -#else -#define CMOVB_THRESHOLD 16 - char *s = (char *)pvSrc; - char *d = (char *)pvDest; - unsigned uDiff; - - if( (char *)(s + uiSize) < d || (char *)(d + uiSize) < s) - { - // The source and destination do not overlap. - - CMoveFast( (void *)s, d, (LONG)uiSize); - } - else if( s < d) - { - // Source preceeds the destination, with overlap. - - uDiff = (unsigned)(d - s); - d += uiSize; - s += uiSize; - if( uDiff >= CMOVB_THRESHOLD) - { - for( ;;) - { - if( uiSize < uDiff) - { - break; - } - - // Copy the tail - - s -= uDiff; - d -= uDiff; - uiSize -= uDiff; - CMoveFast( (void *)s, d, (LONG)uDiff); - } - } - - // Copy remaining bytes. - - while( uiSize--) - { - *--d = *--s; - } - } - else if( s > d) - { - // Source follows the destination, with overlap. - - uDiff = (unsigned)(s - d); - if( uDiff >= CMOVB_THRESHOLD) - { - for( ;;) - { - if( uiSize < uDiff) - { - break; - } - - // Copy the head - - CMoveFast( (void *)s, d, (LONG)uDiff); - uiSize -= uDiff; - d += uDiff; - s += uDiff; - } - } - - // Copy the remaining bytes - - while( uiSize--) - { - *d++ = *s++; - } - } - - // Else, the regions overlap completely (s == d). Do nothing. - - return( pvDest); -#endif -} - -/**************************************************************************** -Desc: Performs a comparison of m1 to m2, for a maximum - length of size bytes. -****************************************************************************/ -#undef f_memcmp -FLMINT f_memcmp( - const void * pvMem1, - const void * pvMem2, - FLMUINT uiSize) -{ - unsigned char * s1; - unsigned char * s2; - - for (s1 = (unsigned char *)pvMem1, s2 = (unsigned char *)pvMem2; - uiSize > 0; uiSize--, s1++, s2++) - { - if (*s1 == *s2) - { - continue; - } - else if( *s1 > *s2) - { - return( 1); - } - else - { - return( -1); - } - } - - return( 0); -} - -/**************************************************************************** -Desc: This routine is required to work around known bugs or inefficiencies - in various incarnations of clib. -****************************************************************************/ -#undef f_stricmp -FLMINT f_stricmp( - const char * pszStr1, - const char * pszStr2) -{ - while( f_toupper( *pszStr1) == f_toupper( *pszStr2) && *pszStr1) - { - pszStr1++; - pszStr2++; - } - return( (FLMINT)( f_toupper( *pszStr1) - f_toupper( *pszStr2))); -} - -/**************************************************************************** -Desc: Performs a signed comparison of s1 to s2, for a maximum - length of n bytes, starting with the first character in - each string and continuing with subsequent characters until - the corresponding characters differ, or until n characters - have been examined. -****************************************************************************/ -#undef f_strnicmp -FLMINT f_strnicmp( - const char * pszStr1, - const char * pszStr2, - FLMINT iLen) -{ - if( !pszStr1 || !pszStr2) - { - return( (pszStr1 == pszStr2) - ? 0 - : (pszStr1 ? 1 : -1)); - } - - while( iLen-- && *pszStr1 && *pszStr2 && - (f_toupper( *pszStr1) == f_toupper( *pszStr2))) - { - pszStr1++; - pszStr2++; - } - - return( (iLen == -1) - ? 0 - : (f_toupper( *pszStr1) - f_toupper( *pszStr2))); - -} - -/**************************************************************************** -Desc: -****************************************************************************/ -#undef f_strupr -char * f_strupr( - char * pszStr) -{ - while( *pszStr) - { - *pszStr = f_toupper( *pszStr); - pszStr++; - } - - return( pszStr); -} - -/**************************************************************************** -Desc: -****************************************************************************/ -#undef f_strstr -char * f_strstr( - const char * pszStr1, - const char * pszStr2) -{ - FLMUINT i; - FLMUINT j; - FLMUINT k; - - if ( !pszStr1 || !pszStr2) - { - return( NULL); - } - - for( i = 0; pszStr1[i] != '\0'; i++) - { - for( j=i, k=0; pszStr2[k] != '\0' && - pszStr1[j] == pszStr2[k]; j++, k++) - { - ; - } - - if ( k > 0 && pszStr2[k] == '\0') - { - return( (char *)&pszStr1[i]); - } - } - - return( NULL); -} - -/**************************************************************************** -Desc: -****************************************************************************/ -#undef f_strchr -char * f_strchr( - const char * pszStr, - char c) -{ - if( !pszStr) - { - return( NULL); - } - - while (*pszStr && *pszStr != (FLMBYTE)c) - { - pszStr++; - } - - return( (char *)((*pszStr == c) - ? pszStr - : NULL)); -} diff --git a/flaim/src/ftkmod.cpp b/flaim/src/ftkmod.cpp deleted file mode 100644 index aa35906..0000000 --- a/flaim/src/ftkmod.cpp +++ /dev/null @@ -1,384 +0,0 @@ -//------------------------------------------------------------------------- -// Desc: Module loading -// Tabs: 3 -// -// Copyright (c) 2004-2006 Novell, Inc. All Rights Reserved. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of version 2 of the GNU General Public -// License as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, contact Novell, Inc. -// -// To contact Novell about this file by physical or electronic mail, -// you may find current contact information at www.novell.com -// -// $Id: ftkmod.cpp 12334 2006-01-23 12:45:35 -0700 (Mon, 23 Jan 2006) dsanders $ -//------------------------------------------------------------------------- - -#include "flaim.h" - -#ifndef FLM_OSX - -// OS X 10.2 and earlier don't have dlopen, dlsym, etc... They have a totally -// different mechanism and since these functions are only used for our unit -// tests, it's probably not worth the time to sort it all out. In 10.3, -// the dl functions were implemented in terms of the native functions and -// this should all work. Pity there's no easy way to determine which version -// we're on... - - -#include "flaimsys.h" - -#ifdef FLM_UNIX - #include -#endif - - -#ifdef FLM_WIN - - FSTATIC RCODE flmSymLoadWin( - const FLMBYTE * pszName, - FlmModHandle hMod, - void ** ppvSym); - -#elif defined (FLM_NLM) - - FSTATIC RCODE flmSymLoadNW( - const FLMBYTE * pszName, - void ** ppvSym); - -#elif defined( FLM_UNIX) - - FSTATIC RCODE flmSymLoadUnix( - const FLMBYTE * pszName, - FlmModHandle hMod, - void ** ppvSym); - -#endif - -/**************************************************************************** -Desc: This routine loads a shared library (cross-platform) -****************************************************************************/ -RCODE FlmModLoad( - const char * pszName, - FlmModHandle * phMod) -{ - RCODE rc = FERR_OK; -#ifdef FLM_WIN - HMODULE hMod; - - if ((hMod = LoadLibrary( pszName)) == NULL) - { - rc = MapWinErrorToFlaim( GetLastError(), FERR_LOAD_LIBRARY); - goto Exit; - } - - if ( phMod) - { - *phMod = (FlmModHandle)hMod; - } - -#elif defined (FLM_UNIX) - FlmModHandle hMod; - - if (!(hMod = dlopen( (const char *)pszName, RTLD_LAZY))) - { - // Note, I can't seem to get any real diagnostic info back - // from the operating system. It does not set errno on failure. - rc = RC_SET( FERR_LOAD_LIBRARY); - goto Exit; - } - - if ( phMod) - { - *phMod = hMod; - } - -#elif defined (FLM_NLM) - - char szLoadName[ 128]; - LONG lErr; - - // The module handle will be passed back in the first 4 bytes of the name - f_strcpy( &szLoadName[4], pszName); - - if ( ( lErr = LoadModule( - GetSystemConsoleScreen(), - (unsigned char *)&szLoadName[4], - LO_RETURN_HANDLE)) != 0) - { - rc = RC_SET( FERR_LOAD_LIBRARY); - goto Exit; - } - - *phMod = (FlmModHandle)&szLoadName[0]; - -#else - #error Unsupported OS -#endif - -Exit: - return( rc); -} - -#ifndef FLM_NLM -/**************************************************************************** -Desc: This routine unloads a shared library (cross-platform) -****************************************************************************/ -RCODE FlmModUnload( FlmModHandle * phMod) -{ - RCODE rc = FERR_OK; - - flmAssert( phMod); -#ifdef FLM_WIN - - if (!FreeLibrary((HMODULE)*phMod)) - { - rc = MapWinErrorToFlaim( GetLastError(), FERR_UNLOAD_LIBRARY); - goto Exit; - } - *phMod = NULL; - -#elif defined (FLM_UNIX) - if (dlclose(phMod) != 0) - { - rc = RC_SET( FERR_UNLOAD_LIBRARY); - goto Exit; - } - *phMod = NULL; -#else - #error Unsupported OS -#endif -Exit: - return( rc); -} -#endif - -#ifdef FLM_NLM - -/**************************************************************************** -Desc: This routine creates a FLAIM file. For whatever reason, NetWare unloads -a module using its path and not its handle. While routines exist that look up -the path given the module handle, I can't use them because they are all LibC -calls -****************************************************************************/ -RCODE FlmModUnload( FLMBYTE * pszModPath) -{ - int iErr; - RCODE rc = FERR_OK; - - if ( (iErr = UnloadModule( - NULL, - (const char *)pszModPath)) != 0) - { - rc = MapNWtoFlaimError( iErr, FERR_UNLOAD_LIBRARY); - goto Exit; - } - -Exit: - return( rc); -} -#endif - -#ifdef FLM_WIN - -/**************************************************************************** -Desc: This routine loads a symbol from a .dll file -****************************************************************************/ -FSTATIC RCODE flmSymLoadWin( - const FLMBYTE * pszName, - FlmModHandle hMod, - void ** ppvSym) -{ - RCODE rc = FERR_OK; - void * pvSym; - - if ( ( pvSym = GetProcAddress( (HMODULE)hMod, (LPCSTR)pszName)) == NULL) - { - rc = MapWinErrorToFlaim( GetLastError(), FERR_IMPORT_SYMBOL); - goto Exit; - } - -Exit: - if ( ppvSym && RC_OK( rc)) - { - *ppvSym = pvSym; - } - - return( rc); -} - -#elif defined (FLM_NLM) - -/**************************************************************************** -Desc: This routine loads a symbol from a .nlm file -****************************************************************************/ -FSTATIC RCODE flmSymLoadNW( - const FLMBYTE * pszName, - void ** ppvSym) -{ - RCODE rc = FERR_OK; - void * pvSym; - FLMUINT uiNameLen; - FLMBYTE * pszLengthPlusName = NULL; - - // NetWare is a little different (of course). You use your own handle - // to query for and retrieve symbols. All loaded modules are queried. - - uiNameLen = f_strlen( (const char *)pszName); - - if ( uiNameLen > 255) - { - - // If the name's length can't be represented in a single byte, - // it's too large. - - rc = RC_SET( FERR_VALUE_TOO_LARGE); - goto Exit; - } - - if ( RC_BAD( rc = f_alloc( uiNameLen + 2, &pszLengthPlusName))) - { - goto Exit; - } - - // The first byte of the name should be the length of the name - - pszLengthPlusName[0] = (FLMBYTE)uiNameLen; - f_strcpy( (char *)&pszLengthPlusName[1], (const char *)pszName); - - if (( pvSym = (void *)ImportPublicSymbol( - f_getNLMHandle(), - (BYTE*)pszLengthPlusName)) == NULL) - { - rc = RC_SET( FERR_IMPORT_SYMBOL); - goto Exit; - } - -Exit: - if ( pszLengthPlusName) - { - f_free( &pszLengthPlusName); - } - - if ( ppvSym && RC_OK( rc)) - { - *ppvSym = pvSym; - } - return( rc); -} - -#elif defined( FLM_UNIX) - -/**************************************************************************** -Desc: This routine loads a symbol from a .so file. -****************************************************************************/ -FSTATIC RCODE flmSymLoadUnix( - const FLMBYTE * pszName, - FlmModHandle hMod, - void ** ppvSym) -{ - RCODE rc = FERR_OK; - void * pvSym; - - if ( ( pvSym = dlsym( hMod, (const char*)pszName)) == NULL) - { - rc = RC_SET( FERR_IMPORT_SYMBOL); - goto Exit; - } - -Exit: - if ( ppvSym && RC_OK( rc)) - { - *ppvSym = pvSym; - } - - return( rc); -} - -#endif - -/**************************************************************************** -Desc: This routine loads a symbol from a shared library (cross-platform) -****************************************************************************/ -RCODE FlmSymLoad( const FLMBYTE * pszName, FlmModHandle hMod, void ** ppvSym) -{ -#ifdef FLM_WIN - return flmSymLoadWin( pszName, hMod, ppvSym); -#elif defined (FLM_NLM) - F_UNREFERENCED_PARM( hMod); - return flmSymLoadNW( pszName, ppvSym); -#elif defined (FLM_UNIX) - return flmSymLoadUnix( pszName, hMod, ppvSym); -#endif -} - -/**************************************************************************** -Desc: This routine unloads a shared library symbol (cross-platform, but only -really useful on NetWare since it seems to be the only platform that keeps a -reference count on loaded symbols) -****************************************************************************/ -RCODE FlmSymUnload( - const FLMBYTE * pszName) -{ -#ifdef FLM_NLM - RCODE rc = FERR_OK; - FLMUINT uiSymLen; - FLMBYTE * pszLenAndSymbol = NULL; - - uiSymLen = f_strlen( (const char *)pszName); - - if ( uiSymLen > 255) - { - rc = RC_SET( FERR_VALUE_TOO_LARGE); - goto Exit; - } - - if ( RC_BAD( rc = f_alloc( uiSymLen + 2, &pszLenAndSymbol))) - { - goto Exit; - } - - pszLenAndSymbol[0] = (FLMBYTE)uiSymLen; - f_strcpy( (char *)&pszLenAndSymbol[1], (const char *)pszName); - - if ((UnImportPublicSymbol ( - f_getNLMHandle(), pszLenAndSymbol)) != 0) - { - rc = RC_SET( FERR_UNIMPORT_SYMBOL); - goto Exit; - } - -Exit: - if( pszLenAndSymbol) - { - f_free( &pszLenAndSymbol); - } - - return( rc); -#else - - // This is only really necessary on NetWare - - F_UNREFERENCED_PARM( pszName); - return FERR_OK; -#endif -} - -#endif - -/**************************************************************************** -Desc: -****************************************************************************/ -#if defined( FLM_OSX) -void gv_ftkmod() -{ -} -#endif diff --git a/flaim/src/ftknlm.h b/flaim/src/ftknlm.h deleted file mode 100644 index 49c5d54..0000000 --- a/flaim/src/ftknlm.h +++ /dev/null @@ -1,1714 +0,0 @@ -//------------------------------------------------------------------------- -// Desc: Toolkit - cross platform APIs for system functionality. -// Tabs: 3 -// -// Copyright (c) 1991-2006 Novell, Inc. All Rights Reserved. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of version 2 of the GNU General Public -// License as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, contact Novell, Inc. -// -// To contact Novell about this file by physical or electronic mail, -// you may find current contact information at www.novell.com -// -// $Id: $ -//------------------------------------------------------------------------- - -#ifndef FTKNLM_H -#define FTKNLM_H - -#pragma pack(push,1) - - typedef unsigned long LONG; - typedef unsigned short WORD; - typedef unsigned char BYTE; - typedef unsigned short wchar_t; - typedef unsigned char wsnchar; - typedef unsigned int BOOL; - typedef unsigned int DWORD; - typedef unsigned int * LPDWORD; - typedef unsigned long ULONG; - typedef unsigned char UCHAR; - typedef DWORD WPARAM; - typedef DWORD LPARAM; - typedef unsigned int UINT; - typedef unsigned int size_t; - typedef void * MUTEX; - typedef void * SEMAPHORE; - typedef unsigned long ERROR; - typedef void * SPINLOCK; - typedef LONG clockAndStatus[3]; - typedef unsigned int SOCKET; - typedef unsigned long f_va_list; - typedef SEMAPHORE F_SEM; - - typedef void (* FLM_EXIT_FUNC)( void); - - #define FSTATIC - - #define F_SEM_NULL 0 - - #define TimerSignature 0x524D4954 - #define SemaphoreSignature 0x504D4553 - #define AllocSignature 0x54524C41 - - #define DOSNameSpace 0 - #define MACNameSpace 1 - #define MacNameSpace MACNameSpace - #define NFSNameSpace 2 - #define FTAMNameSpace 3 - #define OS2NameSpace 4 - #define LONGNameSpace 4 - #define NTNameSpace 5 - #define MAX_NAMESPACES 6 - - #define NO_RIGHTS_CHECK_ON_OPEN_BIT 0x00010000 - #define ALLOW_SECURE_DIRECTORY_ACCESS_BIT 0x00020000 - #define READ_ACCESS_BIT 0x00000001 - #define WRITE_ACCESS_BIT 0x00000002 - #define DENY_READ_BIT 0x00000004 - #define DENY_WRITE_BIT 0x00000008 - #define COMPATABILITY_MODE_BIT 0x00000010 - #define FILE_WRITE_THROUGH_BIT 0x00000040 - #define FILE_READ_THROUGH_BIT 0x00000080 - #define ALWAYS_READ_AHEAD_BIT 0x00001000 - #define NEVER_READ_AHEAD_BIT 0x00002000 - - #define READ_ONLY_BIT 0x00000001 - #define HIDDEN_BIT 0x00000002 - #define SYSTEM_BIT 0x00000004 - #define EXECUTE_BIT 0x00000008 - #define SUBDIRECTORY_BIT 0x00000010 - #define ARCHIVE_BIT 0x00000020 - #define SHAREABLE_BIT 0x00000080 - #define OLD_PRIVATE_BIT 0x00000080 - #define NO_SUBALLOC_BIT 0x00000800 - #define SMODE_BITS 0x00000700 - #define TRANSACTION_BIT 0x00001000 - #define READ_AUDIT_BIT 0x00004000 - #define WRITE_AUDIT_BIT 0x00008000 - #define IMMEDIATE_PURGE_BIT 0x00010000 - #define RENAME_INHIBIT_BIT 0x00020000 - #define DELETE_INHIBIT_BIT 0x00040000 - #define COPY_INHIBIT_BIT 0x00080000 - #define FILE_AUDITING_BIT 0x00100000 - #define REMOTE_DATA_ACCESS_BIT 0x00400000 - #define REMOTE_DATA_INHIBIT_BIT 0x00800000 - #define REMOTE_DATA_SAVE_KEY_BIT 0x01000000 - #define COMPRESS_FILE_IMMEDIATELY_BIT 0x02000000 - #define DATA_STREAM_IS_COMPRESSED_BIT 0x04000000 - #define DO_NOT_COMPRESS_FILE_BIT 0x08000000 - #define CANT_COMPRESS_DATA_STREAM_BIT 0x20000000 - #define ATTR_ARCHIVE_BIT 0x40000000 - #define ZFS_VOLATILE_BIT 0x80000000 - - #define VOLUME_AUDITING_BIT 0x01 - #define SUB_ALLOCATION_ENABLED_BIT 0x02 - #define FILE_COMPRESSION_ENABLED_BIT 0x04 - #define DATA_MIGRATION_ENABLED_BIT 0x08 - #define NEW_TRUSTEE_COUNT_BIT 0x10 - #define DIR_SVCS_OBJ_UPGRADED_BIT 0x20 - #define VOLUME_IMMEDIATE_PURGE_ENABLED_BIT 0x40 - - #define PrimaryDataStream 0 - #define MACResourceForkDataStream 1 - #define FTAMDataStream 2 - - #define DefinedAccessRightsBits 0x01FB - #define MaximumDirectoryAccessBits 0x01FF - #define AllValidAccessBits 0x100001FF - - #define SYNCCLOCK_CLOCK_BIT 0x00000001L - #define SYNCCLOCK_TICK_INCREMENT_BIT 0x00000002L - #define SYNCCLOCK_ADJUSTMENT_BIT 0x00000004L - #define SYNCCLOCK_GROSS_CORRECTION_BIT 0x00000008L - #define SYNCCLOCK_ADJUSTMENT_COUNT_BIT 0x00000010L - #define SYNCCLOCK_STATUS_BIT 0x00000020L - #define SYNCCLOCK_STD_TICK_BIT 0x00000040L - #define SYNCCLOCK_EVENT_TIME_BIT 0x00000080L - #define SYNCCLOCK_EVENT_OFFSET_BIT 0x00000100L - #define SYNCCLOCK_HARDWARE_CLOCK_BIT 0x00000200L - #define SYNCCLOCK_RESERVED1_BIT 0x00000400L - #define SYNCCLOCK_DAYLIGHT_BIT 0x00000800L - #define SYNCCLOCK_TIMEZONE_OFFSET_BIT 0x00001000L - #define SYNCCLOCK_TZNAME_BIT 0x00002000L - #define SYNCCLOCK_TIMEZONE_STR_BIT 0x00004000L - #define SYNCCLOCK_DAYLIGHT_OFFSET_BIT 0x00008000L - #define SYNCCLOCK_DAYLIGHT_ON_OFF_BIT 0x00010000L - #define SYNCCLOCK_START_DST_BIT 0x00020000L - #define SYNCCLOCK_STOP_DST_BIT 0x00040000L - #define SYNCCLOCK_ALL_DEFINED_BITS (0x0007FFFFL & ~SYNCCLOCK_HARDWARE_CLOCK_BIT) - - #define LDModuleIsReEntrantBit 0x00000001 - #define LDModuleCanBeMultiplyLoadedBit 0x00000002 - #define LDSynchronizeStart 0x00000004 - #define LDPseudoPreemptionBit 0x00000008 - #define LDLoadInKernel 0x00000010 - #define Available_0 0x00000020 - #define LDAutoUnload 0x00000040 - #define LDHiddenModule 0x00000080 - #define LDDigitallySignedFile 0x00000100 - #define LDLoadProtected 0x00000200 - #define LDSharedLibraryModule 0x00000400 - #define LDRestartable 0x00000800 - #define LDUnsafeToUnloadNow 0x00001000 - #define LDModuleIsUniprocessor 0x00002000 - #define LDPreemptable 0x00004000 - #define LDHasSystemCalls 0x00008000 - #define LDVirtualMemory 0x00010000 - #define LDAllExportsMTSafe 0x00020000 - - #define DFSFailedCompletion -1 - #define DFSNormalCompletion 0 - #define DFSInsufficientSpace 1 - #define DFSVolumeSegmentDeactivated 4 - #define DFSTruncationFailure 16 - #define DFSHoleInFileError 17 - #define DFSParameterError 18 - #define DFSOverlapError 19 - #define DFSSegmentError 20 - #define DFSBoundryError 21 - #define DFSInsufficientLimboFileSpace 22 - #define DFSNotInDirectFileMode 23 - #define DFSOperationBeyondEndOfFile 24 - #define DFSOutOfHandles 129 - #define DFSHardIOError 131 - #define DFSInvalidFileHandle 136 - #define DFSNoReadPrivilege 147 - #define DFSNoWritePrivilege 148 - #define DFSFileDetached 149 - #define DFSInsufficientMemory 150 - #define DFSInvalidVolume 152 - #define DFSIOLockError 162 - - #define MModifyNameBit 0x0001 - #define MFileAttributesBit 0x0002 - #define MCreateDateBit 0x0004 - #define MCreateTimeBit 0x0008 - #define MOwnerIDBit 0x0010 - #define MLastArchivedDateBit 0x0020 - #define MLastArchivedTimeBit 0x0040 - #define MLastArchivedIDBit 0x0080 - #define MLastUpdatedDateBit 0x0100 - #define MLastUpdatedTimeBit 0x0200 - #define MLastUpdatedIDBit 0x0400 - #define MLastAccessedDateBit 0x0800 - #define MInheritanceRestrictionMaskBit 0x1000 - #define MMaximumSpaceBit 0x2000 - #define MLastUpdatedInSecondsBit 0x4000 - - #define MAX_NETWARE_VOLUME_NAME 16 - #define F_NW_DEFAULT_VOLUME_NUMBER 0 - - #define LO_RETURN_HANDLE 0x00000040 - - #define htonl WS2_32_htonl - #define ntohl WS2_32_ntohl - #define htons WS2_32_htons - #define ioctlsocket WS2_32_ioctlsocket - #define ntohs WS2_32_ntohs - #define send WS2_32_send - #define recv WS2_32_recv - #define bind WS2_32_bind - #define listen WS2_32_listen - #define closesocket WS2_32_closesocket - #define getpeername WS2_32_getpeername - #define getsockname WS2_32_getsockname - #define getsockopt WS2_32_getsockopt - #define select WS2_32_select - #define setsockopt WS2_32_setsockopt - #define socket WS2_32_socket - #define inet_addr WS2_32_inet_addr - #define inet_ntoa WS2_32_inet_ntoa - #define gethostbyaddr WS2_32_gethostbyaddr - #define gethostbyname WS2_32_gethostbyname - #define gethostname WS2_32_gethostname - - #define connect(s,name,namelen) \ - WSAConnect(s,name,namelen, 0,0,0,0) - - #define accept(s,addr,addrlen) \ - WSAAccept(s,addr,addrlen,0,0) - - #define IPPROTO_IP 0 // dummy for IP - #define IPPROTO_ICMP 1 // control message protocol - #define IPPROTO_IGMP 2 // internet group management protocol - #define IPPROTO_GGP 3 // gateway (deprecated) - #define IPPROTO_TCP 6 // tcp - #define IPPROTO_PUP 12 // pup - #define IPPROTO_UDP 17 // user datagram protocol - #define IPPROTO_IDP 22 // xns idp - #define IPPROTO_ND 77 // UNOFFICIAL net disk proto - - #define TCP_NODELAY 0x0001 - - #define SOCK_STREAM 1 // stream socket - #define SOCK_DGRAM 2 // datagram socket - #define SOCK_RAW 3 // raw-protocol interface - #define SOCK_RDM 4 // reliably-delivered message - #define SOCK_SEQPACKET 5 // sequenced packet stream - - #define WSADESCRIPTION_LEN 256 - #define WSASYS_STATUS_LEN 128 - - #define s_addr S_un.S_addr - #define s_host S_un.S_un_b.s_b2 - #define s_net S_un.S_un_b.s_b1 - #define s_imp S_un.S_un_w.s_w2 - #define s_impno S_un.S_un_b.s_b4 - #define s_lh S_un.S_un_b.s_b3 - - #define h_addr h_addr_list[0] - - #define FD_SETSIZE 64 - - #define WINSOCK_VERSION MAKEWORD(2,2) - - #define INVALID_SOCKET (SOCKET)(~0) - #define SOCKET_ERROR (-1) - - #define AF_INET 2 - - #define WSABASEERR 10000 - #define WSAEINTR (WSABASEERR+4) - #define WSAEBADF (WSABASEERR+9) - #define WSAEACCES (WSABASEERR+13) - #define WSAEFAULT (WSABASEERR+14) - #define WSAEINVAL (WSABASEERR+22) - #define WSAEMFILE (WSABASEERR+24) - #define WSAEWOULDBLOCK (WSABASEERR+35) - #define WSAEINPROGRESS (WSABASEERR+36) - #define WSAEALREADY (WSABASEERR+37) - #define WSAENOTSOCK (WSABASEERR+38) - #define WSAEDESTADDRREQ (WSABASEERR+39) - #define WSAEMSGSIZE (WSABASEERR+40) - #define WSAEPROTOTYPE (WSABASEERR+41) - #define WSAENOPROTOOPT (WSABASEERR+42) - #define WSAEPROTONOSUPPORT (WSABASEERR+43) - #define WSAESOCKTNOSUPPORT (WSABASEERR+44) - #define WSAEOPNOTSUPP (WSABASEERR+45) - #define WSAEPFNOSUPPORT (WSABASEERR+46) - #define WSAEAFNOSUPPORT (WSABASEERR+47) - #define WSAEADDRINUSE (WSABASEERR+48) - #define WSAEADDRNOTAVAIL (WSABASEERR+49) - #define WSAENETDOWN (WSABASEERR+50) - #define WSAENETUNREACH (WSABASEERR+51) - #define WSAENETRESET (WSABASEERR+52) - #define WSAECONNABORTED (WSABASEERR+53) - #define WSAECONNRESET (WSABASEERR+54) - #define WSAENOBUFS (WSABASEERR+55) - #define WSAEISCONN (WSABASEERR+56) - #define WSAENOTCONN (WSABASEERR+57) - #define WSAESHUTDOWN (WSABASEERR+58) - #define WSAETOOMANYREFS (WSABASEERR+59) - #define WSAETIMEDOUT (WSABASEERR+60) - #define WSAECONNREFUSED (WSABASEERR+61) - #define WSAELOOP (WSABASEERR+62) - #define WSAENAMETOOLONG (WSABASEERR+63) - #define WSAEHOSTDOWN (WSABASEERR+64) - #define WSAEHOSTUNREACH (WSABASEERR+65) - #define WSAENOTEMPTY (WSABASEERR+66) - #define WSAEPROCLIM (WSABASEERR+67) - #define WSAEUSERS (WSABASEERR+68) - #define WSAEDQUOT (WSABASEERR+69) - #define WSAESTALE (WSABASEERR+70) - #define WSAEREMOTE (WSABASEERR+71) - #define WSASYSNOTREADY (WSABASEERR+91) - #define WSAVERNOTSUPPORTED (WSABASEERR+92) - #define WSANOTINITIALISED (WSABASEERR+93) - #define WSAEDISCON (WSABASEERR+101) - #define WSAENOMORE (WSABASEERR+102) - #define WSAECANCELLED (WSABASEERR+103) - #define WSAEINVALIDPROCTABLE (WSABASEERR+104) - #define WSAEINVALIDPROVIDER (WSABASEERR+105) - #define WSAEPROVIDERFAILEDINIT (WSABASEERR+106) - #define WSASYSCALLFAILURE (WSABASEERR+107) - #define WSASERVICE_NOT_FOUND (WSABASEERR+108) - #define WSATYPE_NOT_FOUND (WSABASEERR+109) - #define WSA_E_NO_MORE (WSABASEERR+110) - #define WSA_E_CANCELLED (WSABASEERR+111) - #define WSAEREFUSED (WSABASEERR+112) - #define WSAHOST_NOT_FOUND (WSABASEERR+1001) - #define WSATRY_AGAIN (WSABASEERR+1002) - #define WSANO_RECOVERY (WSABASEERR+1003) - #define WSANO_DATA (WSABASEERR+1004) - - #define INADDR_ANY 0x00000000 - #define INADDR_LOOPBACK 0x7f000001 - #define INADDR_BROADCAST 0xffffffff - #define INADDR_NONE 0xffffffff - #define ADDR_ANY INADDR_ANY - - /************************************************************************* - Desc: - *************************************************************************/ - typedef struct LoadDefStruct - { - struct LoadDefStruct * LDLink; - struct LoadDefStruct * LDKillLink; - struct LoadDefStruct * LDScanLink; - struct ResourceTagStructure * LDResourceList; - LONG LDIdentificationNumber; - LONG LDCodeImageOffset; - LONG LDCodeImageLength; - LONG LDDataImageOffset; - LONG LDDataImageLength; - LONG LDUninitializedDataLength; - LONG LDCustomDataOffset; - LONG LDCustomDataSize; - LONG LDFlags; - LONG LDType; - LONG (*LDInitializationProcedure)( - struct LoadDefinitionStructure * LoadRecord, - struct ScreenStruct * screenID, - BYTE * CommandLine, - BYTE * loadDirectoryPath, - LONG uninitializedDataLength, - LONG fileHandle, - LONG (*ReadRoutine)( - LONG fileHandle, - LONG offset, - void * buffer, - LONG numberOfBytes), - LONG customDataOffset, - LONG customDataSize); - - void (*LDExitProcedure)(void); - - LONG (*LDCheckUnloadProcedure)( - struct ScreenStruct *screenID); - - void * LDPublics; - BYTE LDFileName[36]; - BYTE LDName[128]; - LONG * LDCLIBLoadStructure; - LONG * LDNLMDebugger; - LONG LDParentID; - LONG LDReservedForCLIB; - void * AllocMemory; - LONG LDTimeStamp; - void * LDModuleObjectHandle; - LONG LDMajorVersion; - LONG LDMinorVersion; - LONG LDRevision; - LONG LDYear; - LONG LDMonth; - LONG LDDay; - BYTE * LDCopyright; - LONG LDSuppressUnloadAllocMsg; - LONG Reserved2; - LONG Reserved3; - LONG Reserved4[64]; - LONG Reserved5[12]; - LONG Reserved6; - void * LDDomainID; - struct LoadDefinitionStructure * LDEnvLink; - void * LDAllocPagesListHead; - void * LDTempPublicList; - LONG LDMessageLanguage; - BYTE ** LDMessages; - LONG LDMessageCount; - BYTE * LDHelpFile; - LONG LDMessageBufferSize; - LONG LDHelpBufferSize; - LONG LDSharedCodeOffset; - LONG LDSharedCodeLength; - LONG LDSharedDataOffset; - LONG LDSharedDataLength; - LONG (*LDSharedInitProcedure)( - struct LoadDefinitionStructure * LoadRecord, - struct ScreenStruct * screenID, - BYTE * CommandLine); - - void (*LDSharedExitProcedure)(void); - - LONG LDRPCDataTable; - LONG LDRealRPCDataTable; - LONG LDRPCDataTableSize; - LONG LDNumberOfReferencedPublics; - void ** LDReferencedPublics; - LONG LDNumberOfReferencedExports; - LONG LDNICIObject; - LONG LDAllocPagesListLocked; - void * LDAddressSpace; - LONG Reserved7; - void * MPKStubAddress; - LONG MPKStubSize; - LONG LDBuildNumber; - void * LDExtensionData; - } LoadDefStruct; - - /************************************************************************* - Desc: - *************************************************************************/ - typedef struct FCBType - { - LONG OpenFileLink; - LONG StationLink; - struct FCBType * ShareLinkNext; - struct FCBType * ShareLinkLast; - struct OwnerRestrictionNodeStructure * OwnerRestrictionNode; - struct SpaceRestrictionNodeStructure * SubdirectoryRestrictionNode; - LONG OpenCount; - LONG DirectoryEntry; - LONG DirectoryNumber; - LONG ActualDirectoryEntry; - LONG FileSize; - LONG FirstCluster; - LONG CurrentBlock; - LONG CurrentCluster; - struct FATStruct * FATTable; - LONG TNodePointer; - LONG DateValueStamp; - void * TurboFAT; - LONG OldFileSize; - LONG TransactionPointer; - LONG Station; - LONG Task; - BYTE HandleCount[4]; - BYTE Flags; - BYTE TTSFlags; - BYTE ByteToBlockShiftFactor; - BYTE BlockToSectorShiftFactor; - BYTE SectorToBlockMask; - BYTE VolumeNumber; - BYTE ExtraFlags; - BYTE DataStream; - LONG CommitSemaphore; - LONG ActualOldLastCluster; - LONG FCBInUseCount; - BYTE ExtraExtraFlags; - BYTE SubAllocFlags; - BYTE RemoveSkipUpdateFlags; - BYTE DeCompressFlags; - LONG VolumeManagerID; - LONG SubAllocSemaphore; - LONG SAStartingSector[2]; - LONG SANumberOfSectors[2]; - LONG SAFATCount; - LONG TempCacheListHead; - LONG TempCacheListTail; - struct CompressControlNodeStructure * CompressControlNode; - struct FCBType * DeCompressFCB; - LONG DeCompressPosition; - LONG DeCompressHandle; - LONG RALastReadStartOffset; - LONG RALastReadEndOffset; - LONG RANextReadAheadOffset; - LONG RAHalfSize; - LONG MoreFlags; - LONG StationBackLink; - SPINLOCK DFSSpinLock; - LONG DFSUseCount; - LONG DFSCurrentCluster; - LONG DFSCurrentBlock; - LONG unused; - LONG unused1; - LONG unused2; - LONG unused3; - } FCBType; - - /************************************************************************* - Desc: - *************************************************************************/ - struct DirectoryStructure - { - #define NumberOfDirectoryTrustees 4 - int DSubdirectory; - LONG DFileAttributes; - BYTE DUniqueID; - BYTE DFlags; - BYTE DNameSpace; - BYTE DFileNameLength; - BYTE DFileName[12]; - LONG DCreateDateAndTime; - LONG DOwnerID; - LONG DLastArchivedDateAndTime; - LONG DLastArchivedID; - LONG DLastUpdatedDateAndTime; - LONG DLastUpdatedID; - LONG DFileSize; - LONG DFirstBlock; - LONG DNextTrusteeEntry; - LONG DTrustees[NumberOfDirectoryTrustees]; - LONG DLookUpEntryNumber; - int DLastUpdatedInSeconds; - WORD DTrusteeMask[NumberOfDirectoryTrustees]; - WORD DChangeReferenceID; - WORD DLastAccessedTime; - WORD DMaximumAccessMask; - WORD DLastAccessedDate; - LONG DDeletedFileTime; - LONG DDeletedDateAndTime; - LONG DDeletedID; - LONG DExtendedAttributes; - LONG DDeletedBlockSequenceNumber; - LONG DPrimaryEntry; - LONG DNameList; - }; - - /************************************************************************* - Desc: - *************************************************************************/ - typedef struct Synchronized_Clock_T - { - #define MAX_TIME_ZONE_STRING_LENGTH 80 - LONG clock[2]; - LONG statusFlags; - LONG adjustmentCount; - LONG adjustment[2]; - LONG grossCorrection[2]; - LONG tickIncrement[2]; - LONG stdTickIncrement[2]; - LONG eventOffset[2]; - LONG eventTime; - LONG daylight; - long timezoneOffset; - long tzname[2]; - char timeZoneString[MAX_TIME_ZONE_STRING_LENGTH]; - long daylightOffset; - long daylightOnOff; - LONG startDSTime; - LONG stopDSTime; - } Synchronized_Clock_T; - - /************************************************************************* - Desc: - *************************************************************************/ - typedef struct - { - char ** ppszArgV; - char * pszArgs; - char * pszThreadName; - int iArgC; - LoadDefStruct * moduleHandle; - } ARG_DATA; - - /************************************************************************* - Desc: - *************************************************************************/ - struct VolumeInformationStructure - { - LONG VolumeAllocationUnitSizeInBytes; - LONG VolumeSizeInAllocationUnits; - LONG VolumeSectorSize; - LONG AllocationUnitsUsed; - LONG AllocationUnitsFreelyAvailable; - LONG AllocationUnitsInDeletedFilesNotAvailable; - LONG AllocationUnitsInAvailableDeletedFiles; - LONG NumberOfPhysicalSegmentsInVolume; - LONG PhysicalSegmentSizeInAllocationUnits[64]; - }; - - /************************************************************************* - Desc: - *************************************************************************/ - struct ModifyStructure - { - BYTE *MModifyName; - LONG MFileAttributes; - LONG MFileAttributesMask; - WORD MCreateDate; - WORD MCreateTime; - LONG MOwnerID; - WORD MLastArchivedDate; - WORD MLastArchivedTime; - LONG MLastArchivedID; - WORD MLastUpdatedDate; - WORD MLastUpdatedTime; - LONG MLastUpdatedID; - WORD MLastAccessedDate; - WORD MInheritanceGrantMask; - WORD MInheritanceRevokeMask; - int MMaximumSpace; - LONG MLastUpdatedInSeconds; - }; - - /************************************************************************* - Desc: - *************************************************************************/ - typedef struct - { - FLMUINT32 time_low; - FLMUINT16 time_mid; - FLMUINT16 time_hi_and_version; - FLMBYTE clk_seq_hi_res; - FLMBYTE clk_seq_low; - FLMBYTE node[6]; - } NWGUID; - - /************************************************************************* - Desc: - *************************************************************************/ - typedef struct WSAData - { - WORD wVersion; - WORD wHighVersion; - char szDescription[ WSADESCRIPTION_LEN + 1]; - char szSystemStatus[ WSASYS_STATUS_LEN + 1]; - unsigned short iMaxSockets; - unsigned short iMaxUdpDg; - char * lpVendorInfo; - } WSADATA, * LPWSADATA; - - /************************************************************************* - Desc: - *************************************************************************/ - struct in_addr - { - union - { - struct - { - unsigned char s_b1; - unsigned char s_b2; - unsigned char s_b3; - unsigned char s_b4; - } S_un_b; - - struct - { - unsigned short s_w1; - unsigned short s_w2; - } S_un_w; - - unsigned long S_addr; - } S_un; - }; - - /************************************************************************* - Desc: - *************************************************************************/ - struct sockaddr_in - { - short sin_family; - unsigned short sin_port; - struct in_addr sin_addr; - char sin_zero[8]; - }; - - /************************************************************************* - Desc: - *************************************************************************/ - struct sockaddr - { - unsigned short sa_family; - char sa_data[14]; - }; - - /************************************************************************* - Desc: - *************************************************************************/ - struct hostent - { - char * h_name; - char ** h_aliases; - short h_addrtype; - short h_length; - char ** h_addr_list; - }; - - /************************************************************************* - Desc: - *************************************************************************/ - struct timeval - { - long tv_sec; - long tv_usec; - }; - - /************************************************************************* - Desc: - *************************************************************************/ - typedef struct fd_set - { - unsigned int fd_count; - SOCKET fd_array[ FD_SETSIZE]; - } fd_set; - - /************************************************************************* - Desc: - *************************************************************************/ - typedef struct _WSABUF - { - unsigned long len; - char * buf; - } WSABUF, * LPWSABUF; - - /************************************************************************* - Desc: - *************************************************************************/ - typedef struct - { - ULONG TokenRate; - ULONG TokenBucketSize; - ULONG PeakBandwidth; - ULONG Latency; - ULONG DelayVariation; - ULONG ServiceType; - ULONG MaxSduSize; - ULONG MinimumPolicedSize; - } FLOWSPEC, *PFLOWSPEC, * LPFLOWSPEC; - - /************************************************************************* - Desc: - *************************************************************************/ - typedef struct - { - FLOWSPEC SendingFlowspec; - FLOWSPEC ReceivingFlowspec; - WSABUF ProviderSpecific; - } QOS, * LPQOS; - - extern "C" FLMBYTE F_NW_Default_Volume_Name[]; - - extern "C" RCODE MapNWtoFlaimError( - LONG lResult, - RCODE defaultRc); - - extern "C" LONG FlaimToNWOpenFlags( - FLMUINT uiAccess, - FLMBOOL bDoDirectIo); - - extern "C" LONG GetCurrentClock( - clockAndStatus * dataPtr); - - extern "C" void GetSyncClockFields( - LONG bitMap, - Synchronized_Clock_T * aClock); - - extern "C" void kYieldThread( void); - - extern "C" int kGetThreadName( - FLMUINT32 ui32ThreadId, - char * szName, - int iBufSize); - - extern "C" void * kCreateThread( - BYTE * name, - void * (*StartAddress)(void *, void *), - void * StackAddressHigh, - LONG StackSize, - void * Argument); - - extern "C" int kSetThreadName( - void * ThreadHandle, - BYTE * buffer); - - extern "C" LONG kScheduleThread( - void * ThreadHandle); - - extern "C" ERROR kDelayThread( - UINT uiMilliseconds); - - extern "C" void * kCurrentThread( void); - - extern "C" int kDestroyThread( - void * ThreadHandle); - - extern "C" void kExitThread( - void * ExitStatus); - - extern "C" LONG kSetThreadLoadHandle( - void * ThreadHandle, - LONG nlmHandle); - - extern "C" LONG GetRunningProcess( void); - - extern "C" void KillMe( - LoadDefStruct * LoadRecord); - - extern "C" void NWYieldIfTime( void); - - extern "C" void CSetD( - LONG value, - void * address, - LONG numberOfDWords); - - extern "C" void CMovB( - void * src, - void * dst, - LONG numberOfBytes); - - extern "C" void * Alloc( - LONG numberOfBytes, - LONG lRTag); - - extern "C" void Free( - void * address); - - extern "C" LONG AllocateResourceTag( - LONG pvLoadRecord, - BYTE * pvResourceDescriptionString, - LONG ResourceSignature); - - extern "C" LONG ReturnResourceTag( - LONG RTag, - BYTE displayErrorsFlag); - - extern "C" LONG ConvertPathString( - LONG stationNumber, - BYTE base, - BYTE * modifierString, - LONG * volumeNumber, - LONG * pathBase, - BYTE * pathString, - LONG * pathCount); - - extern "C" LONG GetEntryFromPathStringBase( - LONG Station, - LONG Volume, - LONG PathBase, - BYTE * PathString, - LONG PathCount, - LONG SourceNameSpace, - LONG DesiredNameSpace, - struct DirectoryStructure ** Dir, - LONG * DirectoryNumber); - - extern "C" LONG NDSCreateStreamFile( - LONG Station, - LONG Task, - BYTE * fileName, - LONG CreateAttributes, - LONG * fileHandle, - LONG * DOSDirectoryBase); - - extern "C" LONG NDSOpenStreamFile( - LONG Station, - LONG Task, - BYTE * fileName, - LONG RequestedRights, - LONG * fileHandle, - LONG * DOSDirectoryBase); - - extern "C" LONG NDSDeleteStreamFile( - LONG Station, - LONG Task, - BYTE * fileName, - LONG * DOSDirectoryBase); - - extern "C" LONG EraseFile( - LONG Station, - LONG Task, - LONG Volume, - LONG PathBase, - BYTE * PathString, - LONG PathCount, - LONG NameSpace, - LONG MatchBits); - - extern "C" LONG RenameEntry( - LONG Station, - LONG Task, - LONG Volume, - LONG PathBase, - BYTE * PathString, - LONG PathCount, - LONG NameSpace, - LONG MatchBits, - BYTE SubdirectoryFlag, - LONG NewBase, - BYTE * NewString, - LONG NewCount, - LONG CompatabilityFlag, - BYTE AllowRenamesToMyselfFlag); - - extern "C" LONG OpenFile( - LONG Station, - LONG Task, - LONG Volume, - LONG PathBase, - BYTE * PathString, - LONG PathCount, - LONG NameSpace, - LONG MatchBits, - LONG RequestedRights, - BYTE DataStreamNumber, - LONG * Handle, - LONG * DirectoryNumber, - void ** DirectoryEntry); - - extern "C" LONG CreateFile( - LONG Station, - LONG Task, - LONG Volume, - LONG PathBase, - BYTE * PathString, - LONG PathCount, - LONG NameSpace, - LONG CreatedAttributes, - LONG FlagBits, - BYTE DataStreamNumber, - LONG * Handle, - LONG * DirectoryNumber, - void ** DirectoryEntry); - - extern "C" LONG CloseFile( - LONG station, - LONG task, - LONG handle); - - extern "C" LONG ReadFile( - LONG stationNumber, - LONG handle, - LONG startingOffset, - LONG bytesToRead, - LONG * actualBytesRead, - void * buffer); - - extern "C" LONG WriteFile( - LONG stationNumber, - LONG handle, - LONG startingOffset, - LONG bytesToWrite, - void * buffer); - - extern "C" LONG SetFileSize( - LONG station, - LONG handle, - LONG filesize, - LONG truncateflag); - - extern "C" LONG GetFileSize( - LONG stationNumber, - LONG handle, - LONG * fileSize); - - extern "C" LONG DirectReadFile( - LONG station, - LONG handle, - LONG startingsector, - LONG sectorcount, - BYTE * buffer); - - extern "C" LONG SwitchToDirectFileMode( - LONG station, - LONG handle); - - extern "C" LONG ReturnVolumeMappingInformation( - LONG volumenumber, - struct VolumeInformationStructure * volumeInformation); - - extern "C" LONG ExpandFileInContiguousBlocks( - LONG station, - LONG handle, - LONG fileblocknumber, - LONG numberofblocks, - LONG vblocknumber, - LONG segnumber); - - extern "C" LONG FreeLimboVolumeSpace( - LONG volumenumber, - LONG numberofblocks); - - extern "C" LONG DirectWriteFileNoWait( - LONG station, - LONG handle, - LONG startingsector, - LONG sectorcount, - BYTE * buffer, - void (*callbackroutine)(LONG, LONG, LONG), - LONG callbackparameter); - - extern "C" LONG DirectWriteFile( - LONG station, - LONG handle, - LONG startingsector, - LONG sectorcount, - BYTE * buffer); - - extern "C" LONG RevokeFileHandleRights( - LONG Station, - LONG Task, - LONG FileHandle, - LONG QueryFlag, - LONG removeRights, - LONG * newRights); - - extern "C" LONG ModifyDirectoryEntry( - LONG Station, - LONG Task, - LONG Volume, - LONG PathBase, - BYTE * PathString, - LONG PathCount, - LONG NameSpace, - LONG MatchBits, - LONG TargetNameSpace, - struct ModifyStructure * ModifyVector, - LONG ModifyBits, - LONG AllowWildCardsFlag); - - extern "C" LONG MapFileHandleToFCB( - LONG handle, - FCBType ** fcb); - - extern "C" LONG MapPathToDirectoryNumber( - LONG Station, - LONG Volume, - LONG PathBase, - BYTE * PathString, - LONG PathCount, - LONG NameSpace, - LONG * DirectoryNumber, - LONG * FileFlag); - - extern "C" LONG CreateDirectory( - LONG Station, - LONG Volume, - LONG PathBase, - BYTE * PathString, - LONG PathCount, - LONG NameSpace, - LONG DirectoryAccessMask, - LONG * ReturnedDirectoryNumber, - void ** ReturnedSubDir); - - extern "C" LONG DeleteDirectory( - LONG Station, - LONG Volume, - LONG PathBase, - BYTE * PathString, - LONG PathCount, - LONG NameSpace); - - extern "C" LONG DirectorySearch( - LONG Station, - LONG Volume, - LONG DirectoryNumber, - LONG NameSpace, - LONG StartEntryNumber, - BYTE * Pattern, - LONG MatchBits, - struct DirectoryStructure ** DirectoryEntry, - LONG * ReturnedDirectoryNumber); - - extern "C" LONG VMGetDirectoryEntry( - LONG volumeNumber, - LONG directoryEntry, - void * directoryEntryPointer); - - extern "C" LONG ImportPublicSymbol( - LONG moduleHandle, - BYTE * symbolName); - - extern "C" LONG UnImportPublicSymbol( - LONG moduleHandle, - BYTE * symbolName); - - extern "C" LONG ExportPublicSymbol( - LONG moduleHandle, - BYTE * symbolName, - LONG address); - - extern "C" void SynchronizeStart( void); - - extern "C" LONG CFindLoadModuleHandle( void *); - - extern "C" int atexit( - FLM_EXIT_FUNC fnExit); - - extern "C" LONG LoadModule( - void * screenID, - BYTE * fileName, - LONG loadOptions); - - extern "C" LONG UnloadModule( - void ** pScreenID, - const char * commandline); - - extern "C" int SGUIDCreate( - NWGUID * guidBfr); - - extern "C" void * GetSystemConsoleScreen( void); - - extern "C" LONG SizeOfAllocBlock( - void * AllocAddress); - - extern "C" SEMAPHORE kSemaphoreAlloc( - BYTE * pSemaName, - UINT SemaCount); - - extern "C" ERROR kSemaphoreFree( - SEMAPHORE SemaHandle); - - extern "C" ERROR kSemaphoreWait( - SEMAPHORE SemaHandle); - - extern "C" ERROR kSemaphoreTimedWait( - SEMAPHORE SemaHandle, - UINT MilliSecondTimeOut); - - extern "C" ERROR kSemaphoreSignal( - SEMAPHORE SemaHandle); - - extern "C" UINT kSemaphoreExamineCount( - SEMAPHORE SemaHandle); - - extern "C" MUTEX kMutexAlloc( - BYTE * MutexName); - - extern "C" ERROR kMutexFree( - MUTEX MutexHandle); - - extern "C" ERROR kMutexLock( - MUTEX MutexHandle); - - extern "C" ERROR kMutexUnlock( - MUTEX MutexHandle); - - extern "C" void CMoveFast( - void * src, - void * dst, - LONG numberOfBytes); - - extern "C" void EnterDebugger( void); - - extern "C" void GetClosestSymbol( - BYTE * szBuffer, - LONG udAddress); - - extern "C" LONG GetCurrentTime( void); - - extern "C" void ConvertTicksToSeconds( - LONG ticks, - LONG * seconds, - LONG * tenthsOfSeconds); - - extern "C" void ConvertSecondsToTicks( - LONG seconds, - LONG tenthsOfSeconds, - LONG * ticks); - - extern "C" LONG GetCacheBufferSize(void); - - extern "C" LONG GetOriginalNumberOfCacheBuffers(void); - - extern "C" LONG GetCurrentNumberOfCacheBuffers(void); - - extern "C" LONG GetNLMAllocMemoryCounts( - FLMUINT moduleHandle, - FLMUINT * freeBytes, - FLMUINT * freeNodes, - FLMUINT * allocatedBytes, - FLMUINT * allocatedNodes, - FLMUINT * totalMemory); - - FLMUINT f_getNLMHandle( void); - - extern "C" LONG atomic_xchg( - volatile LONG * address, - LONG value); - - extern "C" FLMINT32 nlm_AtomicIncrement( - volatile LONG * piTarget); - - extern "C" FLMINT32 nlm_AtomicDecrement( - volatile LONG * piTarget); - - #define nlm_AtomicExchange( piTarget, iValue) \ - ((FLMINT32)atomic_xchg( (volatile LONG *)(piTarget), (LONG)(iValue))) - - /************************************************************************* - Desc: - *************************************************************************/ - #if !defined( __MWERKS__) - #pragma aux nlm_AtomicIncrement parm [ecx]; - #pragma aux nlm_AtomicIncrement = \ - 0xB8 0x01 0x00 0x00 0x00 /* mov eax, 1 */ \ - 0xF0 0x0F 0xC1 0x01 /* lock xadd [ecx], eax */ \ - 0x40 /* inc eax */ \ - parm [ecx] \ - modify exact [eax]; - - #pragma aux nlm_AtomicDecrement parm [ecx]; - #pragma aux nlm_AtomicDecrement = \ - 0xB8 0xFF 0xFF 0xFF 0xFF /* mov eax, 0ffffffffh */ \ - 0xF0 0x0F 0xC1 0x01 /* lock xadd [ecx], eax */ \ - 0x48 /* dec eax */ \ - parm [ecx] \ - modify exact [eax]; - #endif - - /************************************************************************* - Desc: - *************************************************************************/ - #if defined( __MWERKS__) - FINLINE FLMINT32 nlm_AtomicIncrement( - volatile LONG * piTarget) - { - FLMINT32 i32Result; - - __asm - { - mov eax, 1 - mov ecx, piTarget - lock xadd [ecx], eax - inc eax - mov i32Result, eax - } - - return( i32Result); - } - #endif - - /************************************************************************* - Desc: - *************************************************************************/ - #if defined( __MWERKS__) - FINLINE FLMINT32 nlm_AtomicDecrement( - volatile LONG * piTarget) - { - FLMINT32 i32Result; - - __asm - { - mov eax, 0ffffffffh - mov ecx, piTarget - lock xadd [ecx], eax - dec eax - mov i32Result, eax - } - - return( i32Result); - } - #endif - - /************************************************************************* - Desc: - *************************************************************************/ - #define FD_CLR(fd, set) do { \ - unsigned int __i; \ - for (__i = 0; __i < ((fd_set *)(set))->fd_count ; __i++) { \ - if (((fd_set *)(set))->fd_array[__i] == fd) { \ - while (__i < ((fd_set *)(set))->fd_count-1) { \ - ((fd_set *)(set))->fd_array[__i] = \ - ((fd_set *)(set))->fd_array[__i+1]; \ - __i++; \ - } \ - ((fd_set *)(set))->fd_count--; \ - break; \ - } \ - } \ - } while(0) - - /************************************************************************* - Desc: - *************************************************************************/ - #define FD_SET(fd, set) do { \ - unsigned int __i; \ - for (__i = 0; __i < ((fd_set *)(set))->fd_count; __i++) { \ - if (((fd_set *)(set))->fd_array[__i] == (fd)) { \ - break; \ - } \ - } \ - if (__i == ((fd_set *)(set))->fd_count) { \ - if (((fd_set *)(set))->fd_count < FD_SETSIZE) { \ - ((fd_set *)(set))->fd_array[__i] = (fd); \ - ((fd_set *)(set))->fd_count++; \ - } \ - } \ - } while(0) - - #define FD_ZERO(set) \ - (((fd_set *)(set))->fd_count=0) - - #define FD_ISSET(fd, set) \ - __WSAFDIsSet((SOCKET)(fd), (fd_set *)(set)) - - #define MAKEWORD(low,high) \ - ((WORD)(((BYTE)(low)) | ((WORD)((BYTE)(high))) << 8)) - - extern "C" int WSAStartup( - unsigned short wVersionRequested, - LPWSADATA lpWSAData); - - extern "C" int WSACleanup( void); - - extern "C" int gethostname( - char * name, - int namelen); - - extern "C" struct hostent * gethostbyname( - const char * name); - - extern "C" struct hostent * gethostbyaddr( - const char * addr, - int len, - int type); - - extern "C" char * inet_ntoa( - struct in_addr in); - - extern "C" int select( - int nfds, - fd_set * readfds, - fd_set * writefds, - fd_set * exceptfds, - const struct timeval * timeout); - - extern "C" int __WSAFDIsSet( SOCKET, fd_set *); - - extern "C" int recv( - SOCKET s, - char * buf, - int len, - int flags); - - extern "C" int send( - SOCKET s, - const char * buf, - int len, - int flags); - - extern "C" int setsockopt( - SOCKET s, - int level, - int optname, - const char * optval, - int optlen); - - extern "C" int closesocket( - SOCKET s); - - extern "C" SOCKET socket( - int af, - int type, - int protocol); - - extern "C" int bind( - SOCKET s, - const struct sockaddr * name, - int namelen); - - extern "C" int listen( - SOCKET s, - int backlog); - - extern "C" unsigned long inet_addr( - const char * cp); - - extern "C" unsigned short htons( - unsigned short hostshort); - - extern "C" unsigned long htonl( - unsigned long hostlong); - - extern "C" int WSAGetLastError( void); - - extern "C" int WSAConnect( - SOCKET s, - const struct sockaddr * name, - int namelen, - LPWSABUF lpCallerData, - LPWSABUF lpCalleeData, - LPQOS lpSQOS, - LPQOS lpGQOS); - - extern "C" SOCKET WSAAccept( - SOCKET s, - struct sockaddr * addr, - int * addrlen, - void * lpfnCondition, - DWORD dwCallbackData); - - #define f_argsize(x) \ - ((sizeof(x)+sizeof(int)-1) & ~(sizeof(int)-1)) - - #define f_va_start(ap, parmN) \ - ((void)((ap) = (unsigned long)&(parmN) + f_argsize(parmN))) - - #define f_va_arg(ap, type) \ - (*(type *)(((ap) += f_argsize(type)) - (f_argsize(type)))) - - #define f_va_end(ap) \ - ((void)0) - - /************************************************************************* - Desc: - *************************************************************************/ - FINLINE char * f_strcpy( - char * d, - const char * s) - { - while ((*d++ = *s++) != 0); - return( d); - } - - /************************************************************************* - Desc: - *************************************************************************/ - FINLINE unsigned f_strlen( - const char * s) - { - const char * b = s; - - while (*s) - { - s++; - } - - return( s - b); - } - - /************************************************************************* - Desc: - *************************************************************************/ - FINLINE int f_strcmp( - const char * s1, - const char * s2) - { - while( *s1 == *s2 && *s1) - { - s1++; - s2++; - } - return( (int)(*s1 - *s2)); - } - - /************************************************************************* - Desc: - *************************************************************************/ - FINLINE char * f_strncpy( - char * dest, - const char * src, - unsigned n) - { - while( n) - { - *dest++ = *src; - if( *src) - { - src++; - } - n--; - } - - *dest = 0; - return( dest); - } - - /************************************************************************* - Desc: - *************************************************************************/ - FINLINE int f_strncmp( - const char * s1, - const char * s2, - unsigned n) - { - while( *s1 == *s2 && *s1 && n) - { - s1++; - s2++; - n--; - } - - if( n) - { - return( (*s1 - *s2)); - } - - return( (int)0); - } - - /************************************************************************* - Desc: - *************************************************************************/ - FINLINE char * f_strcat( - char * dst, - const char * src) - { - const char * p = src; - char * q = dst; - - while (*q++); - q--; - while( (*q++ = *p++) != 0); - - return(dst); - } - - /************************************************************************* - Desc: - *************************************************************************/ - FINLINE char * f_strncat( - char * dst , - const char * src, - unsigned n) - { - const char * p = src; - char * q = dst; - - while (*q++); - - q--; n++; - - while( --n) - { - if( (*q++ = *p++) == 0) - { - q--; - break; - } - } - - *q = 0; - return( dst); - } - - char * f_strstr( - const char * pszStr1, - const char * pszStr2); - - FLMINT f_stricmp( - const char * pszStr1, - const char * pszStr2); - - FLMINT f_strnicmp( - const char * pszStr1, - const char * pszStr2, - FLMINT iLen); - - char * f_strupr( - char * pszStr); - - FLMINT f_memcmp( - const void * pvMem1, - const void * pvMem2, - FLMUINT uiSize); - - #define f_memcpy( dest, src, size) \ - CMoveFast( (void *)(src), (void *)(dest), size) - - void * f_memset( - void * pvMem, - FLMBYTE ucByte, - FLMUINT uiSize); - - #define f_memset( m, c, size) \ - f_memset( (void *)(m), c, size) - - void * f_memmove( - void * pvDest, - const void * pvSrc, - FLMUINT uiSize); - - /************************************************************************* - Desc: - *************************************************************************/ - FINLINE RCODE f_mutexCreate( - F_MUTEX * phMutex) - { - if( (*phMutex = (F_MUTEX)kMutexAlloc( (BYTE *)"NOVDB")) == F_MUTEX_NULL) - { - return( RC_SET( FERR_MEM)); - } - - return( FERR_OK); - } - - /************************************************************************* - Desc: - *************************************************************************/ - FINLINE void f_mutexDestroy( - F_MUTEX * phMutex) - { - if (*phMutex != F_MUTEX_NULL) - { - (void)kMutexFree( (MUTEX)(*phMutex)); - *phMutex = F_MUTEX_NULL; - } - } - - /************************************************************************* - Desc: - *************************************************************************/ - FINLINE void f_mutexLock( - F_MUTEX hMutex) - { - (void)kMutexLock( (MUTEX)hMutex); - } - - /************************************************************************* - Desc: - *************************************************************************/ - FINLINE void f_mutexUnlock( - F_MUTEX hMutex) - { - (void)kMutexUnlock( (MUTEX)hMutex); - } - - /************************************************************************* - Desc: - *************************************************************************/ - FINLINE RCODE f_semCreate( - F_SEM * phSem) - { - if( (*phSem = (F_SEM)kSemaphoreAlloc( (BYTE *)"NOVDB", 0)) == F_SEM_NULL) - { - return( RC_SET( FERR_MEM)); - } - - return( FERR_OK); - } - - /************************************************************************* - Desc: - *************************************************************************/ - FINLINE void f_semDestroy( - F_SEM * phSem) - { - if (*phSem != F_SEM_NULL) - { - (void)kSemaphoreFree( (SEMAPHORE)(*phSem)); - *phSem = F_SEM_NULL; - } - } - - /************************************************************************* - Desc: - *************************************************************************/ - FINLINE RCODE f_semWait( - F_SEM hSem, - FLMUINT uiTimeout) - { - RCODE rc = FERR_OK; - - if( uiTimeout == F_SEM_WAITFOREVER) - { - if( kSemaphoreWait( (SEMAPHORE)hSem) != 0) - { - rc = RC_SET( FERR_MUTEX_UNABLE_TO_LOCK); - } - } - else - { - if( kSemaphoreTimedWait( (SEMAPHORE)hSem, (UINT)uiTimeout) != 0) - { - rc = RC_SET( FERR_MUTEX_UNABLE_TO_LOCK); - } - } - - return( rc); - } - - /************************************************************************* - Desc: - *************************************************************************/ - FINLINE void f_semSignal( - F_SEM hSem) - { - (void)kSemaphoreSignal( (SEMAPHORE)hSem); - } - -#pragma pack(pop) -#endif diff --git a/flaim/src/ftknsem.cpp b/flaim/src/ftknsem.cpp deleted file mode 100644 index 1fc9db5..0000000 --- a/flaim/src/ftknsem.cpp +++ /dev/null @@ -1,354 +0,0 @@ -//------------------------------------------------------------------------- -// Desc: Cross platform toolkit for named semaphores. -// Tabs: 3 -// -// Copyright (c) 2001,2003,2005-2006 Novell, Inc. All Rights Reserved. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of version 2 of the GNU General Public -// License as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, contact Novell, Inc. -// -// To contact Novell about this file by physical or electronic mail, -// you may find current contact information at www.novell.com -// -// $Id: ftknsem.cpp 12330 2006-01-23 10:07:04 -0700 (Mon, 23 Jan 2006) ahodgkinson $ -//------------------------------------------------------------------------- - -#include "flaimsys.h" - -#if defined( FLM_WIN) - -/**************************************************************************** -Desc: create or open a named semaphore (WIN implementation) -****************************************************************************/ -F_NamedSemaphore::F_NamedSemaphore( - const char * pszName, - FLMUINT uiMaxCount, - eNamedSemFlags eFlags) : m_hSem( F_SEM_NULL), m_bInitialized( FALSE) - -{ - HANDLE hTemp; - - hTemp = CreateSemaphore (NULL, uiMaxCount, uiMaxCount, pszName); - - // Check to see if the create failed, or if the semaphore already existed - // but we asked to create a new one... - - if( (hTemp == NULL) || - ((eFlags == OpenOnly) && (GetLastError() == ERROR_ALREADY_EXISTS)) ) - { - goto Exit; - } - - // If the semaphore already exists, then create will return a handle to it. - // but will also set the error code to ERROR_ALREADY_EXISTS. This only - // matters if we've set the eFlags to OpenOnly. Otherwise, we'll just - // reset the error to success ... - - SetLastError( 0); - - m_hSem = hTemp; - m_bInitialized = TRUE; - -Exit: - - if( !m_bInitialized) - { - CloseHandle( hTemp); - m_hSem = NULL; - } -} - -/**************************************************************************** -Desc: Named Semaphore destructor (WIN implementation) -****************************************************************************/ -F_NamedSemaphore::~F_NamedSemaphore() -{ - if( m_bInitialized) - { - CloseHandle( m_hSem); - } -} - -/**************************************************************************** -Desc: -****************************************************************************/ -RCODE F_NamedSemaphore::wait() -{ - DWORD udError; - - if( !m_bInitialized) - { - return( RC_SET( FERR_NAMED_SEMAPHORE_ERR)); - } - - udError = WaitForSingleObject( m_hSem, INFINITE); - - return( (udError == WAIT_OBJECT_0) - ? FERR_OK - : MapWinErrorToFlaim(udError, FERR_NAMED_SEMAPHORE_ERR) ); -} - -/**************************************************************************** -Desc: -****************************************************************************/ -RCODE F_NamedSemaphore::signal( - FLMUINT uiCount) -{ - - RCODE rc = FERR_OK; - - if( !m_bInitialized) - { - return( RC_SET( FERR_NAMED_SEMAPHORE_ERR)); - } - - if( !ReleaseSemaphore( m_hSem, uiCount, NULL)) - { - rc = MapWinErrorToFlaim(GetLastError(), FERR_NAMED_SEMAPHORE_ERR); - } - - return( rc); -} - -/**************************************************************************** -Desc: Remove the semaphore from memory - -Note: Several objects may actually refer to the same semaphore. This - function only needs to be called once per semaphore, not once per - object. Once this function has been called, attempts by other - objects to reference this semaphore could result in errors or other - unplesantness. This is really only needed on UNIX and Netware; Win - handles this sort of thing automatically. -****************************************************************************/ -RCODE F_NamedSemaphore::destroy( void) -{ - // On Windows, semphore objects are automatically destroyed after the - // last handle has been closed. All this function does then is - // close the handle, and set m_bInitialized to false. This effectively - // keeps the current process from accessing the semaphore, but other - // processes are still able to use it... - - CloseHandle( m_hSem); - m_bInitialized = FALSE; - return( FERR_OK); -} - -#elif defined( FLM_UNIX) - -#include -#include - -/**************************************************************************** -Desc: create or open a named semaphore (Unix implementation) -****************************************************************************/ -F_NamedSemaphore::F_NamedSemaphore( - const char * pszName, - FLMUINT uiMaxCount, - eNamedSemFlags eFlags) : m_hSem( 0), m_bInitialized( FALSE) -{ - FLMBOOL bSemExists; - struct sembuf sops; - - // This switch is just for error checking. These three cases are handled by - // the logic below, but if eFlags is something else, we're in trouble... - switch (eFlags) - { - case OpenOnly: - case CreateOnly: - case OpenOrCreate: - break; - default: - flmAssert( 0); - } - - // Check to see if the semaphore already exists... - - if( (m_hSem = semget( NameToUnixKey( pszName), 1, 0666)) != -1) - { - //It doesn't... - - bSemExists = true; - - //If we were supposed to create a new semaphore, then fail... - - if( eFlags == CreateOnly) - { - goto Exit; - } - } - else - { - bSemExists = false; - - // Now, if the OpenOnly flag was set, we've got a problem... - - if (eFlags == OpenOnly) - { - goto Exit; - } - else - { - if( (m_hSem = semget (NameToUnixKey(pszName), 1, - IPC_CREAT | IPC_EXCL | 0666)) == -1) - { - goto Exit; - } - } - } - - // If we created a new semaphore, then we want to initialize it's value to - // uiMaxCount. If we just opened an existing one, then we want to leave - // it alone... - - if( !bSemExists) - { - sops.sem_num = 0; - sops.sem_op = (unsigned)uiMaxCount; - sops.sem_flg = 0; - - if( semop( m_hSem, &sops, 1) == -1) - { - goto Exit; - } - } - - m_bInitialized = TRUE; - -Exit: - - return; -} - -/**************************************************************************** -Desc: Named Semaphore destructor (Unix implementation) -****************************************************************************/ -F_NamedSemaphore::~F_NamedSemaphore() -{ -} - -/**************************************************************************** -Desc: -****************************************************************************/ -RCODE F_NamedSemaphore::wait() -{ - RCODE rc = FERR_OK; - struct sembuf sops; - - sops.sem_num = 0; - sops.sem_op = -1; - sops.sem_flg = 0; - - if( semop( m_hSem, &sops, 1) == -1) - { - rc = MapErrnoToFlaimErr( errno, FERR_NAMED_SEMAPHORE_ERR); - } - - return( rc); -} - -/**************************************************************************** -Desc: -****************************************************************************/ -RCODE F_NamedSemaphore::signal( - FLMUINT uiCount) -{ - RCODE rc = FERR_OK; - struct sembuf sops; - - sops.sem_num = 0; - sops.sem_op = 1; - sops.sem_flg = 0; - - while( uiCount--) - { - if( semop( m_hSem, &sops, 1) == -1) - { - rc = MapErrnoToFlaimErr( errno, FERR_NAMED_SEMAPHORE_ERR); - goto Exit; - } - } - -Exit: - - return( rc); -} - -/**************************************************************************** -Desc: Remove the semaphore from memory (Unix implementation) - -Note: Several objects may actually refer to the same semaphore. This - function only needs to be called once per semaphore, not once per - object. Once this function has been called, attempts by other - objects to reference this semaphore could result in errors or other - unplesantness. This is really only needed on UNIX and Netware; WIN - handles this sort of thing automatically. -****************************************************************************/ -RCODE F_NamedSemaphore::destroy( void) -{ - RCODE rc = FERR_OK; - - // Call semctl() to remove the semaphore. If any other processes are - // waiting on this semaphore, the wait() will fail. - - if( semctl( m_hSem, 0, IPC_RMID, NULL) == -1) - { - rc = MapErrnoToFlaimErr( errno, FERR_NAMED_SEMAPHORE_ERR); - } - - return( rc); -} - -/**************************************************************************** -Desc: A private function that converts a string into a 32 bit - key value (Unix only) -****************************************************************************/ -FLMUINT32 F_NamedSemaphore::NameToUnixKey( - const char * pszName) -{ - FLMBYTE szLastInt[ 4] = { 0, 0, 0, 0}; - FLMUINT32 * pui32Current; - FLMUINT32 ui32Sum = 0; - FLMUINT uiTemp = 0; - FLMUINT uiLoop; - - // Basically, we're going to divide the name up into 4 character groups, - // treat each of those groups as an unsigned int and add them all together. - // For the last group - since it has a 75% chance of not being 4 bytes - - // we add 0's to the end until it is 4 bytes. - - for( uiLoop = 0; (uiLoop + 3) < f_strlen( pszName); uiLoop += 4) - { - pui32Current = (FLMUINT32 *)&pszName[ uiLoop]; - ui32Sum += *pui32Current; - } - - // The prev loop took care of most of the string, but we have at most - // three chars left in pszName that need to be added to ui32Sum... - - while( uiLoop < f_strlen( pszName)) - { - szLastInt[ uiTemp] = pszName[ uiLoop]; - uiLoop++; - uiTemp++; - } - - pui32Current = (FLMUINT32 *)szLastInt; - ui32Sum += *pui32Current; - - return( ui32Sum); -} - -#elif defined( FLM_NLM) - FLMUINT uiFTKNSEM_Dummy; -#else - #error "Unsupported Platform" -#endif diff --git a/flaim/src/ftknsem.h b/flaim/src/ftknsem.h deleted file mode 100644 index 2aecd4b..0000000 --- a/flaim/src/ftknsem.h +++ /dev/null @@ -1,97 +0,0 @@ -//------------------------------------------------------------------------- -// Desc: Cross-platform toolkit for named semaphores - definitions. -// Tabs: 3 -// -// Copyright (c) 2001-2006 Novell, Inc. All Rights Reserved. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of version 2 of the GNU General Public -// License as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, contact Novell, Inc. -// -// To contact Novell about this file by physical or electronic mail, -// you may find current contact information at www.novell.com -// -// $Id: ftknsem.h 12329 2006-01-20 17:49:30 -0700 (Fri, 20 Jan 2006) ahodgkinson $ -//------------------------------------------------------------------------- - -// Named semaphores are different from regular semaphores in that they're -// designed to control access to a resource in use by multiple processes. -// Regular semaphores might actually do this (depending on the platform) but -// without a name for each semaphore, there's no way for one process to -// signal the semaphore created by another process... - -// This code exists primarily because of the need to coordinate the actions -// of DS and the HTTPCTL utility on Windows and Unix. (Things are done -// differently under Netware.) I never could get it to work properly under -// Netware, and since it's not needed there, I've commented all of the -// Netware stuff out. The problem was so much that I couldn't get it -// to work, but that if the named semaphore was deleted at the wrong time, -// programs using it would cause errors, or worse, crash the system. To -// make matters worse, I couldn't figure out a way to guarentee that the -// semaphore wouldn't be deleted at the wrong time. In light of all this, -// I figured it was best if this class simply didn't exist on Netware. - -#ifndef FTKNSEM_H -#define FTKNSEM_H - -#include "fpackon.h" -// IMPORTANT NOTE: No other include files should follow this one except -// for fpackoff.h - -enum eNamedSemFlags { OpenOnly, CreateOnly, OpenOrCreate }; - -#if defined( FLM_WIN) - typedef HANDLE NAMEDSEMHANDLE; -#elif defined( FLM_UNIX) - typedef int NAMEDSEMHANDLE; -#elif defined( FLM_NLM) -#else - #error "Unsupported Platform" -#endif - -#if defined( FLM_WIN) || defined( FLM_UNIX) -class F_NamedSemaphore : public F_Base -{ -public: - F_NamedSemaphore( - const char * pszName, - FLMUINT uiMaxCount = 1, - eNamedSemFlags eFlags = OpenOrCreate); - - virtual ~F_NamedSemaphore(); - - RCODE wait( void); - - RCODE signal( - FLMUINT uiCount = 1); - - RCODE destroy( void); - - FINLINE FLMBOOL isInitialized( void) - { - return m_bInitialized; - } - -private: - -#if defined( FLM_UNIX) - FLMUINT32 NameToUnixKey( - const char * pszName); -#endif - - NAMEDSEMHANDLE m_hSem; - FLMBOOL m_bInitialized; -}; -#endif - -#include "fpackoff.h" - -#endif // FTKNSEM_H diff --git a/flaim/src/ftkpath.cpp b/flaim/src/ftkpath.cpp deleted file mode 100644 index 9c817cd..0000000 --- a/flaim/src/ftkpath.cpp +++ /dev/null @@ -1,777 +0,0 @@ -//------------------------------------------------------------------------- -// Desc: File name/path parsing and building. -// Tabs: 3 -// -// Copyright (c) 2000-2006 Novell, Inc. All Rights Reserved. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of version 2 of the GNU General Public -// License as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, contact Novell, Inc. -// -// To contact Novell about this file by physical or electronic mail, -// you may find current contact information at www.novell.com -// -// $Id: ftkpath.cpp 12329 2006-01-20 17:49:30 -0700 (Fri, 20 Jan 2006) ahodgkinson $ -//------------------------------------------------------------------------- - -#include "flaimsys.h" - -FSTATIC FLMBOOL f_canReducePath( - const char * pszSource); - -FSTATIC char * f_findFileNameStart( - const char * pszPath); - -FSTATIC char * f_getPathComponent( - char ** ppszPath, - FLMUINT * puiEndChar); - -/**************************************************************************** -Desc: Returns TRUE if character is a "slash" separator -****************************************************************************/ -FINLINE FLMBOOL f_isSlashSeparator( - FLMBYTE ucChar) -{ -#ifdef FLM_UNIX - return( ucChar == '/' ? TRUE : FALSE); -#else - return( ucChar == '/' || ucChar == '\\' ? TRUE : FALSE); -#endif -} - -/**************************************************************************** -Desc: Return a pointer to the next path component in ppszPath. -****************************************************************************/ -FSTATIC char * f_getPathComponent( - char ** ppszPath, - FLMUINT * puiEndChar) -{ - char * pszComponent; - char * pszEnd; - - pszComponent = pszEnd = *ppszPath; - - if( f_isSlashSeparator( *pszEnd)) - { - // handle the condition of sys:\system the colon would have terminated - // the previous token, to pComponent would now be pointing at the '\'. - // We need to move past the '\' to find the next token. - - pszEnd++; - } - - // Find the end of the path component - - while (*pszEnd) - { - if (f_isSlashSeparator( *pszEnd) -#ifndef FLM_UNIX - || *pszEnd == ':' -#endif - ) - { - break; - } - pszEnd++; - } - - if (*pszEnd) - { - - // A delimiter was found, assume that there is another path component - // after this one. - // Return a pointer to the beginning of the next path component - - *ppszPath = pszEnd + 1; - *puiEndChar = *pszEnd; - - // NULL terminate the path component - - *pszEnd = 0; - } - else - { - - // There is no "next path component" so return a pointer to the - // NULL-terminator - - *ppszPath = pszEnd; - *puiEndChar = 0; - } - - // Return the path component - - return( pszComponent); -} - -/**************************************************************************** -Desc: Split the path into its components -Output: - pServer - pointer to a buffer to hold the server name - pVolume - pointer to a buffer to hold the volume name - pDirPath - pointer to a buffer to hold the path - pFileName pointer to a buffer to hold the filename - - All of the output parameters are optional. If you do not want one - of the components, simply give a NULL pointer. - -Note: if the input path has no file name, d:\dir_1 for example, then - pass a NULL pointer for pFileName. Otherwise dir_1 will be returned - as pFileName. - - The server name may be ommitted in the input path: - sys:\system\autoexec.ncf - - UNC paths of the form: - \\server-name\volume-name\dir_1\dir_2\file.ext - are supported. - - DOS paths of the form: - d:\dir_1\dir_2\file.ext - are also supported. - -Example: - Given this input: orm-prod48/sys:\system\autoexec.ncf - The output would be: - pServer = "orm-prod48" - pVolume = "sys:" - pDirPath = "\system" - pFileName "autoexec.ncf" -****************************************************************************/ -FLMEXP void FLMAPI f_pathParse( - const char * pszInputPath, - char * pszServer, - char * pszVolume, - char * pszDirPath, - char * pszFileName) -{ - char szInput[ F_PATH_MAX_SIZE]; - char * pszNext; - char * pszColon; - char * pszComponent; - FLMUINT uiEndChar; - FLMBOOL bUNC = FALSE; - - // Initialize return buffers - - if (pszServer) - { - *pszServer = 0; - } - - if (pszVolume) - { - *pszVolume = 0; - } - - if (pszDirPath) - { - *pszDirPath = 0; - } - - if (pszFileName) - { - // Get the file name - - *pszFileName = 0; - f_pathReduce( pszInputPath, szInput, pszFileName); - } - else - { - f_strcpy( szInput, pszInputPath); - } - - // Split out the rest of the components - - pszComponent = &szInput [0]; - - // Is this a UNC path? - - if( szInput[0] == '\\' && szInput[1] == '\\') - { - // Yes, assume a UNC path - - pszComponent += 2; - bUNC = TRUE; - } - - pszNext = pszColon = pszComponent; - - // Is there a ':' in the szInput path? - - while (*pszColon && *pszColon != ':') - { - pszColon++; - } - if (*pszColon || bUNC) - { - - // Yes, assume there is a volume in the path - - pszComponent = f_getPathComponent( &pszNext, &uiEndChar); - if (uiEndChar != ':') - { - // Assume that this component is the server - - if (pszServer) - { - f_strcpy( pszServer, pszComponent); - } - - // Get the next component - - pszComponent = f_getPathComponent( &pszNext, &uiEndChar); - } - - // Assume that this component is the volume - - if (pszVolume) - { - char * pszSrc = pszComponent; - char * pszDst = pszVolume; - - while (*pszSrc) - { - *pszDst++ = *pszSrc++; - } - *pszDst++ = ':'; - *pszDst = 0; - } - - // For UNC paths, the leading '\' of the path is set to 0 by - // f_getPathComponent. This code restores the leading '\'. - - if (f_isSlashSeparator( (FLMBYTE)uiEndChar)) - { - *(--pszNext) = (FLMBYTE)uiEndChar; - } - } - - // Assume that all that is left of the input is the path - - if (pszDirPath) - { - f_strcpy( pszDirPath, pszNext); - } -} - -/**************************************************************************** -Desc: Will determine whether any format of (UNC, drive based, NetWare - UNC) path can be reduced any further. -****************************************************************************/ -FSTATIC FLMBOOL f_canReducePath( - const char * pszSource) -{ -#if defined FLM_UNIX - F_UNREFERENCED_PARM( pszSource); - return( TRUE); -#else - FLMBOOL bCanReduce; - const char * pszTemp = pszSource; - - // Determine whether the passed path is UNC or not - // (UNC format is: \\FileServer\Volume\Path). - - if (f_strncmp( "\\\\", pszSource, 2 ) == 0) - { - FLMUINT uiSlashCount = 0; - - pszTemp += 2; - - // Search forward for at least two slash separators - // If we find at least two, the path can be reduced. - - bCanReduce = FALSE; - while (*pszTemp) - { - pszTemp++; - if (f_isSlashSeparator( *pszTemp)) - { - ++uiSlashCount; - if (uiSlashCount == 2) - { - bCanReduce = TRUE; - break; - } - } - } - } - else - { - bCanReduce = TRUE; - - // Search forward for the colon. - - while (*pszTemp) - { - if (*pszTemp == ':') - { - - // If nothing comes after the colon, - // we can't reduce any more. - - if (*(pszTemp + 1) == 0) - { - bCanReduce = FALSE; - } - break; - } - pszTemp++; - } - } - - return( bCanReduce); -#endif -} - -/**************************************************************************** -Desc: Return pointer to start of filename part of path. - Search for the last slash separator. -****************************************************************************/ -FSTATIC char * f_findFileNameStart( - const char * pszPath) -{ - const char * pszFileNameStart; - - pszFileNameStart = pszPath; - - while (*pszPath) - { - if (f_isSlashSeparator( *pszPath)) - { - pszFileNameStart = pszPath + 1; - } - pszPath++; - } - - return( (char *)pszFileNameStart); -} - -/**************************************************************************** -Desc: This function will strip off the filename or trailing - directory of a path. The stripped component of the path will - be placed into the area pointed at by string. The source - path will not be modified except to strip off trailing - slashes. The dest path will contain the remainder of the - stripped path. A stripped path can be processed repeatedly - by this function until there is no more path to reduce. If - string is set to NULL, then the copying of the stripped - portion of the path will be bypassed by the function. - -Notes: This function handles drive based, UNC, Netware, and UNIX type - paths. -****************************************************************************/ -FLMEXP RCODE FLMAPI f_pathReduce( - const char * pszPath, - char * pszDir, - char * pszPathComponent) -{ - RCODE rc = FERR_OK; - const char * pszFileNameStart; - char szLocalPath[ F_PATH_MAX_SIZE]; - FLMUINT uiLen; - - // Check for valid path pointers - - if( !pszPath) - { - rc = RC_SET( FERR_INVALID_PARM); - goto Exit; - } - - if ((uiLen = f_strlen( pszPath)) == 0) - { - rc = RC_SET( FERR_IO_AT_PATH_ROOT); - goto Exit; - } - - // Trim out any trailing slash separators - - if( f_isSlashSeparator( pszPath [uiLen - 1])) - { - f_strcpy( szLocalPath, pszPath); - - while( f_isSlashSeparator( szLocalPath[ uiLen - 1])) - { - szLocalPath[ --uiLen] = 0; - if( !uiLen) - { - rc = RC_SET( FERR_IO_AT_PATH_ROOT); - goto Exit; - } - } - - pszPath = szLocalPath; - } - - if( f_canReducePath( pszPath)) - { - // Search for a slash or beginning of path - - pszFileNameStart = f_findFileNameStart( pszPath); - - // Copy the sliced portion of the path if requested by caller - - if( pszPathComponent) - { - f_strcpy( pszPathComponent, pszFileNameStart); - } - - // Copy the reduced source path to the dir path - - if( pszDir) - { - if (pszFileNameStart > pszPath) - { - uiLen = (FLMUINT)(pszFileNameStart - pszPath); - f_memcpy( pszDir, pszPath, uiLen); - - if (uiLen >= 2 && f_isSlashSeparator( pszDir [uiLen - 1]) -#ifndef FLM_UNIX - && pszDir [uiLen - 2] != ':' -#endif - ) - { - // Trim off the trailing path separator - - pszDir [uiLen - 1] = 0; - } - else - { - pszDir [uiLen] = 0; - } - } - else - { - *pszDir = 0; - } - } - } - else - { - // We've found the drive id or server\volume specifier. - - if (pszPathComponent) - { - f_strcpy( pszPathComponent, pszPath); - } - - if( pszDir) - { - *pszDir = 0; - } - } - -Exit: - - return( rc); -} - -/**************************************************************************** -Desc: Append a component to a path name. -****************************************************************************/ -FLMEXP RCODE FLMAPI f_pathAppend( - char * pszPath, - const char * pszPathComponent) -{ - // Don't put a slash separator if pszPath is empty - - if( *pszPath) - { - FLMUINT uiStrLen = f_strlen( pszPath); - char * pszEnd = pszPath + uiStrLen - 1; - - if (!f_isSlashSeparator( *pszEnd)) - { - - // Check for maximum path size - 2 is for slash separator - // and null byte. - - if (uiStrLen + 2 + f_strlen( pszPathComponent) > F_PATH_MAX_SIZE) - { - return( RC_SET( FERR_IO_PATH_TOO_LONG)); - } - - pszEnd++; -#ifdef FLM_UNIX - *pszEnd = '/'; -#else - *pszEnd = '\\'; -#endif - } - else - { - - // Check for maximum path size +1 is for null byte. - - if (uiStrLen + 1 + f_strlen( pszPathComponent) > F_PATH_MAX_SIZE) - { - return( RC_SET( FERR_IO_PATH_TOO_LONG)); - } - } - - f_strcpy( pszEnd + 1, pszPathComponent); - } - else - { - f_strcpy( pszPath, pszPathComponent); - } - - return( FERR_OK); -} - -/**************************************************************************** -Desc: Convert an PATH into a fully qualified, storable C string - reference to a file or directory. -****************************************************************************/ -FLMEXP RCODE FLMAPI f_pathToStorageString( - const char * pszPath, - char * pszStorageString) -{ -#ifdef FLM_WIN - char * pszNamePart; - - if( GetFullPathName( (LPCSTR)pszPath, (DWORD)F_PATH_MAX_SIZE - 1, - (LPSTR)pszStorageString, (LPSTR *)&pszNamePart) != 0) - { - - // GetFullPathName does not convert to upper case, but we need to - // because case does not matter on windows. - - while (*pszStorageString) - { - *pszStorageString = f_toupper( *pszStorageString); - pszStorageString++; - } - } - else - { - // Convert to upper case. - - while (*pszPath) - { - *pszStorageString++ = f_toupper( *pszPath); - pszPath++; - } - *pszStorageString = 0; - } - return FERR_OK; -#elif !defined( FLM_UNIX) - - // Convert to upper case. - - while (*pszPath) - { - *pszStorageString++ = f_toupper( *pszPath); - pszPath++; - } - *pszStorageString = 0; - return FERR_OK; -#else - - RCODE rc = FERR_OK; - char szFile[ F_PATH_MAX_SIZE]; - char szDir[ F_PATH_MAX_SIZE]; - char * pszRealPath = NULL; - - if (RC_BAD( rc = f_pathReduce( pszPath, szDir, szFile))) - { - goto Exit; - } - - if (!szDir [0]) - { - szDir [0] = '.'; - szDir [1] = '\0'; - } - - if (RC_BAD( rc = f_alloc( (FLMUINT)PATH_MAX, &pszRealPath))) - { - goto Exit; - } - - if (!realpath( szDir, pszRealPath)) - { - rc = MapErrnoToFlaimErr( errno, FERR_PARSING_FILE_NAME); - goto Exit; - } - - if (f_strlen( pszRealPath) >= F_PATH_MAX_SIZE) - { - rc = RC_SET( FERR_IO_PATH_TOO_LONG); - goto Exit; - } - - f_strcpy( pszStorageString, pszRealPath); - - if (RC_BAD( rc = f_pathAppend( pszStorageString, szFile))) - { - goto Exit; - } - -Exit: - - if (pszRealPath) - { - f_free( &pszRealPath); - } - - return( rc); -#endif -} - -/**************************************************************************** -Desc: -****************************************************************************/ -FINLINE void HexToNative( - FLMBYTE ucHexVal, - char * pszNativeChar) -{ - *pszNativeChar = (FLMBYTE)(ucHexVal < 10 - ? ucHexVal + NATIVE_ZERO - : (ucHexVal - 10) + NATIVE_LOWER_A); -} - -/**************************************************************************** -Desc: -****************************************************************************/ -FINLINE void SetUpTime( - FLMUINT * puiBaseTime, - char * pbyHighByte) -{ - FLMUINT uiSdTime = 0; - f_timeGetSeconds( &uiSdTime); - *pbyHighByte = (FLMBYTE)(uiSdTime >> 24); - uiSdTime = uiSdTime << 5; - if( *puiBaseTime < uiSdTime) - *puiBaseTime = uiSdTime; -} - -/**************************************************************************** -Desc: Generates a file name given a seed and some modifiers, it is built - to be called in a loop until the file can be sucessfully written or - created with the increment being changed every time. -****************************************************************************/ -FLMEXP void FLMAPI f_pathCreateUniqueName( - FLMUINT * puiTime, - char * pFileName, - const char * pFileExt, - char * pHighChars, - FLMBOOL bModext) -{ - FLMINT iCount, iLength; - FLMUINT uiSdTmp = 0; - FLMUINT uiIncVal = 1; - - SetUpTime( puiTime, pHighChars); - uiSdTmp = *puiTime; - - // Add on the filename extension if passed from the caller - - *(pFileName + 8) = NATIVE_DOT; - f_memset( (pFileName + 9), NATIVE_ZERO, 3 ); - - if( ( pFileExt != NULL )) - { - if ((iLength = f_strlen(pFileExt)) > 3) - { - iLength = 3; - } - f_memmove( (pFileName + 9), pFileExt, iLength); - } - - if( bModext == TRUE) - { - HexToNative((FLMBYTE)(uiSdTmp & 0x0000001F), pFileName+(11)); - } - else - { - uiIncVal = 32; - } - - uiSdTmp = uiSdTmp >> 5; - for( iCount = 0; iCount < 6; iCount++) - { - HexToNative((FLMBYTE)(uiSdTmp & 0x0000000F), pFileName+(7-iCount)); - uiSdTmp = uiSdTmp >> 4; - } - - for( iCount = 0; iCount < 2; iCount++) - { - HexToNative((FLMBYTE)(*pHighChars & 0x0000000F), pFileName+(1-iCount)); - *pHighChars = *pHighChars >> 4; - } - - *(pFileName + 12) = '\0'; - *puiTime += uiIncVal; - - return; -} - -/**************************************************************************** -Desc: Compares the current file against a pattern template -****************************************************************************/ -FLMEXP FLMBOOL FLMAPI f_doesFileMatch( - const char * pszFileName, - const char * pszTemplate) -{ - FLMUINT uiPattern; - FLMUINT uiChar; - - if( !*pszTemplate) - { - return( TRUE); - } - - while( *pszTemplate) - { - uiPattern = *pszTemplate++; - switch( uiPattern) - { - case NATIVE_WILDCARD: - /* if the match_template ends in an asterisk, then we match the*/ - /* remaining string by default, return a match. */ - - if( *pszTemplate == 0) - { - return( TRUE); - } - - /* Found an asterisk somewhere in the match_template, now let's - see if we match anywhere on the remaining input string. */ - - while( *pszFileName) - { - if( f_doesFileMatch( pszFileName, pszTemplate)) - { - return( TRUE); /* found a match, return */ - } - pszFileName++; - } - return( FALSE); /* did not find match, return */ - case NATIVE_QUESTIONMARK: - if( *pszFileName++ == 0) /* skip one character for '?' */ - { - return( FALSE); - } - break; - default: - uiChar = *pszFileName++; - if( f_toupper( uiPattern) != f_toupper( uiChar)) - { - return( FALSE); - } - break; - } - } - - return( (*pszFileName != 0) ? FALSE : TRUE ); -} diff --git a/flaim/src/ftkrand.cpp b/flaim/src/ftkrand.cpp deleted file mode 100644 index c35a5e2..0000000 --- a/flaim/src/ftkrand.cpp +++ /dev/null @@ -1,267 +0,0 @@ -//------------------------------------------------------------------------- -// Desc: Random number generation. -// Tabs: 3 -// -// Copyright (c) 1993-2000,2003,2005-2006 Novell, Inc. All Rights Reserved. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of version 2 of the GNU General Public -// License as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, contact Novell, Inc. -// -// To contact Novell about this file by physical or electronic mail, -// you may find current contact information at www.novell.com -// -// $Id: ftkrand.cpp 12299 2006-01-19 15:01:23 -0700 (Thu, 19 Jan 2006) dsanders $ -//------------------------------------------------------------------------- - -#include "flaimsys.h" - -/**************************************************************************** - This random number generator is based on Park & Miller's "suggested -minimal standard" for random number generation, pp 1192-1201 of the Oct 1988 -issue of _Communications_of_the_ACM_ (vol 31 number 10). It is a Lehmer -generator, which are of the form x[n] = A * x[n-1] % M, with A and M being -judiciously chosen constants. More formally, this is a "prime modulus -multiplicative linear congruential generator," or PMMLCG. - Park & Miller originally suggested A==16807 and M==2**31-1, but an update -in CACM Vol 36, No. 7 pp 108-110 (July 1993) indicates that they have found -a better multiplier (A == 48271) to use with the same modulus (2**31-1). -This implementation uses the updated multiplier. - To quote Park & Miller 1988, "We believe that this is the generator that -should always be used--unless one has access to a random number generator -KNOWN to be better." - This algorithm produces a full-period generator; that is, starting from -any seed between 1 and 2**31-2, it generates all other values between 1 -and 2**31-2 before it returns to the starting point -- whereupon it repeats -the same sequence of 31-bit values. This is true for either choice of A -(16807 or 48271). - The July 1993 article includes criticism by George Marsaglia of the Park -and Miller generator. Marsaglia feels that longer periods are needed. For -a description of his "subtract-with-borrow" (SWB) generators, see "A New -Class of Random Number Generators", The Annals of Applied Probability, -(1991) Vol. 1, No. 3, pp. 462-480. These generators require more state -information (~48 longwords) but produce generators with periods on the -order of 10**445. They also pass more stringent tests than the congruential -generators, and so might be considered 'a random number generator KNOWN to -be better.' However, Marsaglia does not spell out all the details needed to -implement SWB, nor does he give any simple test to determine whether an SWB -implementation is correct. -****************************************************************************/ - -/************************************************************************* -Desc: Set the seed from the date and time -*************************************************************************/ -FLMEXP void FLMAPI f_randomize( - f_randomGenerator * pRand) -{ - FLMUINT uiTime; - - f_timeGetSeconds( &uiTime ); - f_randomSetSeed( pRand, (FLMUINT32)(((FLMUINT32)uiTime % MAX_RANDOM) + 1)); - - return; -} - -/************************************************************************* -Desc: initialize the seed to a known value -*************************************************************************/ -FLMEXP void FLMAPI f_randomSetSeed( - f_randomGenerator * pRand, - FLMINT32 ui32Seed) -{ - register FLMINT32 i32Seed = (FLMINT32) ui32Seed; - - /* fix seed so that it is in legal range */ - - if( i32Seed > 0 && i32Seed <= MAX_RANDOM) - { - pRand->i32Seed = i32Seed; - } - else - { - f_randomSetSeed( pRand, (FLMINT32)(i32Seed < 1 - ? i32Seed + MAX_RANDOM - : i32Seed - MAX_RANDOM)); - } -} - -/************************************************************************* -Desc: Generate the next number in the pseudo-random sequence - i.e., "f_randomLong( &r) > MAX_RANDOM/2" will be true half the - time, on average. Likewise, "f_randomLong( &r) & 0x1" has a 50-50 - chance of being true. -Note: - a b (b is the lower 16 bits of x[n-1]; a is the upper 15 bits) - x c (sixteen-bit value of A) - ------------ - d e (== c * b; d and e are each 16 bits) - + f g (== c * a; f is 15 bits and g is 16 bits) - ------------ - h e (h:e is 31:16 bits, where h is the 31 bit sum f:g + d) - - It might appear that h could be as wide as 32 bits, but since overall we're - doing a 16-bit x 31-bit = 47-bit product; h:e must fit in 31:16 bits. - The mod-by-M operation is then performed by splitting the 47-bit product - h:e into the upper 16 bits ('x') and the lower 31 bits ('y') and applying - the slick mod trick described below. - - The slick mod operation is performed by splitting the 47-bit product z - into the upper 16 bits ('x') and the lower 31 bits ('y'). Then - z % M = x:y % M - = (x * 2**31 + y) % M - Rewriting 2**31 == 2**31 - 1 + 1 == M + 1, produces - = ((x * (M+1) + y) % M - = (x*M + x + y) % M - But x*M == 0 (mod M), so we can cancel the first term, producing - = (x + y) % M. - Now, if x+y < M, then x+y == (x+y) % M, and the answer has been found. - f x+y > M, then the 16-bit + 31-bit sum overflowed into the upper bit. - But we can apply the trick again: z % M = x:y % M = (x+y) % M. In this - case, however, x is the single high-order bit, and y is the low-order 31 - bits. Thus x == 1 and y == z & 0x7FFFFFFF, so x+y can be computed by - clearing the high order bit of z and incrementing the result. Viewed - another way, this operation simply subtracts M: clearing the high-order - bit is equivalent to subtracting 2**31; incrementing the result means - that 2**31-1 has been subtracted instead. - Though it might appear that the result might overflow into the high-order - bit, this can't really happen. The 32-bit value was computed by adding a 16 - bit value to a 31-bit value, so the largest possible result is 0xFFFF - + 0x7FFFFFFF = 0x8000FFFE = 2**31 + 0xFFFE. After subtracting 2**31-1, - the result cannot be any larger than 0xFFFF. - Once the high-order bit is clear the answer is less than or equal to M. - If it is less than M, we're done; if it is equal to M, then the correct - result is zero (M % M == 0). - However, for this application it is unnecessary to handle the case where - the answer is zero, because the 47-bit product is never a multiple of M - (if the input seed is valid -- that is, in the range 1..0x7FFFFFFE). - Proof (by contradiction): Let x be the previous seed, and let z be the - 47-bit product. Then z = A * x. If M divides the product z, then M must - divide either A or x (or both), because M is prime. But M cannot divide - either: both values are greater than one and less than M. -><- - As corroborating evidence, we have the fact that the generator, if - correctly implemented, never generates the value 0; its results are always - in the range 1..0x7FFFFFFE (according to Park & Miller). If it ever were - to produce the value zero, it would be a particularly BAD random number - generator since it would continue to generate nothing but zero from - that point on (it IS a multiplicative generator, after all). -*************************************************************************/ -FLMEXP FLMINT32 FLMAPI f_randomLong( - f_randomGenerator * generator) -{ -#define M 2147483647 -#define A 48271 -#define CHECK 399268537 - - register FLMUINT32 hi; - register FLMUINT32 lo; - register FLMUINT32 ui32Seed =generator->i32Seed; /* input is 31-bit number */ - - hi = (ui32Seed >> 16); /* hi = a (high-order 15 bits of x[n-1]) */ - lo = ui32Seed & 0xFFFF; /* lo = b (low-order 16 bits of x[n-1]) */ - lo *= A; /* lo = c * b = d:e (16:16 bits = 32 bits) */ - hi *= A; /* hi = c * a = f:g (15:16 bits = 31 bits) */ - - hi += (lo >> 16) & 0xFFFF; /* hi = f:g + d = h (31 bits) */ - lo &= 0xFFFF; /* lo = e (16 bits) */ - - /* - * Now, the 'longhand' product has been calculated. It is stored in - * hi:lo (31:16 bits) = h:e (31:16 bits). - * - * Now, redistribute the number h:e (31:16 bits) into x:y (16:31 bits) - */ - - lo |= (hi & 0x7FFF) << 16; /* lo = y = (low 15 bits of h spliced into e) */ - hi >>= 15; /* hi = x (high 16 bits of h) */ - lo += hi; /* lo = z = y + x (32 bits) */ - - /* - * At this point, the value has been reduced modulo M to the 32-bit - * value z, stored in lo. Reduce if the high-order bit is set. - */ - - if( lo & 0x80000000) /* subtract 2**31 - 1 if necessary */ - { - lo &= 0x7FFFFFFF; /* equivalent to lo = lo - 2**31 */ - lo++; /* equivalent to lo = lo + 1 */ - } - - /* we don't need to worry about lo == M, because it can't happen */ - - return( generator->i32Seed = lo); -} - - - -/************************************************************************* -Desc: return a random integer between lo and hi, inclusive. - (where lo and hi are integer arguments). -Example: - The code "RandomChoice( &r, 1, 6) + RandomChoice( &r, 1, 6)" will - simulate the roll of a standard 6-sided die. -Note: The distance (range) between lo and hi must be no greater than - MAX_RANDOM. Normally, RandomChoice computes its answer by taking - a f_randomLong modulo the desired range. If the range is large enough, - aliasing effects would cause some answers to be produced too often. - Therefore, f_randomChoice uses a better but slower algorithm if the - range is >= 1 Meg (2**20). -*************************************************************************/ -FLMEXP FLMINT32 FLMAPI f_randomChoice( - f_randomGenerator * r, - FLMINT32 lo, /* lowest allowed return value */ - FLMINT32 hi /* highest allowed return value */ - ) -{ - register FLMINT32 range = hi - lo + 1; - - if( range < (1L << 20)) - { - return( lo + f_randomLong( r) % range); - } - else - { - register FLMINT32 mask = 0; - register FLMINT32 x; - - range--; - for( x = range; x > 0; x >>= 1) - { - mask = (mask << 1) | 1; - } - - do - { - x = f_randomLong( r) & mask; - } while( x > range); - - return( lo + x); - } -} - - -/************************************************************************* -Desc: return TRUE a certain percentage of the time -Example: - This code will decimate a population (that is, it will kill 10% of - the "life_force" group): - - for( i=0; ilock, NULL)) < 0) - { - goto Exit; - } - - if( (iErr = pthread_cond_init( &sem->cond, NULL)) < 0) - { - pthread_mutex_destroy( &sem->lock); - goto Exit; - } - - sem->count = 0; - -Exit: - - return( iErr); -} - -/**************************************************************************** -Desc: Frees a semaphore handle on AIX -****************************************************************************/ -void sema_destroy( sema_t * sem) -{ - pthread_mutex_destroy( &sem->lock); - pthread_cond_destroy( &sem->cond); -} - -/**************************************************************************** -Desc: Waits for a semaphore to be signaled on AIX -****************************************************************************/ -int sema_wait( sema_t * sem) -{ - int iErr = 0; - - pthread_mutex_lock( &sem->lock); - while( !sem->count) - { - if( (iErr = pthread_cond_wait( &sem->cond, &sem->lock))) - { - if( iErr == EINTR) - { - iErr = 0; - } - else - { - goto Exit; - } - } - } - sem->count--; - flmAssert( sem->count >= 0); - -Exit: - - pthread_mutex_unlock( &sem->lock); - return( iErr); -} - -/**************************************************************************** -Desc: Waits a specified number of miliseconds for a semaphore - to be signaled on AIX -****************************************************************************/ -int sema_timedwait( sema_t * sem, unsigned int msecs) -{ - struct timeval now; - struct timespec abstime; - int iErr = 0; - - // If timeout is F_SEM_WAITFOREVER, do sem_wait. - - if( msecs == F_SEM_WAITFOREVER) - { - iErr = sema_wait( sem); - return( iErr); - } - - pthread_mutex_lock( &sem->lock); - -Restart: - - gettimeofday( &now, NULL); - abstime.tv_sec = now.tv_sec + ((msecs) ? (msecs / 1000) : 0); - abstime.tv_nsec = ( now.tv_usec + ((msecs % 1000) * 1000)) * 1000; - - while( !sem->count) - { - if( (iErr = pthread_cond_timedwait( &sem->cond, - &sem->lock, &abstime))) - { - if( iErr == EINTR) - { - iErr = 0; - goto Restart; - } - goto Exit; - } - } - sem->count--; - flmAssert( sem->count >= 0); - -Exit: - - pthread_mutex_unlock( &sem->lock); - return( iErr); -} - -/**************************************************************************** -Desc: Signals a semaphore on AIX -****************************************************************************/ -int sema_signal( sema_t * sem) -{ - pthread_mutex_lock( &sem->lock); - sem->count++; - flmAssert( sem->count > 0); - pthread_cond_signal( &sem->cond); - pthread_mutex_unlock( &sem->lock); - - return( 0); -} - -#endif // FLM_AIX || FLM_OSX - -/****************************************************************************/ -/****************************************************************************/ - -#if defined( FLM_WIN) - -/****************************************************************************/ -/****************************************************************************/ - -/**************************************************************************** -Desc: create a semaphore handle for use later -Notes: initial state of the semaphore is unlocked. -****************************************************************************/ -RCODE f_mutexCreate( - F_MUTEX * phMutex) -{ - flmAssert( phMutex != NULL); - - // NOTE: Cannot call f_alloc because the memory initialization needs - // to be able to set up mutexes. - - if ((*phMutex = (F_MUTEX)os_malloc( - sizeof( CRITICAL_SECTION))) == F_MUTEX_NULL) - { - return( RC_SET( FERR_MUTEX_OPERATION_FAILED)); - } - - InitializeCriticalSection( (CRITICAL_SECTION *)*phMutex); - return( FERR_OK); -} - -/**************************************************************************** -Desc: Destroy a semaphore that was created previously through f_mutexCreate -****************************************************************************/ -void f_mutexDestroy( - F_MUTEX * phMutex) -{ - flmAssert( phMutex != NULL); - - if (*phMutex != F_MUTEX_NULL) - { - - DeleteCriticalSection( (CRITICAL_SECTION *)*phMutex); - - // NOTE: Cannot call f_free because we had to use os_malloc up above - // due to the fact that the memory subsystem uses a mutex before it is - // completely ready to go. - - os_free( *phMutex); - *phMutex = F_MUTEX_NULL; - } -} - -#elif defined( FLM_UNIX) - -/****************************************************************************/ -/****************************************************************************/ - - -/**************************************************************************** -Desc: create a semaphore handle for use later -Notes: initial state is unlocked -****************************************************************************/ -RCODE f_mutexCreate( - F_MUTEX * phMutex) -{ - RCODE rc = FERR_OK; - - flmAssert( phMutex != NULL); - - // NOTE: Cannot call f_alloc because the memory initialization needs - // to be able to set up mutexes. - - if ((*phMutex = (F_MUTEX)os_malloc( - sizeof( pthread_mutex_t))) == F_MUTEX_NULL) - { - rc = RC_SET( FERR_MEM); - goto Exit; - } - - if( pthread_mutex_init( (pthread_mutex_t *)*phMutex, NULL) != 0) - // SOLARIS2 needs attr==NULL, if default mutex attributes are used - { - - // NOTE: Cannot call f_free because we had to use os_malloc up above - // due to the fact that the memory subsystem uses a mutex before it is - // completely ready to go. - - os_free( *phMutex); - *phMutex = F_MUTEX_NULL; - rc = RC_SET( FERR_MUTEX_OPERATION_FAILED); - goto Exit; - } - -Exit: - - return( rc); -} - -/**************************************************************************** -Desc: create a semaphore handle for use later -****************************************************************************/ -void f_mutexDestroy( - F_MUTEX * phMutex) -{ - flmAssert( phMutex != NULL); - - if (*phMutex != F_MUTEX_NULL) - { - pthread_mutex_destroy( (pthread_mutex_t *)*phMutex); - - // NOTE: Cannot call f_free because we had to use os_malloc up above - // due to the fact that the memory subsystem uses a mutex before it is - // completely ready to go. - - os_free( *phMutex); - *phMutex = F_MUTEX_NULL; - } -} - -/**************************************************************************** -Desc: -****************************************************************************/ -void f_mutexLock( - F_MUTEX hMutex) -{ - while( pthread_mutex_lock( (pthread_mutex_t *)hMutex) != 0); -} - -/**************************************************************************** -Desc: -****************************************************************************/ -void f_mutexUnlock( - F_MUTEX hMutex) -{ - (void)pthread_mutex_unlock( (pthread_mutex_t *)hMutex); -} - -/**************************************************************************** -Desc: create a semaphore handle for use later -Notes: initial state is locked -****************************************************************************/ -RCODE f_semCreate( - F_SEM * phSem) -{ - RCODE rc = FERR_OK; - - flmAssert( phSem != NULL); - -#if defined( FLM_AIX) || defined( FLM_OSX) - if( RC_BAD( rc = f_alloc( sizeof( sema_t), phSem))) - { - goto Exit; - } -#else - if( RC_BAD( rc = f_alloc( sizeof( sem_t), phSem))) - { - goto Exit; - } -#endif - -#if defined( FLM_AIX) || defined( FLM_OSX) - if( sema_init( (sema_t *)*phSem) < 0) -#else - if( sem_init( (sem_t *)*phSem, 0, 0) < 0) -#endif - { - f_free( phSem); - *phSem = F_SEM_NULL; - rc = RC_SET( FERR_SEM_OPERATION_FAILED); - goto Exit; - } - -Exit: - - return( rc); -} - -/**************************************************************************** -Desc: Destroy a semaphore -****************************************************************************/ -void f_semDestroy( - F_SEM * phSem) -{ - flmAssert( phSem != NULL); - - if (*phSem != F_SEM_NULL) - { -#if defined( FLM_AIX) || defined( FLM_OSX) - sema_destroy( (sema_t *)*phSem); -#else - sem_destroy( (sem_t *)*phSem); -#endif - f_free( phSem); - *phSem = F_SEM_NULL; - } -} - -/**************************************************************************** -Desc: Get the lock on a semaphore - p operation -****************************************************************************/ -RCODE f_semWait( - F_SEM hSem, - FLMUINT uiTimeout) -{ - RCODE rc = FERR_OK; - - flmAssert( hSem != F_SEM_NULL); - -#if defined( FLM_AIX) || defined( FLM_OSX) - - // Catch the F_SEM_WAITFOREVER flag so we can directly call sema_wait - // instead of passing F_SEM_WAITFOREVER through to sema_timedwait. - // Note that on AIX the datatype of the uiTimeout (in the timespec - // struct) is surprisingly a signed int, which makes this catch - // essential. - - if( uiTimeout == F_SEM_WAITFOREVER) - { - if( sema_wait( (sema_t *)hSem)) - { - rc = RC_SET( FERR_SEM_UNABLE_TO_LOCK); - } - } - else - { - if( sema_timedwait( (sema_t *)hSem, uiTimeout)) - { - rc = RC_SET( FERR_SEM_UNABLE_TO_LOCK); - } - } -#else - if( !uiTimeout) - { - if( sem_trywait( (sem_t *)hSem) != 0) - { - rc = RC_SET( FERR_SEM_UNABLE_TO_LOCK); - } - } - else - { -Restart: - if( sem_wait( (sem_t *)hSem) != 0) - { - // Defect 243865. Retry sem_wait on EINTR signal. - // This is at best a temporary fix. Signals are handled explicitly - // in NDS. Unfortunately DirXML loads a JVM into the DHOST - // address space. Signal handling for JVM threads gets really messy. - // Hopefully, DirXML will be moved into a separate process - // for Tao SP1. The sem_wait fix is needed till that time. - - if( errno == EINTR) - { - goto Restart; - } - rc = RC_SET( FERR_SEM_UNABLE_TO_LOCK); - } - } - -#endif - - return( rc); -} -#endif - -#if defined( FLM_NLM) && !defined( __MWERKS__) - -int gv_DummyFtksem(void) -{ - return( 0); -} - -#endif diff --git a/flaim/src/ftkthrd.cpp b/flaim/src/ftkthrd.cpp deleted file mode 100644 index 33652a2..0000000 --- a/flaim/src/ftkthrd.cpp +++ /dev/null @@ -1,1062 +0,0 @@ -//------------------------------------------------------------------------- -// Desc: Cross platform toolkit for threads. -// Tabs: 3 -// -// Copyright (c) 2000-2006 Novell, Inc. All Rights Reserved. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of version 2 of the GNU General Public -// License as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, contact Novell, Inc. -// -// To contact Novell about this file by physical or electronic mail, -// you may find current contact information at www.novell.com -// -// $Id: ftkthrd.cpp 12329 2006-01-20 17:49:30 -0700 (Fri, 20 Jan 2006) ahodgkinson $ -//------------------------------------------------------------------------- - -#include "flaimsys.h" - -#if defined( FLM_UNIX) - #include -#endif - -#ifdef FLM_NLM - static void * threadStub( - void * pvUnused, - void * pvThread); -#elif defined( FLM_WIN) - static unsigned __stdcall threadStub( - void * pvThread); -#elif defined( FLM_UNIX) - extern "C" - { - static void * threadStub( - void * pvThread); - } -#endif - -/**************************************************************************** -Desc: Add a Reference to this object. -****************************************************************************/ -FLMINT F_Thread::AddRef( - FLMBOOL bMutexLocked) -{ - FLMINT iRefCnt; - - if( !bMutexLocked) - { - f_mutexLock( m_hMutex); - } - - iRefCnt = F_Base::AddRef(); - - if( !bMutexLocked) - { - f_mutexUnlock( m_hMutex); - } - - return( iRefCnt); -} - -/**************************************************************************** -Desc: Removes a reference to this object. -****************************************************************************/ -FLMINT F_Thread::Release( - FLMBOOL bMutexLocked) -{ - FLMINT iRefCnt; - FLMBOOL bUnlockMutex = FALSE; - - if( !bMutexLocked && m_hMutex != F_MUTEX_NULL) - { - f_mutexLock( m_hMutex); - bUnlockMutex = TRUE; - bMutexLocked = TRUE; - } - - flmAssert( getRefCount() > 0); - iRefCnt = flmAtomicDec( &m_refCnt, m_hMutex, bMutexLocked); - - if( bUnlockMutex) - { - f_mutexUnlock( m_hMutex); - } - - if( !iRefCnt) - { - delete this; - } - - return( iRefCnt); -} - -/**************************************************************************** -Desc: Performs various setup work and starts a new thread -****************************************************************************/ -RCODE F_Thread::startThread( - F_THREAD_FUNC fnThread, - const char * pszThreadName, - FLMUINT uiThreadGroup, - FLMUINT uiAppId, - void * pvParm1, - void * pvParm2, - FLMUINT uiStackSize) -{ - RCODE rc = FERR_OK; - FLMBOOL bManagerMutexLocked = FALSE; -#ifdef FLM_NLM - void * hThread = NULL; -#endif -#ifdef FLM_WIN - unsigned uiThreadId; -#endif -#if defined( FLM_UNIX) - #if defined( _POSIX_THREADS) - pthread_attr_t thread_attr; - pthread_t uiThreadId; - #else - threadid_p uiThreadId; - #endif -#endif - - flmAssert( fnThread != NULL && m_fnThread == NULL); - - m_fnThread = fnThread; - m_pvParm1 = pvParm1; - m_pvParm2 = pvParm2; - - // Initialize the thread's mutex - - if( RC_BAD( rc = f_mutexCreate( &m_hMutex))) - { - goto Exit; - } - - // Set the stack size - - m_uiStackSize = (uiStackSize < F_THREAD_MIN_STACK_SIZE) - ? F_THREAD_MIN_STACK_SIZE - : uiStackSize; - - // Set the thread name - - if( pszThreadName && *pszThreadName) - { - FLMUINT uiNameLen = f_strlen( pszThreadName) + 1; - - if( RC_BAD( rc = f_alloc( uiNameLen, &m_pszThreadName))) - { - goto Exit; - } - - f_memcpy( m_pszThreadName, pszThreadName, uiNameLen); - } - - // Set the thread group ID and the application-specified thread ID - - m_uiThreadGroup = uiThreadGroup; - m_uiAppId = uiAppId; - - // Set the thread's state to "running" -- if we fail to - // start the thread, this will be set back to false when - // the cleanupThread() method is called below. We set this - // to TRUE here so that the stopThread() method won't get - // stuck in an infinite loop if the thread was never started. - - m_bRunning = TRUE; - - // Lock the thread manager's mutex. - - f_mutexLock( gv_FlmSysData.pThreadMgr->m_hMutex); - bManagerMutexLocked = TRUE; - - // Increment the active thread count - - gv_FlmSysData.pThreadMgr->m_uiNumThreads++; - - // Link the thread into the manager's list. We can't link threads in order - // by thread ID at this point, because we don't know what the new thread's - // ID will be. - - if( gv_FlmSysData.pThreadMgr->m_pThreadList) - { - gv_FlmSysData.pThreadMgr->m_pThreadList->m_pPrev = this; - } - - m_pNext = gv_FlmSysData.pThreadMgr->m_pThreadList; - gv_FlmSysData.pThreadMgr->m_pThreadList = this; - - // Increment the reference count of the thread object now - // that it is linked into the thread manager's list. - - AddRef(); - - // Start the thread - -#ifdef FLM_WIN - if( _beginthreadex( - NULL, (unsigned int)m_uiStackSize, threadStub, - (void *)this, 0, &uiThreadId) == 0) // 0 indicates a failure - { - rc = RC_SET( FERR_THREAD_ERR); - goto Exit; - } - m_uiThreadId = (FLMUINT)uiThreadId; -#elif defined( FLM_NLM) - if( (hThread = kCreateThread( - (BYTE *)((m_pszThreadName) - ? (BYTE *)m_pszThreadName - : (BYTE *)"NDSDB"), - threadStub, NULL, (LONG)m_uiStackSize, - (void *)this)) == NULL) - { - rc = RC_SET( FERR_THREAD_ERR); - goto Exit; - } - m_uiThreadId = (FLMUINT)hThread; - - if( kSetThreadLoadHandle( hThread, (LONG)f_getNLMHandle()) != 0) - { - (void)kDestroyThread( hThread); - rc = RC_SET( FERR_THREAD_ERR); - goto Exit; - } - - if( kScheduleThread( hThread) != 0) - { - (void)kDestroyThread( hThread); - rc = RC_SET( FERR_THREAD_ERR); - goto Exit; - } -#elif defined( FLM_UNIX) - #ifdef _POSIX_THREADS - pthread_attr_init( &thread_attr); - pthread_attr_setdetachstate( &thread_attr, PTHREAD_CREATE_DETACHED); - - if (pthread_create( &uiThreadId, &thread_attr, - threadStub, this) != 0) - { - rc = RC_SET( FERR_THREAD_ERR); - goto Exit; - } - #else - m_uiStackSize = f_max( m_uiStackSize, thr_minstack()); - m_uiStackSize = f_max( m_uiStackSize, thr_min_stack()); - - if( thr_create( (void*)NULL, (size_t)uiStackSize, - threadStub, this, (long)0, &uiThreadId) != 0) - { - rc = RC_SET( FERR_THREAD_ERR); - goto Exit; - } - #endif - - m_uiThreadId = (FLMUINT)uiThreadId; - - #ifdef _POSIX_THREADS - pthread_attr_destroy( &thread_attr); - #endif -#endif - - // Code is not designed to handle a thread ID of 0 - - flmAssert( m_uiThreadId != 0); - - // Unlock the thread manager's mutex. - - f_mutexUnlock( gv_FlmSysData.pThreadMgr->m_hMutex); - bManagerMutexLocked = FALSE; - -Exit: - - if( RC_BAD( rc)) - { - // Unlink the thread from the manager's list. This call - // won't do anything if the thread was not linked above. - - gv_FlmSysData.pThreadMgr->unlinkThread( this, bManagerMutexLocked); - - // Reset the thread object back to its initial state - - cleanupThread(); - } - - if( bManagerMutexLocked) - { - f_mutexUnlock( gv_FlmSysData.pThreadMgr->m_hMutex); - } - - return( rc); -} - -/**************************************************************************** -Desc: Stop a running thread -****************************************************************************/ -void F_Thread::stopThread( void) -{ - // Set the shutdown flag and wait for the thread's - // status to be something other than "running" - - m_bShutdown = TRUE; - while( m_bRunning) - { - f_sleep( 10); - } - - // Reset the shutdown flag in case this object is re-used. - - m_bShutdown = FALSE; -} - -/**************************************************************************** -Desc: Begins a new thread of execution and calls the passed function. - Performs generic thread init and cleanup functions. -****************************************************************************/ -#ifdef FLM_NLM -void * threadStub( - void * pvUnused, - void * pvThread) -#elif defined( FLM_WIN) -unsigned __stdcall threadStub( - void * pvThread) -#elif defined( FLM_UNIX) -void * threadStub( - void * pvThread) -#endif -{ - F_Thread * pThread = (F_Thread *)pvThread; - -#ifdef FLM_NLM - F_UNREFERENCED_PARM( pvUnused); -#endif - -#ifdef FLM_UNIX - // Block all signals (main thread will handle all signals) - - sigset_t mask; - sigfillset(&mask); - pthread_sigmask(SIG_SETMASK, &mask, 0); -#endif - - // Lock the manager's mutex - - gv_FlmSysData.pThreadMgr->lockMutex(); - - // At this point, the thread ID must match. - - flmAssert( pThread->m_uiThreadId == f_threadId()); - - // Set the start time - - f_timeGetSeconds( &pThread->m_uiStartTime); - - // Unlock the manager's mutex - - gv_FlmSysData.pThreadMgr->unlockMutex(); - - // Call the thread's function - - pThread->m_exitRc = pThread->m_fnThread( pThread); - - // Add a temporary reference to the thread object so - // it doesn't go away when we unlink it from the - // manager - - pThread->AddRef(); - - // Unlink the thread from the thread manager. - - gv_FlmSysData.pThreadMgr->unlinkThread( pThread, FALSE); - - // Set the running flag to FALSE - - pThread->m_bRunning = FALSE; - - // Release the temporary reference to the thread. Once the - // reference is release, pThread must not be accessed because - // the object may have gone away. - - pThread->Release(); - pThread = NULL; - - // Terminate the thread - -#if defined( FLM_WIN) - _endthreadex( 0); - return( 0); -#elif defined( FLM_NLM) - kExitThread( NULL); -#endif - -#if defined( FLM_NLM) || defined( FLM_UNIX) - return( NULL); -#endif -} - -/**************************************************************************** -Desc: Frees any resources allocated to the thread and resets member - variables to their initial state -****************************************************************************/ -void F_Thread::cleanupThread( void) -{ - flmAssert( !m_pPrev && !m_pNext); - if( m_hMutex != F_MUTEX_NULL) - { - f_mutexDestroy( &m_hMutex); - } - - if( m_pszThreadName) - { - f_free( &m_pszThreadName); - } - - if( m_pszThreadStatus) - { - f_free( &m_pszThreadStatus); - } - - m_uiStatusBufLen = 0; - m_bShutdown = FALSE; - m_fnThread = NULL; - m_bRunning = FALSE; - m_uiStackSize = 0; - m_pvParm1 = NULL; - m_pvParm2 = NULL; - m_uiThreadId = 0; - m_uiThreadGroup = FLM_DEFAULT_THREAD_GROUP; - m_uiAppId = 0; - m_uiStartTime = 0; - m_exitRc = FERR_OK; -} - -/**************************************************************************** -Desc: Set the thread's status -****************************************************************************/ -void F_Thread::_setThreadStatus( - const char * pszStatus) -{ - FLMUINT uiStatusLen = f_strlen( pszStatus) + 1; - - if( m_uiStatusBufLen < uiStatusLen) - { - FLMUINT uiAllocSize = uiStatusLen < 128 ? 128 : uiStatusLen; - - if( m_pszThreadStatus != NULL) - { - f_free( &m_pszThreadStatus); - } - m_uiStatusBufLen = 0; - - if( RC_BAD( f_alloc( uiAllocSize, &m_pszThreadStatus))) - { - m_pszThreadStatus = NULL; - goto Exit; - } - - m_uiStatusBufLen = uiAllocSize; - } - - f_mutexLock( m_hMutex); - f_memcpy( m_pszThreadStatus, pszStatus, uiStatusLen); - f_mutexUnlock( m_hMutex); - -Exit: - - return; -} - -/**************************************************************************** -Desc: Set the thread's status -****************************************************************************/ -void F_Thread::setThreadStatus( - const char * pszFormat, ...) -{ - char pucBuffer[ 128]; - f_va_list args; - - f_va_start( args, pszFormat); - f_vsprintf( pucBuffer, pszFormat, &args); - f_va_end( args); - - _setThreadStatus( pucBuffer); -} - -/**************************************************************************** -Desc: Set the thread's status to a generic string -****************************************************************************/ -void F_Thread::setThreadStatus( - eFlmThreadStatus eGenericStatus) -{ - const char * pszStatus = NULL; - - switch( eGenericStatus) - { - case FLM_THREAD_STATUS_INITIALIZING: - pszStatus = "Initializing"; - break; - - case FLM_THREAD_STATUS_RUNNING: - pszStatus = "Running"; - break; - - case FLM_THREAD_STATUS_SLEEPING: - pszStatus = "Sleeping"; - break; - - case FLM_THREAD_STATUS_TERMINATING: - pszStatus = "Terminating"; - break; - - case FLM_THREAD_STATUS_STARTING_TRANS: - pszStatus = "Starting transaction"; - break; - - case FLM_THREAD_STATUS_COMMITTING_TRANS: - pszStatus = "Committing transaction"; - break; - - case FLM_THREAD_STATUS_ABORTING_TRANS: - pszStatus = "Aborting transaction"; - break; - - case FLM_THREAD_STATUS_UNKNOWN: - default: - pszStatus = "Unknown"; - break; - } - - if( pszStatus) - { - setThreadStatus( pszStatus); - } -} - -/**************************************************************************** -Desc: Allocates resources needed by the thread manager -****************************************************************************/ -RCODE F_ThreadMgr::setupThreadMgr( void) -{ - RCODE rc = FERR_OK; - - flmAssert( m_hMutex == F_MUTEX_NULL); - - if( RC_BAD( rc = f_mutexCreate( &m_hMutex))) - { - goto Exit; - } - -Exit: - - return( rc); -} - -/**************************************************************************** -Desc: Removes a thread from the thread manager's list -Notes: This routine assumes that the manager's mutex is already locked. -****************************************************************************/ -void F_ThreadMgr::unlinkThread( - F_Thread * pThread, - FLMBOOL bMutexIsLocked) -{ - // Lock the thread manager's mutex - - if( !bMutexIsLocked) - { - f_mutexLock( m_hMutex); - } - - // If the thread isn't linked into the list, - // don't do anything - - if( !pThread->m_pPrev && !pThread->m_pNext && - m_pThreadList != pThread) - { - goto Exit; - } - - // Decrement the active thread count - - flmAssert( m_uiNumThreads); - m_uiNumThreads--; - - if( pThread->m_pPrev) - { - pThread->m_pPrev->m_pNext = pThread->m_pNext; - } - else - { - m_pThreadList = pThread->m_pNext; - } - - if( pThread->m_pNext) - { - pThread->m_pNext->m_pPrev = pThread->m_pPrev; - } - - pThread->m_pNext = NULL; - pThread->m_pPrev = NULL; - - // Release the thread object - - pThread->Release(); - -Exit: - - if( !bMutexIsLocked) - { - f_mutexUnlock( m_hMutex); - } -} - -/**************************************************************************** -Desc: Signals all threads in a thread group to shut down and waits - for them to terminate. -****************************************************************************/ -void F_ThreadMgr::shutdownThreadGroup( - FLMUINT uiThreadGroup) -{ - F_Thread * pThread; - FLMUINT uiCount; - - for( ;;) - { - f_mutexLock( m_hMutex); - - uiCount = 0; - pThread = m_pThreadList; - while( pThread) - { - if( pThread->m_uiThreadGroup == uiThreadGroup) - { - pThread->setShutdownFlag(); - uiCount++; - } - pThread = pThread->m_pNext; - } - - f_mutexUnlock( m_hMutex); - - if( !uiCount) - { - break; - } - - // The threads will automatically unlink themselves from - // the manager before they terminate. Just sleep for - // a few milliseconds and look through the list again to - // verify that there are no more threads in the group. - - f_sleep( 200); - } -} - -/**************************************************************************** -Desc: Signals a thread to shut down. -****************************************************************************/ -void F_ThreadMgr::setThreadShutdownFlag( - FLMUINT uiThreadId) -{ - F_Thread * pThread; - - flmAssert( uiThreadId != 0); - - f_mutexLock( m_hMutex); - pThread = m_pThreadList; - while( pThread) - { - if( pThread->m_uiThreadId == uiThreadId) - { - pThread->setShutdownFlag(); - break; - } - pThread = pThread->m_pNext; - } - - f_mutexUnlock( m_hMutex); -} - -/**************************************************************************** -Desc: Allocates an array of F_THREAD_INFO structures and populates them - with information about the threads being managed by this object. -****************************************************************************/ -RCODE F_ThreadMgr::getThreadInfo( - POOL * pPool, - F_THREAD_INFO ** ppThreadInfo, - FLMUINT * puiNumThreads) -{ - RCODE rc = FERR_OK; - FLMUINT uiOffset; - FLMUINT uiLoop; - FLMUINT uiSubLoop; - FLMUINT uiLen; - FLMBOOL bMutexLocked = FALSE; - F_THREAD_INFO * pThreadInfo = NULL; - F_THREAD_INFO tmpThreadInfo; - F_Thread * pCurThread; - void * pvMark = GedPoolMark( pPool); - - *ppThreadInfo = NULL; - *puiNumThreads = 0; - - f_mutexLock( m_hMutex); - bMutexLocked = TRUE; - - if( m_uiNumThreads == 0) - { - goto Exit; - } - - if( (pThreadInfo = (F_THREAD_INFO *)GedPoolCalloc( pPool, - sizeof( F_THREAD_INFO) * m_uiNumThreads)) == NULL) - { - rc = RC_SET( FERR_MEM); - goto Exit; - } - - uiOffset = 0; - pCurThread = m_pThreadList; - while( pCurThread) - { - flmAssert( uiOffset < m_uiNumThreads); - f_mutexLock( pCurThread->m_hMutex); - - pThreadInfo[ uiOffset].uiThreadId = pCurThread->m_uiThreadId; - pThreadInfo[ uiOffset].uiThreadGroup = pCurThread->m_uiThreadGroup; - pThreadInfo[ uiOffset].uiAppId = pCurThread->m_uiAppId; - pThreadInfo[ uiOffset].uiStartTime = pCurThread->m_uiStartTime; - - if( pCurThread->m_pszThreadName) - { - uiLen = f_strlen( pCurThread->m_pszThreadName) + 1; - - if( ( pThreadInfo[ uiOffset].pszThreadName = - (char *)GedPoolCalloc( pPool, uiLen)) != NULL) - { - f_memcpy( pThreadInfo[ uiOffset].pszThreadName, - pCurThread->m_pszThreadName, uiLen); - } - } - - if( pCurThread->m_pszThreadStatus) - { - uiLen = f_strlen( pCurThread->m_pszThreadStatus) + 1; - - if( ( pThreadInfo[ uiOffset].pszThreadStatus = - (char *)GedPoolCalloc( pPool, uiLen)) != NULL) - { - f_memcpy( pThreadInfo[ uiOffset].pszThreadStatus, - pCurThread->m_pszThreadStatus, uiLen); - } - } - - f_mutexUnlock( pCurThread->m_hMutex); - uiOffset++; - pCurThread = pCurThread->m_pNext; - } - - flmAssert( uiOffset == m_uiNumThreads); - *puiNumThreads = m_uiNumThreads; - - f_mutexUnlock( m_hMutex); - bMutexLocked = FALSE; - - // Sort the list by thread ID - - for( uiLoop = 0; uiLoop < *puiNumThreads; uiLoop++) - { - for( uiSubLoop = uiLoop + 1; uiSubLoop < *puiNumThreads; uiSubLoop++) - { - if( pThreadInfo[ uiLoop].uiThreadId > - pThreadInfo[ uiSubLoop].uiThreadId) - { - f_memcpy( &tmpThreadInfo, - &pThreadInfo[ uiLoop], sizeof( F_THREAD_INFO)); - f_memcpy( &pThreadInfo[ uiLoop], - &pThreadInfo[ uiSubLoop], sizeof( F_THREAD_INFO)); - f_memcpy( &pThreadInfo[ uiSubLoop], - &tmpThreadInfo, sizeof( F_THREAD_INFO)); - } - } - } - - *ppThreadInfo = pThreadInfo; - -Exit: - - if( RC_BAD( rc)) - { - GedPoolReset( pPool, pvMark); - } - - if( bMutexLocked) - { - f_mutexUnlock( m_hMutex); - } - - return( rc); -} - -/**************************************************************************** -Desc: Finds a thread based on user-specified identifiers -****************************************************************************/ -RCODE F_ThreadMgr::findThread( - F_Thread ** ppThread, - FLMUINT uiThreadGroup, - FLMUINT uiAppId, - FLMBOOL bOkToFindMe) -{ - RCODE rc = FERR_OK; - FLMBOOL bMutexLocked = FALSE; - F_Thread * pCurThread; - - *ppThread = NULL; - - f_mutexLock( m_hMutex); - bMutexLocked = TRUE; - - if( m_uiNumThreads == 0) - { - rc = RC_SET( FERR_NOT_FOUND); - goto Exit; - } - - pCurThread = m_pThreadList; - while( pCurThread) - { - f_mutexLock( pCurThread->m_hMutex); - - if( pCurThread->m_uiThreadGroup == uiThreadGroup && - pCurThread->m_uiAppId == uiAppId) - { - if( bOkToFindMe || - (!bOkToFindMe && pCurThread->m_uiThreadId != f_threadId())) - { - // Found a match. - - pCurThread->AddRef( TRUE); - *ppThread = pCurThread; - f_mutexUnlock( pCurThread->m_hMutex); - goto Exit; - } - } - - f_mutexUnlock( pCurThread->m_hMutex); - pCurThread = pCurThread->m_pNext; - } - - rc = RC_SET( FERR_NOT_FOUND); - -Exit: - - if( bMutexLocked) - { - f_mutexUnlock( m_hMutex); - } - - return( rc); -} - -/**************************************************************************** -Desc: Finds a thread based on user-specified identifiers -****************************************************************************/ -RCODE F_ThreadMgr::getNextGroupThread( - F_Thread ** ppThread, - FLMUINT uiThreadGroup, - FLMUINT * puiThreadId) -{ - RCODE rc = FERR_OK; - FLMBOOL bMutexLocked = FALSE; - F_Thread * pCurThread; - F_Thread * pFoundThread = NULL; - - f_mutexLock( m_hMutex); - bMutexLocked = TRUE; - - if( m_uiNumThreads == 0) - { - rc = RC_SET( FERR_NOT_FOUND); - goto Exit; - } - - pCurThread = m_pThreadList; - while( pCurThread) - { - if( pCurThread->m_uiThreadGroup == uiThreadGroup && - pCurThread->m_uiThreadId > *puiThreadId) - { - // The threads are not kept in order by thread ID in the - // manager's list. So, we need to make sure we get the - // thread with the next ID beyond the ID passed into the - // routine. - - if( !pFoundThread || - pCurThread->m_uiThreadId < pFoundThread->m_uiThreadId) - { - pFoundThread = pCurThread; - } - } - - pCurThread = pCurThread->m_pNext; - } - - if( !pFoundThread) - { - rc = RC_SET( FERR_NOT_FOUND); - goto Exit; - } - - pFoundThread->AddRef(); - *ppThread = pFoundThread; - *puiThreadId = pFoundThread->m_uiThreadId; - -Exit: - - if( RC_BAD( rc)) - { - *ppThread = NULL; - *puiThreadId = 0xFFFFFFFF; - } - - if( bMutexLocked) - { - f_mutexUnlock( m_hMutex); - } - - return( rc); -} - -/**************************************************************************** -Desc: Returns a count of the number of threads in a specified group -****************************************************************************/ -FLMUINT F_ThreadMgr::getThreadGroupCount( - FLMUINT uiThreadGroup) -{ - F_Thread * pThread; - FLMUINT uiCount; - - f_mutexLock( m_hMutex); - - uiCount = 0; - pThread = m_pThreadList; - while( pThread) - { - if( pThread->m_uiThreadGroup == uiThreadGroup) - { - uiCount++; - } - pThread = pThread->m_pNext; - } - - f_mutexUnlock( m_hMutex); - return( uiCount); -} - -/**************************************************************************** -Desc: Allocate a thread object and start the thread -****************************************************************************/ -RCODE f_threadCreate( - F_Thread ** ppThread, - F_THREAD_FUNC fnThread, - const char * pszThreadName, - FLMUINT uiThreadGroup, - FLMUINT uiAppId, - void * pvParm1, - void * pvParm2, - FLMUINT uiStackSize) -{ - RCODE rc = FERR_OK; - F_Thread * pThread = NULL; - - if( ppThread) - { - *ppThread = NULL; - } - - if( (pThread = f_new F_Thread) == NULL) - { - rc = RC_SET( FERR_MEM); - goto Exit; - } - - if( RC_BAD( rc = pThread->startThread( - fnThread, pszThreadName, uiThreadGroup, uiAppId, - pvParm1, pvParm2, uiStackSize))) - { - goto Exit; - } - - if( ppThread) - { - *ppThread = pThread; - - // Set pThread to NULL so that the object won't be released - // below. The application has indicated (by passing in a - // non-NULL ppThread) that it wants to keep a reference to - // the thread. - - pThread = NULL; - } - -Exit: - - if( pThread) - { - pThread->Release(); - } - - return( rc); -} - -/**************************************************************************** -Desc: Deletes a thread object and sets the passed-in pointer to NULL -Notes: Should not be used on threads that were started with the - auto-destroy flag set to TRUE -****************************************************************************/ -void f_threadDestroy( - F_Thread ** ppThread) -{ - // Shutdown the thread - - if( *ppThread != NULL) - { - (*ppThread)->stopThread(); - (*ppThread)->Release(); - *ppThread = NULL; - } -} - -/**************************************************************************** -Desc: Destructor -****************************************************************************/ -F_ThreadMgr::~F_ThreadMgr() -{ - F_Thread * pTmpThread; - - if( m_hMutex != F_MUTEX_NULL) - { - f_mutexLock( m_hMutex); - pTmpThread = m_pThreadList; - while( pTmpThread) - { - pTmpThread->setShutdownFlag(); - pTmpThread = pTmpThread->m_pNext; - } - - while( m_pThreadList) - { - f_mutexUnlock( m_hMutex); - f_sleep( 50); - f_mutexLock( m_hMutex); - } - f_mutexUnlock( m_hMutex); - f_mutexDestroy( &m_hMutex); - } -} diff --git a/flaim/src/ftkthrd.h b/flaim/src/ftkthrd.h deleted file mode 100644 index 90349f9..0000000 --- a/flaim/src/ftkthrd.h +++ /dev/null @@ -1,344 +0,0 @@ -//------------------------------------------------------------------------- -// Desc: Cross platform toolkit for threads - definitions -// Tabs: 3 -// -// Copyright (c) 2000-2006 Novell, Inc. All Rights Reserved. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of version 2 of the GNU General Public -// License as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, contact Novell, Inc. -// -// To contact Novell about this file by physical or electronic mail, -// you may find current contact information at www.novell.com -// -// $Id: ftkthrd.h 12329 2006-01-20 17:49:30 -0700 (Fri, 20 Jan 2006) ahodgkinson $ -//------------------------------------------------------------------------- - -#ifndef FTKTHRD_H -#define FTKTHRD_H - -#if defined( FLM_UNIX) - #include - #include // defines _POSIX_THREADS - #ifndef _POSIX_THREADS - #define _POSIX_THREADS - #endif -#endif - -#if defined( FLM_NLM) || defined( FLM_WIN) || defined( FLM_UNIX) - #define F_MULTI_THREADED -#endif - -#ifdef FLM_WIN - #define f_threadId() (FLMUINT)_threadid -#endif - -#include "fpackon.h" -// IMPORTANT NOTE: No other include files should follow this one except -// for fpackoff.h - -#ifdef FLM_NLM - extern "C" - { - // WARNING! The following come from mpktypes.h - - void * kCurrentThread(void); - } - #define f_threadId() ((FLMUINT)kCurrentThread()) -#endif - -#ifdef FLM_UNIX - FINLINE FLMUINT f_threadId(void) - { - #ifdef _POSIX_THREADS - pthread_t thrd = pthread_self(); - #endif - - #if defined( SCO) - return( (FLMUINT) thrd.field2); - #else - return( (FLMUINT) thrd); - #endif - } -#endif - -#define F_THREAD_MIN_STACK_SIZE (16 * 1024) -#define F_THREAD_DEFAULT_STACK_SIZE (16 * 1024) - -// Forward declarations - -class F_Thread; -class F_ThreadMgr; - -// Thread types - -#define FLM_DEFAULT_THREAD_GROUP 1 -#define FLM_CHECKPOINT_THREAD_GROUP 2 -#define FLM_BACKGROUND_INDEXING_THREAD_GROUP 3 -#define FLM_DB_THREAD_GROUP 4 -#define FLM_DB_MONITOR_THREAD_GROUP 5 - -/**************************************************************************** -Desc: Class for managing a set of threads -****************************************************************************/ -class F_ThreadMgr : public F_Base -{ -public: - - // Constructors - - F_ThreadMgr() - { - m_hMutex = F_MUTEX_NULL; - m_pThreadList = NULL; - m_uiNumThreads = 0; - } - - // Destructor - - virtual ~F_ThreadMgr(); - - // Setup - - RCODE setupThreadMgr( void); - - // Shutdown - - void shutdownThreadGroup( - FLMUINT uiThreadGroup); - - void setThreadShutdownFlag( - FLMUINT uiThreadId); - - // Search - - RCODE findThread( - F_Thread ** ppThread, - FLMUINT uiThreadGroup, - FLMUINT uiAppId = 0, - FLMBOOL bOkToFindMe = TRUE); - - RCODE getNextGroupThread( - F_Thread ** ppThread, - FLMUINT uiThreadGroup, - FLMUINT * puiThreadId); - - // Statistics - - RCODE getThreadInfo( - POOL * pPool, - F_THREAD_INFO ** ppThreadInfo, - FLMUINT * puiNumThreads); - - FLMUINT getThreadGroupCount( - FLMUINT uiThreadGroup); - - FINLINE void lockMutex( void) - { - f_mutexLock( m_hMutex); - } - - FINLINE void unlockMutex( void) - { - f_mutexUnlock( m_hMutex); - } - - void unlinkThread( - F_Thread * pThread, - FLMBOOL bMutexLocked); - -private: - - F_MUTEX m_hMutex; - F_Thread * m_pThreadList; - FLMUINT m_uiNumThreads; - -friend class F_Thread; -}; - -typedef enum -{ - FLM_THREAD_STATUS_UNKNOWN = 0, - FLM_THREAD_STATUS_INITIALIZING, - FLM_THREAD_STATUS_RUNNING, - FLM_THREAD_STATUS_SLEEPING, - FLM_THREAD_STATUS_TERMINATING, - FLM_THREAD_STATUS_STARTING_TRANS, - FLM_THREAD_STATUS_COMMITTING_TRANS, - FLM_THREAD_STATUS_ABORTING_TRANS -} eFlmThreadStatus; - -typedef RCODE (* F_THREAD_FUNC)(F_Thread *); - -/**************************************************************************** -Desc: Class for creating and managing a thread -****************************************************************************/ -class F_Thread : public F_Base -{ -public: - - F_Thread() - { - m_hMutex = F_MUTEX_NULL; - m_pszThreadName = NULL; - m_pszThreadStatus = NULL; - m_uiStatusBufLen = 0; - m_pPrev = NULL; - m_pNext = NULL; - cleanupThread(); - } - - virtual ~F_Thread() - { - stopThread(); - cleanupThread(); - } - - FLMINT AddRef( - FLMBOOL bMutexLocked); - - FINLINE FLMINT AddRef( void) - { - return( AddRef( FALSE)); - } - - FLMINT Release( - FLMBOOL bMutexLocked); - - FINLINE FLMINT Release( void) - { - return( Release( FALSE)); - } - - RCODE startThread( - F_THREAD_FUNC fnThread, - const char * pszThreadName = NULL, - FLMUINT uiThreadGroup = FLM_DEFAULT_THREAD_GROUP, - FLMUINT uiAppId = 0, - void * pvParm1 = NULL, - void * pvParm2 = NULL, - FLMUINT uiStackSize = F_THREAD_DEFAULT_STACK_SIZE); - - void stopThread( void); - - FINLINE FLMUINT getThreadId( void) - { - return( m_uiThreadId); - } - - FINLINE FLMBOOL getShutdownFlag( void) - { - return( m_bShutdown); - } - - FINLINE RCODE getExitCode( void) - { - return( m_exitRc); - } - - FINLINE void * getParm1( void) - { - return( m_pvParm1); - } - - FINLINE void setParm1( - void * pvParm) - { - m_pvParm1 = pvParm; - } - - FINLINE void * getParm2( void) - { - return( m_pvParm2); - } - - FINLINE void setParm2( - void * pvParm) - { - m_pvParm2 = pvParm; - } - - FINLINE void setShutdownFlag( void) - { - m_bShutdown = TRUE; - } - - FINLINE FLMBOOL isThreadRunning( void) - { - return( m_bRunning); - } - - void setThreadStatus( - const char * pszBuffer, ...); - - void setThreadStatus( - eFlmThreadStatus eGenericStatus); - - FINLINE void setThreadAppId( - FLMUINT uiAppId) - { - f_mutexLock( m_hMutex); - m_uiAppId = uiAppId; - f_mutexUnlock( m_hMutex); - } - - FINLINE FLMUINT getThreadAppId( void) - { - return( m_uiAppId); - } - - FINLINE FLMUINT getThreadGroup( void) - { - return( m_uiThreadGroup); - } - - void cleanupThread( void); - - void _setThreadStatus( - const char * pszStatus); - - F_MUTEX m_hMutex; - F_Thread * m_pPrev; - F_Thread * m_pNext; - char * m_pszThreadName; - char * m_pszThreadStatus; - FLMUINT m_uiStatusBufLen; - FLMBOOL m_bShutdown; - F_THREAD_FUNC m_fnThread; - FLMBOOL m_bRunning; - FLMUINT m_uiStackSize; - void * m_pvParm1; - void * m_pvParm2; - FLMUINT m_uiThreadId; - FLMUINT m_uiThreadGroup; - FLMUINT m_uiAppId; - FLMUINT m_uiStartTime; - RCODE m_exitRc; - -friend class F_ThreadMgr; -}; - -RCODE f_threadCreate( - F_Thread ** ppThread, - F_THREAD_FUNC fnThread, - const char * pszThreadName = NULL, - FLMUINT uiThreadGroup = 0, - FLMUINT uiAppId = 0, - void * pvParm1 = NULL, - void * pvParm2 = NULL, - FLMUINT uiStackSize = (16 * 1024)); - -void f_threadDestroy( - F_Thread ** ppThread); - -#include "fpackoff.h" - -#endif diff --git a/flaim/src/ftktime.cpp b/flaim/src/ftktime.cpp deleted file mode 100644 index 38b9f14..0000000 --- a/flaim/src/ftktime.cpp +++ /dev/null @@ -1,442 +0,0 @@ -//------------------------------------------------------------------------- -// Desc: Cross platform toolkit for time functions. -// Tabs: 3 -// -// Copyright (c) 2000,2002-2003,2005-2006 Novell, Inc. All Rights Reserved. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of version 2 of the GNU General Public -// License as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, contact Novell, Inc. -// -// To contact Novell about this file by physical or electronic mail, -// you may find current contact information at www.novell.com -// -// $Id: ftktime.cpp 12299 2006-01-19 15:01:23 -0700 (Thu, 19 Jan 2006) dsanders $ -//------------------------------------------------------------------------- - -#include "flaimsys.h" - -#ifdef FLM_NLM - - #if !defined( __MWERKS__) - #pragma warning 007 9 - #endif - - FINLINE unsigned long time( - unsigned long * pulSeconds) - { - clockAndStatus clock; - - GetCurrentClock( &clock); - - if (pulSeconds) - { - *pulSeconds = (unsigned long)clock [0]; - } - - return ( (unsigned long)clock[0] ); - } -#endif - -#define BASEYR 1970 /* all gmt calcs done since 1970 */ -#define SECONDSPERDAY 86400l /* 24 hours * 60 minutes * 60 seconds */ -#define SECONDSPERHOUR 3600 /* 60 minutes * 60 seconds */ -#define DDAYSPERYEAR 365 /* 365 days/year */ - -static FLMUINT8 ui8NumDaysPerMonth[2][12] = { /* days of the months */ - {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}, - {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31} }; - -static FLMUINT16 ui16NumDaysFromJan1st[2][12] = { - /* current total of the days in the year by mon */ - { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334}, - { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335} }; - -static F_TMSTAMP maxdate = - { 2106, 1, 6, 11, 0, 0, 0 }; - -static FLMUINT f_timeLeapYearsSince1970( - FLMUINT16 year); - -#define f_timeIsLeapYear( year) \ - ((((year) & 0x03) == 0) && (((year) % 100) != 0) || \ - (((year) % 400) == 0)) - -/**************************************************************************** -Desc: Gets the number of seconds since 1980 or 1970. -****************************************************************************/ -FLMEXP void FLMAPI f_timeGetSeconds( - FLMUINT * puiSeconds) -{ -#if defined( FLM_WIN) - *puiSeconds = (FLMUINT) time( (time_t *) 0 ); - -#elif defined( FLM_NLM) - *puiSeconds = (FLMUINT) time( NULL); - -#elif defined( FLM_UNIX) - *puiSeconds = (FLMUINT) time( 0); - -#else -#error Platform not supported -#endif -} - -/**************************************************************************** -Desc: Gets the time stamp from the system clock. -****************************************************************************/ -FLMEXP void FLMAPI f_timeGetTimeStamp( - F_TMSTAMP * pTimeStamp) -{ -#if defined( FLM_WIN) - SYSTEMTIME rightnow; - - GetLocalTime( &rightnow ); - - pTimeStamp->year = rightnow.wYear; - pTimeStamp->month = (FLMUINT8)(rightnow.wMonth - 1); - pTimeStamp->day = (FLMUINT8)rightnow.wDay; - - pTimeStamp->hour = (FLMUINT8)rightnow.wHour; - pTimeStamp->minute = (FLMUINT8)rightnow.wMinute; - pTimeStamp->second = (FLMUINT8)rightnow.wSecond; - pTimeStamp->hundredth = rightnow.wMilliseconds / 10; - -#elif defined( FLM_NLM) - f_timeSecondsToDate( (FLMUINT) - time( NULL) - f_timeGetLocalOffset(), pTimeStamp); - -#elif defined( FLM_UNIX) - time_t now; - struct tm rightnow; - - now = time( (time_t *) 0 ); - (void)localtime_r( &now, &rightnow ); - - pTimeStamp->year = rightnow.tm_year + 1900; - pTimeStamp->month = rightnow.tm_mon; - pTimeStamp->day = rightnow.tm_mday; - pTimeStamp->hour = rightnow.tm_hour; - pTimeStamp->minute = rightnow.tm_min; - pTimeStamp->second = rightnow.tm_sec; - pTimeStamp->hundredth = 0; -#else -#error Platform not supported -#endif -} - -/**************************************************************************** -Desc: Returns the local time bias in seconds -****************************************************************************/ -FLMEXP FLMINT FLMAPI f_timeGetLocalOffset( void) -{ - FLMINT iOffset = 0; - -#if defined( FLM_WIN) - TIME_ZONE_INFORMATION tzInfo; - DWORD retVal; - - retVal = GetTimeZoneInformation( &tzInfo); - - if( retVal != TIME_ZONE_ID_UNKNOWN) - { - iOffset = - (retVal == TIME_ZONE_ID_DAYLIGHT && tzInfo.DaylightDate.wMonth - ? tzInfo.Bias + tzInfo.DaylightBias - : tzInfo.Bias) * 60; - } - -#elif defined( FLM_NLM) - - Synchronized_Clock_T SynchronizedClock; - - f_memset( &SynchronizedClock, 0, sizeof( SynchronizedClock)); - GetSyncClockFields( - SYNCCLOCK_DAYLIGHT_BIT | SYNCCLOCK_DAYLIGHT_OFFSET_BIT | - SYNCCLOCK_DAYLIGHT_ON_OFF_BIT | SYNCCLOCK_TIMEZONE_OFFSET_BIT, - &SynchronizedClock); - - iOffset = (FLMINT)SynchronizedClock.timezoneOffset; - if( SynchronizedClock.daylight && SynchronizedClock.daylightOnOff) - { - iOffset += (FLMINT)SynchronizedClock.daylightOffset; - } -#elif defined( FLM_UNIX) - time_t gmtTime; - time_t localTime; - struct tm gmtTm; - - gmtTime = time( (time_t *)0); - gmtime_r( &gmtTime, &gmtTm); - localTime = mktime( &gmtTm); - iOffset = (FLMINT)((FLMINT64)localTime - (FLMINT64)gmtTime); - -#else -#error Platform not supported -#endif - - return( iOffset); -} - -/**************************************************************************** -Desc: Count the number of leap years from 1970 to given year. -Notes: According to the Gregorian calendar (which we currently use), the - year is a leap year if it is divisible by 4, unless it is a century - year, then it must be divisible by 400. -****************************************************************************/ -static FLMUINT f_timeLeapYearsSince1970( - FLMUINT16 ui16Year) -{ - FLMUINT uiTemp; - - /* first calculate # of leap years since 1600 */ - - ui16Year -= 1601; /* ui16Year = number of years since 1600*/ - uiTemp = ( /* Count leap years */ - (ui16Year / 4) - /* Count potential leap years */ - (ui16Year / 100) + /* Subtract out century years */ - (ui16Year / 400) + /* Add back in quadricentenial years*/ - 1 /* And don't forget to count 1600 */ - ); - - /* now subtract # of leap years between 1600 and 1970 */ - /* (the following becomes a constant at compile time) */ - - uiTemp -= ((BASEYR-1600) / 4) - ((BASEYR-1600) / 100) + 1; - return(uiTemp); -} - -/**************************************************************************** -Desc: Convert from seconds to the F_TMSTAMP structure. -****************************************************************************/ -FLMEXP void FLMAPI f_timeSecondsToDate( - FLMUINT uiSeconds, - F_TMSTAMP * date) -{ - FLMUINT uiLeapYear; - FLMUINT uiMonth; - FLMUINT uiDaysInMonth; - FLMUINT uiDay; - - uiDay = uiSeconds / SECONDSPERDAY; // # of days since 1970 - date->year = (FLMUINT16)((uiDay / DDAYSPERYEAR) + BASEYR); - uiDay = uiDay % DDAYSPERYEAR; // # of days into year - - /* - Check to see that the value for the current day is greater than the - number of leap years since 1970. This is because we will be - subtracting the leap days from the current day and we don't want - the value for the day to go negative. - */ - - while( uiDay < f_timeLeapYearsSince1970(date->year)) // if day < # of leap years - { - date->year--; // decrement the year - uiDay += DDAYSPERYEAR; // adjust day by days/year - } - - uiDay -= f_timeLeapYearsSince1970( date->year); // subtract leap days - uiLeapYear = f_timeIsLeapYear( date->year ); // set leap year flag - - /* - Find what our offset into the current month is. - To do this, we subtract out the number of days for each month, until - the number of days left does not span the end of the current month - */ - - for( uiMonth = 0; - uiMonth < 12 && - (uiDay >= (uiDaysInMonth = ui8NumDaysPerMonth[uiLeapYear][uiMonth])); - uiMonth++) - { - uiDay -= uiDaysInMonth; // subtract days in month - } - date->month = (FLMUINT8) uiMonth; // set month, day - date->day = (FLMUINT8) (++uiDay); - - uiDay = uiSeconds % SECONDSPERDAY; // mod by seconds/day - date->hour = (FLMUINT8)(uiDay / SECONDSPERHOUR);// get # of hours - uiDay = uiDay % SECONDSPERHOUR; - date->minute = (FLMUINT8)(uiDay / 60); // get # of minutes - date->second = (FLMUINT8)(uiDay % 60); - date->hundredth = 0; // no fractional seconds -} - -/**************************************************************************** -Desc: Convert a time stamp to the number of seconds. -****************************************************************************/ -FLMEXP void FLMAPI f_timeDateToSeconds( - F_TMSTAMP * pTimeStamp, // [in] - time stamp of date - FLMUINT * puiSeconds) // [out] - seconds of time stamp -{ - - FLMUINT uiDays = 0; - - // is date past max? - if( f_timeCompareTimeStamps( pTimeStamp, &maxdate, COMPARE_DATE_AND_TIME) > 0) - { - *pTimeStamp = maxdate; - } - - // Do date portion of calculation - result is days since 1/1/1970. - - if( pTimeStamp->year) - { - uiDays = - (pTimeStamp->year - BASEYR) * 365 + // years since BASE * days - f_timeLeapYearsSince1970( pTimeStamp->year) +// leap years since BASE - ui16NumDaysFromJan1st[ f_timeIsLeapYear(pTimeStamp->year)][pTimeStamp->month] + - pTimeStamp->day - 1; // days since 1st of month - } - - // Do time part of calculation - secs since 1/1/1970 12:00am. - - *puiSeconds = (((uiDays * 24) + // convert days to hours - pTimeStamp->hour ) * 60 + // convert hours to min - pTimeStamp->minute) * 60 + // convert min to sec - pTimeStamp->second; // give secs granularity - -} - -/**************************************************************************** -Desc: Compare two time stamps -****************************************************************************/ -FLMEXP FLMINT FLMAPI f_timeCompareTimeStamps( - F_TMSTAMP * pTimeStamp1, - F_TMSTAMP * pTimeStamp2, - FLMUINT uiCompareFlag) -{ - if( uiCompareFlag != COMPARE_TIME_ONLY) /* not comparing times only */ - { - if( pTimeStamp1->year != pTimeStamp2->year) - { - return((pTimeStamp1->year < pTimeStamp2->year) ? -1 : 1); - } - if( pTimeStamp1->month != pTimeStamp2->month) - { - return((pTimeStamp1->month < pTimeStamp2->month) ? -1 : 1); - } - if( pTimeStamp1->day != pTimeStamp2->day) - { - return((pTimeStamp1->day < pTimeStamp2->day) ? -1 : 1); - } - } - if( uiCompareFlag != COMPARE_DATE_ONLY) - { - if( pTimeStamp1->hour != pTimeStamp2->hour) - { - return((pTimeStamp1->hour < pTimeStamp2->hour) ? -1 : 1); - } - if( pTimeStamp1->minute != pTimeStamp2->minute) - { - return((pTimeStamp1->minute < pTimeStamp2->minute) ? -1 : 1); - } - if( pTimeStamp1->second != pTimeStamp2->second) - { - return((pTimeStamp1->second < pTimeStamp2->second) ? -1 : 1); - } - } - return(0); -} - -/**************************************************************************** -Desc: Get the current time in milliseconds. -****************************************************************************/ -#if defined( FLM_UNIX) -FLMEXP FLMUINT FLMAPI f_timeGetMilliTime() -{ -#ifdef FLM_SOLARIS - static hrtime_t epoch = 0; - hrtime_t now = gethrtime(); /* hrtime returns in nanosecs */ - - if (!epoch) - epoch = now; - - return( (FLMUINT)((now - epoch) / (1000 * 1000))); -#else - static int epoch = 0; - struct timeval tv; - - gettimeofday(&tv, 0); - if (!epoch) - epoch = tv.tv_sec; - - return( (FLMUINT)((tv.tv_sec - epoch) * 1000 + tv.tv_usec / 1000)); -#endif -} -#endif - -/**************************************************************************** -Desc: Get the current time as platform-dependent timer units. -****************************************************************************/ -FLMEXP FLMUINT FLMAPI f_getCurrTimeAsTimerUnits( void) -{ - return( FLM_GET_TIMER()); -} - -/**************************************************************************** -Desc: Convert seconds to platform-dependent timer units. -****************************************************************************/ -FLMEXP FLMUINT FLMAPI f_secondsToTimerUnits( - FLMUINT uiSeconds) -{ - FLMUINT uiTimerUnits; - - FLM_SECS_TO_TIMER_UNITS( uiSeconds, uiTimerUnits); - return( uiTimerUnits); -} - -/**************************************************************************** -Desc: Convert platform-dependent timer units to seconds. -****************************************************************************/ -FLMEXP FLMUINT FLMAPI f_timerUnitsToSeconds( - FLMUINT uiTimerUnits) -{ - FLMUINT uiSeconds; - - FLM_TIMER_UNITS_TO_SECS( uiTimerUnits, uiSeconds); - return( uiSeconds); -} - -/**************************************************************************** -Desc: Convert milliseconds to platform-dependent timer units. -****************************************************************************/ -FLMEXP FLMUINT FLMAPI f_milliSecondsToTimerUnits( - FLMUINT uiMilliSeconds) -{ - FLMUINT uiTimerUnits; - - FLM_MILLI_TO_TIMER_UNITS( uiMilliSeconds, uiTimerUnits); - return( uiTimerUnits); -} - -/**************************************************************************** -Desc: Convert platform-dependent timer units to milli-seconds. -****************************************************************************/ -FLMEXP FLMUINT FLMAPI f_timerUnitsToMilliSeconds( - FLMUINT uiTimerUnits) -{ - FLMUINT uiMilliSeconds; - - FLM_TIMER_UNITS_TO_MILLI( uiTimerUnits, uiMilliSeconds); - return( uiMilliSeconds); -} - -/**************************************************************************** -Desc: Return elapsed time (as platform-dependent timer units). Input - parameters must be passed in as platform-dependent timer units. -****************************************************************************/ -FLMEXP FLMUINT FLMAPI f_elapsedTimeTimerUnits( - FLMUINT uiEarlierTimeTimerUnits, - FLMUINT uiLaterTimeTimerUnits) -{ - return( FLM_ELAPSED_TIME( uiLaterTimeTimerUnits, uiEarlierTimeTimerUnits)); -} diff --git a/flaim/src/ftrace.cpp b/flaim/src/ftrace.cpp deleted file mode 100644 index a40107b..0000000 --- a/flaim/src/ftrace.cpp +++ /dev/null @@ -1,767 +0,0 @@ -//------------------------------------------------------------------------- -// Desc: Trace class. -// Tabs: 3 -// -// Copyright (c) 1999-2000,2003-2006 Novell, Inc. All Rights Reserved. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of version 2 of the GNU General Public -// License as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, contact Novell, Inc. -// -// To contact Novell about this file by physical or electronic mail, -// you may find current contact information at www.novell.com -// -// $Id: ftrace.cpp 12329 2006-01-20 17:49:30 -0700 (Fri, 20 Jan 2006) ahodgkinson $ -//------------------------------------------------------------------------- - -#include "flaimsys.h" - -FSTATIC FLMUINT traceFormatNumber( - FLMUINT64 ui64Number, - FLMINT uiBase, - char * pszDest); - -/**************************************************************************** -Public: Constructors -****************************************************************************/ -FlmTrace::FlmTrace() -{ - m_hMutex = F_MUTEX_NULL; - m_uiLockCnt = 0; -#ifdef FLM_DEBUG - m_uiLockThreadId = 0; -#endif - m_uiEnabledCategories = 0; - m_pTracePipe = NULL; -} - -/**************************************************************************** -Public: Destructor -****************************************************************************/ -FlmTrace::~FlmTrace() -{ - flmAssert( m_uiLockCnt == 0); - if (m_hMutex != F_MUTEX_NULL) - { - f_mutexDestroy( &m_hMutex); - } - if (m_pTracePipe) - { - m_pTracePipe->Release(); - } -} - -/**************************************************************************** -Public: addRef -Desc: Add a reference to this object. -****************************************************************************/ -FLMINT FlmTrace::AddRef( void) -{ - FLMINT iRefCnt; - - lock(); - iRefCnt = flmAtomicInc( &m_refCnt, m_hMutex, TRUE); - unlock(); - - return( iRefCnt); -} - -/**************************************************************************** -Public: release -Desc: Removes a reference to this object. -****************************************************************************/ -FLMINT FlmTrace::Release( void) -{ - FLMINT iRefCnt; - - lock(); - iRefCnt = flmAtomicDec( &m_refCnt, m_hMutex, TRUE); - unlock(); - - if( !iRefCnt) - { - delete this; - } - - return( iRefCnt); -} - -/**************************************************************************** -Public: FlmTrace::trace -Desc: Outputs the formatted message to the appropriate places. -****************************************************************************/ -void FlmTrace::trace( - FLMUINT uiCategory, - const char * pszFormat, - ... - ) -{ - f_va_list args; - - f_va_start( args, pszFormat); - - // First see if the stuff is enabled. - - if (uiCategory & m_uiEnabledCategories) - { - lock(); - - // Leave room for terminator. - - m_uiMaxLen = sizeof( m_szDestStr) - 1; - m_pszDestStr = &m_szDestStr [0]; - m_uiCurrentForeColor = FLM_CURRENT_COLOR; - m_uiCurrentBackColor = FLM_CURRENT_COLOR; - m_uiForeColorDepth = 0; - m_uiBackColorDepth = 0; - m_uiCategory = uiCategory; - traceOutputArgs( pszFormat, (f_va_list *)&args); - outputCurrentText( m_uiCurrentForeColor, m_uiCurrentBackColor); - unlock(); - } - f_va_end( args); -} - -/**************************************************************************** -Public: FlmTrace::setMultiThreaded -Desc: Enables this as a multi-threaded trace object. -****************************************************************************/ -FLMBOOL FlmTrace::setMultiThreaded( void) -{ - FLMBOOL bOk = TRUE; - - if (m_hMutex == F_MUTEX_NULL) - { - if (RC_BAD( f_mutexCreate( &m_hMutex))) - { - bOk = FALSE; - } - } - return( bOk); -} - -/**************************************************************************** -Public: FlmTrace::setPipe -Desc: Sets a FlmTrace object to pipe output to. -****************************************************************************/ -void FlmTrace::setPipe( - FlmTrace * pTracePipe - ) -{ - lock(); - if (m_pTracePipe && m_pTracePipe != pTracePipe) - { - m_pTracePipe->Release(); - } - if ((m_pTracePipe = pTracePipe) != NULL) - { - m_pTracePipe->AddRef(); - } - unlock(); -} - -/**************************************************************************** -Public: FlmTrace::lock -Desc: Locks the object for multi-threaded use. -****************************************************************************/ -void FlmTrace::lock( void) -{ - if (m_uiLockCnt) - { -#ifdef FLM_DEBUG - flmAssert( m_uiLockThreadId == f_threadId()); -#endif - m_uiLockCnt++; - } - else if (m_hMutex != F_MUTEX_NULL) - { - f_mutexLock( m_hMutex); - m_uiLockCnt++; -#ifdef FLM_DEBUG - m_uiLockThreadId = f_threadId(); -#endif - } -} - -/**************************************************************************** -Public: FlmTrace::unlock -Desc: Unlocks the object for multi-threaded use. -****************************************************************************/ -void FlmTrace::unlock( void) -{ - if (m_uiLockCnt) - { -#ifdef FLM_DEBUG - flmAssert( m_uiLockThreadId == f_threadId()); -#endif - m_uiLockCnt--; - if (!m_uiLockCnt && m_hMutex != F_MUTEX_NULL) - { - f_mutexUnlock( m_hMutex); -#ifdef FLM_DEBUG - m_uiLockThreadId = 0; -#endif - } - } -} - -/**************************************************************************** -Public: FlmTrace::outputText -Desc: Calls outputString and then forwards to pipe for output. -****************************************************************************/ -void FlmTrace::outputText( - FLMUINT uiCategory, - FLMUINT uiForeColor, - FLMUINT uiBackColor, - const char * pszString) -{ - lock(); - outputString( uiCategory, uiForeColor, uiBackColor, pszString); - unlock(); - - if (m_pTracePipe) - { - if (uiCategory & m_pTracePipe->getEnabledCategories()) - { - m_pTracePipe->outputText( uiCategory, uiForeColor, uiBackColor, - pszString); - } - } -} - -/**************************************************************************** -Desc: Parameter 'ppszFormat' points to text following a '%' sign. Process - legal field information. Leave 'ppszFormat' pointing at the format - specifier character. -****************************************************************************/ -void FlmTrace::processFieldInfo( - const char ** ppszFormat, - FLMUINT * puiWidth, - FLMUINT * puiPrecision, - FLMUINT * puiFlags, - f_va_list * args) -{ - const char * pszTmp = *ppszFormat; - - /* process flags */ - - *puiFlags = 0; - for (;;) - { - switch (*pszTmp) - { - case '-': *puiFlags |= FORMAT_MINUS_FLAG; break; - case '+': *puiFlags |= FORMAT_PLUS_FLAG; break; - case ' ': *puiFlags |= FORMAT_SPACE_FLAG; break; - case '#': *puiFlags |= FORMAT_POUND_FLAG; break; - case '0': *puiFlags |= FORMAT_ZERO_FLAG; break; - default: - goto Out1; - } - pszTmp++; - } -Out1: - - // process width - - *puiWidth = 0; - if (*pszTmp == '*') - { - *puiWidth = f_va_arg( *args, unsigned int); - ++pszTmp; - } - else while (*pszTmp >= '0' && *pszTmp <= '9') - { - *puiWidth = (*puiWidth * 10) + (*pszTmp - '0'); - ++pszTmp; - } - - // process precision - - *puiPrecision = 0; - if (*pszTmp == '.') - { - ++pszTmp; - if (*pszTmp == '*') - { - *puiPrecision = f_va_arg( *args, unsigned int); - ++pszTmp; - } - else while (*pszTmp >= '0' && *pszTmp <= '9') - { - *puiPrecision = (*puiPrecision * 10) + (*pszTmp - '0'); - ++pszTmp; - } - } - - // size modifiers - - switch( *pszTmp) - { - case 'L': *puiFlags |= FORMAT_DOUBLE_FLAG; ++pszTmp; break; - case 'l': *puiFlags |= FORMAT_LONG_FLAG; ++pszTmp; break; - case 'h': *puiFlags |= FORMAT_SHORT_FLAG; ++pszTmp; break; - case 'I': - { - if( pszTmp[1] == '6' && pszTmp[2] == '4') - { - *puiFlags |= FORMAT_INT64_FLAG; - pszTmp += 3; - } - break; - } - } - *ppszFormat = pszTmp; -} - -/**************************************************************************** -Desc: Handle text portions of the text string. -****************************************************************************/ -void FlmTrace::processStringText( - FLMUINT uiLen, - ...) -{ - f_va_list args; - - f_va_start(args, uiLen); - if (uiLen) - { - formatString( 0, uiLen, uiLen, 0, (f_va_list *)&args); - } - f_va_end(args); -} - -/**************************************************************************** -Desc: Parse arguments in pszFormat, calling approopriate handlers. -****************************************************************************/ -void FlmTrace::traceOutputArgs( - const char * pszFormat, - f_va_list * args) -{ - FLMUINT uiChar; - FLMUINT uiWidth; - FLMUINT uiPrecision; - FLMUINT uiFlags; - const char * pszTextStart = pszFormat; - - while ((uiChar = (FLMUINT)*pszFormat++) != 0) - { - if (uiChar != '%') - { - continue; - } - uiWidth = pszFormat - pszTextStart - 1; - processStringText( uiWidth, pszTextStart); - processFieldInfo( &pszFormat, &uiWidth, &uiPrecision, &uiFlags, args); - uiChar = (FLMUINT)*pszFormat++; - - switch (uiChar) - { - case 'c': - case '%': - formatChar( uiChar, args); - break; - case 'B': - case 'F': - formatColor( uiChar, uiWidth, uiFlags); - break; - case 'd': - case 'o': - case 'u': - case 'x': - case 'X': - formatNumber( uiChar, uiWidth, uiPrecision, uiFlags, args); - break; - case 's': - case 'S': - case 'U': - formatString( uiChar, uiWidth, uiPrecision, uiFlags, args); - break; - - default: - formatNotHandled(); - break; - } - pszTextStart = pszFormat; - } - processStringText( (FLMUINT)(pszFormat - pszTextStart) - 1, pszTextStart); -} - -/**************************************************************************** -Desc: Change colors - may only push or pop a color on to the color stack. -****************************************************************************/ -void FlmTrace::formatColor( - FLMUINT uiChar, - FLMUINT uiColor, - FLMUINT uiFlags) -{ - FLMUINT uiPrevForeColor = m_uiCurrentForeColor; - FLMUINT uiPrevBackColor = m_uiCurrentBackColor; - - if (uiChar == 'F') // Foreground color - { - if ((uiFlags & FORMAT_PLUS_FLAG) && m_uiForeColorDepth < 8) - { - m_uiForeColorStack [m_uiForeColorDepth++] = m_uiCurrentForeColor; - } - else if ((uiFlags & FORMAT_MINUS_FLAG) && m_uiForeColorDepth > 0) - { - m_uiCurrentForeColor = m_uiForeColorStack [--m_uiForeColorDepth]; - } - else - { - m_uiCurrentForeColor = uiColor; - } - } - else // uiChar == 'B' - background color - { - if ((uiFlags & FORMAT_PLUS_FLAG) && m_uiBackColorDepth < 8) - { - m_uiBackColorStack [m_uiBackColorDepth++] = m_uiCurrentBackColor; - } - else if ((uiFlags & FORMAT_MINUS_FLAG) && m_uiBackColorDepth > 0) - { - m_uiCurrentBackColor = m_uiBackColorStack [--m_uiBackColorDepth]; - } - else - { - m_uiCurrentBackColor = uiColor; - } - } - - // If the color changed, output the current text with the last - // colors we had. - - if ((m_uiCurrentForeColor != uiPrevForeColor) || - (m_uiCurrentBackColor != uiPrevBackColor)) - { - outputCurrentText( uiPrevForeColor, uiPrevBackColor); - } -} - -/**************************************************************************** -Desc: String formatter. - Outputs the asciiz string specified by ADDRESS in 's'. - Outputs length preceeded string specified by ADDRESS in 'S'. - Outputs unicode string specified by ADDRESS in 'U'. - Format: %[flags][width][.prec]'s'|'S'|'U' - flags = '-' left justifies if string length < width - width = minimum number of characters to print - prec = maximum number of characters to print -****************************************************************************/ -void FlmTrace::formatString( - FLMUINT uiFormatChar, - FLMUINT uiWidth, - FLMUINT uiPrecision, - FLMUINT uiFlags, - f_va_list * args) -{ - F_SPRINTF_INFO info; - - info.pszDestStr = m_pszDestStr; - flmSprintfStringFormatter( (FLMBYTE)uiFormatChar, uiWidth, - uiPrecision, uiFlags, &info, args); - m_pszDestStr = info.pszDestStr; -} - -/**************************************************************************** -Desc: This is used by printf and sprintf to output numbers. It uses - recursion to separate the numbers down to individual digits and - output them in the proper order. -****************************************************************************/ -FSTATIC FLMUINT traceFormatNumber( - FLMUINT64 ui64Number, - FLMINT uiBase, - char * pszDest) -{ - char c = (char)(ui64Number % uiBase); - FLMUINT64 ui64Index = ui64Number / uiBase; - - ui64Index = ui64Index - ? traceFormatNumber( ui64Index, uiBase, pszDest) - : 0; - pszDest [ui64Index] = (char)((c > 9) - ? c + 'a' - 10 - : c + '0'); - return (FLMUINT)(ui64Index + 1); -} - -// Percent formating prefixes - -#define P_NONE 0 -#define P_MINUS 1 -#define P_PLUS 2 -#define P_POUND 3 - -/**************************************************************************** -Desc: Number formatter. - Formats the number specified by VALUE in 'd', 'o', 'u', 'x', or 'X' - Format: %[flags][width][.prec]'E' - flags = 'h' value is uint16 - 'l' value is uint32 - '-' left align result - '+' print plus sign if positive - '#' print '0x' in front of hex numbers - '0' zero-fill - width = minimum number of characters to output - prec = maximum number of characters to output (truncates or rounds) -****************************************************************************/ -void FlmTrace::formatNumber( - FLMUINT uiFormatChar, - FLMUINT uiWidth, - FLMUINT uiPrecision, - FLMUINT uiFlags, - f_va_list * args) -{ - FLMUINT uiCount; - FLMUINT uiPrefix = P_NONE; - FLMUINT uiLength; - FLMUINT uiBase = 10; - char szNumberBuffer [64]; - char * pszStr; - FLMUINT64 ui64Arg; - - if (uiFlags & FORMAT_SHORT_FLAG) - { - ui64Arg = f_va_arg( *args, int); - } - else if (uiFlags & FORMAT_LONG_FLAG) - { - ui64Arg = f_va_arg( *args, long int); - } - else if ( uiFlags & FORMAT_INT64_FLAG) - { - ui64Arg = f_va_arg( *args, FLMUINT64); - } - else - { - ui64Arg = f_va_arg( *args, int); - } - - switch (uiFormatChar) - { - case 'd': - if ((long)ui64Arg < 0) - { - // handle negatives - - uiPrefix = P_MINUS; - if (uiWidth > 0) - { - uiWidth--; - } - ui64Arg = -(long)ui64Arg; - } - else if (uiFlags & FORMAT_PLUS_FLAG) - { - uiPrefix = P_PLUS; - if (uiWidth > 0) - uiWidth--; - } - break; - - case 'o': - uiBase = 8; - break; - - case 'x': - case 'X': - if (uiFlags & FORMAT_POUND_FLAG && ui64Arg) - { - uiPrefix = P_POUND; - if (uiWidth > 1) - { - uiWidth -= 2; - } - } - uiBase = 16; - break; - } - uiLength = traceFormatNumber( ui64Arg, uiBase, szNumberBuffer); - szNumberBuffer [uiLength] = 0; - if (uiFormatChar == 'X') - { - char * p = &szNumberBuffer [0]; - while (*p) - { - if ((*p >= 'a') && (*p <= 'z')) - { - *p = (char)(*p - 'a' + 'A'); - } - p++; - } - } - if (uiWidth < uiLength) - { - uiWidth = uiLength; - } - - if (uiFlags & FORMAT_ZERO_FLAG) - { - uiPrecision = uiWidth; // zero fill - } - else if (!(uiFlags & FORMAT_MINUS_FLAG)) - { - // Right justify. - - while ((uiWidth > uiLength) && - (uiWidth > uiPrecision)) - { - if (!m_uiMaxLen) - { - outputCurrentText( m_uiCurrentForeColor, m_uiCurrentBackColor); - } - *m_pszDestStr++ = ' '; - m_uiMaxLen--; - --uiWidth; - } - } - - // handle the prefix if any - - if (!m_uiMaxLen) - { - outputCurrentText( m_uiCurrentForeColor, m_uiCurrentBackColor); - } - switch (uiPrefix) - { - case P_MINUS: - *m_pszDestStr++ = '-'; - m_uiMaxLen--; - break; - case P_PLUS: - *m_pszDestStr++ = '+'; - m_uiMaxLen--; - break; - case P_POUND: - *m_pszDestStr++ = '0'; - m_uiMaxLen--; - if (!m_uiMaxLen) - { - outputCurrentText( m_uiCurrentForeColor, m_uiCurrentBackColor); - } - *m_pszDestStr++ = (char)uiFormatChar; - m_uiMaxLen--; - break; - } - - // handle the precision - - while (uiLength < uiPrecision) - { - if (!m_uiMaxLen) - { - outputCurrentText( m_uiCurrentForeColor, m_uiCurrentBackColor); - } - *m_pszDestStr++ = '0'; - m_uiMaxLen--; - --uiPrecision; - --uiWidth; - } - - // print out the number - - for (uiCount = uiLength, pszStr = szNumberBuffer; - uiCount > 0; - uiCount--, m_uiMaxLen--) - { - if (!m_uiMaxLen) - { - outputCurrentText( m_uiCurrentForeColor, m_uiCurrentBackColor); - } - *m_pszDestStr++ = *pszStr++; - } - - if (uiFlags & FORMAT_MINUS_FLAG) - { - while (uiLength < uiWidth) // left justify - { - if (!m_uiMaxLen) - { - outputCurrentText( m_uiCurrentForeColor, m_uiCurrentBackColor); - } - *m_pszDestStr++ = ' '; - m_uiMaxLen--; - --uiWidth; - } - } -} - -/**************************************************************************** -Desc: Character formatter. - FOrmats the character specified by VALUE in 'c', or the '%' character. - Format: %[flags][width][.prec]'c' - flags = - width = - prec = -****************************************************************************/ -void FlmTrace::formatChar( - FLMUINT uiFormatChar, - f_va_list * args) -{ - char c = (uiFormatChar == '%') - ? '%' - : f_va_arg( *args, int); - - if (!m_uiMaxLen) - { - outputCurrentText( m_uiCurrentForeColor, m_uiCurrentBackColor); - } - *m_pszDestStr++ = c; - m_uiMaxLen--; -} - - -/**************************************************************************** -Desc: Handles all formatting stuff that is invalid. -****************************************************************************/ -void FlmTrace::formatNotHandled( void) -{ - const char * pszNoFormatter = ""; - FLMUINT uiLen = f_strlen( pszNoFormatter); - FLMUINT uiTmpLen; - - while (uiLen) - { - if (!m_uiMaxLen) - { - outputCurrentText( m_uiCurrentForeColor, m_uiCurrentBackColor); - } - if ((uiTmpLen = uiLen) > m_uiMaxLen) - { - uiTmpLen = m_uiMaxLen; - } - f_memcpy( m_pszDestStr, (void *)pszNoFormatter, uiTmpLen); - m_pszDestStr += uiTmpLen; - m_uiMaxLen -= uiTmpLen; - uiLen -= uiTmpLen; - pszNoFormatter += uiTmpLen; - } -} - -/**************************************************************************** -Desc: Outputs the current text that we have buffered. -****************************************************************************/ -void FlmTrace::outputCurrentText( - FLMUINT uiForeColor, - FLMUINT uiBackColor - ) -{ - FLMUINT uiLen = (FLMUINT)(m_pszDestStr - &m_szDestStr [0]); - - if (uiLen) - { - m_szDestStr [uiLen] = 0; - outputText( m_uiCategory, uiForeColor, uiBackColor, m_szDestStr); - m_uiMaxLen = sizeof( m_szDestStr) - 1; - m_pszDestStr = &m_szDestStr [0]; - } -} diff --git a/flaim/src/ftrace.h b/flaim/src/ftrace.h deleted file mode 100644 index 21041b5..0000000 --- a/flaim/src/ftrace.h +++ /dev/null @@ -1,238 +0,0 @@ -//------------------------------------------------------------------------- -// Desc: Trace class - definitions. -// Tabs: 3 -// -// Copyright (c) 1999-2000,2002-2006 Novell, Inc. All Rights Reserved. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of version 2 of the GNU General Public -// License as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, contact Novell, Inc. -// -// To contact Novell about this file by physical or electronic mail, -// you may find current contact information at www.novell.com -// -// $Id: ftrace.h 12329 2006-01-20 17:49:30 -0700 (Fri, 20 Jan 2006) ahodgkinson $ -//------------------------------------------------------------------------- - -#ifndef FTRACE_H -#define FTRACE_H - -#include "fpackon.h" -// IMPORTANT NOTE: No other include files should follow this one except -// for fpackoff.h - -#define FORMAT_MINUS_FLAG 0x0001 -#define FORMAT_PLUS_FLAG 0x0002 -#define FORMAT_SPACE_FLAG 0x0004 -#define FORMAT_POUND_FLAG 0x0008 -#define FORMAT_ZERO_FLAG 0x0010 -#define FORMAT_SHORT_FLAG 0x0020 -#define FORMAT_LONG_FLAG 0x0040 -#define FORMAT_DOUBLE_FLAG 0x0080 -#define FORMAT_INT64_FLAG 0x0100 - -// Special strings to embed in trace() calls. - -#define FORE_BLACK "%0F" -#define FORE_BLUE "%1F" -#define FORE_GREEN "%2F" -#define FORE_CYAN "%3F" -#define FORE_RED "%4F" -#define FORE_MAGENTA "%5F" -#define FORE_BROWN "%6F" -#define FORE_LIGHTGRAY "%7F" -#define FORE_DARKGRAY "%8F" -#define FORE_LIGHTBLUE "%9F" -#define FORE_LIGHTGREEN "%10F" -#define FORE_LIGHTCYAN "%11F" -#define FORE_LIGHTRED "%12F" -#define FORE_LIGHTMAGENTA "%13F" -#define FORE_YELLOW "%14F" -#define FORE_WHITE "%15F" - -#define BACK_BLACK "%0B" -#define BACK_BLUE "%1B" -#define BACK_GREEN "%2B" -#define BACK_CYAN "%3B" -#define BACK_RED "%4B" -#define BACK_MAGENTA "%5B" -#define BACK_BROWN "%6B" -#define BACK_LIGHTGRAY "%7B" -#define BACK_DARKGRAY "%8B" -#define BACK_LIGHTBLUE "%9B" -#define BACK_LIGHTGREEN "%10B" -#define BACK_LIGHTCYAN "%11B" -#define BACK_LIGHTRED "%12B" -#define BACK_LIGHTMAGENTA "%13B" -#define BACK_YELLOW "%14B" -#define BACK_WHITE "%15B" - -#define PUSH_FORE_COLOR "%+F" -#define POP_FORE_COLOR "%-F" - -#define PUSH_BACK_COLOR "%+B" -#define POP_BACK_COLOR "%-B" - -// Standard trace categories - -// Categories reserved for users - -#define USER_CATEGORY1 0x8000000 -#define USER_CATEGORY2 0x4000000 -#define USER_CATEGORY3 0x2000000 -#define USER_CATEGORY4 0x1000000 -#define USER_CATEGORY5 0x0800000 -#define USER_CATEGORY6 0x0400000 -#define USER_CATEGORY7 0x0200000 -#define USER_CATEGORY8 0x0100000 - -/**************************************************************************** -Desc: Abstract base class which provides the record interface that - FLAIM uses to access and manipulate all records. -****************************************************************************/ - -class FlmTrace : public F_Base -{ -public: - - FlmTrace(); - - virtual ~FlmTrace(); - - FLMINT AddRef( void); - - FLMINT Release( void); - - FINLINE void enableCategory( - FLMUINT uiCategory) - { - m_uiEnabledCategories |= uiCategory; - } - - FINLINE void disableCategory( - FLMUINT uiCategory) - { - m_uiEnabledCategories &= (~(uiCategory)); - } - - FINLINE FLMBOOL categoryEnabled( - FLMUINT uiCategory) - { - return( ((m_uiEnabledCategories & uiCategory) == uiCategory) - ? TRUE - : FALSE); - } - - FINLINE FLMUINT getEnabledCategories( void) - { - return( m_uiEnabledCategories); - } - - void trace( - FLMUINT uiCategory, - const char * pszFormat, - ...); - - FLMBOOL setMultiThreaded( void); - - void setPipe( - FlmTrace * pTracePipe); - - void lock( void); - - void unlock( void); - - void outputText( - FLMUINT uiCategory, - FLMUINT uiForeColor, - FLMUINT uiBackColor, - const char * pszString); - - virtual void outputString( - FLMUINT uiCategory, - FLMUINT uiForeColor, - FLMUINT uiBackColor, - const char * pszString) = 0; - -private: - - void processFieldInfo( - const char ** ppszFormat, - FLMUINT * puiWidth, - FLMUINT * puiPrecision, - FLMUINT * puiFlags, - f_va_list * args); - - void processStringText( - FLMUINT uiLen, - ...); - - void traceOutputArgs( - const char * pszFormat, - f_va_list * args); - - void formatColor( - FLMUINT uiChar, - FLMUINT uiColor, - FLMUINT uiFlags); - - void formatString( - FLMUINT uiFormatChar, - FLMUINT uiWidth, - FLMUINT uiPrecision, - FLMUINT uiFlags, - f_va_list * args); - - void formatNumber( - FLMUINT uiFormatChar, - FLMUINT uiWidth, - FLMUINT uiPrecision, - FLMUINT uiFlags, - f_va_list * args); - - void formatChar( - FLMUINT uiFormatChar, - f_va_list * args); - - void formatNotHandled( void); - - void outputCurrentText( - FLMUINT uiForeColor, - FLMUINT uiBackColor); - - F_MUTEX m_hMutex; - FLMUINT m_uiLockCnt; -#ifdef FLM_DEBUG - FLMUINT m_uiLockThreadId; -#endif - FLMUINT m_uiEnabledCategories; - FlmTrace * m_pTracePipe; - - // Variables used to do the printf stuff - -#define MAX_FORMAT_STR_SIZE 1000 - - char m_szDestStr [MAX_FORMAT_STR_SIZE]; - char * m_pszDestStr; - FLMUINT m_uiMaxLen; - FLMUINT m_uiForeColorDepth; - FLMUINT m_uiBackColorDepth; - FLMUINT m_uiForeColorStack [8]; - FLMUINT m_uiBackColorStack [8]; - FLMUINT m_uiCurrentForeColor; - FLMUINT m_uiCurrentBackColor; - FLMUINT m_uiCategory; - -}; - -#include "fpackoff.h" - -#endif diff --git a/flaim/src/ftrans.cpp b/flaim/src/ftrans.cpp index 2b56dc3..7f65db1 100644 --- a/flaim/src/ftrans.cpp +++ b/flaim/src/ftrans.cpp @@ -119,7 +119,7 @@ FLMEXP RCODE FLMAPI FlmDbTransBegin( if( pucHeader) { - if( RC_BAD( rc = pDb->pSFileHdl->ReadHeader( + if( RC_BAD( rc = pDb->pSFileHdl->readHeader( 0, 2048, pucHeader, &uiBytesRead))) { goto Exit; diff --git a/flaim/src/furl.h b/flaim/src/furl.h index 3453388..263029b 100644 --- a/flaim/src/furl.h +++ b/flaim/src/furl.h @@ -40,7 +40,7 @@ typedef FUrl * FUrl_p; /**************************************************************************** Desc: The FUrl class is for dealing with URLs. ****************************************************************************/ -class FUrl: public F_Base +class FUrl: public F_Object { private: diff --git a/flaim/src/fwin.cpp b/flaim/src/fwin.cpp deleted file mode 100644 index 2585dfe..0000000 --- a/flaim/src/fwin.cpp +++ /dev/null @@ -1,1757 +0,0 @@ -//------------------------------------------------------------------------- -// Desc: Windows I/O -// Tabs: 3 -// -// Copyright (c) 1999-2003,2005-2006 Novell, Inc. All Rights Reserved. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of version 2 of the GNU General Public -// License as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, contact Novell, Inc. -// -// To contact Novell about this file by physical or electronic mail, -// you may find current contact information at www.novell.com -// -// $Id: fwin.cpp 12329 2006-01-20 17:49:30 -0700 (Fri, 20 Jan 2006) ahodgkinson $ -//------------------------------------------------------------------------- - -#include "flaimsys.h" - -#if defined( FLM_WIN) - extern RCODE gv_CriticalFSError; - - FSTATIC RCODE _DeleteFile( - const char * path); -#endif - -/*************************************************************************** -Desc: Maps WIN errors to IO errors. -***************************************************************************/ -#if defined( FLM_WIN) -RCODE MapWinErrorToFlaim( - DWORD udErrCode, - RCODE defaultRc) -{ - // Switch on passed in error code value - - switch (udErrCode) - { - case ERROR_NOT_ENOUGH_MEMORY: - case ERROR_OUTOFMEMORY: - return( RC_SET( FERR_MEM)); - case ERROR_BAD_NETPATH: - case ERROR_BAD_PATHNAME: - case ERROR_DIRECTORY: - case ERROR_FILE_NOT_FOUND: - case ERROR_INVALID_DRIVE: - case ERROR_INVALID_NAME: - case ERROR_NO_NET_OR_BAD_PATH: - case ERROR_PATH_NOT_FOUND: - return( RC_SET( FERR_IO_PATH_NOT_FOUND)); - - case ERROR_ACCESS_DENIED: - case ERROR_SHARING_VIOLATION: - case ERROR_FILE_EXISTS: - case ERROR_ALREADY_EXISTS: - return( RC_SET( FERR_IO_ACCESS_DENIED)); - - case ERROR_BUFFER_OVERFLOW: - case ERROR_FILENAME_EXCED_RANGE: - return( RC_SET( FERR_IO_PATH_TOO_LONG)); - - case ERROR_DISK_FULL: - case ERROR_HANDLE_DISK_FULL: - return( RC_SET( FERR_IO_DISK_FULL)); - - case ERROR_CURRENT_DIRECTORY: - case ERROR_DIR_NOT_EMPTY: - return( RC_SET( FERR_IO_MODIFY_ERR)); - - case ERROR_DIRECT_ACCESS_HANDLE: - case ERROR_INVALID_HANDLE: - case ERROR_INVALID_TARGET_HANDLE: - return( RC_SET( FERR_IO_BAD_FILE_HANDLE)); - - case ERROR_HANDLE_EOF: - return( RC_SET( FERR_IO_END_OF_FILE)); - - case ERROR_OPEN_FAILED: - return( RC_SET( FERR_IO_OPEN_ERR)); - - case ERROR_CANNOT_MAKE: - return( RC_SET( FERR_IO_PATH_CREATE_FAILURE)); - - case ERROR_LOCK_FAILED: - case ERROR_LOCK_VIOLATION: - return( RC_SET( FERR_IO_FILE_LOCK_ERR)); - - case ERROR_NEGATIVE_SEEK: - case ERROR_SEEK: - case ERROR_SEEK_ON_DEVICE: - return( RC_SET( FERR_IO_SEEK_ERR)); - - case ERROR_NO_MORE_FILES: - case ERROR_NO_MORE_SEARCH_HANDLES: - return( RC_SET( FERR_IO_NO_MORE_FILES)); - - case ERROR_TOO_MANY_OPEN_FILES: - return( RC_SET( FERR_IO_TOO_MANY_OPEN_FILES)); - - case NO_ERROR: - return( FERR_OK); - - case ERROR_DISK_CORRUPT: - case ERROR_DISK_OPERATION_FAILED: - case ERROR_FILE_CORRUPT: - case ERROR_FILE_INVALID: - case ERROR_NOT_SAME_DEVICE: - case ERROR_IO_DEVICE: - default: - return( RC_SET( defaultRc)); - - } -} -#endif - -/**************************************************************************** -Desc: Default Constructor for F_FileHdl class -****************************************************************************/ -#if defined( FLM_WIN) -F_FileHdlImp::F_FileHdlImp() -{ - m_FileHandle = INVALID_HANDLE_VALUE; - m_uiBlockSize = 0; - m_uiBytesPerSector = 0; - m_uiNotOnSectorBoundMask = 0; - m_uiGetSectorBoundMask = 0; - m_bDoDirectIO = FALSE; - m_uiExtendSize = 0; - m_uiMaxAutoExtendSize = gv_FlmSysData.uiMaxFileSize; - m_pucAlignedBuff = NULL; - m_uiAlignedBuffSize = 0; - m_uiCurrentPos = 0; - m_bCanDoAsync = FALSE; // Change to TRUE when we want to do async writes. - m_Overlapped.hEvent = NULL; -} -#endif - -/**************************************************************************** -Desc: Destructor for F_FileHdl class -****************************************************************************/ -#if defined( FLM_WIN) -F_FileHdlImp::~F_FileHdlImp() -{ - // Close file if it was open. - - if( m_bFileOpened) - { - (void)Close(); - } - - if (m_pucAlignedBuff) - { - f_mutexLock( gv_FlmSysData.hShareMutex); - flmAssert( gv_FlmSysData.SCacheMgr.Usage.uiTotalBytesAllocated >= - m_uiAlignedBuffSize); - gv_FlmSysData.SCacheMgr.Usage.uiTotalBytesAllocated -= - m_uiAlignedBuffSize; - f_mutexUnlock( gv_FlmSysData.hShareMutex); - - (void)VirtualFree( m_pucAlignedBuff, 0, MEM_RELEASE); - m_pucAlignedBuff = NULL; - m_uiAlignedBuffSize = 0; - } - - if (m_Overlapped.hEvent) - { - CloseHandle( m_Overlapped.hEvent); - } -} -#endif - -/*************************************************************************** -Desc: Open or create a file. -***************************************************************************/ -#if defined( FLM_WIN) -RCODE F_FileHdlImp::OpenOrCreate( - const char * pFileName, - FLMUINT uiAccess, - FLMBOOL bCreateFlag) -{ - char szSaveFileName[ F_PATH_MAX_SIZE]; - RCODE rc = FERR_OK; - DWORD udAccessMode = 0; - DWORD udShareMode = 0; - DWORD udCreateMode = 0; - DWORD udAttrFlags = 0; - DWORD udErrCode; - - if( RC_BAD( rc = GET_FS_ERROR())) - { - goto Exit; - } - - m_bDoDirectIO = (uiAccess & F_IO_DIRECT) ? TRUE : FALSE; - - if( uiAccess & F_IO_DELETE_ON_CLOSE) - { - if( !m_pszIoPath) - { - if( RC_BAD( rc = f_alloc( F_PATH_MAX_SIZE, &m_pszIoPath))) - { - goto Exit; - } - } - f_strcpy( m_pszIoPath, pFileName); - m_bDeleteOnClose = TRUE; - } - else - { - m_bDeleteOnClose = FALSE; - } - - // Save the file name in case we have to create the directory - - if ((bCreateFlag) && (uiAccess & F_IO_CREATE_DIR)) - { - f_strcpy( (char *)(&szSaveFileName), (char *)pFileName); - } - - // If doing direct IO, need to get the sector size. - - if (m_bDoDirectIO) - { - if (!m_uiBlockSize) - { - m_bDoDirectIO = FALSE; - } - else - { - if (RC_BAD( rc = gv_FlmSysData.pFileSystem->GetSectorSize( - pFileName, &m_uiBytesPerSector))) - { - goto Exit; - } - m_uiNotOnSectorBoundMask = m_uiBytesPerSector - 1; - m_uiGetSectorBoundMask = ~m_uiNotOnSectorBoundMask; - - // Can't do direct IO if the block size isn't a multiple of - // the sector size. - - if (m_uiBlockSize < m_uiBytesPerSector || - m_uiBlockSize % m_uiBytesPerSector != 0) - { - m_bDoDirectIO = FALSE; - } - } - } - - // Only enable asynchronous writes if direct I/O is enabled. - - if (m_bDoDirectIO) - { - m_bCanDoAsync = gv_FlmSysData.bOkToDoAsyncWrites; - } - - // Set up the file characteristics requested by caller. - - if (uiAccess & F_IO_SH_DENYRW) - { - udShareMode = 0; - uiAccess &= ~F_IO_SH_DENYRW; - } - else if (uiAccess & F_IO_SH_DENYWR) - { - udShareMode = FILE_SHARE_READ; - uiAccess &= ~F_IO_SH_DENYWR; - } - else if (uiAccess & F_IO_SH_DENYNONE) - { - udShareMode = (FILE_SHARE_READ | FILE_SHARE_WRITE); - uiAccess &= ~F_IO_SH_DENYNONE; - } - else - { - udShareMode = (FILE_SHARE_READ | FILE_SHARE_WRITE); - } - - // Begin setting the CreateFile flags and fields - - udAttrFlags = FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS; - if (m_bDoDirectIO) - { - udAttrFlags |= FILE_FLAG_NO_BUFFERING; - } - - if (m_bCanDoAsync) - { - udAttrFlags |= FILE_FLAG_OVERLAPPED; - } - - if (bCreateFlag) - { - if (uiAccess & F_IO_EXCL) - { - udCreateMode = CREATE_NEW; - } - else - { - udCreateMode = CREATE_ALWAYS; - } - } - else - { - udCreateMode = OPEN_EXISTING; - } - - udAccessMode = GENERIC_READ | GENERIC_WRITE; - - if ( (!bCreateFlag) && (uiAccess & F_IO_RDONLY) ) - udAccessMode = GENERIC_READ; - -Retry_Create: - - // Try to create or open the file - - if( (m_FileHandle = CreateFile( (LPCTSTR)pFileName, udAccessMode, - udShareMode, NULL, udCreateMode, - udAttrFlags, NULL)) == INVALID_HANDLE_VALUE) - { - udErrCode = GetLastError(); - if ((udErrCode == ERROR_PATH_NOT_FOUND) && (uiAccess & F_IO_CREATE_DIR)) - { - char szTemp[ F_PATH_MAX_SIZE]; - char ioDirPath[ F_PATH_MAX_SIZE]; - - uiAccess &= ~F_IO_CREATE_DIR; - - // Remove the file name for which we are creating the directory - - if( RC_OK( f_pathReduce( szSaveFileName, ioDirPath, szTemp))) - { - if( RC_OK( rc = gv_FlmSysData.pFileSystem->CreateDir( ioDirPath))) - { - goto Retry_Create; - } - else - { - goto Exit; - } - } - } - - rc = MapWinErrorToFlaim( udErrCode, - (RCODE)(bCreateFlag - ? (RCODE)(m_bDoDirectIO - ? (RCODE)FERR_DIRECT_CREATING_FILE - : (RCODE)FERR_CREATING_FILE) - : (RCODE)(m_bDoDirectIO - ? (RCODE)FERR_DIRECT_OPENING_FILE - : (RCODE)FERR_OPENING_FILE))); - goto Exit; - } - -Exit: - - if (RC_BAD( rc)) - { - m_FileHandle = INVALID_HANDLE_VALUE; - } - - return( rc ); -} -#endif - -/**************************************************************************** -Desc: Create a file -****************************************************************************/ -#if defined( FLM_WIN) -RCODE F_FileHdlImp::Create( - const char * pszIoPath, - FLMUINT uiIoFlags) -{ - RCODE rc = FERR_OK; - - flmAssert( m_bFileOpened == FALSE); - - if( RC_BAD( rc = GET_FS_ERROR())) - { - goto Exit; - } - - if( RC_BAD( rc = OpenOrCreate( pszIoPath, uiIoFlags, TRUE))) - { - goto Exit; - } - - m_bFileOpened = TRUE; - m_uiCurrentPos = 0; - m_bOpenedExclusive = (uiIoFlags & F_IO_SH_DENYRW) ? TRUE : FALSE; - -Exit: - - return( rc); -} -#endif - -/**************************************************************************** -Desc: -****************************************************************************/ -#if defined( FLM_WIN) -RCODE F_FileHdlImp::CreateUnique( - char * pszIoPath, - const char * pszFileExtension, - FLMUINT uiIoFlags) -{ - RCODE rc = FERR_OK; - char * pszTmp; - FLMBOOL bModext = TRUE; - FLMUINT uiBaseTime = 0; - char ucHighByte = 0; - char szFileName[ F_FILENAME_SIZE]; - char szDirPath[ F_PATH_MAX_SIZE]; - char szTmpPath[ F_PATH_MAX_SIZE]; - FLMUINT uiCount; - - szFileName[0] = '\0'; - szTmpPath[0] = '\0'; - flmAssert( !m_bFileOpened); - - if( RC_BAD( rc = GET_FS_ERROR())) - { - goto Exit; - } - - f_strcpy( szDirPath, pszIoPath); - - // Search backwards replacing trailing spaces with NULLs. - - pszTmp = (char *) szDirPath; - pszTmp += (f_strlen( pszTmp) - 1); - while( pszTmp >= (char *) szDirPath && (*pszTmp == 0x20)) - { - *pszTmp = 0; - pszTmp--; - } - - if (pszTmp >= (char *) szDirPath && *pszTmp != '\\') - { - pszTmp++; - *pszTmp++ = '\\'; - } - else - { - pszTmp++; - } - *pszTmp = 0; - - if ((pszFileExtension) && (f_strlen( pszFileExtension) >= 3)) - { - bModext = FALSE; - } - - uiCount = 0; - do - { - f_pathCreateUniqueName( &uiBaseTime, szFileName, pszFileExtension, - &ucHighByte, bModext); - - // Need to strcpy to the buffer b/c it is uninitialized - - f_strcpy( szTmpPath, szDirPath); - f_pathAppend( szTmpPath, szFileName); - - rc = Create( szTmpPath, uiIoFlags | F_IO_EXCL); - - if (rc == FERR_IO_DISK_FULL) - { - (void)_DeleteFile( szTmpPath); - goto Exit; - } - - if ((rc == FERR_IO_PATH_NOT_FOUND) || (rc == FERR_IO_INVALID_PASSWORD)) - { - goto Exit; - } - } while ((rc != FERR_OK) && (uiCount++ < 10)); - - // Check if the path was created - - if ((uiCount >= 10) && (rc != FERR_OK)) - { - rc = RC_SET( FERR_IO_PATH_CREATE_FAILURE); - goto Exit; - } - - m_bFileOpened = TRUE; - m_bOpenedExclusive = (uiIoFlags & F_IO_SH_DENYRW) ? TRUE : FALSE; - - // Created file name needs to be returned. - - f_strcpy( pszIoPath, szTmpPath); - -Exit: - - return( rc); -} -#endif - -/**************************************************************************** -Desc: Open a file -****************************************************************************/ -#if defined( FLM_WIN) -RCODE F_FileHdlImp::Open( - const char * pszIoPath, - FLMUINT uiIoFlags) -{ - RCODE rc = FERR_OK; - - flmAssert( m_bFileOpened == FALSE); - - if( RC_BAD( rc = GET_FS_ERROR())) - { - goto Exit; - } - - // Loop on error open conditions. - - for(;;) - { - if( RC_OK( rc = OpenOrCreate( pszIoPath, uiIoFlags, FALSE))) - break; - - if( rc != FERR_IO_TOO_MANY_OPEN_FILES ) - { - goto Exit; - } - - // If for some reason we cannot open the file, then - // try to close some other file handle in the list. - - if( RC_BAD( gv_FlmSysData.pFileHdlMgr->ReleaseOneAvail())) - { - goto Exit; - } - } - - m_bFileOpened = TRUE; - m_uiCurrentPos = 0; - m_bOpenedReadOnly = (uiIoFlags & F_IO_RDONLY) ? TRUE : FALSE; - m_bOpenedExclusive = (uiIoFlags & F_IO_SH_DENYRW) ? TRUE : FALSE; - -Exit: - - return( rc); -} -#endif - -/**************************************************************************** -Desc: Close a file -****************************************************************************/ -#if defined( FLM_WIN) -RCODE F_FileHdlImp::Close( void) -{ - FLMBOOL bDeleteAllowed = TRUE; - RCODE rc = FERR_OK; - - if( !m_bFileOpened) - { - goto Exit; - } - -#ifdef FLM_DEBUG - if( RC_BAD( rc = GET_FS_ERROR())) - { - bDeleteAllowed = FALSE; - } -#endif - if (!CloseHandle( m_FileHandle)) - { - rc = MapWinErrorToFlaim( GetLastError(), FERR_CLOSING_FILE); - goto Exit; - } - - m_FileHandle = INVALID_HANDLE_VALUE; - m_bFileOpened = m_bOpenedReadOnly = m_bOpenedExclusive = FALSE; - - if( m_bDeleteOnClose) - { - flmAssert( m_pszIoPath ); - - if( bDeleteAllowed) - { - (void)_DeleteFile( m_pszIoPath); - } - m_bDeleteOnClose = FALSE; - } - - if( m_pszIoPath) - { - f_free( &m_pszIoPath); - } - -Exit: - - return( rc); -} -#endif - -/**************************************************************************** -Desc: -****************************************************************************/ -#if defined( FLM_WIN) -RCODE F_FileHdlImp::Flush( void) -{ - RCODE rc = FERR_OK; - - if (m_bDoDirectIO) - { - rc = GET_FS_ERROR(); - } - else - { - if (!FlushFileBuffers( m_FileHandle)) - { - rc = MapWinErrorToFlaim( GetLastError(), FERR_FLUSHING_FILE); - } - } - return( rc); -} -#endif - -/**************************************************************************** -Desc: Allocate an aligned buffer. -****************************************************************************/ -#if defined( FLM_WIN) -RCODE F_FileHdlImp::AllocAlignBuffer( void) -{ - RCODE rc = FERR_OK; - - // Allocate at least 64K - this will handle most read and write - // operations and will also be a multiple of the sector size most of - // the time. The calculation below rounds it up to the next sector - // boundary if it is not already on one. - - m_uiAlignedBuffSize = RoundToNextSector( 64 * 1024); - - if ((m_pucAlignedBuff = (FLMBYTE *)VirtualAlloc( NULL, - (DWORD)m_uiAlignedBuffSize, - MEM_COMMIT, PAGE_READWRITE)) == NULL) - { - rc = MapWinErrorToFlaim( GetLastError(), FERR_MEM); - goto Exit; - } - - f_mutexLock( gv_FlmSysData.hShareMutex); - gv_FlmSysData.SCacheMgr.Usage.uiTotalBytesAllocated += - m_uiAlignedBuffSize; - f_mutexUnlock( gv_FlmSysData.hShareMutex); - -Exit: - return( rc); -} -#endif - -/**************************************************************************** -Desc: Position and do a single read operation. -****************************************************************************/ -#if defined( FLM_WIN) -RCODE F_FileHdlImp::DoOneRead( - DWORD udReadOffset, - DWORD udBytesToRead, - LPVOID pvReadBuffer, - LPDWORD pudBytesRead) -{ - RCODE rc = FERR_OK; - OVERLAPPED * pOverlapped; - LONG lDummy; - DWORD udErr; - - // Position the file to the specified offset. - - if (!m_bCanDoAsync) - { - lDummy = 0; - if (SetFilePointer( m_FileHandle, (LONG)udReadOffset, - &lDummy, FILE_BEGIN) == 0xFFFFFFFF) - { - rc = MapWinErrorToFlaim( GetLastError(), - FERR_POSITIONING_IN_FILE); - goto Exit; - } - pOverlapped = NULL; - } - else - { - if (!m_Overlapped.hEvent) - { - if ((m_Overlapped.hEvent = CreateEvent( NULL, TRUE, - FALSE, NULL)) == NULL) - { - rc = MapWinErrorToFlaim( GetLastError(), - FERR_SETTING_UP_FOR_READ); - goto Exit; - } - } - pOverlapped = &m_Overlapped; - pOverlapped->Offset = udReadOffset; - pOverlapped->OffsetHigh = 0; - if (!ResetEvent( pOverlapped->hEvent)) - { - rc = MapWinErrorToFlaim( GetLastError(), - FERR_SETTING_UP_FOR_READ); - goto Exit; - } - } - - // Do the read - - if (!ReadFile( m_FileHandle, pvReadBuffer, - udBytesToRead, pudBytesRead, pOverlapped)) - { - udErr = GetLastError(); - if (udErr == ERROR_IO_PENDING && m_bCanDoAsync) - { - if (!GetOverlappedResult( m_FileHandle, pOverlapped, - pudBytesRead, TRUE)) - { - rc = MapWinErrorToFlaim( GetLastError(), FERR_READING_FILE); - goto Exit; - } - } - else - { - rc = MapWinErrorToFlaim( udErr, FERR_READING_FILE); - goto Exit; - } - } - -Exit: - - return( rc); -} -#endif - -/**************************************************************************** -Desc: Read from a file - reads using aligned buffers and offsets - only - sector boundaries -****************************************************************************/ -#if defined( FLM_WIN) -RCODE F_FileHdlImp::DirectRead( - FLMUINT uiReadOffset, - FLMUINT uiBytesToRead, - void * pvBuffer, - FLMBOOL bBuffHasFullSectors, - FLMUINT * puiBytesReadRV) -{ - RCODE rc = FERR_OK; - DWORD udBytesRead; - FLMBYTE * pucReadBuffer; - FLMBYTE * pucDestBuffer; - FLMUINT uiMaxBytesToRead; - FLMBOOL bHitEOF; - - flmAssert( m_bFileOpened); - - if( puiBytesReadRV) - { - *puiBytesReadRV = 0; - } - - if( RC_BAD( rc = GET_FS_ERROR())) - { - goto Exit; - } - - if (uiReadOffset == F_IO_CURRENT_POS) - uiReadOffset = m_uiCurrentPos; - - // This loop does multiple reads (if necessary) to get all of the - // data. It uses aligned buffers and reads at sector offsets. - - pucDestBuffer = (FLMBYTE *)pvBuffer; - for (;;) - { - - // See if we are using an aligned buffer. If not, allocate - // one (if not already allocated), and use it. - - if ((uiReadOffset & m_uiNotOnSectorBoundMask) || - (((FLMUINT)pucDestBuffer) & m_uiNotOnSectorBoundMask) || - ((uiBytesToRead & m_uiNotOnSectorBoundMask) && - (!bBuffHasFullSectors))) - { - if (!m_pucAlignedBuff) - { - if (RC_BAD( rc = AllocAlignBuffer())) - { - goto Exit; - } - } - pucReadBuffer = m_pucAlignedBuff; - - // Must read enough bytes to cover all of the sectors that - // contain the data we are trying to read. The value of - // (uiReadOffset & m_uiNotOnSectorBoundMask) will give us the - // number of additional bytes that are in the sector prior to - // the read offset. We then round that up to the next sector - // to get the total number of bytes we are going to read. - - uiMaxBytesToRead = RoundToNextSector( uiBytesToRead + - (uiReadOffset & m_uiNotOnSectorBoundMask)); - - // Can't read more than the aligned buffer will hold. - - if (uiMaxBytesToRead > m_uiAlignedBuffSize) - { - uiMaxBytesToRead = m_uiAlignedBuffSize; - } - } - else - { - uiMaxBytesToRead = RoundToNextSector( uiBytesToRead); - flmAssert( uiMaxBytesToRead >= uiBytesToRead); - pucReadBuffer = pucDestBuffer; - } - - bHitEOF = FALSE; - if (RC_BAD( rc = DoOneRead( - (DWORD)TruncateToPrevSector( uiReadOffset), - (DWORD)uiMaxBytesToRead, - (LPVOID)pucReadBuffer, - &udBytesRead))) - { - goto Exit; - } - if (udBytesRead < (DWORD)uiMaxBytesToRead) - { - bHitEOF = TRUE; - } - - // If the offset we want to read from is not on a sector - // boundary, increment the read buffer pointer to the - // offset where the data we need starts and decrement the - // bytes read by the difference between the start of the - // sector and the actual read offset. - - if (uiReadOffset & m_uiNotOnSectorBoundMask) - { - pucReadBuffer += (uiReadOffset & m_uiNotOnSectorBoundMask); - flmAssert( (FLMUINT)udBytesRead >= m_uiBytesPerSector); - udBytesRead -= (DWORD)(uiReadOffset & m_uiNotOnSectorBoundMask); - } - - // If bytes read is more than we actually need, truncate it back - // so that we only copy what we actually need. - - if ((FLMUINT)udBytesRead > uiBytesToRead) - { - udBytesRead = (DWORD)uiBytesToRead; - } - - uiBytesToRead -= (FLMUINT)udBytesRead; - - if( puiBytesReadRV) - { - (*puiBytesReadRV) += (FLMUINT)udBytesRead; - } - - m_uiCurrentPos = uiReadOffset + (FLMUINT)udBytesRead; - - // If using a different buffer for reading, copy the - // data read into the destination buffer. - - if (pucDestBuffer != pucReadBuffer) - { - f_memcpy( pucDestBuffer, pucReadBuffer, udBytesRead); - } - - if (!uiBytesToRead) - { - break; - } - - // Still more to read - did we hit EOF above? - - if (bHitEOF) - { - rc = RC_SET( FERR_IO_END_OF_FILE); - break; - } - - pucDestBuffer += udBytesRead; - uiReadOffset += (FLMUINT)udBytesRead; - } - -Exit: - - return( rc); -} -#endif - -/**************************************************************************** -Desc: Read from a file -****************************************************************************/ -#if defined( FLM_WIN) -RCODE F_FileHdlImp::Read( - FLMUINT uiReadOffset, - FLMUINT uiBytesToRead, - void * pvBuffer, - FLMUINT * puiBytesReadRV) -{ - RCODE rc = FERR_OK; - DWORD udBytesRead; - - // Do the direct IO call if enabled. - - if (m_bDoDirectIO) - { - rc = DirectRead( uiReadOffset, uiBytesToRead, - pvBuffer, FALSE, puiBytesReadRV); - goto Exit; - } - - // If not doing direct IO, a single read call will do. - - flmAssert( m_bFileOpened); - if( puiBytesReadRV) - { - *puiBytesReadRV = 0; - } - - if( RC_BAD( rc = GET_FS_ERROR())) - { - goto Exit; - } - - if (uiReadOffset == F_IO_CURRENT_POS) - uiReadOffset = m_uiCurrentPos; - - if (RC_BAD( rc = DoOneRead( (DWORD)uiReadOffset, - (DWORD)uiBytesToRead, - (LPVOID)pvBuffer, - &udBytesRead))) - { - goto Exit; - } - - if( puiBytesReadRV) - { - *puiBytesReadRV = (FLMUINT)udBytesRead; - } - - m_uiCurrentPos = uiReadOffset + (FLMUINT)udBytesRead; - - if (udBytesRead < (DWORD)uiBytesToRead) - { - rc = RC_SET( FERR_IO_END_OF_FILE); - goto Exit; - } - -Exit: - - return( rc); -} -#endif - -/**************************************************************************** -Desc: Sets current position of file. -****************************************************************************/ -#if defined( FLM_WIN) -RCODE F_FileHdlImp::Seek( - FLMUINT uiOffset, - FLMINT iWhence, - FLMUINT * puiNewOffset) // [out] new file offset -{ - RCODE rc = FERR_OK; - - if( RC_BAD( rc = GET_FS_ERROR())) - { - goto Exit; - } - - switch (iWhence) - { - case F_IO_SEEK_CUR: - m_uiCurrentPos += uiOffset; - break; - case F_IO_SEEK_SET: - m_uiCurrentPos = uiOffset; - break; - case F_IO_SEEK_END: - rc = Size( &m_uiCurrentPos ); - if ( rc ) - { - goto Exit; - } - break; - default: - rc = RC_SET( FERR_NOT_IMPLEMENTED); - goto Exit; - } - - *puiNewOffset = m_uiCurrentPos; - -Exit: - - return( rc); -} -#endif - -/**************************************************************************** -Desc: Return the size of the file -****************************************************************************/ -#if defined( FLM_WIN) -RCODE F_FileHdlImp::Size( - FLMUINT * puiSize) -{ - RCODE rc; - - if( RC_BAD( rc = GET_FS_ERROR())) - { - goto Exit; - } - - if ((*puiSize = (FLMUINT)GetFileSize( m_FileHandle, NULL )) == - 0xFFFFFFFF) - { - rc = MapWinErrorToFlaim( GetLastError(), FERR_GETTING_FILE_SIZE); - goto Exit; - } - -Exit: - - return( rc); -} -#endif - -/**************************************************************************** -Desc: Returns m_uiCurrentPos -****************************************************************************/ -#if defined( FLM_WIN) -RCODE F_FileHdlImp::Tell( - FLMUINT * puiOffset) -{ - RCODE rc; - - if( RC_BAD( rc = GET_FS_ERROR())) - { - goto Exit; - } - - *puiOffset = m_uiCurrentPos; - -Exit: - - return( rc ); -} -#endif - -/**************************************************************************** -Desc: Truncate the file to the indicated size -WARNING: Direct IO methods are calling this method. Make sure that all changes - to this method work in direct IO mode. -****************************************************************************/ -#if defined( FLM_WIN) -RCODE F_FileHdlImp::Truncate( - FLMUINT uiSize) -{ - RCODE rc = FERR_OK; - LONG lDummy; - - flmAssert( m_bFileOpened == TRUE); - - if( RC_BAD( rc = GET_FS_ERROR())) - { - goto Exit; - } - - // Position the file to the nearest sector below the read offset. - - lDummy = 0; - if (SetFilePointer( m_FileHandle, - (LONG)uiSize, &lDummy, FILE_BEGIN) == 0xFFFFFFFF) - { - rc = MapWinErrorToFlaim( GetLastError(), FERR_POSITIONING_IN_FILE); - goto Exit; - } - - // Set the new file size. - - if (!SetEndOfFile( m_FileHandle)) - { - rc = MapWinErrorToFlaim( GetLastError(), FERR_TRUNCATING_FILE); - goto Exit; - } - -Exit: - - return( rc); -} -#endif - -/**************************************************************************** -Desc: Handles when a file is extended in direct IO mode. May extend the - file some more. Will always call FlushFileBuffers to ensure that - the new file size gets written out. -****************************************************************************/ -#if defined( FLM_WIN) -RCODE F_FileHdlImp::extendFile( - FLMUINT uiEndOfLastWrite, // Must be on a sector boundary - FLMUINT uiMaxBytesToExtend, - FLMBOOL bFlush) -{ - RCODE rc = FERR_OK; - FLMUINT uiTotalBytesToExtend; - FLMUINT uiBytesToWrite; - DWORD udBytesWritten; - LONG lDummy; - DWORD udErr; - OVERLAPPED * pOverlapped; - - if ((uiTotalBytesToExtend = uiMaxBytesToExtend) != 0) - { - if (uiEndOfLastWrite > m_uiMaxAutoExtendSize) - { - uiTotalBytesToExtend = 0; - } - else - { - - // Don't extend beyond maximum file size. - - if (m_uiMaxAutoExtendSize - uiEndOfLastWrite < uiTotalBytesToExtend) - { - uiTotalBytesToExtend = m_uiMaxAutoExtendSize - uiEndOfLastWrite; - } - - // If the extend size is not on a sector boundary, round it down. - - uiTotalBytesToExtend = TruncateToPrevSector( uiTotalBytesToExtend); - } - } - - if (uiTotalBytesToExtend) - { - - // Allocate an aligned buffer if we haven't already. - - if (!m_pucAlignedBuff) - { - if (RC_BAD( rc = AllocAlignBuffer())) - { - goto Exit; - } - } - f_memset( m_pucAlignedBuff, 0, m_uiAlignedBuffSize); - } - - // Extend the file until we run out of bytes to write. - - while (uiTotalBytesToExtend) - { - if ((uiBytesToWrite = m_uiAlignedBuffSize) > uiTotalBytesToExtend) - { - uiBytesToWrite = uiTotalBytesToExtend; - } - if (!m_bCanDoAsync) - { - lDummy = 0; - if (SetFilePointer( m_FileHandle, (LONG)uiEndOfLastWrite, - &lDummy, FILE_BEGIN) == 0xFFFFFFFF) - { - rc = MapWinErrorToFlaim( GetLastError(), - FERR_POSITIONING_IN_FILE); - goto Exit; - } - pOverlapped = NULL; - } - else - { - pOverlapped = &m_Overlapped; - if (!pOverlapped->hEvent) - { - if ((pOverlapped->hEvent = CreateEvent( NULL, TRUE, - FALSE, NULL)) == NULL) - { - rc = MapWinErrorToFlaim( GetLastError(), - FERR_SETTING_UP_FOR_WRITE); - goto Exit; - } - } - pOverlapped->Offset = (DWORD)uiEndOfLastWrite; - pOverlapped->OffsetHigh = 0; - if (!ResetEvent( pOverlapped->hEvent)) - { - rc = MapWinErrorToFlaim( GetLastError(), - FERR_SETTING_UP_FOR_WRITE); - goto Exit; - } - } - - // Do the write - - if (!WriteFile( m_FileHandle, (LPVOID)m_pucAlignedBuff, - (DWORD)uiBytesToWrite, &udBytesWritten, - pOverlapped)) - { - udErr = GetLastError(); - if (udErr == ERROR_IO_PENDING && m_bCanDoAsync) - { - if (!GetOverlappedResult( m_FileHandle, pOverlapped, - &udBytesWritten, TRUE)) - { - rc = MapWinErrorToFlaim( GetLastError(), - FERR_WRITING_FILE); - - } - } - else - { - rc = MapWinErrorToFlaim( udErr, FERR_WRITING_FILE); - } - } - if (RC_BAD( rc)) - { - - // Don't care if it is a disk full error, because - // extending the file is optional work. - - if (rc == FERR_IO_DISK_FULL) - { - rc = FERR_OK; - break; - } - goto Exit; - } - - // NO more room on disk, but that's OK because we were only - // extending the file beyond where it needed to be. If that - // fails, we will just flush what we have done so far. - - if (udBytesWritten < (DWORD)uiBytesToWrite) - { - break; - } - uiTotalBytesToExtend -= uiBytesToWrite; - uiEndOfLastWrite += uiBytesToWrite; - } - - // Flush the file buffers to ensure that the file size gets written - // out. - - if (bFlush) - { - if (!FlushFileBuffers( m_FileHandle)) - { - rc = MapWinErrorToFlaim( GetLastError(), FERR_FLUSHING_FILE); - goto Exit; - } - } - -Exit: - - return( rc); -} -#endif - -/**************************************************************************** -Desc: Write to a file using direct IO -****************************************************************************/ -#if defined( FLM_WIN) -RCODE F_FileHdlImp::DirectWrite( - FLMUINT uiWriteOffset, - FLMUINT uiBytesToWrite, - const void * pvBuffer, - F_IOBuffer * pBufferObj, - FLMBOOL bBuffHasFullSectors, - FLMBOOL bZeroFill, - FLMUINT * puiBytesWrittenRV) -{ - RCODE rc = FERR_OK; - DWORD udBytesRead; - DWORD udBytesWritten; - FLMBYTE * pucWriteBuffer; - FLMBYTE * pucSrcBuffer; - FLMUINT uiMaxBytesToWrite; - FLMUINT uiCurrFileSize; - FLMUINT uiBytesBeingOutput; - OVERLAPPED * pOverlapped; - LONG lDummy; - DWORD udErr; - FLMBOOL bExtendFile = FALSE; - FLMBOOL bDoAsync = (pBufferObj != NULL) - ? TRUE - : FALSE; - FLMBOOL bDidAsync = FALSE; - FLMUINT uiLastWriteOffset; - FLMUINT uiLastWriteSize; - - flmAssert( m_bFileOpened); - -#ifdef FLM_DEBUG - if (bDoAsync) - { - flmAssert( m_bCanDoAsync); - } -#endif - - if( puiBytesWrittenRV) - { - *puiBytesWrittenRV = 0; - } - - if( RC_BAD( rc = GET_FS_ERROR())) - { - goto Exit; - } - - if (uiWriteOffset == F_IO_CURRENT_POS) - { - uiWriteOffset = m_uiCurrentPos; - } - - // Determine if the write will extend the file beyond its - // current size. If so, we will need to call FlushFileBuffers - - if ((uiCurrFileSize = (FLMUINT)GetFileSize( m_FileHandle, NULL )) == - 0xFFFFFFFF) - { - rc = MapWinErrorToFlaim( GetLastError(), FERR_GETTING_FILE_SIZE); - goto Exit; - } - if (uiWriteOffset + uiBytesToWrite > uiCurrFileSize && - m_uiExtendSize != (FLMUINT)(~0)) - { - bExtendFile = TRUE; - - if (uiWriteOffset > uiCurrFileSize) - { - - // Fill in the empty space. - - if (RC_BAD( rc = extendFile( uiCurrFileSize, - RoundToNextSector( uiWriteOffset - uiCurrFileSize), - FALSE))) - { - goto Exit; - } - } - - // Can't do asynchronous if we are going to extend the file. - - bDoAsync = FALSE; - } - - // This loop is for direct IO - must make sure we use - // aligned buffers. - - pucSrcBuffer = (FLMBYTE *)pvBuffer; - for (;;) - { - - // See if we are using an aligned buffer. If not, allocate - // one (if not already allocated), and use it. - - if ((uiWriteOffset & m_uiNotOnSectorBoundMask) || - (((FLMUINT)pucSrcBuffer) & m_uiNotOnSectorBoundMask) || - ((uiBytesToWrite & m_uiNotOnSectorBoundMask) && - (!bBuffHasFullSectors))) - { - - // Cannot be using a temporary write buffer if we are doing - // asynchronous writes! - - flmAssert( !bDoAsync || !m_bCanDoAsync); - if (!m_pucAlignedBuff) - { - if (RC_BAD( rc = AllocAlignBuffer())) - { - goto Exit; - } - } - pucWriteBuffer = m_pucAlignedBuff; - - // Must write enough bytes to cover all of the sectors that - // contain the data we are trying to write out. The value of - // (uiWriteOffset & m_uiNotOnSectorBoundMask) will give us the - // number of additional bytes that are in the sector prior to - // the read offset. We then round to the next sector to get the - // total number of bytes we are going to write. - - uiMaxBytesToWrite = RoundToNextSector( uiBytesToWrite + - (uiWriteOffset & m_uiNotOnSectorBoundMask)); - - // Can't write more than the aligned buffer will hold. - - if (uiMaxBytesToWrite > m_uiAlignedBuffSize) - { - uiMaxBytesToWrite = m_uiAlignedBuffSize; - uiBytesBeingOutput = uiMaxBytesToWrite - - (uiWriteOffset & m_uiNotOnSectorBoundMask); - } - else - { - uiBytesBeingOutput = uiBytesToWrite; - } - - // If the write offset is not on a sector boundary, we must - // read at least the first sector into the buffer. - - if (uiWriteOffset & m_uiNotOnSectorBoundMask) - { - - // Read the first sector that is to be written out. - // Read one sector's worth of data - so that we will - // preserve what is already in the sector before - // writing it back out again. - - if (RC_BAD( rc = DoOneRead( - (DWORD)TruncateToPrevSector( uiWriteOffset), - (DWORD)m_uiBytesPerSector, - (LPVOID)pucWriteBuffer, - &udBytesRead))) - { - goto Exit; - } - } - - // If we are writing more than one sector, and the last sector's - // worth of data we are writing out is only a partial sector, - // we must read in this sector as well. - - if ((uiMaxBytesToWrite > m_uiBytesPerSector) && - (uiMaxBytesToWrite > uiBytesToWrite) && - (!bBuffHasFullSectors)) - { - - // Read the last sector that is to be written out. - // Read one sector's worth of data - so that we will - // preserve what is already in the sector before - // writing it back out again. - - if (RC_BAD( rc = DoOneRead( - (DWORD)(TruncateToPrevSector( uiWriteOffset)) + - (DWORD)(uiMaxBytesToWrite - m_uiBytesPerSector), - (DWORD)m_uiBytesPerSector, - (LPVOID)(&pucWriteBuffer [uiMaxBytesToWrite - m_uiBytesPerSector]), - &udBytesRead))) - { - if (rc == FERR_IO_END_OF_FILE) - { - rc = FERR_OK; - f_memset( &pucWriteBuffer [uiMaxBytesToWrite - m_uiBytesPerSector], - 0, m_uiBytesPerSector); - } - else - { - goto Exit; - } - } - } - - // Finally, copy the data from the source buffer into the - // write buffer. - - f_memcpy( &pucWriteBuffer [uiWriteOffset & m_uiNotOnSectorBoundMask], - pucSrcBuffer, uiBytesBeingOutput); - } - else - { - uiMaxBytesToWrite = RoundToNextSector( uiBytesToWrite); - uiBytesBeingOutput = uiBytesToWrite; - pucWriteBuffer = pucSrcBuffer; - if( bZeroFill && uiMaxBytesToWrite > uiBytesToWrite) - { - f_memset( &pucWriteBuffer [uiBytesToWrite], 0, - uiMaxBytesToWrite - uiBytesToWrite); - } - } - - // Position the file to the nearest sector below the write offset. - - uiLastWriteOffset = TruncateToPrevSector( uiWriteOffset); - if (!m_bCanDoAsync) - { - lDummy = 0; - if (SetFilePointer( m_FileHandle, (LONG)uiLastWriteOffset, - &lDummy, FILE_BEGIN) == 0xFFFFFFFF) - { - rc = MapWinErrorToFlaim( GetLastError(), - FERR_POSITIONING_IN_FILE); - goto Exit; - } - pOverlapped = NULL; - } - else - { - if (!pBufferObj) - { - pOverlapped = &m_Overlapped; - } - else - { - pOverlapped = pBufferObj->getOverlapped(); - pBufferObj->setFileHandle( m_FileHandle); - } - - if (!pOverlapped->hEvent) - { - if ((pOverlapped->hEvent = CreateEvent( NULL, TRUE, - FALSE, NULL)) == NULL) - { - rc = MapWinErrorToFlaim( GetLastError(), - FERR_SETTING_UP_FOR_WRITE); - goto Exit; - } - } - pOverlapped->Offset = (DWORD)uiLastWriteOffset; - pOverlapped->OffsetHigh = 0; - if (!ResetEvent( pOverlapped->hEvent)) - { - rc = MapWinErrorToFlaim( GetLastError(), - FERR_SETTING_UP_FOR_WRITE); - goto Exit; - } - } - - // Do the write - - uiLastWriteSize = uiMaxBytesToWrite; - if (!WriteFile( m_FileHandle, (LPVOID)pucWriteBuffer, - (DWORD)uiMaxBytesToWrite, &udBytesWritten, - pOverlapped)) - { - udErr = GetLastError(); - if (udErr == ERROR_IO_PENDING && m_bCanDoAsync) - { - - // If an async structure was passed in, we better have - // been able to finish in a single write operation. - // Otherwise, we are in deep trouble because we are not - // set up to do multiple async write operations within - // a single call. - - if( bDoAsync) - { - pBufferObj->makePending(); - bDidAsync = TRUE; - break; - } - - if (!GetOverlappedResult( m_FileHandle, pOverlapped, - &udBytesWritten, TRUE)) - { - rc = MapWinErrorToFlaim( GetLastError(), - FERR_WRITING_FILE); - goto Exit; - } - } - else - { - rc = MapWinErrorToFlaim( udErr, FERR_WRITING_FILE); - goto Exit; - } - } - - if (udBytesWritten < (DWORD)uiMaxBytesToWrite) - { - rc = RC_SET( FERR_IO_DISK_FULL); - goto Exit; - } - - uiBytesToWrite -= uiBytesBeingOutput; - if( puiBytesWrittenRV) - { - (*puiBytesWrittenRV) += uiBytesBeingOutput; - } - m_uiCurrentPos = uiWriteOffset + uiBytesBeingOutput; - if (!uiBytesToWrite) - { - break; - } - - pucSrcBuffer += uiBytesBeingOutput; - uiWriteOffset += uiBytesBeingOutput; - } - - // See if we extended the file. If so, we may want to extend it some - // more and then also do a flush. - - if (bExtendFile) - { - - // NOTE: uiLastWriteOffset + uiLastWrite is guaranteed to be - // on a sector boundary. - - if (RC_BAD( rc = extendFile( - uiLastWriteOffset + uiLastWriteSize, - m_uiExtendSize, TRUE))) - { - goto Exit; - } - } - -Exit: - - if( !bDidAsync && pBufferObj) - { - pBufferObj->notifyComplete( rc); - } - - return( rc ); -} -#endif - -/**************************************************************************** -Desc: Write to a file -****************************************************************************/ -#if defined( FLM_WIN) -RCODE F_FileHdlImp::Write( - FLMUINT uiWriteOffset, - FLMUINT uiBytesToWrite, - const void * pvBuffer, - FLMUINT * puiBytesWrittenRV) -{ - RCODE rc = FERR_OK; - DWORD udBytesWritten; - OVERLAPPED * pOverlapped; - LONG lDummy; - DWORD udErr; - - if (m_bDoDirectIO) - { - rc = DirectWrite( uiWriteOffset, uiBytesToWrite, pvBuffer, - NULL, FALSE, FALSE, puiBytesWrittenRV); - goto Exit; - } - - // If not doing direct IO, a single write call will do. - - flmAssert( m_bFileOpened); - - if( puiBytesWrittenRV) - { - *puiBytesWrittenRV = 0; - } - - if( RC_BAD( rc = GET_FS_ERROR())) - { - goto Exit; - } - - if (uiWriteOffset == F_IO_CURRENT_POS) - { - uiWriteOffset = m_uiCurrentPos; - } - - // Position the file. - - if (!m_bCanDoAsync) - { - lDummy = 0; - if (SetFilePointer( m_FileHandle, (LONG)uiWriteOffset, - &lDummy, FILE_BEGIN) == 0xFFFFFFFF) - { - rc = MapWinErrorToFlaim( GetLastError(), - FERR_POSITIONING_IN_FILE); - goto Exit; - } - pOverlapped = NULL; - } - else - { - if (!m_Overlapped.hEvent) - { - if ((m_Overlapped.hEvent = CreateEvent( NULL, TRUE, - FALSE, NULL)) == NULL) - { - rc = MapWinErrorToFlaim( GetLastError(), - FERR_SETTING_UP_FOR_WRITE); - goto Exit; - } - } - pOverlapped = &m_Overlapped; - pOverlapped->Offset = (DWORD)uiWriteOffset; - pOverlapped->OffsetHigh = 0; - if (!ResetEvent( pOverlapped->hEvent)) - { - rc = MapWinErrorToFlaim( GetLastError(), - FERR_SETTING_UP_FOR_WRITE); - goto Exit; - } - } - - if (!WriteFile( m_FileHandle, (LPVOID)pvBuffer, - (DWORD)uiBytesToWrite, &udBytesWritten, - pOverlapped)) - { - udErr = GetLastError(); - if (udErr == ERROR_IO_PENDING && m_bCanDoAsync) - { - if (!GetOverlappedResult( m_FileHandle, pOverlapped, - &udBytesWritten, TRUE)) - { - rc = MapWinErrorToFlaim( GetLastError(), - FERR_WRITING_FILE); - goto Exit; - } - } - else - { - rc = MapWinErrorToFlaim( udErr, FERR_WRITING_FILE); - goto Exit; - } - } - - if( puiBytesWrittenRV) - { - *puiBytesWrittenRV = (FLMUINT)udBytesWritten; - } - - m_uiCurrentPos = uiWriteOffset + (FLMUINT)udBytesWritten; - if (udBytesWritten < (DWORD)uiBytesToWrite) - { - rc = RC_SET( FERR_IO_DISK_FULL); - goto Exit; - } - -Exit: - - return( rc); -} -#endif - -/**************************************************************************** -Desc: Deletes a file. -****************************************************************************/ -#if defined( FLM_WIN) -FSTATIC RCODE _DeleteFile( - const char * path) -{ - RCODE rc = FERR_OK; - - if( DeleteFile( (LPTSTR)path) == FALSE) - { - rc = MapWinErrorToFlaim( GetLastError(), FERR_DELETING_FILE); - } - - return( rc); -} -#endif - -/**************************************************************************** -Desc: -****************************************************************************/ -int fwinDummy( void) -{ - return( 0); -} - diff --git a/flaim/src/fwin.h b/flaim/src/fwin.h deleted file mode 100644 index 9c1f2ff..0000000 --- a/flaim/src/fwin.h +++ /dev/null @@ -1,235 +0,0 @@ -//------------------------------------------------------------------------- -// Desc: Windows I/O - definitions. -// Tabs: 3 -// -// Copyright (c) 2000-2006 Novell, Inc. All Rights Reserved. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of version 2 of the GNU General Public -// License as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, contact Novell, Inc. -// -// To contact Novell about this file by physical or electronic mail, -// you may find current contact information at www.novell.com -// -// $Id: fwin.h 12329 2006-01-20 17:49:30 -0700 (Fri, 20 Jan 2006) ahodgkinson $ -//------------------------------------------------------------------------- - -#ifndef FWIN_H -#define FWIN_H - -#include "fpackon.h" - -// IMPORTANT NOTE: No other include files should follow this one except -// for fpackoff.h - -class F_FileHdlImp : public F_FileHdlImpBase -{ -public: - - F_FileHdlImp(); - - virtual ~F_FileHdlImp(); - - RCODE Setup( - FLMUINT uiFileId); - - RCODE Close( void); - - RCODE Create( - const char * pszIoPath, - FLMUINT uiIoFlags); - - RCODE CreateUnique( - char * pszIoPath, - const char * pszFileExtension, - FLMUINT uiIoFlags); - - RCODE Open( - const char * pszIoPath, - FLMUINT uiIoFlags); - - RCODE Flush( void); - - RCODE Read( - FLMUINT uiOffset, - FLMUINT uiLength, - void * pvBuffer, - FLMUINT * puiBytesRead); - - RCODE Seek( - FLMUINT uiOffset, - FLMINT iWhence, - FLMUINT * puiNewOffset); - - RCODE Size( - FLMUINT * puiSize); - - RCODE Tell( - FLMUINT * puiOffset); - - RCODE Truncate( - FLMUINT uiSize); - - RCODE Write( - FLMUINT uiOffset, - FLMUINT uiLength, - const void * pvBuffer, - FLMUINT * puiBytesWritten); - - FINLINE RCODE SectorRead( - FLMUINT uiReadOffset, - FLMUINT uiBytesToRead, - void * pvBuffer, - FLMUINT * puiBytesReadRV) - { - if( m_bDoDirectIO) - { - return( DirectRead( uiReadOffset, uiBytesToRead, - pvBuffer, TRUE, puiBytesReadRV)); - } - else - { - return( Read( uiReadOffset, uiBytesToRead, pvBuffer, puiBytesReadRV)); - } - } - - FINLINE RCODE SectorWrite( - FLMUINT uiWriteOffset, - FLMUINT uiBytesToWrite, - const void * pvBuffer, - FLMUINT uiBufferSize, - F_IOBuffer * pBufferObj, - FLMUINT * puiBytesWrittenRV, - FLMBOOL bZeroFill = TRUE) - { - uiBufferSize = uiBufferSize; - if( m_bDoDirectIO) - { - return( DirectWrite( uiWriteOffset, uiBytesToWrite, - pvBuffer, pBufferObj, TRUE, bZeroFill, puiBytesWrittenRV)); - } - else - { - flmAssert( pBufferObj == NULL); - return( Write( uiWriteOffset, uiBytesToWrite, pvBuffer, - puiBytesWrittenRV)); - } - } - - FINLINE FLMBOOL CanDoAsync( void) - { - return( m_bCanDoAsync); - } - - FINLINE void setExtendSize( - FLMUINT uiExtendSize) - { - m_uiExtendSize = uiExtendSize; - } - - FINLINE void setMaxAutoExtendSize( - FLMUINT uiMaxAutoExtendSize) - { - m_uiMaxAutoExtendSize = uiMaxAutoExtendSize; - } - - FINLINE FLMUINT GetSectorSize( void) - { - return( m_uiBytesPerSector); - } - - FINLINE void SetBlockSize( - FLMUINT uiBlockSize) - { - m_uiBlockSize = uiBlockSize; - } - - FINLINE HANDLE getFileHandle( void) - { - return m_FileHandle; - } - -private: - - RCODE OpenOrCreate( - const char * pszFileName, - FLMUINT uiAccess, - FLMBOOL bCreateFlag); - - RCODE AllocAlignBuffer( void); - - RCODE DoOneRead( - DWORD udReadOffset, - DWORD udBytesToRead, - LPVOID pvReadBuffer, - LPDWORD pudBytesRead); - - RCODE DoOneRead( - FLMUINT uiOffset, - FLMUINT uiLength, - void * pvBuffer, - FLMBOOL bBuffHasFullSectors, - FLMUINT * puiBytesRead); - - RCODE DirectRead( - FLMUINT uiOffset, - FLMUINT uiLength, - void * pvBuffer, - FLMBOOL bBuffHasFullSectors, - FLMUINT * puiBytesRead); - - RCODE DirectWrite( - FLMUINT uiOffset, - FLMUINT uiLength, - const void * pvBuffer, - F_IOBuffer * pBufferObj, - FLMBOOL bBuffHasFullSectors, - FLMBOOL bZeroFill, - FLMUINT * puiBytesWritten); - - FINLINE FLMUINT RoundToNextSector( - FLMUINT uiBytes) - { - return( ((uiBytes) + m_uiNotOnSectorBoundMask) & - m_uiGetSectorBoundMask); - } - - FINLINE FLMUINT TruncateToPrevSector( - FLMUINT uiOffset) - { - return( (uiOffset) & m_uiGetSectorBoundMask); - } - - RCODE extendFile( - FLMUINT uiEndOfLastWrite, - FLMUINT uiMaxBytesToExtend, - FLMBOOL bFlush); - - HANDLE m_FileHandle; - FLMUINT m_uiBlockSize; - FLMUINT m_uiBytesPerSector; - FLMUINT m_uiNotOnSectorBoundMask; - FLMUINT m_uiGetSectorBoundMask; - FLMBOOL m_bDoDirectIO; - FLMUINT m_uiExtendSize; - FLMUINT m_uiMaxAutoExtendSize; - FLMBYTE * m_pucAlignedBuff; - FLMUINT m_uiAlignedBuffSize; - FLMUINT m_uiCurrentPos; - FLMBOOL m_bCanDoAsync; - OVERLAPPED m_Overlapped; - - friend class F_FileHdlPage; -}; - -#include "fpackoff.h" - -#endif diff --git a/flaim/src/fxml.cpp b/flaim/src/fxml.cpp deleted file mode 100644 index a419ebe..0000000 --- a/flaim/src/fxml.cpp +++ /dev/null @@ -1,6334 +0,0 @@ -//------------------------------------------------------------------------- -// Desc: XML Wrapper -// Tabs: 3 -// -// Copyright (c) 2000-2006 Novell, Inc. All Rights Reserved. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of version 2 of the GNU General Public -// License as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, contact Novell, Inc. -// -// To contact Novell about this file by physical or electronic mail, -// you may find current contact information at www.novell.com -// -// $Id: fxml.cpp 12334 2006-01-23 12:45:35 -0700 (Mon, 23 Jan 2006) dsanders $ -//------------------------------------------------------------------------- - -#include "flaimsys.h" - -#ifdef FLM_UNIX - #define CRLFSTR "\n" - #define CRLFSTRLEN 1 -#else - #define CRLFSTR "\r\n" - #define CRLFSTRLEN 2 -#endif - -#define F_XML_BASE_CHAR 0x01 -#define F_XML_IDEOGRAPHIC 0x02 -#define F_XML_COMBINING_CHAR 0x04 -#define F_XML_DIGIT 0x08 -#define F_XML_EXTENDER 0x10 -#define F_XML_WHITESPACE 0x20 - -typedef struct -{ - char * pszEntity; - FLMUINT uiValue; -} CharEntity; - -typedef struct -{ - FLMUNICODE uLowChar; - FLMUNICODE uHighChar; - FLMUINT16 ui16Flag; -} CHAR_TBL; - -extern char * FlmReservedTags[]; - -CHAR_TBL charTbl[] = -{ - {0x0041, 0x005A, F_XML_BASE_CHAR}, - {0x0061, 0x007A, F_XML_BASE_CHAR}, - {0x00C0, 0x00D6, F_XML_BASE_CHAR}, - {0x00D8, 0x00F6, F_XML_BASE_CHAR}, - {0x00F8, 0x00FF, F_XML_BASE_CHAR}, - {0x0100, 0x0131, F_XML_BASE_CHAR}, - {0x0134, 0x013E, F_XML_BASE_CHAR}, - {0x0141, 0x0148, F_XML_BASE_CHAR}, - {0x014A, 0x017E, F_XML_BASE_CHAR}, - {0x0180, 0x01C3, F_XML_BASE_CHAR}, - {0x01CD, 0x01F0, F_XML_BASE_CHAR}, - {0x01F4, 0x01F5, F_XML_BASE_CHAR}, - {0x01FA, 0x0217, F_XML_BASE_CHAR}, - {0x0250, 0x02A8, F_XML_BASE_CHAR}, - {0x02BB, 0x02C1, F_XML_BASE_CHAR}, - {0x0386, 0x0386, F_XML_BASE_CHAR}, - {0x0388, 0x038A, F_XML_BASE_CHAR}, - {0x038C, 0x038C, F_XML_BASE_CHAR}, - {0x038E, 0x03A1, F_XML_BASE_CHAR}, - {0x03A3, 0x03CE, F_XML_BASE_CHAR}, - {0x03D0, 0x03D6, F_XML_BASE_CHAR}, - {0x03DA, 0x03DA, F_XML_BASE_CHAR}, - {0x03DC, 0x03DC, F_XML_BASE_CHAR}, - {0x03DE, 0x03DE, F_XML_BASE_CHAR}, - {0x03E0, 0x03E0, F_XML_BASE_CHAR}, - {0x03E2, 0x03F3, F_XML_BASE_CHAR}, - {0x0401, 0x040C, F_XML_BASE_CHAR}, - {0x040E, 0x044F, F_XML_BASE_CHAR}, - {0x0451, 0x045C, F_XML_BASE_CHAR}, - {0x045E, 0x0481, F_XML_BASE_CHAR}, - {0x0490, 0x04C4, F_XML_BASE_CHAR}, - {0x04C7, 0x04C8, F_XML_BASE_CHAR}, - {0x04CB, 0x04CC, F_XML_BASE_CHAR}, - {0x04D0, 0x04EB, F_XML_BASE_CHAR}, - {0x04EE, 0x04F5, F_XML_BASE_CHAR}, - {0x04F8, 0x04F9, F_XML_BASE_CHAR}, - {0x0531, 0x0556, F_XML_BASE_CHAR}, - {0x0559, 0x0559, F_XML_BASE_CHAR}, - {0x0561, 0x0586, F_XML_BASE_CHAR}, - {0x05D0, 0x05EA, F_XML_BASE_CHAR}, - {0x05F0, 0x05F2, F_XML_BASE_CHAR}, - {0x0621, 0x063A, F_XML_BASE_CHAR}, - {0x0641, 0x06B7, F_XML_BASE_CHAR}, - {0x06BA, 0x06BE, F_XML_BASE_CHAR}, - {0x06C0, 0x06CE, F_XML_BASE_CHAR}, - {0x06D0, 0x06D3, F_XML_BASE_CHAR}, - {0x06D5, 0x06D5, F_XML_BASE_CHAR}, - {0x06E5, 0x06E6, F_XML_BASE_CHAR}, - {0x0905, 0x0939, F_XML_BASE_CHAR}, - {0x093D, 0x093D, F_XML_BASE_CHAR}, - {0x0958, 0x0961, F_XML_BASE_CHAR}, - {0x0985, 0x098C, F_XML_BASE_CHAR}, - {0x098F, 0x0990, F_XML_BASE_CHAR}, - {0x0993, 0x09A8, F_XML_BASE_CHAR}, - {0x09AA, 0x09B0, F_XML_BASE_CHAR}, - {0x09B2, 0x09B2, F_XML_BASE_CHAR}, - {0x09B6, 0x09B9, F_XML_BASE_CHAR}, - {0x0061, 0x007A, F_XML_BASE_CHAR}, - {0x09DC, 0x09DD, F_XML_BASE_CHAR}, - {0x09DF, 0x09E1, F_XML_BASE_CHAR}, - {0x09F0, 0x09F1, F_XML_BASE_CHAR}, - {0x0A05, 0x0A0A, F_XML_BASE_CHAR}, - {0x0A0F, 0x0A10, F_XML_BASE_CHAR}, - {0x0A13, 0x0A28, F_XML_BASE_CHAR}, - {0x0A2A, 0x0A30, F_XML_BASE_CHAR}, - {0x0A32, 0x0A33, F_XML_BASE_CHAR}, - {0x0A35, 0x0A36, F_XML_BASE_CHAR}, - {0x0A38, 0x0A39, F_XML_BASE_CHAR}, - {0x0A59, 0x0A5C, F_XML_BASE_CHAR}, - {0x0A5E, 0x0A5E, F_XML_BASE_CHAR}, - {0x0A72, 0x0A74, F_XML_BASE_CHAR}, - {0x0A85, 0x0A8B, F_XML_BASE_CHAR}, - {0x0A8D, 0x0A8D, F_XML_BASE_CHAR}, - {0x0A8F, 0x0A91, F_XML_BASE_CHAR}, - {0x0A93, 0x0AA8, F_XML_BASE_CHAR}, - {0x0AAA, 0x0AB0, F_XML_BASE_CHAR}, - {0x0AB2, 0x0AB3, F_XML_BASE_CHAR}, - {0x0AB5, 0x0AB9, F_XML_BASE_CHAR}, - {0x0ABD, 0x0ABD, F_XML_BASE_CHAR}, - {0x0AE0, 0x0AE0, F_XML_BASE_CHAR}, - {0x0B05, 0x0B0C, F_XML_BASE_CHAR}, - {0x0B0F, 0x0B10, F_XML_BASE_CHAR}, - {0x0B13, 0x0B28, F_XML_BASE_CHAR}, - {0x0B2A, 0x0B30, F_XML_BASE_CHAR}, - {0x0B32, 0x0B33, F_XML_BASE_CHAR}, - {0x0B36, 0x0B39, F_XML_BASE_CHAR}, - {0x0B3D, 0x0B3D, F_XML_BASE_CHAR}, - {0x0B5C, 0x0B5D, F_XML_BASE_CHAR}, - {0x0B5F, 0x0B61, F_XML_BASE_CHAR}, - {0x0B85, 0x0B8A, F_XML_BASE_CHAR}, - {0x0B8E, 0x0B90, F_XML_BASE_CHAR}, - {0x0B92, 0x0B95, F_XML_BASE_CHAR}, - {0x0B99, 0x0B9A, F_XML_BASE_CHAR}, - {0x0B9C, 0x0B9C, F_XML_BASE_CHAR}, - {0x0B9E, 0x0B9F, F_XML_BASE_CHAR}, - {0x0BA3, 0x0BA4, F_XML_BASE_CHAR}, - {0x0BA8, 0x0BAA, F_XML_BASE_CHAR}, - {0x0BAE, 0x0BB5, F_XML_BASE_CHAR}, - {0x0BB7, 0x0BB9, F_XML_BASE_CHAR}, - {0x0C05, 0x0C0C, F_XML_BASE_CHAR}, - {0x0C0E, 0x0C10, F_XML_BASE_CHAR}, - {0x0C12, 0x0C28, F_XML_BASE_CHAR}, - {0x0C2A, 0x0C33, F_XML_BASE_CHAR}, - {0x0C35, 0x0C39, F_XML_BASE_CHAR}, - {0x0C60, 0x0C61, F_XML_BASE_CHAR}, - {0x0C85, 0x0C8C, F_XML_BASE_CHAR}, - {0x0C8E, 0x0C90, F_XML_BASE_CHAR}, - {0x0C92, 0x0CA8, F_XML_BASE_CHAR}, - {0x0CAA, 0x0CB3, F_XML_BASE_CHAR}, - {0x0CB5, 0x0CB9, F_XML_BASE_CHAR}, - {0x0CDE, 0x0CDE, F_XML_BASE_CHAR}, - {0x0CE0, 0x0CE1, F_XML_BASE_CHAR}, - {0x0D05, 0x0D0C, F_XML_BASE_CHAR}, - {0x0D0E, 0x0D10, F_XML_BASE_CHAR}, - {0x0D12, 0x0D28, F_XML_BASE_CHAR}, - {0x0D2A, 0x0D39, F_XML_BASE_CHAR}, - {0x0D60, 0x0D61, F_XML_BASE_CHAR}, - {0x0E01, 0x0E2E, F_XML_BASE_CHAR}, - {0x0E30, 0x0E30, F_XML_BASE_CHAR}, - {0x0E32, 0x0E33, F_XML_BASE_CHAR}, - {0x0E40, 0x0E45, F_XML_BASE_CHAR}, - {0x0E81, 0x0E82, F_XML_BASE_CHAR}, - {0x0E84, 0x0E84, F_XML_BASE_CHAR}, - {0x0E87, 0x0E88, F_XML_BASE_CHAR}, - {0x0E8A, 0x0E8A, F_XML_BASE_CHAR}, - {0x0E8D, 0x0E8D, F_XML_BASE_CHAR}, - {0x0E94, 0x0E97, F_XML_BASE_CHAR}, - {0x0E99, 0x0E9F, F_XML_BASE_CHAR}, - {0x0EA1, 0x0EA3, F_XML_BASE_CHAR}, - {0x0EA5, 0x0EA5, F_XML_BASE_CHAR}, - {0x0EA7, 0x0EA7, F_XML_BASE_CHAR}, - {0x0EAA, 0x0EAB, F_XML_BASE_CHAR}, - {0x0EAD, 0x0EAE, F_XML_BASE_CHAR}, - {0x0EB0, 0x0EB0, F_XML_BASE_CHAR}, - {0x0EB2, 0x0EB3, F_XML_BASE_CHAR}, - {0x0EBD, 0x0EBD, F_XML_BASE_CHAR}, - {0x0EC0, 0x0EC4, F_XML_BASE_CHAR}, - {0x0F40, 0x0F47, F_XML_BASE_CHAR}, - {0x0F49, 0x0F69, F_XML_BASE_CHAR}, - {0x10A0, 0x10C5, F_XML_BASE_CHAR}, - {0x10D0, 0x10F6, F_XML_BASE_CHAR}, - {0x1100, 0x1100, F_XML_BASE_CHAR}, - {0x1102, 0x1103, F_XML_BASE_CHAR}, - {0x1105, 0x1107, F_XML_BASE_CHAR}, - {0x1109, 0x1109, F_XML_BASE_CHAR}, - {0x110B, 0x110C, F_XML_BASE_CHAR}, - {0x110E, 0x1112, F_XML_BASE_CHAR}, - {0x113C, 0x113C, F_XML_BASE_CHAR}, - {0x113E, 0x113E, F_XML_BASE_CHAR}, - {0x1140, 0x1140, F_XML_BASE_CHAR}, - {0x114C, 0x114C, F_XML_BASE_CHAR}, - {0x114E, 0x114E, F_XML_BASE_CHAR}, - {0x1150, 0x1150, F_XML_BASE_CHAR}, - {0x1154, 0x1155, F_XML_BASE_CHAR}, - {0x1159, 0x1159, F_XML_BASE_CHAR}, - {0x115F, 0x1161, F_XML_BASE_CHAR}, - {0x1163, 0x1163, F_XML_BASE_CHAR}, - {0x1165, 0x1165, F_XML_BASE_CHAR}, - {0x1167, 0x1167, F_XML_BASE_CHAR}, - {0x1169, 0x1169, F_XML_BASE_CHAR}, - {0x116D, 0x116E, F_XML_BASE_CHAR}, - {0x1172, 0x1173, F_XML_BASE_CHAR}, - {0x1175, 0x1175, F_XML_BASE_CHAR}, - {0x119E, 0x119E, F_XML_BASE_CHAR}, - {0x11A8, 0x11A8, F_XML_BASE_CHAR}, - {0x11AB, 0x11AB, F_XML_BASE_CHAR}, - {0x11AE, 0x11AF, F_XML_BASE_CHAR}, - {0x11B7, 0x11B8, F_XML_BASE_CHAR}, - {0x11BA, 0x11BA, F_XML_BASE_CHAR}, - {0x11BC, 0x11C2, F_XML_BASE_CHAR}, - {0x11EB, 0x11EB, F_XML_BASE_CHAR}, - {0x11F0, 0x11F0, F_XML_BASE_CHAR}, - {0x11F9, 0x11F9, F_XML_BASE_CHAR}, - {0x1E00, 0x1E9B, F_XML_BASE_CHAR}, - {0x1EA0, 0x1EF9, F_XML_BASE_CHAR}, - {0x1F00, 0x1F15, F_XML_BASE_CHAR}, - {0x1F18, 0x1F1D, F_XML_BASE_CHAR}, - {0x1F20, 0x1F45, F_XML_BASE_CHAR}, - {0x1F48, 0x1F4D, F_XML_BASE_CHAR}, - {0x1F50, 0x1F57, F_XML_BASE_CHAR}, - {0x1F59, 0x1F59, F_XML_BASE_CHAR}, - {0x1F5B, 0x1F5B, F_XML_BASE_CHAR}, - {0x1F5D, 0x1F5D, F_XML_BASE_CHAR}, - {0x1F5F, 0x1F7D, F_XML_BASE_CHAR}, - {0x1F80, 0x1FB4, F_XML_BASE_CHAR}, - {0x1FB6, 0x1FBC, F_XML_BASE_CHAR}, - {0x1FBE, 0x1FBE, F_XML_BASE_CHAR}, - {0x1FC2, 0x1FC4, F_XML_BASE_CHAR}, - {0x1FC6, 0x1FCC, F_XML_BASE_CHAR}, - {0x1FD0, 0x1FD3, F_XML_BASE_CHAR}, - {0x1FD6, 0x1FDB, F_XML_BASE_CHAR}, - {0x1FE0, 0x1FEC, F_XML_BASE_CHAR}, - {0x1FF2, 0x1FF4, F_XML_BASE_CHAR}, - {0x1FF6, 0x1FFC, F_XML_BASE_CHAR}, - {0x2126, 0x2126, F_XML_BASE_CHAR}, - {0x212A, 0x212B, F_XML_BASE_CHAR}, - {0x212E, 0x212E, F_XML_BASE_CHAR}, - {0x2180, 0x2182, F_XML_BASE_CHAR}, - {0x3041, 0x3094, F_XML_BASE_CHAR}, - {0x30A1, 0x30FA, F_XML_BASE_CHAR}, - {0x3105, 0x312C, F_XML_BASE_CHAR}, - {0xAC00, 0xD7A3, F_XML_BASE_CHAR}, - {0x4E00, 0x9FA5, F_XML_IDEOGRAPHIC}, - {0x3007, 0x3007, F_XML_IDEOGRAPHIC}, - {0x3021, 0x3029, F_XML_IDEOGRAPHIC}, - {0x0300, 0x0345, F_XML_COMBINING_CHAR}, - {0x0360, 0x0361, F_XML_COMBINING_CHAR}, - {0x0483, 0x0486, F_XML_COMBINING_CHAR}, - {0x0591, 0x05A1, F_XML_COMBINING_CHAR}, - {0x05A3, 0x05B9, F_XML_COMBINING_CHAR}, - {0x05BB, 0x05BD, F_XML_COMBINING_CHAR}, - {0x05BF, 0x05BF, F_XML_COMBINING_CHAR}, - {0x05C1, 0x05C2, F_XML_COMBINING_CHAR}, - {0x05C4, 0x05C4, F_XML_COMBINING_CHAR}, - {0x064B, 0x0652, F_XML_COMBINING_CHAR}, - {0x0670, 0x0670, F_XML_COMBINING_CHAR}, - {0x06D6, 0x06DC, F_XML_COMBINING_CHAR}, - {0x06DD, 0x06DF, F_XML_COMBINING_CHAR}, - {0x06E0, 0x06E4, F_XML_COMBINING_CHAR}, - {0x06E7, 0x06E8, F_XML_COMBINING_CHAR}, - {0x06EA, 0x06ED, F_XML_COMBINING_CHAR}, - {0x0901, 0x0903, F_XML_COMBINING_CHAR}, - {0x093C, 0x093C, F_XML_COMBINING_CHAR}, - {0x093E, 0x094C, F_XML_COMBINING_CHAR}, - {0x094D, 0x094D, F_XML_COMBINING_CHAR}, - {0x0951, 0x0954, F_XML_COMBINING_CHAR}, - {0x0962, 0x0963, F_XML_COMBINING_CHAR}, - {0x0981, 0x0983, F_XML_COMBINING_CHAR}, - {0x09BC, 0x09BC, F_XML_COMBINING_CHAR}, - {0x09BE, 0x09BE, F_XML_COMBINING_CHAR}, - {0x09BF, 0x09BF, F_XML_COMBINING_CHAR}, - {0x09C0, 0x09C4, F_XML_COMBINING_CHAR}, - {0x09C7, 0x09C8, F_XML_COMBINING_CHAR}, - {0x09CB, 0x09CD, F_XML_COMBINING_CHAR}, - {0x09D7, 0x09D7, F_XML_COMBINING_CHAR}, - {0x09E2, 0x09E3, F_XML_COMBINING_CHAR}, - {0x0A02, 0x0A02, F_XML_COMBINING_CHAR}, - {0x0A3C, 0x0A3C, F_XML_COMBINING_CHAR}, - {0x0A3E, 0x0A3E, F_XML_COMBINING_CHAR}, - {0x0A3F, 0x0A3F, F_XML_COMBINING_CHAR}, - {0x0A40, 0x0A42, F_XML_COMBINING_CHAR}, - {0x0A47, 0x0A48, F_XML_COMBINING_CHAR}, - {0x0A4B, 0x0A4D, F_XML_COMBINING_CHAR}, - {0x0A70, 0x0A71, F_XML_COMBINING_CHAR}, - {0x0A81, 0x0A83, F_XML_COMBINING_CHAR}, - {0x0ABC, 0x0ABC, F_XML_COMBINING_CHAR}, - {0x0ABE, 0x0AC5, F_XML_COMBINING_CHAR}, - {0x0AC7, 0x0AC9, F_XML_COMBINING_CHAR}, - {0x0ACB, 0x0ACD, F_XML_COMBINING_CHAR}, - {0x0B01, 0x0B03, F_XML_COMBINING_CHAR}, - {0x0B3C, 0x0B3C, F_XML_COMBINING_CHAR}, - {0x0B3E, 0x0B43, F_XML_COMBINING_CHAR}, - {0x0B47, 0x0B48, F_XML_COMBINING_CHAR}, - {0x0B4B, 0x0B4D, F_XML_COMBINING_CHAR}, - {0x0B56, 0x0B57, F_XML_COMBINING_CHAR}, - {0x0B82, 0x0B83, F_XML_COMBINING_CHAR}, - {0x0BBE, 0x0BC2, F_XML_COMBINING_CHAR}, - {0x0BC6, 0x0BC8, F_XML_COMBINING_CHAR}, - {0x0BCA, 0x0BCD, F_XML_COMBINING_CHAR}, - {0x0BD7, 0x0BD7, F_XML_COMBINING_CHAR}, - {0x0C01, 0x0C03, F_XML_COMBINING_CHAR}, - {0x0C3E, 0x0C44, F_XML_COMBINING_CHAR}, - {0x0C46, 0x0C48, F_XML_COMBINING_CHAR}, - {0x0C4A, 0x0C4D, F_XML_COMBINING_CHAR}, - {0x0C55, 0x0C56, F_XML_COMBINING_CHAR}, - {0x0C82, 0x0C83, F_XML_COMBINING_CHAR}, - {0x0CBE, 0x0CC4, F_XML_COMBINING_CHAR}, - {0x0CC6, 0x0CC8, F_XML_COMBINING_CHAR}, - {0x0CCA, 0x0CCD, F_XML_COMBINING_CHAR}, - {0x0CD5, 0x0CD6, F_XML_COMBINING_CHAR}, - {0x0D02, 0x0D03, F_XML_COMBINING_CHAR}, - {0x0D3E, 0x0D43, F_XML_COMBINING_CHAR}, - {0x0D46, 0x0D48, F_XML_COMBINING_CHAR}, - {0x0D4A, 0x0D4D, F_XML_COMBINING_CHAR}, - {0x0D57, 0x0D57, F_XML_COMBINING_CHAR}, - {0x0E31, 0x0E31, F_XML_COMBINING_CHAR}, - {0x0E34, 0x0E3A, F_XML_COMBINING_CHAR}, - {0x0E47, 0x0E4E, F_XML_COMBINING_CHAR}, - {0x0EB1, 0x0EB1, F_XML_COMBINING_CHAR}, - {0x0EB4, 0x0EB9, F_XML_COMBINING_CHAR}, - {0x0EBB, 0x0EBC, F_XML_COMBINING_CHAR}, - {0x0EC8, 0x0ECD, F_XML_COMBINING_CHAR}, - {0x0F18, 0x0F19, F_XML_COMBINING_CHAR}, - {0x0F35, 0x0F35, F_XML_COMBINING_CHAR}, - {0x0F37, 0x0F37, F_XML_COMBINING_CHAR}, - {0x0F39, 0x0F39, F_XML_COMBINING_CHAR}, - {0x0F3E, 0x0F3E, F_XML_COMBINING_CHAR}, - {0x0F3F, 0x0F3F, F_XML_COMBINING_CHAR}, - {0x0F71, 0x0F84, F_XML_COMBINING_CHAR}, - {0x0F86, 0x0F8B, F_XML_COMBINING_CHAR}, - {0x0F90, 0x0F95, F_XML_COMBINING_CHAR}, - {0x0F97, 0x0F97, F_XML_COMBINING_CHAR}, - {0x0F99, 0x0FAD, F_XML_COMBINING_CHAR}, - {0x0FB1, 0x0FB7, F_XML_COMBINING_CHAR}, - {0x0FB9, 0x0FB9, F_XML_COMBINING_CHAR}, - {0x20D0, 0x20DC, F_XML_COMBINING_CHAR}, - {0x20E1, 0x20E1, F_XML_COMBINING_CHAR}, - {0x302A, 0x302F, F_XML_COMBINING_CHAR}, - {0x3099, 0x3099, F_XML_COMBINING_CHAR}, - {0x309A, 0x309A, F_XML_COMBINING_CHAR}, - {0x0030, 0x0039, F_XML_DIGIT}, - {0x0660, 0x0669, F_XML_DIGIT}, - {0x06F0, 0x06F9, F_XML_DIGIT}, - {0x0966, 0x096F, F_XML_DIGIT}, - {0x09E6, 0x09EF, F_XML_DIGIT}, - {0x0A66, 0x0A6F, F_XML_DIGIT}, - {0x0AE6, 0x0AEF, F_XML_DIGIT}, - {0x0B66, 0x0B6F, F_XML_DIGIT}, - {0x0BE7, 0x0BEF, F_XML_DIGIT}, - {0x0C66, 0x0C6F, F_XML_DIGIT}, - {0x0CE6, 0x0CEF, F_XML_DIGIT}, - {0x0D66, 0x0D6F, F_XML_DIGIT}, - {0x0E50, 0x0E59, F_XML_DIGIT}, - {0x0ED0, 0x0ED9, F_XML_DIGIT}, - {0x0F20, 0x0F29, F_XML_DIGIT}, - {0x00B7, 0x00B7, F_XML_EXTENDER}, - {0x02D0, 0x02D0, F_XML_EXTENDER}, - {0x02D1, 0x02D1, F_XML_EXTENDER}, - {0x0387, 0x0387, F_XML_EXTENDER}, - {0x0640, 0x0640, F_XML_EXTENDER}, - {0x0E46, 0x0E46, F_XML_EXTENDER}, - {0x0EC6, 0x0EC6, F_XML_EXTENDER}, - {0x3005, 0x3005, F_XML_EXTENDER}, - {0x3031, 0x3035, F_XML_EXTENDER}, - {0x309D, 0x309E, F_XML_EXTENDER}, - {0x30FC, 0x30FE, F_XML_EXTENDER}, - {0x0009, 0x0009, F_XML_WHITESPACE}, - {0x000A, 0x000A, F_XML_WHITESPACE}, - {0x000D, 0x000D, F_XML_WHITESPACE}, - {0x0020, 0x0020, F_XML_WHITESPACE}, - {0x0000, 0x0000, 0x0000} // Mark the end. -}; - -// Function / Method Implementations - -/**************************************************************************** -Desc: Constructor -****************************************************************************/ -F_XML::F_XML() -{ - m_pCharTable = NULL; - GedPoolInit( &m_tmpPool, 1024); -} - -/**************************************************************************** -Desc: Destructor -****************************************************************************/ -F_XML::~F_XML() -{ - if( m_pCharTable) - { - f_free( &m_pCharTable); - } - GedPoolFree( &m_tmpPool); -} - -/**************************************************************************** -Desc: Sets a character's type flag in the character lookup table -****************************************************************************/ -void F_XML::setCharFlag( - FLMUNICODE uLowChar, - FLMUNICODE uHighChar, - FLMUINT16 ui16Flag) -{ - FLMUINT uiLoop; - - flmAssert( uLowChar <= uHighChar); - - for( uiLoop = (FLMUINT)uLowChar; uiLoop <= (FLMUINT)uHighChar; uiLoop++) - { - m_pCharTable[ uiLoop].ucFlags |= (FLMBYTE)ui16Flag; - } -} - -/**************************************************************************** -Desc: Builds a character lookup table -****************************************************************************/ -RCODE F_XML::buildCharTable( void) -{ - RCODE rc = FERR_OK; - FLMUINT uiLoop; - - if( m_pCharTable) - { - f_free( &m_pCharTable); - } - - if( RC_BAD( rc = f_alloc( sizeof( XMLCHAR) * 0xFFFF, &m_pCharTable))) - { - goto Exit; - } - - f_memset( m_pCharTable, 0, sizeof( XMLCHAR) * 0x0000FFFF); - - for (uiLoop = 0; charTbl[uiLoop].ui16Flag; uiLoop++) - { - setCharFlag( charTbl[uiLoop].uLowChar, - charTbl[uiLoop].uHighChar, - charTbl[uiLoop].ui16Flag); - } - -Exit: - - return( rc); -} - -/**************************************************************************** -Desc: Returns TRUE if the character is a valid XML PubID character -****************************************************************************/ -FINLINE FLMBOOL F_XML::isPubidChar( - FLMUNICODE uChar) -{ - if( uChar == F_XML_UNI_SPACE || - uChar == F_XML_UNI_LINEFEED || - (uChar >= F_XML_UNI_a && uChar <= F_XML_UNI_z) || - (uChar >= F_XML_UNI_A && uChar <= F_XML_UNI_Z) || - (uChar >= F_XML_UNI_0 && uChar <= F_XML_UNI_9) || - uChar == F_XML_UNI_HYPHEN || - uChar == F_XML_UNI_APOS || - uChar == F_XML_UNI_LPAREN || - uChar == F_XML_UNI_RPAREN || - uChar == F_XML_UNI_PLUS || - uChar == F_XML_UNI_COMMA || - uChar == F_XML_UNI_PERIOD || - uChar == F_XML_UNI_FSLASH || - uChar == F_XML_UNI_COLON || - uChar == F_XML_UNI_EQ || - uChar == F_XML_UNI_QUEST || - uChar == F_XML_UNI_SEMI || - uChar == F_XML_UNI_BANG || - uChar == F_XML_UNI_ASTERISK || - uChar == F_XML_UNI_POUND || - uChar == F_XML_UNI_ATSIGN || - uChar == F_XML_UNI_DOLLAR || - uChar == F_XML_UNI_UNDERSCORE || - uChar == F_XML_UNI_PERCENT) - { - return( TRUE); - } - - return( FALSE); -} - -/**************************************************************************** -Desc: Returns TRUE if the character is a single or double quote character -****************************************************************************/ -inline FLMBOOL F_XML::isQuoteChar( - FLMUNICODE uChar) -{ - if( uChar == F_XML_UNI_QUOTE || - uChar == F_XML_UNI_APOS) - { - return( TRUE); - } - - return( FALSE); -} - -/**************************************************************************** -Desc: Returns TRUE if the character is a whitespace character -****************************************************************************/ -FINLINE FLMBOOL F_XML::isWhitespace( - FLMUNICODE uChar) -{ - if( (m_pCharTable[ uChar].ucFlags & F_XML_WHITESPACE) != 0) - { - return( TRUE); - } - - return( FALSE); -} - -/**************************************************************************** -Desc: Returns TRUE if the character is an extender character -****************************************************************************/ -FINLINE FLMBOOL F_XML::isExtender( - FLMUNICODE uChar) -{ - if( (m_pCharTable[ uChar].ucFlags & F_XML_EXTENDER) != 0) - { - return( TRUE); - } - - return( FALSE); -} - -/**************************************************************************** -Desc: Returns TRUE if the character is a combining character -****************************************************************************/ -FINLINE FLMBOOL F_XML::isCombiningChar( - FLMUNICODE uChar) -{ - if( (m_pCharTable[ uChar].ucFlags & F_XML_COMBINING_CHAR) != 0) - { - return( TRUE); - } - - return( FALSE); -} - -/**************************************************************************** -Desc: Returns TRUE if the character is a digit -****************************************************************************/ -FINLINE FLMBOOL F_XML::isDigit( - FLMUNICODE uChar) -{ - if( (m_pCharTable[ uChar].ucFlags & F_XML_DIGIT) != 0) - { - return( TRUE); - } - - return( FALSE); -} - -/**************************************************************************** -Desc: Returns TRUE if the character is an ideographic character -****************************************************************************/ -FINLINE FLMBOOL F_XML::isIdeographic( - FLMUNICODE uChar) -{ - if( (m_pCharTable[ uChar].ucFlags & F_XML_IDEOGRAPHIC) != 0) - { - return( TRUE); - } - - return( FALSE); -} - -/**************************************************************************** -Desc: Returns TRUE if the character is a base character -****************************************************************************/ -FINLINE FLMBOOL F_XML::isBaseChar( - FLMUNICODE uChar) -{ - if( (m_pCharTable[ uChar].ucFlags & F_XML_BASE_CHAR) != 0) - { - return( TRUE); - } - - return( FALSE); -} - -/**************************************************************************** -Desc: Returns TRUE if the character is a letter -****************************************************************************/ -FINLINE FLMBOOL F_XML::isLetter( - FLMUNICODE uChar) -{ - if( isBaseChar( uChar) || isIdeographic( uChar)) - { - return( TRUE); - } - - return( FALSE); -} - -/**************************************************************************** -Desc: Returns TRUE if the character is a valid XML naming character -****************************************************************************/ -FINLINE FLMBOOL F_XML::isNameChar( - FLMUNICODE uChar) -{ - if( isLetter( uChar) || - isDigit( uChar) || - uChar == F_XML_UNI_PERIOD || - uChar == F_XML_UNI_HYPHEN || - uChar == F_XML_UNI_UNDERSCORE || - uChar == F_XML_UNI_COLON || - isCombiningChar( uChar) || isExtender( uChar)) - { - return( TRUE); - } - - return( FALSE); -} - -/**************************************************************************** -Desc: Returns TRUE if the name is a valid XML name -****************************************************************************/ -FLMBOOL F_XML::isNameValid( - const FLMUNICODE * puzName, - const char * pszName) -{ - FLMBOOL bValid = FALSE; - - if( puzName) - { - const FLMUNICODE * puzTmp; - - if( !isLetter( *puzName) && *puzName != F_XML_UNI_UNDERSCORE && - *puzName != F_XML_UNI_COLON) - { - goto Exit; - } - - puzTmp = &puzName[ 1]; - while( *puzTmp) - { - if( !isNameChar( *puzTmp)) - { - goto Exit; - } - puzTmp++; - } - } - - if( pszName) - { - const char * pszTmp; - - if( !isLetter( *pszName) && *pszName != F_XML_UNI_UNDERSCORE && - *pszName != F_XML_UNI_COLON) - { - goto Exit; - } - - pszTmp = &pszName[ 1]; - while( *pszTmp) - { - if( !isNameChar( *pszTmp)) - { - goto Exit; - } - pszTmp++; - } - } - - bValid = TRUE; - -Exit: - - return( bValid); -} - -/**************************************************************************** -Desc: Constructor -****************************************************************************/ -F_XMLExport::F_XMLExport() -{ - f_memset( m_szSpaces, 0x20, sizeof( m_szSpaces)); - m_uiTmpBufSize = 0; - m_pszTmpBuf = NULL; - m_pByteStream = NULL; - m_bSetup = FALSE; -} - -/**************************************************************************** -Desc: Destructor -****************************************************************************/ -F_XMLExport::~F_XMLExport() -{ - if( m_pszTmpBuf) - { - f_free( &m_pszTmpBuf); - } - - if( m_pByteStream) - { - m_pByteStream->Release(); - } -} - -/**************************************************************************** -Desc: Initializes the object (allocates buffers, etc.) -****************************************************************************/ -RCODE F_XMLExport::setup( void) -{ - RCODE rc = FERR_OK; - - m_uiTmpBufSize = 64 * 1024; - if( RC_BAD( rc = f_alloc( m_uiTmpBufSize, &m_pszTmpBuf))) - { - goto Exit; - } - - if( (m_pByteStream = f_new FCS_BIOS) == NULL) - { - rc = RC_SET( FERR_MEM); - goto Exit; - } - - if( RC_BAD( rc = buildCharTable())) - { - goto Exit; - } - - m_bSetup = TRUE; - -Exit: - - return( rc); -} - -/**************************************************************************** -Desc: Exports a FLAIM record object as XML text. -****************************************************************************/ -RCODE F_XMLExport::exportRecord( - F_NameTable * pNameTable, - FlmRecord * pRec, - FLMUINT uiStartIndent, - FLMUINT uiIndentSize, - POOL * pPool, - char ** ppszXML, - FLMUINT * puiBytes) -{ - FLMUINT uiBytes; - char szNameBuf[ 256]; - FLMBYTE szTmpBuf[ 256]; - FlmBlob * pBlob = NULL; - void * pvCur; - void * pvPrev; - void * pvStart; - void * pvEnd; - RCODE rc = FERR_OK; - - if( ppszXML) - { - *ppszXML = NULL; - } - - if( puiBytes) - { - *puiBytes = 0; - } - - if( !pNameTable) - { - rc = RC_SET( FERR_INVALID_PARM); - goto Exit; - } - - if( RC_BAD( rc = m_pByteStream->reset())) - { - goto Exit; - } - - pvCur = pRec->root(); - while( pvCur) - { - m_szSpaces[ (pRec->getLevel( pvCur) * - uiIndentSize) + uiStartIndent] = '\0'; - - if( !pNameTable->getFromTagNum( pRec->getFieldID( pvCur), - NULL, szNameBuf, sizeof( szNameBuf))) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - - if( !isNameValid( NULL, szNameBuf)) - { - f_sprintf( (char *)szNameBuf, "tag_%u", - (unsigned)pRec->getFieldID( pvCur)); - } - - uiBytes = f_sprintf( (char *)szTmpBuf, "%s<%s>", - m_szSpaces, szNameBuf); - - m_szSpaces[ (pRec->getLevel( pvCur) * - uiIndentSize) + uiStartIndent] = ' '; - if( RC_BAD( rc = m_pByteStream->write( szTmpBuf, uiBytes))) - { - goto Exit; - } - - if( pRec->getDataLength( pvCur)) - { - FLMUINT uiNum; - FLMINT iNum; - - switch( pRec->getDataType( pvCur)) - { - case FLM_CONTEXT_TYPE: - { - if( RC_BAD( rc = pRec->getUINT( pvCur, &uiNum))) - { - goto Exit; - } - - uiBytes = f_sprintf( (char *)szTmpBuf, "%u", (unsigned)uiNum); - if( RC_BAD( rc = m_pByteStream->write( szTmpBuf, uiBytes))) - { - goto Exit; - } - break; - } - - case FLM_TEXT_TYPE: - { - FLMUNICODE * pUnicode = (FLMUNICODE *)m_pszTmpBuf; - FLMUINT uiUniSize = m_uiTmpBufSize; - - if( RC_BAD( rc = pRec->getUnicode( pvCur, - pUnicode, &uiUniSize))) - { - goto Exit; - } - - uiBytes = 0; - while( *pUnicode) - { - if( *pUnicode >= F_XML_UNI_SPACE && - *pUnicode <= F_XML_UNI_TILDE && - *pUnicode != F_XML_UNI_AMP && *pUnicode != F_XML_UNI_SEMI && - *pUnicode != F_XML_UNI_GT && *pUnicode != F_XML_UNI_LT) - { - uiBytes = f_sprintf( (char *)szTmpBuf, "%c", (char)*pUnicode); - } - else if( *pUnicode == F_XML_UNI_AMP) - { - uiBytes = f_sprintf( (char *)szTmpBuf, "&"); - } - else if( *pUnicode == F_XML_UNI_LT) - { - uiBytes = f_sprintf( (char *)szTmpBuf, "<"); - } - else if( *pUnicode == F_XML_UNI_GT) - { - uiBytes = f_sprintf( (char *)szTmpBuf, ">"); - } - else - { - uiBytes = f_sprintf( (char *)szTmpBuf, "&#%u;", - (unsigned)*pUnicode); - } - - if( RC_BAD( rc = m_pByteStream->write( - szTmpBuf, uiBytes))) - { - goto Exit; - } - - pUnicode++; - } - - break; - } - - case FLM_NUMBER_TYPE: - { - if( RC_BAD( rc = pRec->getUINT( pvCur, &uiNum))) - { - if( rc == FERR_CONV_NUM_UNDERFLOW) - { - if( RC_BAD( rc = pRec->getINT( pvCur, &iNum))) - { - goto Exit; - } - - uiBytes = f_sprintf( (char *)szTmpBuf, "%d", - (int)iNum); - } - else - { - goto Exit; - } - } - else - { - uiBytes = f_sprintf( (char *)szTmpBuf, "%u", - (unsigned)uiNum); - } - - if( RC_BAD( rc = m_pByteStream->write( - szTmpBuf, uiBytes))) - { - goto Exit; - } - - break; - } - - case FLM_BINARY_TYPE: - { - FLMUINT uiBinLen = m_uiTmpBufSize; - FLMUINT uiLoop; - - if( RC_BAD( rc = pRec->getBinary( pvCur, - m_pszTmpBuf, &uiBinLen))) - { - goto Exit; - } - - for( uiLoop = 0; uiLoop < uiBinLen; uiLoop++) - { - FLMBYTE ucHexChar1; - FLMBYTE ucHexChar2; - - ucHexChar1 = (m_pszTmpBuf[ uiLoop] & 0xF0) >> 4; - if( ucHexChar1 <= 9) - { - ucHexChar1 += '0'; - } - else if( ucHexChar1 >= 0x0A && ucHexChar1 <= 0x0F) - { - ucHexChar1 = (ucHexChar1 - 0x0A) + 'A'; - } - - ucHexChar2 = (m_pszTmpBuf[ uiLoop] & 0x0F); - if( ucHexChar2 <= 9) - { - ucHexChar2 += '0'; - } - else if( ucHexChar2 >= 0x0A && ucHexChar2 <= 0x0F) - { - ucHexChar2 = (ucHexChar2 - 0x0A) + 'A'; - } - - szTmpBuf[ 0] = ucHexChar1; - szTmpBuf[ 1] = ucHexChar2; - - if( RC_BAD( rc = m_pByteStream->write( - szTmpBuf, 2))) - { - goto Exit; - } - } - - break; - } - - case FLM_BLOB_TYPE: - { - char szPath[ F_PATH_MAX_SIZE]; - char * pszTmp; - - if( RC_BAD( rc = pRec->getBlob( pvCur, &pBlob))) - { - goto Exit; - } - - if( RC_BAD( rc = pBlob->buildFileName( szPath))) - { - goto Exit; - } - - pszTmp = &szPath[ 0]; - while( *pszTmp) - { - if( *pszTmp >= F_XML_UNI_SPACE && - *pszTmp <= F_XML_UNI_TILDE && - *pszTmp != F_XML_UNI_AMP && *pszTmp != F_XML_UNI_SEMI && - *pszTmp != F_XML_UNI_GT && *pszTmp != F_XML_UNI_LT) - { - szTmpBuf[ 0] = *pszTmp; - uiBytes = 1; - } - else if( *pszTmp == F_XML_UNI_AMP) - { - uiBytes = f_sprintf( (char *)szTmpBuf, "&"); - } - else if( *pszTmp == F_XML_UNI_LT) - { - uiBytes = f_sprintf( (char *)szTmpBuf, "<"); - } - else if( *pszTmp == F_XML_UNI_GT) - { - uiBytes = f_sprintf( (char *)szTmpBuf, ">"); - } - else - { - uiBytes = f_sprintf( (char *)szTmpBuf, "&#%u;", - (unsigned)*pszTmp); - } - - if( RC_BAD( rc = m_pByteStream->write( - szTmpBuf, uiBytes))) - { - goto Exit; - } - - pszTmp++; - } - pBlob->Release(); - pBlob = NULL; - break; - } - - default: - { - flmAssert( 0); - rc = RC_SET( FERR_NOT_IMPLEMENTED); - goto Exit; - } - } - } - - if( pRec->firstChild( pvCur)) - { - uiBytes = f_sprintf( (char *)szTmpBuf, "%s", CRLFSTR); - } - else - { - uiBytes = f_sprintf( (char *)szTmpBuf, "%s", - szNameBuf, CRLFSTR); - } - - if( RC_BAD( rc = m_pByteStream->write( szTmpBuf, uiBytes))) - { - goto Exit; - } - - pvPrev = pvCur; - pvCur = pRec->next( pvCur); - pvStart = pRec->parent( pvPrev); - - if( pvCur) - { - pvEnd = pvCur; - } - else - { - pvEnd = pRec->root(); - } - - while( pvStart && pRec->getLevel( pvStart) >= pRec->getLevel( pvEnd)) - { - if( RC_BAD( rc = m_pByteStream->write( m_szSpaces, - (pRec->getLevel( pvStart) * uiIndentSize) + uiStartIndent))) - { - goto Exit; - } - - if( !pNameTable->getFromTagNum( pRec->getFieldID( pvStart), - NULL, szNameBuf, sizeof( szNameBuf))) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - - if( !isNameValid( NULL, szNameBuf)) - { - f_sprintf( (char *)szNameBuf, "tag_%u", - (unsigned)pRec->getFieldID( pvStart)); - } - - uiBytes = f_sprintf( (char *)szTmpBuf, "%s", - szNameBuf, CRLFSTR); - if( RC_BAD( rc = m_pByteStream->write( szTmpBuf, uiBytes))) - { - goto Exit; - } - - if( pRec->getLevel( pvStart) == pRec->getLevel( pvEnd)) - { - break; - } - - pvStart = pRec->parent( pvStart); - } - } - - if( RC_BAD( rc = m_pByteStream->endMessage())) - { - goto Exit; - } - - uiBytes = m_pByteStream->getAvailable(); - if( ppszXML) - { - if( (*ppszXML = (char *)GedPoolAlloc( pPool, uiBytes + 1)) == NULL) - { - rc = RC_SET( FERR_MEM); - goto Exit; - } - - if( RC_BAD( rc = m_pByteStream->read( (FLMBYTE *)*ppszXML, uiBytes, &uiBytes))) - { - goto Exit; - } - - (*ppszXML)[ uiBytes] = 0; - } - - if( puiBytes) - { - *puiBytes = uiBytes; - } - -Exit: - - if( pBlob) - { - pBlob->Release(); - } - - m_pByteStream->reset(); - return( rc); -} - -/**************************************************************************** -Desc: Constructor -****************************************************************************/ -F_XMLImport::F_XMLImport() -{ - reset(); - m_uiValBufSize = 0; - m_puValBuf = NULL; - m_bSetup = FALSE; -} - -/**************************************************************************** -Desc: Destructor -****************************************************************************/ -F_XMLImport::~F_XMLImport() -{ - if( m_puValBuf) - { - f_free( &m_puValBuf); - } -} - -/**************************************************************************** -Desc: Resets member variables so the object can be reused -****************************************************************************/ -void F_XMLImport::reset( void) -{ - m_uiUngetPos = 0; - m_ucUngetByte = 0; - m_pStream = NULL; - m_bSubset = FALSE; - m_pNameTable = NULL; - m_hDb = HFDB_NULL; -} - -/**************************************************************************** -Desc: Initializes the object (allocates buffers, etc.) -****************************************************************************/ -RCODE F_XMLImport::setup( void) -{ - RCODE rc = FERR_OK; - - flmAssert( !m_bSetup); - - m_uiValBufSize = 32 * 1024; // # of Unicode characters - - if( RC_BAD( rc = f_alloc( - sizeof( FLMUNICODE) * m_uiValBufSize, &m_puValBuf))) - { - goto Exit; - } - - if( RC_BAD( rc = buildCharTable())) - { - goto Exit; - } - - m_bSetup = TRUE; - -Exit: - - return( rc); -} -/**************************************************************************** -Desc: Returns a fields type and tag given its real name or - its TAG_##### equivalent -****************************************************************************/ -RCODE F_XMLImport::getFieldTagAndType( - FLMUNICODE * puzName, - FLMUINT * puiTagNum, - FLMUINT * puiDataType) -{ - RCODE rc = FERR_OK; - void * pvMark = GedPoolMark( &m_tmpPool); - char * pszName; - FLMUINT uiTagNum; - FLMUINT uiType; - FLMUINT uiDataType; - - if( !m_pNameTable || - !m_pNameTable->getFromTagTypeAndName( puzName, NULL, - FLM_FIELD_TAG, puiTagNum, puiDataType)) - { - // Convert the tag name to ASCII - - if( RC_BAD( rc = fcsConvertUnicodeToNative( &m_tmpPool, - m_uChars, &pszName))) - { - goto Exit; - } - - if( f_strnicmp( pszName, "TAG_", 4) == 0) - { - uiTagNum = f_atoud( &pszName[ 4]); - - if( puiTagNum) - { - *puiTagNum = uiTagNum; - } - - if( !m_pNameTable->getFromTagNum( uiTagNum, NULL, - NULL, 0, &uiType, &uiDataType) || uiType != FLM_FIELD_TAG) - { - rc = RC_SET( FERR_NOT_FOUND); - goto Exit; - } - - if( puiDataType) - { - *puiDataType = uiDataType; - } - } - else - { - rc = RC_SET( FERR_NOT_FOUND); - goto Exit; - } - } - -Exit: - - GedPoolReset( &m_tmpPool, pvMark); - return( rc); -} - -/**************************************************************************** -Desc: Reads data from the input stream and builds a FLAIM record -****************************************************************************/ -RCODE F_XMLImport::importDocument( - HFDB hDb, - F_NameTable * pNameTable, - FCS_ISTM * pStream, - FLMBOOL bSubset, - FlmRecord ** ppRecord) -{ - FlmRecord * pRec = NULL; - void * pvParent; - RCODE rc = FERR_OK; - - *ppRecord = NULL; - - reset(); - m_pStream = pStream; - m_hDb = hDb; - m_bSubset = bSubset; - - if( !pNameTable) - { - if( (m_pNameTable = f_new F_NameTable) == NULL) - { - rc = RC_SET( FERR_MEM); - goto Exit; - } - - if( RC_BAD( rc = m_pNameTable->setupFromDb( hDb))) - { - goto Exit; - } - } - else - { - m_pNameTable = pNameTable; - } - - if( (pRec = f_new FlmRecord) == NULL) - { - rc = RC_SET( FERR_MEM); - goto Exit; - } - - pvParent = NULL; - if( !m_bSubset) - { - if( RC_BAD( rc = pRec->insertLast( 0, - F_XML_DOCUMENT_TAG, FLM_TEXT_TYPE, &pvParent))) - { - goto Exit; - } - } - - if( RC_BAD( rc = processProlog( pRec, pvParent))) - { - goto Exit; - } - - if( RC_BAD( rc = processElement( pRec, pvParent))) - { - goto Exit; - } - - if( RC_BAD( rc = processMisc( pRec, pvParent))) - { - goto Exit; - } - - *ppRecord = pRec; - pRec = NULL; - -Exit: - - if( pRec) - { - pRec->Release(); - } - - if( m_pNameTable != pNameTable) - { - m_pNameTable->Release(); - m_pNameTable = NULL; - } - - return( rc); -} - -/**************************************************************************** -Desc: Process an XML prolog -****************************************************************************/ -RCODE F_XMLImport::processProlog( - FlmRecord * pRec, - void * pvParent) -{ - FLMBOOL bTmp; - RCODE rc = FERR_OK; - - if( RC_BAD( rc = isXMLDecl( &bTmp))) - { - goto Exit; - } - - if( bTmp) - { - if( RC_BAD( rc = processXMLDecl( pRec, pvParent))) - { - goto Exit; - } - } - - if( RC_BAD( rc = processMisc( pRec, pvParent))) - { - goto Exit; - } - - if( RC_BAD( rc = isDocTypeDecl( &bTmp))) - { - goto Exit; - } - - if( bTmp) - { - if( RC_BAD( rc = processDocTypeDecl( pRec, pvParent))) - { - goto Exit; - } - - if( RC_BAD( rc = processMisc( pRec, pvParent))) - { - goto Exit; - } - } - -Exit: - - return( rc); -} - -/**************************************************************************** -Desc: Converts a Unicode string to a number -****************************************************************************/ -RCODE F_XMLImport::unicodeToNumber( - const FLMUNICODE * puzVal, - FLMUINT * puiVal, - FLMBOOL * pbNeg) -{ - char szTmpBuf[ 32]; - FLMUINT uiLoop; - FLMBOOL bNeg = FALSE; - FLMUNICODE uChar; - RCODE rc = FERR_OK; - - for( uiLoop = 0; uiLoop < sizeof( szTmpBuf); uiLoop++) - { - if( (uChar = puzVal[ uiLoop]) == 0) - { - break; - } - else if( uiLoop == 0 && uChar == F_XML_UNI_HYPHEN) - { - bNeg = TRUE; - continue; - } - - if( !((uChar >= '0' && uChar <= '9') || - (uChar >= 'A' && uChar <= 'F') || - (uChar >= 'a' && uChar <= 'f') || - uChar == 'X' || uChar == 'x')) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - - szTmpBuf[ uiLoop] = (FLMBYTE)uChar; - } - - if( uiLoop == sizeof( szTmpBuf)) - { - rc = RC_SET( FERR_CONV_DEST_OVERFLOW); - goto Exit; - } - - szTmpBuf[ uiLoop] = 0; - *puiVal = f_atoud( szTmpBuf); - - if( pbNeg) - { - *pbNeg = bNeg; - } - -Exit: - - return( rc); -} - -/**************************************************************************** -Desc: Sets an element field's value -****************************************************************************/ -RCODE F_XMLImport::setElementValue( - FlmRecord * pRec, - void * pvField, - const FLMUNICODE * puzValue) -{ - FLMUINT uiDataType = pRec->getDataType( pvField); - FLMUINT uiVal; - FLMBOOL bNeg; - FlmBlob * pBlob = NULL; - void * pvMark = GedPoolMark( &m_tmpPool); - RCODE rc = FERR_OK; - - switch( uiDataType) - { - case FLM_TEXT_TYPE: - { - if( RC_BAD( rc = pRec->setUnicode( pvField, puzValue))) - { - goto Exit; - } - break; - } - - case FLM_NUMBER_TYPE: - { - if( RC_BAD( rc = unicodeToNumber( puzValue, &uiVal, &bNeg))) - { - goto Exit; - } - - if( !bNeg) - { - if( RC_BAD( rc = pRec->setUINT( pvField, uiVal))) - { - goto Exit; - } - } - else - { - if( RC_BAD( rc = pRec->setINT( pvField, -((FLMINT)uiVal)))) - { - goto Exit; - } - } - break; - } - - case FLM_CONTEXT_TYPE: - { - if( RC_BAD( rc = unicodeToNumber( puzValue, &uiVal, &bNeg))) - { - goto Exit; - } - - if( bNeg) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - - if( RC_BAD( rc = pRec->setRecPointer( pvField, uiVal))) - { - goto Exit; - } - - break; - } - - case FLM_BINARY_TYPE: - { - FLMBYTE * pucCur = (FLMBYTE *)&puzValue[ 0]; - FLMBYTE ucVal; - FLMUINT uiLoop; - FLMBOOL bShift = TRUE; - FLMUINT uiBytes = 0; - FLMUNICODE uChar; - - for( uiLoop = 0; puzValue[ uiLoop]; uiLoop++) - { - uChar = puzValue[ uiLoop]; - - if( isWhitespace( uChar)) - { - continue; - } - - if( uChar >= F_XML_UNI_0 && uChar <= F_XML_UNI_9) - { - ucVal = (FLMBYTE)(uChar - F_XML_UNI_0); - } - else if( uChar >= F_XML_UNI_A && uChar <= F_XML_UNI_F) - { - ucVal = (FLMBYTE)((uChar - F_XML_UNI_A) + 0x0A); - } - else if( uChar >= F_XML_UNI_a && uChar <= F_XML_UNI_f) - { - ucVal = (FLMBYTE)((uChar - F_XML_UNI_a) + 0x0A); - } - else - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - - if( bShift) - { - *pucCur = ucVal << 4; - bShift = FALSE; - } - else - { - *pucCur |= ucVal; - pucCur++; - uiBytes++; - bShift = TRUE; - } - } - - if( !bShift) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - - if( uiBytes) - { - if( RC_BAD( rc = pRec->setBinary( pvField, (FLMBYTE *)&puzValue[ 0], - uiBytes))) - { - goto Exit; - } - } - - break; - } - - case FLM_BLOB_TYPE: - { - char * pszPath; - - if( m_hDb == HFDB_NULL) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - - if ( (pBlob = f_new FlmBlobImp) == NULL) - { - rc = RC_SET( FERR_MEM); - goto Exit; - } - - GedPoolReset( &m_tmpPool, pvMark); - if( RC_BAD( rc = fcsConvertUnicodeToNative( &m_tmpPool, - puzValue, &pszPath))) - { - goto Exit; - } - - if( RC_BAD( rc = pBlob->referenceFile( m_hDb, pszPath, TRUE))) - { - goto Exit; - } - - if( RC_BAD( rc = pRec->setBlob( pvField, pBlob))) - { - goto Exit; - } - - pBlob->Release(); - pBlob = NULL; - break; - } - - default: - { - flmAssert( 0); - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - } - -Exit: - - if( pBlob) - { - pBlob->Release(); - } - - GedPoolReset( &m_tmpPool, pvMark); - return( rc); -} - -/**************************************************************************** -Desc: Processes an XML element -****************************************************************************/ -RCODE F_XMLImport::processElement( - FlmRecord * pRec, - void * pvParent) -{ - FLMBOOL bHasContent; - FLMBOOL bValueSet = FALSE; - FLMUINT uiLen; - FLMUINT uiChars; - FLMUINT uiOffset = 0; - FLMUNICODE uChar; - void * pvElementRoot; - void * pvField; - RCODE rc = FERR_OK; - - if( RC_BAD( rc = processSTag( pRec, pvParent, - &bHasContent, &pvElementRoot))) - { - goto Exit; - } - - if( bHasContent) - { - for( ;;) - { - if( RC_BAD( rc = getChar( &m_uChars[ 0]))) - { - goto Exit; - } - - if( m_uChars[ 0] == F_XML_UNI_LT) - { - if( uiOffset) - { - // Flush the value to the record - - m_puValBuf[ uiOffset] = 0; - if( m_bSubset) - { - if( bValueSet) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - - if( RC_BAD( rc = setElementValue( pRec, - pvElementRoot, m_puValBuf))) - { - goto Exit; - } - } - else - { - if( RC_BAD( rc = pRec->insertLast( - pRec->getLevel( pvElementRoot) + 1, - F_XML_ELEMENTVAL_TAG, FLM_TEXT_TYPE, &pvField))) - { - goto Exit; - } - - if( RC_BAD( rc = pRec->setUnicode( pvField, m_puValBuf))) - { - goto Exit; - } - } - - uiOffset = 0; - bValueSet = TRUE; - } - - if( RC_BAD( rc = getChar( &m_uChars[ 1]))) - { - goto Exit; - } - - if( m_uChars[ 1] == F_XML_UNI_QUEST) - { - if( RC_BAD( rc = ungetChars( m_uChars, 2))) - { - goto Exit; - } - - if( RC_BAD( rc = processPI( pRec, - m_bSubset ? NULL : pvElementRoot))) - { - goto Exit; - } - } - else if( m_uChars[ 1] == F_XML_UNI_BANG) - { - uiChars = 2; - if( RC_BAD( rc = getChars( &m_uChars[ 2], &uiChars))) - { - goto Exit; - } - - if( m_uChars[ 2] == F_XML_UNI_HYPHEN && - m_uChars[ 3] == F_XML_UNI_HYPHEN) - { - if( RC_BAD( rc = ungetChars( m_uChars, 4))) - { - goto Exit; - } - - if( RC_BAD( rc = processComment( pRec, - m_bSubset ? NULL : pvElementRoot))) - { - goto Exit; - } - } - else if( m_uChars[ 2] == F_XML_UNI_LBRACKET && - m_uChars[ 3] == F_XML_UNI_C) - { - uiChars = 5; - if( RC_BAD( rc = getChars( &m_uChars[ 4], &uiChars))) - { - goto Exit; - } - - if( m_uChars[ 4] != F_XML_UNI_D || - m_uChars[ 5] != F_XML_UNI_A || - m_uChars[ 6] != F_XML_UNI_T || - m_uChars[ 7] != F_XML_UNI_A || - m_uChars[ 8] != F_XML_UNI_LBRACKET) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - - if( RC_BAD( rc = ungetChars( m_uChars, 9))) - { - goto Exit; - } - - if( RC_BAD( rc = processCDATA( pRec, - m_bSubset ? NULL : pvElementRoot))) - { - goto Exit; - } - } - else - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - } - else if( isNameChar( m_uChars[ 1])) - { - if( RC_BAD( rc = ungetChars( m_uChars, 2))) - { - goto Exit; - } - - if( RC_BAD( rc = processElement( pRec, pvElementRoot))) - { - goto Exit; - } - } - else if( m_uChars[ 1] == F_XML_UNI_FSLASH) - { - if( uiOffset) - { - // Flush the value to the record - - m_puValBuf[ uiOffset] = 0; - if( m_bSubset) - { - if( bValueSet) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - - if( RC_BAD( rc = setElementValue( pRec, - pvElementRoot, m_puValBuf))) - { - goto Exit; - } - } - else - { - if( RC_BAD( rc = pRec->insertLast( - pRec->getLevel( pvElementRoot) + 1, - F_XML_ELEMENTVAL_TAG, FLM_TEXT_TYPE, &pvField))) - { - goto Exit; - } - - if( RC_BAD( rc = pRec->setUnicode( pvField, m_puValBuf))) - { - goto Exit; - } - } - - uiOffset = 0; - bValueSet = TRUE; - } - break; - } - else - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - } - else - { - if( RC_BAD( rc = ungetChar( m_uChars[ 0]))) - { - goto Exit; - } - - for( ;;) - { - if( RC_BAD( rc = getChar( &uChar))) - { - goto Exit; - } - - if( m_bSubset && uChar == F_XML_UNI_AMP) - { - if( RC_BAD( rc = processReference( pRec, NULL, &uChar))) - { - goto Exit; - } - - m_puValBuf[ uiOffset++] = uChar; - if( uiOffset >= m_uiValBufSize) - { - rc = RC_SET( FERR_CONV_DEST_OVERFLOW); - goto Exit; - } - continue; - } - - if( uiOffset && (uChar == F_XML_UNI_LT || - uChar == F_XML_UNI_AMP)) - { - if( uiOffset) - { - // Flush the value to the record - - m_puValBuf[ uiOffset] = 0; - if( m_bSubset) - { - if( bValueSet) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - - if( RC_BAD( rc = setElementValue( pRec, - pvElementRoot, m_puValBuf))) - { - goto Exit; - } - } - else - { - if( RC_BAD( rc = pRec->insertLast( - pRec->getLevel( pvElementRoot) + 1, - F_XML_ELEMENTVAL_TAG, FLM_TEXT_TYPE, &pvField))) - { - goto Exit; - } - - if( RC_BAD( rc = pRec->setUnicode( pvField, m_puValBuf))) - { - goto Exit; - } - } - - uiOffset = 0; - bValueSet = TRUE; - } - } - - if( uChar == F_XML_UNI_LT) - { - if( RC_BAD( rc = ungetChar( uChar))) - { - goto Exit; - } - break; - } - else if( uChar == F_XML_UNI_AMP) - { - if( RC_BAD( rc = ungetChar( uChar))) - { - goto Exit; - } - - if( RC_BAD( rc = processReference( pRec, pvElementRoot))) - { - goto Exit; - } - } - else if( uChar == F_XML_UNI_LINEFEED && m_bSubset) - { - if( RC_BAD( rc = skipWhitespace( NULL))) - { - goto Exit; - } - } - else - { - m_puValBuf[ uiOffset++] = uChar; - if( uiOffset >= m_uiValBufSize) - { - rc = RC_SET( FERR_CONV_DEST_OVERFLOW); - goto Exit; - } - } - } - } - } - - flmAssert( !uiOffset); - flmAssert( m_uChars[ 0] == F_XML_UNI_LT); - flmAssert( m_uChars[ 1] == F_XML_UNI_FSLASH); - - uiChars = F_XML_MAX_CHARS; - if( RC_BAD( rc = getName( m_uChars, &uiChars))) - { - goto Exit; - } - - // Validate the end tag against the start tag - - if( m_bSubset) - { - FLMUINT uiTagNum; - FLMUINT uiDataType; - - if( RC_BAD( rc = getFieldTagAndType( m_uChars, - &uiTagNum, &uiDataType))) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - - if( pRec->getFieldID( pvElementRoot) != uiTagNum || - pRec->getDataType( pvElementRoot) != uiDataType) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - } - else - { - uiLen = m_uiValBufSize * sizeof( FLMUNICODE); - if( RC_BAD( rc = pRec->getUnicode( pvElementRoot, - m_puValBuf, &uiLen))) - { - goto Exit; - } - - if( f_unicmp( m_uChars, m_puValBuf) != 0) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - } - - // Skip any whitespace after the name - - if( RC_BAD( rc = skipWhitespace( pvParent))) - { - goto Exit; - } - - // Get the closing bracket character - - if( RC_BAD( rc = getChar( &uChar))) - { - goto Exit; - } - - // Expecting a closing bracket - - if( uChar != F_XML_UNI_GT) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - } - -Exit: - - return( rc); -} - -/**************************************************************************** -Desc: Processes an XML STag -****************************************************************************/ -RCODE F_XMLImport::processSTag( - FlmRecord * pRec, - void * pvParent, - FLMBOOL * pbHasContent, - void ** ppvElementRoot) -{ - FLMUNICODE uChar; - FLMUINT uiChars; - FLMUINT uiTagNum; - FLMUINT uiDataType; - void * pvMark = GedPoolMark( &m_tmpPool); - void * pvField; - RCODE rc = FERR_OK; - - *pbHasContent = FALSE; - *ppvElementRoot = NULL; - - if( RC_BAD( rc = getChar( &uChar))) - { - goto Exit; - } - - if( uChar != F_XML_UNI_LT) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - - uiChars = F_XML_MAX_CHARS; - if( RC_BAD( rc = getName( m_uChars, &uiChars))) - { - goto Exit; - } - - if( m_bSubset) - { - // Find the name in the name table - - if( RC_BAD( rc = getFieldTagAndType( m_uChars, - &uiTagNum, &uiDataType))) - { - if( rc == FERR_NOT_FOUND) - { - rc = RC_SET( FERR_SYNTAX); - } - goto Exit; - } - - if( RC_BAD( rc = pRec->insertLast( - pvParent ? pRec->getLevel( pvParent) + 1 : 0, - uiTagNum, uiDataType, &pvField))) - { - goto Exit; - } - } - else - { - if( RC_BAD( rc = pRec->insertLast( - pRec->getLevel( pvParent) + 1, - F_XML_ELEMENTNAME_TAG, FLM_TEXT_TYPE, &pvField))) - { - goto Exit; - } - - if( RC_BAD( rc = pRec->setUnicode( pvField, m_uChars))) - { - goto Exit; - } - } - - *ppvElementRoot = pvField; - - if( RC_BAD( rc = skipWhitespace( pvParent))) - { - goto Exit; - } - - if( RC_BAD( rc = peekChar( &uChar))) - { - goto Exit; - } - - if( uChar != F_XML_UNI_GT) - { - if( RC_BAD( rc = processAttributes( pRec, - m_bSubset ? NULL : pvField))) - { - goto Exit; - } - } - - if( RC_BAD( rc = skipWhitespace( - m_bSubset ? NULL : pvField))) - { - goto Exit; - } - - if( RC_BAD( rc = getChar( &uChar))) - { - goto Exit; - } - - if( uChar == F_XML_UNI_GT) - { - *pbHasContent = TRUE; - } - else if( uChar == F_XML_UNI_FSLASH) - { - if( RC_BAD( rc = getChar( &uChar))) - { - goto Exit; - } - - if( uChar != F_XML_UNI_GT) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - } - -Exit: - - GedPoolReset( &m_tmpPool, pvMark); - return( rc); -} - -/**************************************************************************** -Desc: Processes an element's attributes -****************************************************************************/ -RCODE F_XMLImport::processAttributes( - FlmRecord * pRec, - void * pvParent) -{ - FLMUNICODE uChar; - FLMUINT uiChars; - void * pvField = NULL; - RCODE rc = FERR_OK; - - for( ;;) - { - if( RC_BAD( rc = skipWhitespace( pvParent))) - { - goto Exit; - } - - if( RC_BAD( rc = peekChar( &uChar))) - { - goto Exit; - } - - if( !isNameChar( uChar)) - { - break; - } - - uiChars = F_XML_MAX_CHARS; - if( RC_BAD( rc = getName( m_uChars, &uiChars))) - { - goto Exit; - } - - if( pvParent) - { - if( RC_BAD( rc = pRec->insertLast( - pRec->getLevel( pvParent) + 1, - F_XML_ATTNAME_TAG, FLM_TEXT_TYPE, &pvField))) - { - goto Exit; - } - - if( RC_BAD( rc = pRec->setUnicode( pvField, m_uChars))) - { - goto Exit; - } - } - - if( RC_BAD( rc = skipWhitespace( pvParent))) - { - goto Exit; - } - - if( RC_BAD( rc = getChar( &uChar))) - { - goto Exit; - } - - if( uChar != F_XML_UNI_EQ) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - - if( RC_BAD( rc = skipWhitespace( pvParent))) - { - goto Exit; - } - - if( RC_BAD( rc = processAttValue( pRec, pvField))) - { - goto Exit; - } - } - -Exit: - - return( rc); -} - -/**************************************************************************** -Desc: Processes an XML declaration -****************************************************************************/ -RCODE F_XMLImport::processXMLDecl( - FlmRecord * pRec, - void * pvParent) -{ - FLMUNICODE uChar; - FLMUINT uiChars; - void * pvField = NULL; - RCODE rc = FERR_OK; - - if( pvParent) - { - if( RC_BAD( rc = pRec->insertLast( - pRec->getLevel( pvParent) + 1, - F_XML_XMLDECL_TAG, FLM_TEXT_TYPE, &pvField))) - { - goto Exit; - } - } - - if( RC_BAD( rc = skipWhitespace( pvParent))) - { - goto Exit; - } - - uiChars = 5; - if( RC_BAD( rc = getChars( m_uChars, &uiChars))) - { - goto Exit; - } - - if( m_uChars[ 0] != F_XML_UNI_LT || - m_uChars[ 1] != F_XML_UNI_QUEST || - m_uChars[ 2] != F_XML_UNI_x || - m_uChars[ 3] != F_XML_UNI_m || - m_uChars[ 4] != F_XML_UNI_l) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - - if( pvField) - { - m_uChars[ 5] = 0; - if( RC_BAD( rc = pRec->setUnicode( pvField, &m_uChars[ 2]))) - { - goto Exit; - } - } - - if( RC_BAD( rc = skipWhitespace( pvParent, TRUE))) - { - goto Exit; - } - - if( RC_BAD( rc = processVersion( pRec, pvField))) - { - goto Exit; - } - - if( RC_BAD( rc = skipWhitespace( pvField, TRUE))) - { - if( rc != FERR_SYNTAX) - { - goto Exit; - } - - if( RC_BAD( rc = peekChar( &uChar))) - { - goto Exit; - } - - if( uChar != F_XML_UNI_QUEST) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - } - - if( RC_BAD( rc = peekChar( &uChar))) - { - goto Exit; - } - - if( uChar == F_XML_UNI_e) - { - if( RC_BAD( rc = processEncodingDecl( pRec, pvField))) - { - goto Exit; - } - - if( RC_BAD( rc = skipWhitespace( pvField, TRUE))) - { - if( rc != FERR_SYNTAX) - { - goto Exit; - } - - if( RC_BAD( rc = peekChar( &uChar))) - { - goto Exit; - } - - if( uChar != F_XML_UNI_QUEST) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - } - } - - if( RC_BAD( rc = peekChar( &uChar))) - { - goto Exit; - } - - if( uChar == F_XML_UNI_s) - { - if( RC_BAD( rc = processSDDecl( pRec, pvField))) - { - goto Exit; - } - } - - if( RC_BAD( rc = skipWhitespace( pvField))) - { - goto Exit; - } - - if( RC_BAD( rc = getChar( &uChar))) - { - goto Exit; - } - - if( uChar != F_XML_UNI_QUEST) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - - if( RC_BAD( rc = getChar( &uChar))) - { - goto Exit; - } - - if( uChar != F_XML_UNI_GT) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - -Exit: - - return( rc); -} - -/**************************************************************************** -Desc: Processes an XML document type declaration -****************************************************************************/ -RCODE F_XMLImport::processDocTypeDecl( - FlmRecord * pRec, - void * pvParent) -{ - FLMUNICODE uChar; - FLMUINT uiChars; - FLMBOOL bTmp; - void * pvField = NULL; - RCODE rc = FERR_OK; - - if( pvParent) - { - if( RC_BAD( rc = pRec->insertLast( - pRec->getLevel( pvParent) + 1, - F_XML_DOCTYPEDECL_TAG, FLM_TEXT_TYPE, &pvField))) - { - goto Exit; - } - } - - if( RC_BAD( rc = skipWhitespace( pvParent))) - { - goto Exit; - } - - uiChars = 9; - if( RC_BAD( rc = getChars( m_uChars, &uiChars))) - { - goto Exit; - } - - if( m_uChars[ 0] != F_XML_UNI_LT || - m_uChars[ 1] != F_XML_UNI_BANG || - m_uChars[ 2] != F_XML_UNI_D || - m_uChars[ 3] != F_XML_UNI_O || - m_uChars[ 4] != F_XML_UNI_C || - m_uChars[ 5] != F_XML_UNI_T || - m_uChars[ 6] != F_XML_UNI_Y || - m_uChars[ 7] != F_XML_UNI_P || - m_uChars[ 8] != F_XML_UNI_E) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - - if( RC_BAD( rc = skipWhitespace( pvField))) - { - goto Exit; - } - - uiChars = F_XML_MAX_CHARS; - if( RC_BAD( rc = getName( m_uChars, &uiChars))) - { - goto Exit; - } - - if( pvField) - { - if( RC_BAD( rc = pRec->setUnicode( pvField, m_uChars))) - { - goto Exit; - } - } - - if( RC_BAD( rc = peekChar( &uChar))) - { - goto Exit; - } - - bTmp = FALSE; - if( isWhitespace( uChar)) - { - if( RC_BAD( rc = skipWhitespace( pvField))) - { - goto Exit; - } - bTmp = TRUE; - } - - if( RC_BAD( rc = peekChar( &uChar))) - { - goto Exit; - } - - if( uChar == F_XML_UNI_S || uChar == F_XML_UNI_P) - { - if( !bTmp) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - - if( RC_BAD( rc = processID( pRec, pvField, &bTmp))) - { - goto Exit; - } - - if( bTmp) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - - if( RC_BAD( rc = skipWhitespace( pvField))) - { - goto Exit; - } - - if( RC_BAD( rc = peekChar( &uChar))) - { - goto Exit; - } - } - - if( uChar == F_XML_UNI_LBRACKET) - { - if( RC_BAD( rc = getChar( &uChar))) - { - goto Exit; - } - - for( ;;) - { - if( RC_BAD( rc = skipWhitespace( pvField))) - { - goto Exit; - } - - if( RC_BAD( rc = peekChar( &uChar))) - { - goto Exit; - } - - if( uChar == F_XML_UNI_PERCENT) - { - if( RC_BAD( rc = processPERef( pRec, pvField))) - { - goto Exit; - } - } - else if( uChar == F_XML_UNI_RBRACKET) - { - if( RC_BAD( rc = getChar( &uChar))) - { - goto Exit; - } - break; - } - else - { - if( RC_BAD( rc = processMarkupDecl( pRec, pvField))) - { - goto Exit; - } - } - } - } - - if( RC_BAD( rc = skipWhitespace( pvField))) - { - goto Exit; - } - - if( RC_BAD( rc = getChar( &uChar))) - { - goto Exit; - } - - if( uChar != F_XML_UNI_GT) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - -Exit: - - return( rc); -} - -/**************************************************************************** -Desc: Processes an XML markup declaration -****************************************************************************/ -RCODE F_XMLImport::processMarkupDecl( - FlmRecord * pRec, - void * pvParent) -{ - FLMUINT uiChars; - RCODE rc = FERR_OK; - - uiChars = 10; - rc = getChars( m_uChars, &uiChars); - if( RC_BAD( rc) && rc != FERR_EOF_HIT) - { - goto Exit; - } - - if( RC_BAD( rc = ungetChars( m_uChars, uiChars))) - { - goto Exit; - } - - if( uiChars >= 10 && - m_uChars[ 0] == F_XML_UNI_LT && - m_uChars[ 1] == F_XML_UNI_BANG && - m_uChars[ 2] == F_XML_UNI_N && - m_uChars[ 3] == F_XML_UNI_O && - m_uChars[ 4] == F_XML_UNI_T && - m_uChars[ 5] == F_XML_UNI_A && - m_uChars[ 6] == F_XML_UNI_T && - m_uChars[ 7] == F_XML_UNI_I && - m_uChars[ 8] == F_XML_UNI_O && - m_uChars[ 9] == F_XML_UNI_N) - { - if( RC_BAD( rc = processNotationDecl( pRec, pvParent))) - { - goto Exit; - } - } - else if( uiChars >= 9 && - m_uChars[ 0] == F_XML_UNI_LT && - m_uChars[ 1] == F_XML_UNI_BANG && - m_uChars[ 2] == F_XML_UNI_E && - m_uChars[ 3] == F_XML_UNI_L && - m_uChars[ 4] == F_XML_UNI_E && - m_uChars[ 5] == F_XML_UNI_M && - m_uChars[ 6] == F_XML_UNI_E && - m_uChars[ 7] == F_XML_UNI_N && - m_uChars[ 8] == F_XML_UNI_T) - { - if( RC_BAD( rc = processElementDecl( pRec, pvParent))) - { - goto Exit; - } - } - else if( uiChars >= 9 && - m_uChars[ 0] == F_XML_UNI_LT && - m_uChars[ 1] == F_XML_UNI_BANG && - m_uChars[ 2] == F_XML_UNI_A && - m_uChars[ 3] == F_XML_UNI_T && - m_uChars[ 4] == F_XML_UNI_T && - m_uChars[ 5] == F_XML_UNI_L && - m_uChars[ 6] == F_XML_UNI_I && - m_uChars[ 7] == F_XML_UNI_S && - m_uChars[ 8] == F_XML_UNI_T) - { - if( RC_BAD( rc = processAttListDecl( pRec, pvParent))) - { - goto Exit; - } - } - else if( uiChars >= 8 && - m_uChars[ 0] == F_XML_UNI_LT && - m_uChars[ 1] == F_XML_UNI_BANG && - m_uChars[ 2] == F_XML_UNI_E && - m_uChars[ 3] == F_XML_UNI_N && - m_uChars[ 4] == F_XML_UNI_T && - m_uChars[ 5] == F_XML_UNI_I && - m_uChars[ 6] == F_XML_UNI_T && - m_uChars[ 7] == F_XML_UNI_Y) - { - if( RC_BAD( rc = processEntityDecl( pRec, pvParent))) - { - goto Exit; - } - } - else if( uiChars >= 4 && - m_uChars[ 0] == F_XML_UNI_LT && - m_uChars[ 1] == F_XML_UNI_BANG && - m_uChars[ 2] == F_XML_UNI_HYPHEN && - m_uChars[ 3] == F_XML_UNI_HYPHEN) - { - if( RC_BAD( rc = processComment( pRec, pvParent))) - { - goto Exit; - } - } - else if( uiChars >= 2 && - m_uChars[ 0] == F_XML_UNI_LT && - m_uChars[ 1] == F_XML_UNI_QUEST) - { - if( RC_BAD( rc = processPI( pRec, pvParent))) - { - goto Exit; - } - } - else - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - -Exit: - - return( rc); -} - -/**************************************************************************** -Desc: Processes an XML element declaration -****************************************************************************/ -RCODE F_XMLImport::processElementDecl( - FlmRecord * pRec, - void * pvParent) -{ - FLMUNICODE uChar; - FLMUINT uiChars; - void * pvField = NULL; - RCODE rc = FERR_OK; - - if( pvParent) - { - if( RC_BAD( rc = pRec->insertLast( - pRec->getLevel( pvParent) + 1, - F_XML_ELEMENTDECL_TAG, FLM_TEXT_TYPE, &pvField))) - { - goto Exit; - } - } - - uiChars = 9; - if( RC_BAD( rc = getChars( m_uChars, &uiChars))) - { - goto Exit; - } - - if( m_uChars[ 0] != F_XML_UNI_LT || - m_uChars[ 1] != F_XML_UNI_BANG || - m_uChars[ 2] != F_XML_UNI_E || - m_uChars[ 3] != F_XML_UNI_L || - m_uChars[ 4] != F_XML_UNI_E || - m_uChars[ 5] != F_XML_UNI_M || - m_uChars[ 6] != F_XML_UNI_E || - m_uChars[ 7] != F_XML_UNI_N || - m_uChars[ 8] != F_XML_UNI_T) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - - if( RC_BAD( rc = skipWhitespace( pvField))) - { - goto Exit; - } - - uiChars = F_XML_MAX_CHARS; - if( RC_BAD( rc = getName( m_uChars, &uiChars))) - { - goto Exit; - } - - if( pvField) - { - if( RC_BAD( rc = pRec->setUnicode( pvField, m_uChars))) - { - goto Exit; - } - } - - if( RC_BAD( rc = skipWhitespace( pvField))) - { - goto Exit; - } - - if( RC_BAD( rc = processContentSpec( pRec, pvField))) - { - goto Exit; - } - - if( RC_BAD( rc = skipWhitespace( pvField))) - { - goto Exit; - } - - if( RC_BAD( rc = getChar( &uChar))) - { - goto Exit; - } - - if( uChar != F_XML_UNI_GT) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - -Exit: - - return( rc); -} - -/**************************************************************************** -Desc: Processes an attribute list declaration -****************************************************************************/ -RCODE F_XMLImport::processAttListDecl( - FlmRecord * pRec, - void * pvParent) -{ - FLMUNICODE uChar; - FLMUINT uiChars; - FLMUINT uiAttDefCount = 0; - void * pvField = NULL; - RCODE rc = FERR_OK; - - if( pvParent) - { - if( RC_BAD( rc = pRec->insertLast( - pRec->getLevel( pvParent) + 1, - F_XML_ATTLISTDECL_TAG, FLM_TEXT_TYPE, &pvField))) - { - goto Exit; - } - } - - uiChars = 9; - if( RC_BAD( rc = getChars( m_uChars, &uiChars))) - { - goto Exit; - } - - if( m_uChars[ 0] != F_XML_UNI_LT || - m_uChars[ 1] != F_XML_UNI_BANG || - m_uChars[ 2] != F_XML_UNI_A || - m_uChars[ 3] != F_XML_UNI_T || - m_uChars[ 4] != F_XML_UNI_T || - m_uChars[ 5] != F_XML_UNI_L || - m_uChars[ 6] != F_XML_UNI_I || - m_uChars[ 7] != F_XML_UNI_S || - m_uChars[ 8] != F_XML_UNI_T) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - - if( RC_BAD( rc = skipWhitespace( pvField, TRUE))) - { - goto Exit; - } - - uiChars = F_XML_MAX_CHARS; - if( RC_BAD( rc = getName( m_uChars, &uiChars))) - { - goto Exit; - } - - if( RC_BAD( rc = pRec->setUnicode( pvField, m_uChars))) - { - goto Exit; - } - - for( ;;) - { - if( RC_BAD( rc = skipWhitespace( pvField))) - { - goto Exit; - } - - if( RC_BAD( rc = peekChar( &uChar))) - { - goto Exit; - } - - if( uChar == F_XML_UNI_GT) - { - if( !uiAttDefCount) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - break; - } - - if( RC_BAD( rc = processAttDef( pRec, pvField))) - { - goto Exit; - } - - uiAttDefCount++; - } - - if( RC_BAD( rc = getChar( &uChar))) - { - goto Exit; - } - - if( uChar != F_XML_UNI_GT) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - -Exit: - - return( rc); -} - -/**************************************************************************** -Desc: Processes and entity declaration -****************************************************************************/ -RCODE F_XMLImport::processEntityDecl( - FlmRecord * pRec, - void * pvParent) -{ - FLMUNICODE uChar; - FLMUINT uiChars; - FLMBOOL bTmp; - FLMBOOL bGEDecl = FALSE; - void * pvEntityField = NULL; - void * pvField = NULL; - RCODE rc = FERR_OK; - - if( pvParent) - { - if( RC_BAD( rc = pRec->insertLast( - pRec->getLevel( pvParent) + 1, - F_XML_ENTITYDECL_TAG, FLM_TEXT_TYPE, &pvEntityField))) - { - goto Exit; - } - } - - uiChars = 8; - if( RC_BAD( rc = getChars( m_uChars, &uiChars))) - { - goto Exit; - } - - if( m_uChars[ 0] != F_XML_UNI_LT || - m_uChars[ 1] != F_XML_UNI_BANG || - m_uChars[ 2] != F_XML_UNI_E || - m_uChars[ 3] != F_XML_UNI_N || - m_uChars[ 4] != F_XML_UNI_T || - m_uChars[ 5] != F_XML_UNI_I || - m_uChars[ 6] != F_XML_UNI_T || - m_uChars[ 7] != F_XML_UNI_Y) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - - if( RC_BAD( rc = skipWhitespace( pvEntityField, TRUE))) - { - goto Exit; - } - - if( RC_BAD( rc = peekChar( &uChar))) - { - goto Exit; - } - - if( uChar == F_XML_UNI_PERCENT) - { - if( RC_BAD( rc = getChar( &uChar))) - { - goto Exit; - } - - if( RC_BAD( rc = skipWhitespace( pvEntityField, TRUE))) - { - goto Exit; - } - } - else - { - bGEDecl = TRUE; - } - - uiChars = F_XML_MAX_CHARS; - if( RC_BAD( rc = getName( m_uChars, &uiChars))) - { - goto Exit; - } - - if( pvEntityField) - { - if( RC_BAD( rc = pRec->setUnicode( pvEntityField, m_uChars))) - { - goto Exit; - } - } - - if( RC_BAD( rc = skipWhitespace( pvEntityField, TRUE))) - { - goto Exit; - } - - if( RC_BAD( rc = peekChar( &uChar))) - { - goto Exit; - } - - if( isQuoteChar( uChar)) - { - if( RC_BAD( rc = processEntityValue( pRec, pvEntityField))) - { - goto Exit; - } - } - else - { - if( RC_BAD( rc = processID( pRec, pvEntityField, &bTmp))) - { - goto Exit; - } - - if( bTmp) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - - if( RC_BAD( rc = skipWhitespace( pvEntityField))) - { - goto Exit; - } - - if( RC_BAD( rc = peekChar( &uChar))) - { - goto Exit; - } - - if( uChar != F_XML_UNI_GT) - { - if( bGEDecl) - { - uiChars = 6; - if( RC_BAD( rc = getChars( m_uChars, &uiChars))) - { - goto Exit; - } - - if( m_uChars[ 0] != F_XML_UNI_N || - m_uChars[ 1] != F_XML_UNI_D || - m_uChars[ 2] != F_XML_UNI_A || - m_uChars[ 3] != F_XML_UNI_T || - m_uChars[ 4] != F_XML_UNI_A || - !isWhitespace( m_uChars[ 5])) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - - if( RC_BAD( rc = skipWhitespace( pvEntityField))) - { - goto Exit; - } - - uiChars = F_XML_MAX_CHARS; - if( RC_BAD( rc = getName( m_uChars, &uiChars))) - { - goto Exit; - } - - if( pvEntityField) - { - if( RC_BAD( rc = pRec->insertLast( - pRec->getLevel( pvEntityField) + 1, - F_XML_NDATADECL_TAG, FLM_TEXT_TYPE, &pvField))) - { - goto Exit; - } - - if( RC_BAD( rc = pRec->setUnicode( pvField, m_uChars))) - { - goto Exit; - } - } - - if( RC_BAD( rc = skipWhitespace( pvEntityField))) - { - goto Exit; - } - } - else - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - } - } - - if( RC_BAD( rc = getChar( &uChar))) - { - goto Exit; - } - - if( uChar != F_XML_UNI_GT) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - -Exit: - - return( rc); -} - -/**************************************************************************** -Desc: Processes an XML ID -****************************************************************************/ -RCODE F_XMLImport::processID( - FlmRecord * pRec, - void * pvParent, - FLMBOOL * pbPublicId) -{ - FLMUNICODE uChar; - FLMUINT uiChars; - void * pvExtIdField = NULL; - void * pvLiteralField = NULL; - RCODE rc = FERR_OK; - - *pbPublicId = FALSE; - - uiChars = 7; - if( RC_BAD( rc = getChars( m_uChars, &uiChars))) - { - goto Exit; - } - - if( m_uChars[ 0] == F_XML_UNI_S && - m_uChars[ 1] == F_XML_UNI_Y && - m_uChars[ 2] == F_XML_UNI_S && - m_uChars[ 3] == F_XML_UNI_T && - m_uChars[ 4] == F_XML_UNI_E && - m_uChars[ 5] == F_XML_UNI_M && - isWhitespace( m_uChars[ 6])) - { - if( RC_BAD( rc = skipWhitespace( NULL))) - { - goto Exit; - } - - uiChars = F_XML_MAX_CHARS; - if( RC_BAD( rc = getSystemLiteral( m_uChars, &uiChars))) - { - goto Exit; - } - - if( pvParent) - { - if( RC_BAD( rc = pRec->insertLast( - pRec->getLevel( pvParent) + 1, - F_XML_EXTERNALID_TAG, FLM_TEXT_TYPE, &pvExtIdField))) - { - goto Exit; - } - - if( RC_BAD( rc = pRec->insertLast( - pRec->getLevel( pvExtIdField) + 1, - F_XML_SYSLITERAL_TAG, FLM_TEXT_TYPE, &pvLiteralField))) - { - goto Exit; - } - - if( RC_BAD( rc = pRec->setUnicode( pvLiteralField, m_uChars))) - { - goto Exit; - } - } - } - else if( m_uChars[ 0] == F_XML_UNI_P && - m_uChars[ 1] == F_XML_UNI_U && - m_uChars[ 2] == F_XML_UNI_B && - m_uChars[ 3] == F_XML_UNI_L && - m_uChars[ 4] == F_XML_UNI_I && - m_uChars[ 5] == F_XML_UNI_C && - isWhitespace( m_uChars[ 6])) - { - if( RC_BAD( rc = skipWhitespace( NULL))) - { - goto Exit; - } - - uiChars = F_XML_MAX_CHARS; - if( RC_BAD( rc = getPubidLiteral( m_uChars, &uiChars))) - { - goto Exit; - } - - if( RC_BAD( rc = skipWhitespace( NULL, TRUE))) - { - if( rc != FERR_SYNTAX) - { - goto Exit; - } - - if( RC_BAD( rc = peekChar( &uChar))) - { - goto Exit; - } - - if( uChar == F_XML_UNI_GT) - { - *pbPublicId = TRUE; - - if( pvParent) - { - if( RC_BAD( rc = pRec->insertLast( - pRec->getLevel( pvParent) + 1, - F_XML_PUBIDLITERAL_TAG, FLM_TEXT_TYPE, &pvLiteralField))) - { - goto Exit; - } - - if( RC_BAD( rc = pRec->setUnicode( pvLiteralField, m_uChars))) - { - goto Exit; - } - } - } - else - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - goto Exit; - } - - if( pvParent) - { - if( RC_BAD( rc = pRec->insertLast( - pRec->getLevel( pvParent) + 1, - F_XML_EXTERNALID_TAG, FLM_TEXT_TYPE, &pvExtIdField))) - { - goto Exit; - } - - if( RC_BAD( rc = pRec->insertLast( - pRec->getLevel( pvExtIdField) + 1, - F_XML_PUBIDLITERAL_TAG, FLM_TEXT_TYPE, &pvLiteralField))) - { - goto Exit; - } - - if( RC_BAD( rc = pRec->setUnicode( pvLiteralField, m_uChars))) - { - goto Exit; - } - } - - uiChars = F_XML_MAX_CHARS; - if( RC_BAD( rc = getSystemLiteral( m_uChars, &uiChars))) - { - goto Exit; - } - - if( pvExtIdField) - { - if( RC_BAD( rc = pRec->insertLast( - pRec->getLevel( pvExtIdField) + 1, - F_XML_SYSLITERAL_TAG, FLM_TEXT_TYPE, &pvLiteralField))) - { - goto Exit; - } - - if( RC_BAD( rc = pRec->setUnicode( pvLiteralField, m_uChars))) - { - goto Exit; - } - } - } - else - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - -Exit: - - return( rc); -} - -/**************************************************************************** -Desc: Processes a notation declaration -****************************************************************************/ -RCODE F_XMLImport::processNotationDecl( - FlmRecord * pRec, - void * pvParent) -{ - FLMUNICODE uChar; - FLMUINT uiChars; - FLMBOOL bTmp; - void * pvField = NULL; - RCODE rc = FERR_OK; - - if( pvParent) - { - if( RC_BAD( rc = pRec->insertLast( - pRec->getLevel( pvParent) + 1, - F_XML_NOTATIONDECL_TAG, FLM_TEXT_TYPE, &pvField))) - { - goto Exit; - } - } - - uiChars = 10; - if( RC_BAD( rc = getChars( m_uChars, &uiChars))) - { - goto Exit; - } - - if( m_uChars[ 0] != F_XML_UNI_LT || - m_uChars[ 1] != F_XML_UNI_BANG || - m_uChars[ 2] != F_XML_UNI_N || - m_uChars[ 3] != F_XML_UNI_O || - m_uChars[ 4] != F_XML_UNI_T || - m_uChars[ 5] != F_XML_UNI_A || - m_uChars[ 6] != F_XML_UNI_T || - m_uChars[ 7] != F_XML_UNI_I || - m_uChars[ 8] != F_XML_UNI_O || - m_uChars[ 9] != F_XML_UNI_N) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - - if( RC_BAD( rc = skipWhitespace( pvField, TRUE))) - { - goto Exit; - } - - if( RC_BAD( rc = peekChar( &uChar))) - { - goto Exit; - } - - uiChars = F_XML_MAX_CHARS; - if( RC_BAD( rc = getName( m_uChars, &uiChars))) - { - goto Exit; - } - - if( pvField) - { - if( RC_BAD( rc = pRec->setUnicode( pvField, m_uChars))) - { - goto Exit; - } - } - - if( RC_BAD( rc = skipWhitespace( pvField, TRUE))) - { - goto Exit; - } - - if( RC_BAD( rc = processID( pRec, pvField, &bTmp))) - { - goto Exit; - } - - if( RC_BAD( rc = skipWhitespace( pvField))) - { - goto Exit; - } - - if( RC_BAD( rc = getChar( &uChar))) - { - goto Exit; - } - - if( uChar != F_XML_UNI_GT) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - -Exit: - - return( rc); -} - -/**************************************************************************** -Desc: Processes and attribute definition -****************************************************************************/ -RCODE F_XMLImport::processAttDef( - FlmRecord * pRec, - void * pvParent) -{ - FLMUINT uiChars; - void * pvField = NULL; - RCODE rc = FERR_OK; - - if( pvParent) - { - if( RC_BAD( rc = pRec->insertLast( - pRec->getLevel( pvParent) + 1, - F_XML_ATTRDEF_TAG, FLM_TEXT_TYPE, &pvField))) - { - goto Exit; - } - } - - uiChars = F_XML_MAX_CHARS; - if( RC_BAD( rc = getName( m_uChars, &uiChars))) - { - goto Exit; - } - - if( pvField) - { - if( RC_BAD( rc = pRec->setUnicode( pvField, m_uChars))) - { - goto Exit; - } - } - - if( RC_BAD( rc = skipWhitespace( pvField, TRUE))) - { - goto Exit; - } - - if( RC_BAD( rc = processAttType( pRec, pvField))) - { - goto Exit; - } - - if( RC_BAD( rc = skipWhitespace( pvField, TRUE))) - { - goto Exit; - } - - if( RC_BAD( rc = processDefaultDecl( pRec, pvField))) - { - goto Exit; - } - -Exit: - - return( rc); -} - -/**************************************************************************** -Desc: Processes an attribute type -****************************************************************************/ -RCODE F_XMLImport::processAttType( - FlmRecord * pRec, - void * pvParent) -{ - FLMUNICODE uChar; - FLMUINT uiChars; - void * pvType = NULL; - void * pvToken = NULL; - RCODE rc = FERR_OK; - - if( pvParent) - { - if( RC_BAD( rc = pRec->insertLast( - pRec->getLevel( pvParent) + 1, - F_XML_ATTTYPE_TAG, FLM_TEXT_TYPE, &pvType))) - { - goto Exit; - } - } - - if( RC_BAD( rc = getChar( &m_uChars[ 0]))) - { - goto Exit; - } - - if( m_uChars[ 0] == F_XML_UNI_C) - { - uiChars = 4; - if( RC_BAD( rc = getChars( &m_uChars[ 1], &uiChars))) - { - goto Exit; - } - - if( m_uChars[ 1] != F_XML_UNI_D || - m_uChars[ 2] != F_XML_UNI_A || - m_uChars[ 3] != F_XML_UNI_T || - m_uChars[ 4] != F_XML_UNI_A) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - - if( pvType) - { - m_uChars[ 5] = 0; - if( RC_BAD( rc = pRec->setUnicode( pvType, m_uChars))) - { - goto Exit; - } - } - } - else if( m_uChars[ 0] == F_XML_UNI_I) - { - uiChars = 2; - if( RC_BAD( rc = getChars( &m_uChars[ 1], &uiChars))) - { - goto Exit; - } - - if( m_uChars[ 1] == F_XML_UNI_D && - isWhitespace( m_uChars[ 2])) - { - if( pvType) - { - m_uChars[ 2] = 0; - if( RC_BAD( rc = pRec->setUnicode( pvType, m_uChars))) - { - goto Exit; - } - } - } - else if( m_uChars[ 1] == F_XML_UNI_D && - m_uChars[ 2] == F_XML_UNI_R) - { - uiChars = 3; - if( RC_BAD( rc = getChars( &m_uChars[ 3], &uiChars))) - { - goto Exit; - } - - if( m_uChars[ 3] == F_XML_UNI_E && - m_uChars[ 4] == F_XML_UNI_F) - { - if( isWhitespace( m_uChars[ 5])) - { - if( pvType) - { - m_uChars[ 5] = 0; - if( RC_BAD( rc = pRec->setUnicode( pvType, m_uChars))) - { - goto Exit; - } - } - } - else if( m_uChars[ 5] == F_XML_UNI_S) - { - if( RC_BAD( rc = peekChar( &uChar))) - { - goto Exit; - } - - if( isWhitespace( uChar)) - { - if( pvType) - { - m_uChars[ 6] = 0; - if( RC_BAD( rc = pRec->setUnicode( pvType, m_uChars))) - { - goto Exit; - } - } - } - else - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - } - else - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - } - } - else - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - } - else if( m_uChars[ 0] == F_XML_UNI_E) - { - uiChars = 6; - if( RC_BAD( rc = getChars( &m_uChars[ 1], &uiChars))) - { - goto Exit; - } - - if( m_uChars[ 1] == F_XML_UNI_N && - m_uChars[ 2] == F_XML_UNI_T && - m_uChars[ 3] == F_XML_UNI_I && - m_uChars[ 4] == F_XML_UNI_T) - { - if( m_uChars[ 5] == F_XML_UNI_Y && - isWhitespace( m_uChars[ 6])) - { - if( pvType) - { - m_uChars[ 6] = 0; - if( RC_BAD( rc = pRec->setUnicode( pvType, m_uChars))) - { - goto Exit; - } - } - } - else if( m_uChars[ 5] == F_XML_UNI_I && - m_uChars[ 6] == F_XML_UNI_E) - { - if( RC_BAD( rc = getChar( &m_uChars[ 7]))) - { - goto Exit; - } - - if( m_uChars[ 7] != F_XML_UNI_S) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - - if( pvType) - { - m_uChars[ 8] = 0; - if( RC_BAD( rc = pRec->setUnicode( pvType, m_uChars))) - { - goto Exit; - } - } - - if( RC_BAD( rc = peekChar( &uChar))) - { - goto Exit; - } - - if( !isWhitespace( uChar)) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - } - else - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - } - else - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - } - else if( m_uChars[ 0] == F_XML_UNI_N) - { - uiChars = 7; - if( RC_BAD( rc = getChars( &m_uChars[ 1], &uiChars))) - { - goto Exit; - } - - if( m_uChars[ 1] == F_XML_UNI_M && - m_uChars[ 2] == F_XML_UNI_T && - m_uChars[ 3] == F_XML_UNI_O && - m_uChars[ 4] == F_XML_UNI_K && - m_uChars[ 5] == F_XML_UNI_E && - m_uChars[ 6] == F_XML_UNI_N) - { - if( isWhitespace( m_uChars[ 7])) - { - if( pvType) - { - m_uChars[ 7] = 0; - if( RC_BAD( rc = pRec->setUnicode( pvType, m_uChars))) - { - goto Exit; - } - } - } - else if( m_uChars[ 7] == F_XML_UNI_S) - { - if( RC_BAD( rc = peekChar( &uChar))) - { - goto Exit; - } - - if( isWhitespace( uChar)) - { - if( pvType) - { - m_uChars[ 8] = 0; - if( RC_BAD( rc = pRec->setUnicode( pvType, m_uChars))) - { - goto Exit; - } - } - } - else - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - } - else - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - } - else if( m_uChars[ 1] == F_XML_UNI_O && - m_uChars[ 2] == F_XML_UNI_T && - m_uChars[ 3] == F_XML_UNI_A && - m_uChars[ 4] == F_XML_UNI_T && - m_uChars[ 5] == F_XML_UNI_I && - m_uChars[ 6] == F_XML_UNI_O && - m_uChars[ 7] == F_XML_UNI_N) - { - if( RC_BAD( rc = skipWhitespace( NULL, TRUE))) - { - goto Exit; - } - - if( pvType) - { - m_uChars[ 8] = 0; - if( RC_BAD( rc = pRec->setUnicode( pvType, m_uChars))) - { - goto Exit; - } - } - - if( RC_BAD( rc = getChar( &uChar))) - { - goto Exit; - } - - if( uChar != F_XML_UNI_LPAREN) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - - for( ;;) - { - if( RC_BAD( rc = skipWhitespace( NULL))) - { - goto Exit; - } - - uiChars = F_XML_MAX_CHARS; - if( RC_BAD( rc = getName( m_uChars, &uiChars))) - { - goto Exit; - } - - if( pvType) - { - if( RC_BAD( rc = pRec->insertLast( - pRec->getLevel( pvType) + 1, - F_XML_ATTTYPE_TAG, FLM_TEXT_TYPE, &pvToken))) - { - goto Exit; - } - - if( RC_BAD( rc = pRec->setUnicode( pvToken, m_uChars))) - { - goto Exit; - } - } - - if( RC_BAD( rc = skipWhitespace( NULL))) - { - goto Exit; - } - - if( RC_BAD( rc = getChar( &uChar))) - { - goto Exit; - } - - if( uChar == F_XML_UNI_RPAREN) - { - break; - } - else if( uChar != F_XML_UNI_PIPE) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - } - } - else - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - } - else if( m_uChars[ 0] == F_XML_UNI_LPAREN) - { - if( pvType) - { - if( RC_BAD( rc = pRec->setNative( pvType, "ENUM"))) - { - goto Exit; - } - } - - for( ;;) - { - if( RC_BAD( rc = skipWhitespace( NULL))) - { - goto Exit; - } - - uiChars = F_XML_MAX_CHARS; - if( RC_BAD( rc = getNmtoken( m_uChars, &uiChars))) - { - goto Exit; - } - - if( !uiChars) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - - if( pvType) - { - if( RC_BAD( rc = pRec->insertLast( - pRec->getLevel( pvType) + 1, - F_XML_ATTTYPE_TAG, FLM_TEXT_TYPE, &pvToken))) - { - goto Exit; - } - - if( RC_BAD( rc = pRec->setUnicode( pvToken, m_uChars))) - { - goto Exit; - } - } - - if( RC_BAD( rc = skipWhitespace( NULL))) - { - goto Exit; - } - - if( RC_BAD( rc = getChar( &uChar))) - { - goto Exit; - } - - if( uChar == F_XML_UNI_RPAREN) - { - break; - } - else if( uChar != F_XML_UNI_PIPE) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - } - } - else - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - -Exit: - - return( rc); -} - -/**************************************************************************** -Desc: Processes a default declaration -****************************************************************************/ -RCODE F_XMLImport::processDefaultDecl( - FlmRecord * pRec, - void * pvParent) -{ - FLMUNICODE uChar; - FLMUINT uiChars; - FLMBOOL bAttValOk = TRUE; - FLMBOOL bShouldHaveVal = TRUE; - RCODE rc = FERR_OK; - - if( RC_BAD( rc = getChar( &uChar))) - { - goto Exit; - } - - if( uChar == F_XML_UNI_POUND) - { - uiChars = 6; - if( RC_BAD( rc = getChars( m_uChars, &uiChars))) - { - goto Exit; - } - - if( m_uChars[ 0] == F_XML_UNI_F && - m_uChars[ 1] == F_XML_UNI_I && - m_uChars[ 2] == F_XML_UNI_X && - m_uChars[ 3] == F_XML_UNI_E && - m_uChars[ 4] == F_XML_UNI_D && - isWhitespace( m_uChars[ 5])) - { - } - else if( m_uChars[ 0] == F_XML_UNI_I && - m_uChars[ 1] == F_XML_UNI_M && - m_uChars[ 2] == F_XML_UNI_P && - m_uChars[ 3] == F_XML_UNI_L && - m_uChars[ 4] == F_XML_UNI_I && - m_uChars[ 5] == F_XML_UNI_E) - { - if( RC_BAD( rc = getChar( &uChar))) - { - goto Exit; - } - - if( uChar != F_XML_UNI_D) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - - bShouldHaveVal = FALSE; - } - else if( m_uChars[ 0] == F_XML_UNI_R && - m_uChars[ 1] == F_XML_UNI_E && - m_uChars[ 2] == F_XML_UNI_Q && - m_uChars[ 3] == F_XML_UNI_U && - m_uChars[ 4] == F_XML_UNI_I && - m_uChars[ 5] == F_XML_UNI_R) - { - uiChars = 2; - if( RC_BAD( rc = getChars( m_uChars, &uiChars))) - { - goto Exit; - } - - if( m_uChars[ 0] != F_XML_UNI_E || - m_uChars[ 1] != F_XML_UNI_D) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - - bShouldHaveVal = FALSE; - } - else - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - } - - if( !bShouldHaveVal) - { - goto Exit; - } - - if( uChar == F_XML_UNI_QUOTE || - uChar == F_XML_UNI_APOS) - { - if( !bAttValOk) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - - if( RC_BAD( rc = ungetChar( uChar))) - { - goto Exit; - } - - if( RC_BAD( rc = processAttValue( pRec, pvParent))) - { - goto Exit; - } - } - else - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - -Exit: - - return( rc); -} - -/**************************************************************************** -Desc: Processes a content specification -****************************************************************************/ -RCODE F_XMLImport::processContentSpec( - FlmRecord * pRec, - void * pvParent) -{ - FLMUINT uiChars; - void * pvField = NULL; - FLMUNICODE uChar; - RCODE rc = FERR_OK; - - if( pvParent) - { - if( RC_BAD( rc = pRec->insertLast( - pRec->getLevel( pvParent) + 1, - F_XML_CONTENTSPEC_TAG, FLM_TEXT_TYPE, &pvField))) - { - goto Exit; - } - } - - if( RC_BAD( rc = getChar( &m_uChars[ 0]))) - { - goto Exit; - } - - if( m_uChars[ 0] == F_XML_UNI_E) - { - uiChars = 4; - if( RC_BAD( rc = getChars( &m_uChars[ 1], &uiChars))) - { - goto Exit; - } - - if( m_uChars[ 1] != F_XML_UNI_M || - m_uChars[ 2] != F_XML_UNI_P || - m_uChars[ 3] != F_XML_UNI_T || - m_uChars[ 4] != F_XML_UNI_Y) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - - if( pvField) - { - m_uChars[ 5] = 0; - if( RC_BAD( rc = pRec->setUnicode( pvField, m_uChars))) - { - goto Exit; - } - } - } - else if( m_uChars[ 0] == F_XML_UNI_A) - { - uiChars = 2; - if( RC_BAD( rc = getChars( &m_uChars[ 1], &uiChars))) - { - goto Exit; - } - - if( m_uChars[ 1] != F_XML_UNI_N || - m_uChars[ 2] != F_XML_UNI_Y) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - - if( pvField) - { - m_uChars[ 3] = 0; - if( RC_BAD( rc = pRec->setUnicode( pvField, m_uChars))) - { - goto Exit; - } - } - } - else if( m_uChars[ 0] == F_XML_UNI_LPAREN) - { - if( RC_BAD( rc = skipWhitespace( NULL))) - { - goto Exit; - } - - if( RC_BAD( rc = peekChar( &uChar))) - { - goto Exit; - } - - if( RC_BAD( rc = ungetChar( F_XML_UNI_LPAREN))) - { - goto Exit; - } - - if( uChar == F_XML_UNI_POUND) - { - if( RC_BAD( rc = processMixedContent( pRec, pvParent))) - { - goto Exit; - } - } - else - { - if( RC_BAD( rc = processChildContent( pRec, pvParent))) - { - goto Exit; - } - } - } - -Exit: - - return( rc); -} - -/**************************************************************************** -Desc: Processes mixed content -****************************************************************************/ -RCODE F_XMLImport::processMixedContent( - FlmRecord * pRec, - void * pvParent) -{ - FLMUNICODE uChar; - FLMUINT uiChars; - void * pvTop = NULL; - void * pvName = NULL; - RCODE rc = FERR_OK; - - if( pvParent) - { - if( RC_BAD( rc = pRec->insertLast( - pRec->getLevel( pvParent) + 1, - F_XML_MIXED_TAG, FLM_TEXT_TYPE, &pvTop))) - { - goto Exit; - } - } - - if( RC_BAD( rc = getChar( &uChar))) - { - goto Exit; - } - - if( uChar != F_XML_UNI_LPAREN) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - - if( RC_BAD( rc = skipWhitespace( pvTop))) - { - goto Exit; - } - - uiChars = 7; - if( RC_BAD( rc = getChars( m_uChars, &uiChars))) - { - goto Exit; - } - - if( m_uChars[ 0] != F_XML_UNI_POUND || - m_uChars[ 1] != F_XML_UNI_P || - m_uChars[ 2] != F_XML_UNI_C || - m_uChars[ 3] != F_XML_UNI_D || - m_uChars[ 4] != F_XML_UNI_A || - m_uChars[ 5] != F_XML_UNI_T || - m_uChars[ 6] != F_XML_UNI_A) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - - for( ;;) - { - if( RC_BAD( rc = skipWhitespace( pvTop))) - { - goto Exit; - } - - if( RC_BAD( rc = getChar( &uChar))) - { - goto Exit; - } - - if( uChar == F_XML_UNI_RPAREN) - { - break; - } - else if( uChar == F_XML_UNI_PIPE) - { - if( RC_BAD( rc = skipWhitespace( NULL))) - { - goto Exit; - } - - uiChars = F_XML_MAX_CHARS; - if( RC_BAD( rc = getName( m_uChars, &uiChars))) - { - goto Exit; - } - - if( pvTop) - { - if( RC_BAD( rc = pRec->insertLast( - pRec->getLevel( pvTop) + 1, - F_XML_NAME_TAG, FLM_TEXT_TYPE, &pvName))) - { - goto Exit; - } - - if( RC_BAD( rc = pRec->setUnicode( pvName, m_uChars))) - { - goto Exit; - } - } - } - else - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - } - -Exit: - - return( rc); -} - -/**************************************************************************** -Desc: Processes child content -****************************************************************************/ -RCODE F_XMLImport::processChildContent( - FlmRecord * pRec, - void * pvParent) -{ - FLMUNICODE uChar; - FLMUINT uiChars; - FLMUINT uiItemCount = 0; - FLMUINT uiDelimCount = 0; - FLMBOOL bChoice = FALSE; - FLMBOOL bSeq = FALSE; - void * pvTop = NULL; - void * pvName = NULL; - void * pvOccurs = NULL; - RCODE rc = FERR_OK; - - if( pvParent) - { - if( RC_BAD( rc = pRec->insertLast( - pRec->getLevel( pvParent) + 1, - F_XML_UNKNOWN_TAG, FLM_TEXT_TYPE, &pvTop))) - { - goto Exit; - } - } - - if( RC_BAD( rc = getChar( &uChar))) - { - goto Exit; - } - - if( uChar != F_XML_UNI_LPAREN) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - - for( ;;) - { - if( RC_BAD( rc = skipWhitespace( NULL))) - { - goto Exit; - } - - if( RC_BAD( rc = getChar( &uChar))) - { - goto Exit; - } - - if( uChar == F_XML_UNI_LPAREN) - { - if( RC_BAD( rc = ungetChar( uChar))) - { - goto Exit; - } - - if( RC_BAD( rc = processChildContent( pRec, pvTop))) - { - goto Exit; - } - - uiItemCount++; - } - else if( uChar == F_XML_UNI_RPAREN) - { - if( !uiItemCount || (uiItemCount - 1) != uiDelimCount) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - - break; - } - else if( uChar == F_XML_UNI_PIPE) - { - if( bSeq) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - bChoice = TRUE; - uiDelimCount++; - } - else if( uChar == F_XML_UNI_COMMA) - { - if( bChoice) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - bSeq = TRUE; - uiDelimCount++; - } - else - { - if( RC_BAD( rc = ungetChar( uChar))) - { - goto Exit; - } - - uiChars = F_XML_MAX_CHARS; - if( RC_BAD( rc = getName( m_uChars, &uiChars))) - { - goto Exit; - } - uiItemCount++; - - if( pvTop) - { - if( RC_BAD( rc = pRec->insertLast( - pRec->getLevel( pvTop) + 1, - F_XML_NAME_TAG, FLM_TEXT_TYPE, &pvName))) - { - goto Exit; - } - - if( RC_BAD( rc = pRec->setUnicode( pvName, m_uChars))) - { - goto Exit; - } - } - - if( RC_BAD( rc = peekChar( &uChar))) - { - goto Exit; - } - - if( uChar == F_XML_UNI_QUEST || - uChar == F_XML_UNI_ASTERISK || - uChar == F_XML_UNI_PLUS) - { - if( RC_BAD( rc = getChar( &uChar))) - { - goto Exit; - } - - if( pvName) - { - if( RC_BAD( rc = pRec->insertLast( - pRec->getLevel( pvName) + 1, - F_XML_OCCURS_TAG, FLM_TEXT_TYPE, &pvOccurs))) - { - goto Exit; - } - - m_uChars[ 0] = uChar; - m_uChars[ 1] = 0; - if( RC_BAD( rc = pRec->setUnicode( pvOccurs, m_uChars))) - { - goto Exit; - } - } - } - } - } - - if( RC_BAD( rc = peekChar( &uChar))) - { - goto Exit; - } - - if( uChar == F_XML_UNI_QUEST || - uChar == F_XML_UNI_ASTERISK || - uChar == F_XML_UNI_PLUS) - { - if( RC_BAD( rc = getChar( &uChar))) - { - goto Exit; - } - - if( pvTop) - { - if( RC_BAD( rc = pRec->insertLast( - pRec->getLevel( pvTop) + 1, - F_XML_OCCURS_TAG, FLM_TEXT_TYPE, &pvOccurs))) - { - goto Exit; - } - - m_uChars[ 0] = uChar; - m_uChars[ 1] = 0; - if( RC_BAD( rc = pRec->setUnicode( pvOccurs, m_uChars))) - { - goto Exit; - } - } - } - - if( pvTop) - { - pRec->setFieldID( pvTop, - bChoice ? F_XML_CHOICE_TAG : F_XML_SEQ_TAG); - } - -Exit: - - return( rc); -} - -/**************************************************************************** -Desc: Processes a misc. declaration -****************************************************************************/ -RCODE F_XMLImport::processMisc( - FlmRecord * pRec, - void * pvParent) -{ - FLMUINT uiChars; - RCODE rc = FERR_OK; - - for( ;;) - { - if( RC_BAD( rc = skipWhitespace( NULL))) - { - if( rc == FERR_IO_END_OF_FILE || rc == FERR_EOF_HIT) - { - rc = FERR_OK; - } - goto Exit; - } - - uiChars = 4; - rc = getChars( m_uChars, &uiChars); - if( RC_BAD( rc) && rc != FERR_EOF_HIT) - { - goto Exit; - } - - if( RC_BAD( rc = ungetChars( m_uChars, uiChars))) - { - goto Exit; - } - - if( uiChars >= 4 && - m_uChars[ 0] == F_XML_UNI_LT && - m_uChars[ 1] == F_XML_UNI_BANG && - m_uChars[ 2] == F_XML_UNI_HYPHEN && - m_uChars[ 3] == F_XML_UNI_HYPHEN) - { - if( RC_BAD( rc = processComment( pRec, pvParent))) - { - goto Exit; - } - } - else if( uiChars >= 3 && - m_uChars[ 0] == F_XML_UNI_LT && - m_uChars[ 1] == F_XML_UNI_BANG && - m_uChars[ 2] == F_XML_UNI_QUEST) - { - if( RC_BAD( rc = processPI( pRec, pvParent))) - { - goto Exit; - } - } - else - { - break; - } - } - -Exit: - - return( rc); -} - -/**************************************************************************** -Desc: Processes a processing instruction -****************************************************************************/ -RCODE F_XMLImport::processPI( - FlmRecord * pRec, - void * pvParent) -{ - FLMUNICODE uChar; - FLMUINT uiChars; - RCODE rc = FERR_OK; - - F_UNREFERENCED_PARM( pRec); - F_UNREFERENCED_PARM( pvParent); - - if( RC_BAD( rc = getChar( &uChar))) - { - goto Exit; - } - - if( uChar != F_XML_UNI_LT) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - - if( RC_BAD( rc = getChar( &uChar))) - { - goto Exit; - } - - if( uChar != F_XML_UNI_QUEST) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - - uiChars = F_XML_MAX_CHARS; - if( RC_BAD( rc = getName( m_uChars, &uiChars))) - { - goto Exit; - } - - if( uiChars >= 3 && - (m_uChars[ 0] == F_XML_UNI_X || - m_uChars[ 0] == F_XML_UNI_x) && - (m_uChars[ 1] == F_XML_UNI_M || - m_uChars[ 1] == F_XML_UNI_m) && - (m_uChars[ 2] == F_XML_UNI_L || - m_uChars[ 2] == F_XML_UNI_l)) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - - if( RC_BAD( rc = peekChar( &uChar))) - { - goto Exit; - } - - if( uChar == F_XML_UNI_QUEST) - { - if( RC_BAD( rc = getChar( &uChar))) - { - goto Exit; - } - - if( RC_BAD( rc = getChar( &uChar))) - { - goto Exit; - } - - if( uChar != F_XML_UNI_GT) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - goto Exit; - } - - if( RC_BAD( rc = skipWhitespace( NULL, TRUE))) - { - goto Exit; - } - - for( ;;) - { - if( RC_BAD( rc = getChar( &uChar))) - { - goto Exit; - } - - if( uChar == F_XML_UNI_QUEST) - { - if( RC_BAD( rc = getChar( &uChar))) - { - goto Exit; - } - - if( uChar == F_XML_UNI_GT) - { - break; - } - - if( RC_BAD( rc = ungetChar( uChar))) - { - goto Exit; - } - - uChar = F_XML_UNI_QUEST; - } - } - -Exit: - - return( rc); -} - -/**************************************************************************** -Desc: Gets a single byte from the input stream -****************************************************************************/ -RCODE F_XMLImport::getByte( - FLMBYTE * pucByte) -{ - RCODE rc = FERR_OK; - - if( m_ucUngetByte) - { - *pucByte = m_ucUngetByte; - m_ucUngetByte = 0; - } - else - { - if( RC_BAD( rc = m_pStream->read( pucByte, 1, NULL))) - { - goto Exit; - } - } - -Exit: - - return( rc); -} - -/**************************************************************************** -Desc: Pushes a single byte back into the input stream -****************************************************************************/ -RCODE F_XMLImport::ungetByte( - FLMBYTE ucByte) -{ - flmAssert( !m_ucUngetByte); - m_ucUngetByte = ucByte; - return( FERR_OK); -} - -/**************************************************************************** -Desc: Pushes a single Unicode character back into the input stream -****************************************************************************/ -RCODE F_XMLImport::ungetChar( - FLMUNICODE uChar) -{ - RCODE rc = FERR_OK; - - if( m_uiUngetPos >= F_XML_MAX_UNGET) - { - rc = RC_SET( FERR_MEM); - goto Exit; - } - - m_puUngetBuf[ m_uiUngetPos++] = uChar; - -Exit: - - return( rc); -} - -/**************************************************************************** -Desc: Pushes multiple Unicode characters back into the input stream -****************************************************************************/ -RCODE F_XMLImport::ungetChars( - FLMUNICODE * puChars, - FLMUINT uiChars) -{ - RCODE rc = FERR_OK; - FLMUINT uiLoop; - - for( uiLoop = 1; uiLoop <= uiChars; uiLoop++) - { - if( RC_BAD( rc = ungetChar( puChars[ uiChars - uiLoop]))) - { - goto Exit; - } - } - -Exit: - - return( rc); -} - -/**************************************************************************** -Desc: Returns the next character in the input stream without removing it -****************************************************************************/ -RCODE F_XMLImport::peekChar( - FLMUNICODE * puChar) -{ - RCODE rc = FERR_OK; - - if( m_uiUngetPos) - { - *puChar = m_puUngetBuf[ m_uiUngetPos - 1]; - } - else - { - if( RC_BAD( rc = getChar( puChar))) - { - goto Exit; - } - - if( RC_BAD( rc = ungetChar( *puChar))) - { - goto Exit; - } - } - -Exit: - - return( rc); -} - -/**************************************************************************** -Desc: Gets an XML name from the input stream -****************************************************************************/ -RCODE F_XMLImport::getName( - FLMUNICODE * puzName, - FLMUINT * puiChars) -{ - RCODE rc = FERR_OK; - FLMUINT uiMaxChars = *puiChars; - FLMUINT uiOffset = 0; - FLMUNICODE uChar; - - flmAssert( uiMaxChars >= 2); - - if( RC_BAD( rc = getChar( &uChar))) - { - goto Exit; - } - - if( !isLetter( uChar) && uChar != F_XML_UNI_UNDERSCORE && - uChar != F_XML_UNI_COLON) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - - puzName[ uiOffset++] = uChar; - - for( ;;) - { - if( RC_BAD( rc = getChar( &uChar))) - { - goto Exit; - } - - if( !isNameChar( uChar)) - { - break; - } - - if( uiOffset >= uiMaxChars) - { - rc = RC_SET( FERR_CONV_DEST_OVERFLOW); - goto Exit; - } - - puzName[ uiOffset++] = uChar; - } - - puzName[ uiOffset] = 0; - - if( RC_BAD( rc = ungetChar( uChar))) - { - goto Exit; - } - -Exit: - - *puiChars = uiOffset; - return( rc); -} - -/**************************************************************************** -Desc: Gets an XML Nmtoken from the input stream -****************************************************************************/ -RCODE F_XMLImport::getNmtoken( - FLMUNICODE * puzName, - FLMUINT * puiChars) -{ - RCODE rc = FERR_OK; - FLMUINT uiMaxChars = *puiChars; - FLMUINT uiOffset = 0; - FLMUNICODE uChar; - - flmAssert( uiMaxChars >= 2); - - for( ;;) - { - if( RC_BAD( rc = getChar( &uChar))) - { - goto Exit; - } - - if( !isNameChar( uChar)) - { - break; - } - - if( uiOffset >= uiMaxChars) - { - rc = RC_SET( FERR_CONV_DEST_OVERFLOW); - goto Exit; - } - - puzName[ uiOffset++] = uChar; - } - - puzName[ uiOffset] = 0; - - if( RC_BAD( rc = ungetChar( uChar))) - { - goto Exit; - } - -Exit: - - *puiChars = uiOffset; - return( rc); -} - -/**************************************************************************** -Desc: Processes the XML version information encoded within the document -****************************************************************************/ -RCODE F_XMLImport::processVersion( - FlmRecord * pRec, - void * pvParent) -{ - RCODE rc = FERR_OK; - FLMUINT uiChars; - FLMBOOL bSingleQuote = FALSE; - FLMUINT uiOffset = 0; - void * pvField = NULL; - FLMUNICODE uChar; - - if( pvParent) - { - if( RC_BAD( rc = pRec->insertLast( - pRec->getLevel( pvParent) + 1, - F_XML_VERSION_TAG, FLM_TEXT_TYPE, &pvField))) - { - goto Exit; - } - } - - uiChars = 7; - if( RC_BAD( rc = getChars( m_uChars, &uiChars))) - { - goto Exit; - } - - if( m_uChars[ 0] != F_XML_UNI_v || - m_uChars[ 1] != F_XML_UNI_e || - m_uChars[ 2] != F_XML_UNI_r || - m_uChars[ 3] != F_XML_UNI_s || - m_uChars[ 4] != F_XML_UNI_i || - m_uChars[ 5] != F_XML_UNI_o || - m_uChars[ 6] != F_XML_UNI_n) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - - if( RC_BAD( rc = skipWhitespace( NULL))) - { - goto Exit; - } - - if( RC_BAD( rc = getChar( &uChar))) - { - goto Exit; - } - - if( uChar != F_XML_UNI_EQ) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - - if( RC_BAD( rc = skipWhitespace( NULL))) - { - goto Exit; - } - - if( RC_BAD( rc = getChar( &uChar))) - { - goto Exit; - } - - if( uChar == F_XML_UNI_APOS) - { - bSingleQuote = TRUE; - } - else if( uChar != F_XML_UNI_QUOTE) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - - m_uChars[ uiOffset++] = uChar; - - for( ;;) - { - if( RC_BAD( rc = getChar( &uChar))) - { - goto Exit; - } - - m_uChars[ uiOffset++] = uChar; - if( uiOffset >= F_XML_MAX_CHARS) - { - rc = RC_SET( FERR_CONV_DEST_OVERFLOW); - goto Exit; - } - - if( (uChar == F_XML_UNI_APOS && bSingleQuote) || - (uChar == F_XML_UNI_QUOTE && !bSingleQuote)) - { - break; - } - else if( !((uChar >= F_XML_UNI_A && uChar <= F_XML_UNI_Z) || - (uChar >= F_XML_UNI_a && uChar <= F_XML_UNI_z) || - (uChar >= F_XML_UNI_0 && uChar <= F_XML_UNI_9) || - uChar == F_XML_UNI_UNDERSCORE || - uChar == F_XML_UNI_PERIOD || - uChar == F_XML_UNI_COLON || - uChar == F_XML_UNI_HYPHEN)) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - } - - if( !uiOffset) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - - if( pvField) - { - m_uChars[ uiOffset] = 0; - if( RC_BAD( rc = pRec->setUnicode( pvField, m_uChars))) - { - goto Exit; - } - } - -Exit: - - return( rc); -} - -/**************************************************************************** -Desc: Processes an XML encoding declaration -****************************************************************************/ -RCODE F_XMLImport::processEncodingDecl( - FlmRecord * pRec, - void * pvParent) -{ - RCODE rc = FERR_OK; - FLMUINT uiChars; - FLMBOOL bSingleQuote = FALSE; - FLMUINT uiOffset = 0; - void * pvField = NULL; - FLMUNICODE uChar; - - if( pvParent) - { - if( RC_BAD( rc = pRec->insertLast( - pRec->getLevel( pvParent) + 1, - F_XML_ENCODING_TAG, FLM_TEXT_TYPE, &pvField))) - { - goto Exit; - } - } - - uiChars = 8; - if( RC_BAD( rc = getChars( m_uChars, &uiChars))) - { - goto Exit; - } - - if( m_uChars[ 0] != F_XML_UNI_e || - m_uChars[ 1] != F_XML_UNI_n || - m_uChars[ 2] != F_XML_UNI_c || - m_uChars[ 3] != F_XML_UNI_o || - m_uChars[ 4] != F_XML_UNI_d || - m_uChars[ 5] != F_XML_UNI_i || - m_uChars[ 6] != F_XML_UNI_n || - m_uChars[ 7] != F_XML_UNI_g) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - - if( RC_BAD( rc = skipWhitespace( NULL))) - { - goto Exit; - } - - if( RC_BAD( rc = getChar( &uChar))) - { - goto Exit; - } - - if( uChar != F_XML_UNI_EQ) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - - if( RC_BAD( rc = skipWhitespace( NULL))) - { - goto Exit; - } - - if( RC_BAD( rc = getChar( &uChar))) - { - goto Exit; - } - - if( uChar == F_XML_UNI_APOS) - { - bSingleQuote = TRUE; - } - else if( uChar != F_XML_UNI_QUOTE) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - - // VISIT: Make sure the encoding decl starts with - // [A-Za-z] - - m_uChars[ uiOffset++] = uChar; - - for( ;;) - { - if( RC_BAD( rc = getChar( &uChar))) - { - goto Exit; - } - - m_uChars[ uiOffset++] = uChar; - if( uiOffset >= F_XML_MAX_CHARS) - { - rc = RC_SET( FERR_CONV_DEST_OVERFLOW); - goto Exit; - } - - if( (uChar == F_XML_UNI_APOS && bSingleQuote) || - (uChar == F_XML_UNI_QUOTE && !bSingleQuote)) - { - break; - } - else if( !((uChar >= F_XML_UNI_A && uChar <= F_XML_UNI_Z) || - (uChar >= F_XML_UNI_a && uChar <= F_XML_UNI_z) || - (uChar >= F_XML_UNI_0 && uChar <= F_XML_UNI_9) || - uChar == F_XML_UNI_UNDERSCORE || - uChar == F_XML_UNI_PERIOD || - uChar == F_XML_UNI_HYPHEN)) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - } - - if( !uiOffset) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - - if( pvField) - { - m_uChars[ uiOffset] = 0; - if( RC_BAD( rc = pRec->setUnicode( pvField, m_uChars))) - { - goto Exit; - } - } - -Exit: - - return( rc); -} - -/**************************************************************************** -Desc: Processes an XML SD declaration -****************************************************************************/ -RCODE F_XMLImport::processSDDecl( - FlmRecord * pRec, - void * pvParent) -{ - RCODE rc = FERR_OK; - FLMUINT uiChars; - FLMBOOL bSingleQuote = FALSE; - FLMUINT uiOffset = 0; - void * pvField = NULL; - FLMUNICODE uChar; - - if( pvParent) - { - if( RC_BAD( rc = pRec->insertLast( - pRec->getLevel( pvParent) + 1, - F_XML_SDDECL_TAG, FLM_TEXT_TYPE, &pvField))) - { - goto Exit; - } - } - - uiChars = 10; - if( RC_BAD( rc = getChars( m_uChars, &uiChars))) - { - goto Exit; - } - - if( m_uChars[ 0] != F_XML_UNI_s || - m_uChars[ 1] != F_XML_UNI_t || - m_uChars[ 2] != F_XML_UNI_a || - m_uChars[ 3] != F_XML_UNI_n || - m_uChars[ 4] != F_XML_UNI_d || - m_uChars[ 5] != F_XML_UNI_a || - m_uChars[ 6] != F_XML_UNI_l || - m_uChars[ 7] != F_XML_UNI_o || - m_uChars[ 8] != F_XML_UNI_n || - m_uChars[ 9] != F_XML_UNI_e) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - - if( RC_BAD( rc = skipWhitespace( NULL))) - { - goto Exit; - } - - if( RC_BAD( rc = getChar( &uChar))) - { - goto Exit; - } - - if( uChar != F_XML_UNI_EQ) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - - if( RC_BAD( rc = skipWhitespace( NULL))) - { - goto Exit; - } - - if( RC_BAD( rc = getChar( &uChar))) - { - goto Exit; - } - - if( uChar == F_XML_UNI_APOS) - { - bSingleQuote = TRUE; - } - else if( uChar != F_XML_UNI_QUOTE) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - - m_uChars[ uiOffset++] = uChar; - - if( RC_BAD( rc = getChar( &uChar))) - { - goto Exit; - } - - if( uChar == F_XML_UNI_y) - { - if( RC_BAD( rc = getChar( &uChar))) - { - goto Exit; - } - - if( uChar != F_XML_UNI_e) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - - if( RC_BAD( rc = getChar( &uChar))) - { - goto Exit; - } - - if( uChar != F_XML_UNI_s) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - - m_uChars[ uiOffset++] = F_XML_UNI_y; - m_uChars[ uiOffset++] = F_XML_UNI_e; - m_uChars[ uiOffset++] = F_XML_UNI_s; - } - else if( uChar == F_XML_UNI_n) - { - if( RC_BAD( rc = getChar( &uChar))) - { - goto Exit; - } - - if( uChar != F_XML_UNI_o) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - - m_uChars[ uiOffset++] = F_XML_UNI_n; - m_uChars[ uiOffset++] = F_XML_UNI_o; - } - - if( RC_BAD( rc = getChar( &uChar))) - { - goto Exit; - } - - if( bSingleQuote) - { - if( uChar != F_XML_UNI_APOS) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - } - else - { - if( uChar != F_XML_UNI_QUOTE) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - } - - if( pvField) - { - m_uChars[ uiOffset++] = uChar; - m_uChars[ uiOffset] = 0; - if( RC_BAD( rc = pRec->setUnicode( pvField, m_uChars))) - { - goto Exit; - } - } - -Exit: - - return( rc); -} - -/**************************************************************************** -Desc: Reads a UTF-8 encoded character from the input stream. -****************************************************************************/ -RCODE F_XMLImport::getChar( - FLMUNICODE * pChar) -{ - FLMBYTE ucByte1; - FLMBYTE ucByte2; - FLMBYTE ucByte3; - FLMBYTE ucLoByte; - FLMBYTE ucHiByte; - RCODE rc = FERR_OK; - - if( m_uiUngetPos) - { - *pChar = m_puUngetBuf[ --m_uiUngetPos]; - goto Exit; - } - - // Read and decode the bytes. - - if( RC_BAD( rc = getByte( &ucByte1))) - { - goto Exit; - } - - // Convert CRLF->CR - - if( ucByte1 == (FLMBYTE)0x0D) - { - if( RC_BAD( rc = getByte( &ucByte1))) - { - goto Exit; - } - - if( ucByte1 != (FLMBYTE)0x0A) - { - if( RC_BAD( rc = ungetByte( ucByte1))) - { - goto Exit; - } - - ucByte1 = (FLMBYTE)0x0A; - } - } - - if( (ucByte1 & 0xC0) != 0xC0) - { - ucHiByte = 0; - ucLoByte = ucByte1; - } - else - { - if( RC_BAD( rc = getByte( &ucByte2))) - { - goto Exit; - } - - if( (ucByte1 & 0xE0) == 0xE0) - { - if( RC_BAD( rc = getByte( &ucByte3))) - { - goto Exit; - } - - ucHiByte = - (FLMBYTE)(((ucByte1 & 0x0F) << 4) | ((ucByte2 & 0x3C) >> 2)); - ucLoByte = (FLMBYTE)(((ucByte2 & 0x03) << 6) | (ucByte3 & 0x3F)); - } - else - { - ucHiByte = (FLMBYTE)(((ucByte1 & 0x1C) >> 2)); - ucLoByte = (FLMBYTE)(((ucByte1 & 0x03) << 6) | (ucByte2 & 0x3F)); - } - } - - *pChar = (FLMUNICODE)((((FLMUNICODE)(ucHiByte)) << 8) | - ((FLMUNICODE)(ucLoByte))); - -Exit: - - return( rc); -} - -/**************************************************************************** -Desc: Reads multiple UTF-8 encoded characters from the stream. -****************************************************************************/ -RCODE F_XMLImport::getChars( - FLMUNICODE * uzChars, - FLMUINT * puiCount) -{ - RCODE rc = FERR_OK; - FLMUINT uiCount = *puiCount; - FLMUINT uiLoop; - - for( uiLoop = 0; uiLoop < uiCount; uiLoop++) - { - if( RC_BAD( rc = getChar( &uzChars[ uiLoop]))) - { - goto Exit; - } - } - -Exit: - - *puiCount = uiLoop; - return( rc); -} - -/**************************************************************************** -Desc: Reads an XML character entity -****************************************************************************/ -RCODE F_XMLImport::getCharEntity( - FLMUNICODE * puChar) -{ - FLMBYTE ucByte; - RCODE rc = FERR_OK; - - F_UNREFERENCED_PARM( puChar); - - if( RC_BAD( rc = getByte( &ucByte))) - { - goto Exit; - } - - if( ucByte == '&') - { - if( RC_BAD( rc = getByte( &ucByte))) - { - goto Exit; - } - - if( ucByte == '#') - { - if( RC_BAD( rc = getByte( &ucByte))) - { - goto Exit; - } - } - - while( ucByte != ';') - { - if( RC_BAD( rc = getByte( &ucByte))) - { - goto Exit; - } - } - } - -Exit: - - return( rc); -} - -/**************************************************************************** -Desc: Processes an XML entity value -****************************************************************************/ -RCODE F_XMLImport::processEntityValue( - FlmRecord * pRec, - void * pvParent) -{ - FLMUNICODE uChar; - FLMBOOL bSingleQuote = FALSE; - RCODE rc = FERR_OK; - - if( RC_BAD( rc = getChar( &uChar))) - { - goto Exit; - } - - if( uChar == F_XML_UNI_APOS) - { - bSingleQuote = TRUE; - } - else if( uChar != F_XML_UNI_QUOTE) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - - for( ;;) - { - if( RC_BAD( rc = getChar( &uChar))) - { - goto Exit; - } - - if( (uChar == F_XML_UNI_APOS && bSingleQuote) || - (uChar == F_XML_UNI_QUOTE && !bSingleQuote)) - { - break; - } - else if( uChar == F_XML_UNI_PERCENT) - { - if( RC_BAD( rc = ungetChar( uChar))) - { - goto Exit; - } - - if( RC_BAD( rc = processPERef( pRec, pvParent))) - { - goto Exit; - } - } - else if( uChar == F_XML_UNI_AMP) - { - if( RC_BAD( rc = ungetChar( uChar))) - { - goto Exit; - } - - if( RC_BAD( rc = processReference( pRec, pvParent, NULL))) - { - goto Exit; - } - } - - // VISIT: Add the character to the buffer - } - -Exit: - - return( rc); -} - -/**************************************************************************** -Desc: Processes an XML PERef -****************************************************************************/ -RCODE F_XMLImport::processPERef( - FlmRecord * pRec, - void * pvParent) -{ - FLMUNICODE uChar; - FLMUINT uiChars; - void * pvField = NULL; - RCODE rc = FERR_OK; - - if( pvParent) - { - if( RC_BAD( rc = pRec->insertLast( - pRec->getLevel( pvParent) + 1, - F_XML_PEREF_TAG, FLM_TEXT_TYPE, &pvField))) - { - goto Exit; - } - } - - if( RC_BAD( rc = getChar( &uChar))) - { - goto Exit; - } - - if( uChar != F_XML_UNI_PERCENT) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - - uiChars = F_XML_MAX_CHARS; - if( RC_BAD( rc = getName( m_uChars, &uiChars))) - { - goto Exit; - } - - if( pvField) - { - if( RC_BAD( rc = pRec->setUnicode( pvField, m_uChars))) - { - goto Exit; - } - } - - if( RC_BAD( rc = getChar( &uChar))) - { - goto Exit; - } - - if( uChar != F_XML_UNI_SEMI) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - -Exit: - - return( rc); -} - -/**************************************************************************** -Desc: Processes an XML reference -****************************************************************************/ -RCODE F_XMLImport::processReference( - FlmRecord * pRec, - void * pvParent, - FLMUNICODE * puChar) -{ - FLMUNICODE uChar; - FLMUINT uiChars; - void * pvField = NULL; - RCODE rc = FERR_OK; - - if( RC_BAD( rc = getChar( &uChar))) - { - goto Exit; - } - - if( uChar != F_XML_UNI_AMP) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - - if( RC_BAD( rc = peekChar( &uChar))) - { - goto Exit; - } - - if( uChar == F_XML_UNI_POUND) - { - if( RC_BAD( rc = getChar( &uChar))) - { - goto Exit; - } - - uiChars = 0; - for( ;;) - { - if( RC_BAD( rc = getChar( &uChar))) - { - goto Exit; - } - - if( uChar == F_XML_UNI_SEMI) - { - if( RC_BAD( rc = ungetChar( uChar))) - { - goto Exit; - } - break; - } - - // Validate that the characters are valid dec/hex characters - - if( !((uChar >= '0' && uChar <= '9') || - (uChar >= 'A' && uChar <= 'F') || - (uChar >= 'a' && uChar <= 'f'))) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - - m_uChars[ uiChars++] = uChar; - if( uiChars >= F_XML_MAX_CHARS) - { - rc = RC_SET( FERR_CONV_DEST_OVERFLOW); - goto Exit; - } - } - - m_uChars[ uiChars] = 0; - - if( pvParent) - { - if( RC_BAD( rc = pRec->insertLast( - pRec->getLevel( pvParent) + 1, - F_XML_CHARREF_TAG, FLM_TEXT_TYPE, &pvField))) - { - goto Exit; - } - - if( RC_BAD( rc = pRec->setUnicode( pvField, m_uChars))) - { - goto Exit; - } - } - - if( puChar) - { - FLMUINT uiVal = 0; - - unicodeToNumber( m_uChars, &uiVal, NULL); - *puChar = (FLMUNICODE)uiVal; - } - } - else - { - uiChars = F_XML_MAX_CHARS; - if( RC_BAD( rc = getName( m_uChars, &uiChars))) - { - goto Exit; - } - - if( pvParent) - { - if( RC_BAD( rc = pRec->insertLast( - pRec->getLevel( pvParent) + 1, - F_XML_ENTITYREF_TAG, FLM_TEXT_TYPE, &pvField))) - { - goto Exit; - } - - if( RC_BAD( rc = pRec->setUnicode( pvField, m_uChars))) - { - goto Exit; - } - } - - if( puChar) - { - // Translate pre-defined references - - *puChar = 0; - if( uiChars == 2) - { - if( m_uChars[ 0] == (FLMUNICODE)'l' && - m_uChars[ 1] == (FLMUNICODE)'t') - { - *puChar = F_XML_UNI_LT; - } - else if( m_uChars[ 0] == (FLMUNICODE)'g' && - m_uChars[ 1] == (FLMUNICODE)'t') - { - *puChar = F_XML_UNI_GT; - } - } - else if( uiChars == 3) - { - if( m_uChars[ 0] == (FLMUNICODE)'a' && - m_uChars[ 1] == (FLMUNICODE)'m' && - m_uChars[ 2] == (FLMUNICODE)'p') - { - *puChar = F_XML_UNI_AMP; - } - } - else if( uiChars == 4) - { - if( m_uChars[ 0] == (FLMUNICODE)'a' && - m_uChars[ 1] == (FLMUNICODE)'p' && - m_uChars[ 2] == (FLMUNICODE)'o' && - m_uChars[ 3] == (FLMUNICODE)'s') - { - *puChar = F_XML_UNI_APOS; - } - else if( m_uChars[ 0] == (FLMUNICODE)'q' && - m_uChars[ 1] == (FLMUNICODE)'u' && - m_uChars[ 2] == (FLMUNICODE)'o' && - m_uChars[ 3] == (FLMUNICODE)'t') - { - *puChar = F_XML_UNI_QUOTE; - } - } - - if( *puChar == 0) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - } - } - - if( RC_BAD( rc = getChar( &uChar))) - { - goto Exit; - } - - if( uChar != F_XML_UNI_SEMI) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - -Exit: - - return( rc); -} - -/**************************************************************************** -Desc: Processes an attribute value -****************************************************************************/ -RCODE F_XMLImport::processAttValue( - FlmRecord * pRec, - void * pvParent) -{ - FLMUNICODE uChar; - FLMBOOL bSingleQuote = FALSE; - FLMUINT uiOffset = 0; - void * pvField = NULL; - RCODE rc = FERR_OK; - - if( RC_BAD( rc = getChar( &uChar))) - { - goto Exit; - } - - if( uChar == F_XML_UNI_APOS) - { - bSingleQuote = TRUE; - } - else if( uChar != F_XML_UNI_QUOTE) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - - m_puValBuf[ uiOffset++] = uChar; - if( uiOffset >= m_uiValBufSize) - { - rc = RC_SET( FERR_CONV_DEST_OVERFLOW); - goto Exit; - } - - for( ;;) - { - if( RC_BAD( rc = getChar( &uChar))) - { - goto Exit; - } - - if( (uChar == F_XML_UNI_APOS && bSingleQuote) || - (uChar == F_XML_UNI_QUOTE && !bSingleQuote)) - { - m_puValBuf[ uiOffset++] = uChar; - if( uiOffset >= m_uiValBufSize) - { - rc = RC_SET( FERR_CONV_DEST_OVERFLOW); - goto Exit; - } - break; - } - else if( uChar == F_XML_UNI_AMP) - { - if( pvParent && uiOffset) - { - if( RC_BAD( rc = pRec->insertLast( - pRec->getLevel( pvParent) + 1, - F_XML_ATTVAL_TAG, FLM_TEXT_TYPE, &pvField))) - { - goto Exit; - } - - m_puValBuf[ uiOffset] = 0; - if( RC_BAD( rc = pRec->setUnicode( pvField, m_puValBuf))) - { - goto Exit; - } - uiOffset = 0; - } - - if( RC_BAD( rc = processReference( pRec, pvParent, NULL))) - { - goto Exit; - } - } - else if( uChar == F_XML_UNI_PERCENT) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - - m_puValBuf[ uiOffset++] = uChar; - if( uiOffset >= m_uiValBufSize) - { - rc = RC_SET( FERR_CONV_DEST_OVERFLOW); - goto Exit; - } - } - - if( pvParent && uiOffset) - { - if( RC_BAD( rc = pRec->insertLast( - pRec->getLevel( pvParent) + 1, - F_XML_ATTVAL_TAG, FLM_TEXT_TYPE, &pvField))) - { - goto Exit; - } - - m_puValBuf[ uiOffset] = 0; - if( RC_BAD( rc = pRec->setUnicode( pvField, m_puValBuf))) - { - goto Exit; - } - } - -Exit: - - return( rc); -} - -/**************************************************************************** -Desc: Reads an XML system literal from the input stream -****************************************************************************/ -RCODE F_XMLImport::getSystemLiteral( - FLMUNICODE * puBuf, - FLMUINT * puiMaxChars) -{ - FLMUNICODE uChar; - FLMUINT uiMaxChars = *puiMaxChars; - FLMBOOL bSingleQuote = FALSE; - FLMUINT uiOffset = 0; - RCODE rc = FERR_OK; - - if( RC_BAD( rc = getChar( &uChar))) - { - goto Exit; - } - - if( uChar == F_XML_UNI_APOS) - { - bSingleQuote = TRUE; - } - else if( uChar != F_XML_UNI_QUOTE) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - - for( ;;) - { - if( RC_BAD( rc = getChar( &uChar))) - { - goto Exit; - } - - if( (uChar == F_XML_UNI_APOS && bSingleQuote) || - (uChar == F_XML_UNI_QUOTE && !bSingleQuote)) - { - break; - } - - puBuf[ uiOffset++] = uChar; - if( uiOffset >= uiMaxChars) - { - rc = RC_SET( FERR_CONV_DEST_OVERFLOW); - goto Exit; - } - } - - puBuf[ uiOffset] = 0; - -Exit: - - *puiMaxChars = uiOffset; - return( rc); -} - -/**************************************************************************** -Desc: Reads an XML public ID literal from the input stream -****************************************************************************/ -RCODE F_XMLImport::getPubidLiteral( - FLMUNICODE * puBuf, - FLMUINT * puiMaxChars) -{ - FLMUNICODE uChar; - FLMUINT uiMaxChars = *puiMaxChars; - FLMBOOL bSingleQuote = FALSE; - FLMUINT uiOffset = 0; - RCODE rc = FERR_OK; - - if( RC_BAD( rc = getChar( &uChar))) - { - goto Exit; - } - - if( uChar == F_XML_UNI_APOS) - { - bSingleQuote = TRUE; - } - else if( uChar != F_XML_UNI_QUOTE) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - - for( ;;) - { - if( RC_BAD( rc = getChar( &uChar))) - { - goto Exit; - } - - if( (uChar == F_XML_UNI_APOS && bSingleQuote) || - (uChar == F_XML_UNI_QUOTE && !bSingleQuote)) - { - break; - } - else if( !isPubidChar( uChar)) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - - puBuf[ uiOffset++] = uChar; - if( uiOffset >= uiMaxChars) - { - rc = RC_SET( FERR_CONV_DEST_OVERFLOW); - goto Exit; - } - } - - puBuf[ uiOffset] = 0; - -Exit: - - *puiMaxChars = uiOffset; - return( rc); -} - -/**************************************************************************** -Desc: Returns TRUE if the next item in the input stream is an XML - declaration -****************************************************************************/ -RCODE F_XMLImport::isXMLDecl( - FLMBOOL * pbIsXMLDecl) -{ - FLMUINT uiChars; - RCODE rc = FERR_OK; - - *pbIsXMLDecl = FALSE; - uiChars = 5; - if( RC_BAD( rc = getChars( m_uChars, &uiChars))) - { - if( rc == FERR_IO_END_OF_FILE || rc == FERR_EOF_HIT) - { - if( uiChars) - { - rc = ungetChars( m_uChars, uiChars); - } - else - { - rc = FERR_OK; - } - } - goto Exit; - } - - if( m_uChars[ 0] == F_XML_UNI_LT && - m_uChars[ 1] == F_XML_UNI_QUEST && - m_uChars[ 2] == F_XML_UNI_x && - m_uChars[ 3] == F_XML_UNI_m && - m_uChars[ 4] == F_XML_UNI_l) - { - *pbIsXMLDecl = TRUE; - } - - if( RC_BAD( rc = ungetChars( m_uChars, uiChars))) - { - goto Exit; - } - -Exit: - - return( rc); -} - -/**************************************************************************** -Desc: Returns TRUE if the next item in the input stream is an XML - document type declaration -****************************************************************************/ -RCODE F_XMLImport::isDocTypeDecl( - FLMBOOL * pbIsDocTypeDecl) -{ - FLMUINT uiChars; - RCODE rc = FERR_OK; - - *pbIsDocTypeDecl = FALSE; - uiChars = 9; - if( RC_BAD( rc = getChars( m_uChars, &uiChars))) - { - if( rc == FERR_IO_END_OF_FILE || rc == FERR_EOF_HIT) - { - if( uiChars) - { - rc = ungetChars( m_uChars, uiChars); - } - else - { - rc = FERR_OK; - } - } - goto Exit; - } - - if( m_uChars[ 0] == F_XML_UNI_LT && - m_uChars[ 1] == F_XML_UNI_BANG && - m_uChars[ 2] == F_XML_UNI_D && - m_uChars[ 3] == F_XML_UNI_O && - m_uChars[ 4] == F_XML_UNI_C && - m_uChars[ 5] == F_XML_UNI_T && - m_uChars[ 6] == F_XML_UNI_Y && - m_uChars[ 7] == F_XML_UNI_P && - m_uChars[ 8] == F_XML_UNI_E) - { - *pbIsDocTypeDecl = TRUE; - } - - if( RC_BAD( rc = ungetChars( m_uChars, uiChars))) - { - goto Exit; - } - -Exit: - - return( rc); -} - -/**************************************************************************** -Desc: Processes an XML comment -****************************************************************************/ -RCODE F_XMLImport::processComment( - FlmRecord * pRec, - void * pvParent) -{ - FLMUNICODE uChar; - FLMUNICODE uChar1; - FLMUNICODE uChar2; - FLMUINT uiChars; - FLMUINT uiOffset; - FLMUINT uiMaxOffset; - void * pvField = NULL; - RCODE rc = FERR_OK; - - if( pvParent) - { - if( RC_BAD( rc = pRec->insertLast( - pRec->getLevel( pvParent) + 1, - F_XML_COMMENT_TAG, FLM_TEXT_TYPE, &pvField))) - { - goto Exit; - } - } - - uiChars = 4; - if( RC_BAD( rc = getChars( m_uChars, &uiChars))) - { - goto Exit; - } - - if( m_uChars[ 0] != F_XML_UNI_LT || - m_uChars[ 1] != F_XML_UNI_BANG || - m_uChars[ 2] != F_XML_UNI_HYPHEN || - m_uChars[ 3] != F_XML_UNI_HYPHEN) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - - uiOffset = 0; - uiMaxOffset = m_uiValBufSize; - for( ;;) - { - if( RC_BAD( rc = getChar( &uChar))) - { - goto Exit; - } - - if( uChar == F_XML_UNI_HYPHEN) - { - if( RC_BAD( rc = getChar( &uChar1))) - { - goto Exit; - } - - if( uChar1 == F_XML_UNI_HYPHEN) - { - if( RC_BAD( rc = getChar( &uChar2))) - { - goto Exit; - } - - if( uChar2 != F_XML_UNI_GT) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - break; - } - else - { - if( RC_BAD( rc = ungetChar( uChar1))) - { - goto Exit; - } - } - } - - m_puValBuf[ uiOffset++] = uChar; - if( uiOffset >= uiMaxOffset) - { - rc = RC_SET( FERR_CONV_DEST_OVERFLOW); - goto Exit; - } - } - - if( pvField) - { - m_puValBuf[ uiOffset] = 0; - if( RC_BAD( rc = pRec->setUnicode( pvField, m_puValBuf))) - { - goto Exit; - } - } - -Exit: - - return( rc); -} - -/**************************************************************************** -Desc: Processes a CDATA tag -****************************************************************************/ -RCODE F_XMLImport::processCDATA( - FlmRecord * pRec, - void * pvParent) -{ - FLMUNICODE uChar; - FLMUINT uiChars; - FLMUINT uiOffset = 0; - void * pvField = NULL; - RCODE rc = FERR_OK; - - uiChars = 9; - if( RC_BAD( rc = getChars( m_uChars, &uiChars))) - { - goto Exit; - } - - if( m_uChars[ 0] != F_XML_UNI_LT || - m_uChars[ 1] != F_XML_UNI_BANG || - m_uChars[ 2] != F_XML_UNI_LBRACKET || - m_uChars[ 3] != F_XML_UNI_C || - m_uChars[ 4] != F_XML_UNI_D || - m_uChars[ 5] != F_XML_UNI_A || - m_uChars[ 6] != F_XML_UNI_T || - m_uChars[ 7] != F_XML_UNI_A || - m_uChars[ 8] != F_XML_UNI_LBRACKET) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - - for( ;;) - { - if( RC_BAD( rc = getChar( &uChar))) - { - goto Exit; - } - - if( uChar == F_XML_UNI_RBRACKET) - { - if( RC_BAD( rc = getChar( &uChar))) - { - goto Exit; - } - - if( uChar == F_XML_UNI_RBRACKET) - { - if( RC_BAD( rc = getChar( &uChar))) - { - goto Exit; - } - - if( uChar == F_XML_UNI_GT) - { - break; - } - else - { - if( RC_BAD( rc = ungetChar( uChar))) - { - goto Exit; - } - - if( RC_BAD( rc = ungetChar( F_XML_UNI_RBRACKET))) - { - goto Exit; - } - - uChar = F_XML_UNI_RBRACKET; - } - } - else - { - if( RC_BAD( rc = ungetChar( uChar))) - { - goto Exit; - } - - uChar = F_XML_UNI_RBRACKET; - } - } - - m_puValBuf[ uiOffset++] = uChar; - if( uiOffset >= m_uiValBufSize) - { - rc = RC_SET( FERR_CONV_DEST_OVERFLOW); - goto Exit; - } - } - - if( pvParent) - { - m_puValBuf[ uiOffset] = 0; - if( RC_BAD( rc = pRec->insertLast( - pRec->getLevel( pvParent) + 1, - F_XML_CDATA_TAG, FLM_TEXT_TYPE, &pvField))) - { - goto Exit; - } - - m_puValBuf[ uiOffset] = 0; - if( RC_BAD( rc = pRec->setUnicode( pvField, m_puValBuf))) - { - goto Exit; - } - } - -Exit: - - return( rc); -} - -/**************************************************************************** -Desc: Skips any whitespace characters in the input stream -****************************************************************************/ -RCODE F_XMLImport::skipWhitespace( - void * pvParent, - FLMBOOL bRequired) -{ - FLMUNICODE uChar; - FLMUINT uiCount = 0; - RCODE rc = FERR_OK; - - F_UNREFERENCED_PARM( pvParent); - - for( ;;) - { - if( RC_BAD( rc = getChar( &uChar))) - { - goto Exit; - } - - if( !isWhitespace( uChar)) - { - if( RC_BAD( rc = ungetChar( uChar))) - { - goto Exit; - } - break; - } - uiCount++; - } - - if( !uiCount && bRequired) - { - rc = RC_SET( FERR_SYNTAX); - goto Exit; - } - -Exit: - - return( rc); -} diff --git a/flaim/src/fxml.h b/flaim/src/fxml.h deleted file mode 100644 index 8ad3c26..0000000 --- a/flaim/src/fxml.h +++ /dev/null @@ -1,529 +0,0 @@ -//------------------------------------------------------------------------- -// Desc: XML Wrapper - class definitions -// Tabs: 3 -// -// Copyright (c) 2000,2002-2006 Novell, Inc. All Rights Reserved. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of version 2 of the GNU General Public -// License as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, contact Novell, Inc. -// -// To contact Novell about this file by physical or electronic mail, -// you may find current contact information at www.novell.com -// -// $Id: fxml.h 12329 2006-01-20 17:49:30 -0700 (Fri, 20 Jan 2006) ahodgkinson $ -//------------------------------------------------------------------------- - -#ifndef FXML_H -#define FXML_H - -#include "fpackon.h" -// IMPORTANT NOTE: No other include files should follow this one except -// for fpackoff.h - -// Constants - -#define F_XML_DOCUMENT_TAG 40000 -#define F_XML_XMLDECL_TAG 40001 -#define F_XML_VERSION_TAG 40002 -#define F_XML_ENCODING_TAG 40003 -#define F_XML_SDDECL_TAG 40004 -#define F_XML_COMMENT_TAG 40005 -#define F_XML_NOTATIONDECL_TAG 40006 -#define F_XML_SYSLITERAL_TAG 40007 -#define F_XML_PUBIDLITERAL_TAG 40008 -#define F_XML_EXTERNALID_TAG 40009 -#define F_XML_ENTITYDECL_TAG 40010 -#define F_XML_NDATADECL_TAG 40011 -#define F_XML_ATTRDEF_TAG 40012 -#define F_XML_ENTITYREF_TAG 40013 -#define F_XML_CHARREF_TAG 40014 -#define F_XML_PEREF_TAG 40015 -#define F_XML_ATTNAME_TAG 40016 -#define F_XML_ATTVAL_TAG 40017 -#define F_XML_ELEMENTNAME_TAG 40018 -#define F_XML_DOCTYPEDECL_TAG 40019 -#define F_XML_ELEMENTVAL_TAG 40020 -#define F_XML_CDATA_TAG 40021 -#define F_XML_ELEMENTDECL_TAG 40022 -#define F_XML_ATTLISTDECL_TAG 40023 -#define F_XML_NAME_TAG 40024 -#define F_XML_OCCURS_TAG 40025 -#define F_XML_CHOICE_TAG 40026 -#define F_XML_SEQ_TAG 40027 -#define F_XML_MIXED_TAG 40028 -#define F_XML_CONTENTSPEC_TAG 40029 -#define F_XML_ATTTYPE_TAG 40030 - -#define F_XML_WHITESPACE_TAG 41000 -#define F_XML_UNKNOWN_TAG 41001 - -// Characters - -#define F_XML_UNI_LINEFEED ((FLMUNICODE)10) -#define F_XML_UNI_SPACE ((FLMUNICODE)32) -#define F_XML_UNI_BANG ((FLMUNICODE)33) -#define F_XML_UNI_QUOTE ((FLMUNICODE)34) -#define F_XML_UNI_POUND ((FLMUNICODE)35) -#define F_XML_UNI_DOLLAR ((FLMUNICODE)36) -#define F_XML_UNI_PERCENT ((FLMUNICODE)37) -#define F_XML_UNI_AMP ((FLMUNICODE)38) -#define F_XML_UNI_APOS ((FLMUNICODE)39) -#define F_XML_UNI_LPAREN ((FLMUNICODE)40) -#define F_XML_UNI_RPAREN ((FLMUNICODE)41) -#define F_XML_UNI_ASTERISK ((FLMUNICODE)42) -#define F_XML_UNI_PLUS ((FLMUNICODE)43) -#define F_XML_UNI_COMMA ((FLMUNICODE)44) -#define F_XML_UNI_HYPHEN ((FLMUNICODE)45) -#define F_XML_UNI_PERIOD ((FLMUNICODE)46) -#define F_XML_UNI_FSLASH ((FLMUNICODE)47) - -#define F_XML_UNI_0 ((FLMUNICODE)48) -#define F_XML_UNI_1 ((FLMUNICODE)49) -#define F_XML_UNI_2 ((FLMUNICODE)50) -#define F_XML_UNI_3 ((FLMUNICODE)51) -#define F_XML_UNI_4 ((FLMUNICODE)52) -#define F_XML_UNI_5 ((FLMUNICODE)53) -#define F_XML_UNI_6 ((FLMUNICODE)54) -#define F_XML_UNI_7 ((FLMUNICODE)55) -#define F_XML_UNI_8 ((FLMUNICODE)56) -#define F_XML_UNI_9 ((FLMUNICODE)57) - -#define F_XML_UNI_COLON ((FLMUNICODE)58) -#define F_XML_UNI_SEMI ((FLMUNICODE)59) -#define F_XML_UNI_LT ((FLMUNICODE)60) -#define F_XML_UNI_EQ ((FLMUNICODE)61) -#define F_XML_UNI_GT ((FLMUNICODE)62) -#define F_XML_UNI_QUEST ((FLMUNICODE)63) -#define F_XML_UNI_ATSIGN ((FLMUNICODE)64) - -#define F_XML_UNI_A ((FLMUNICODE)65) -#define F_XML_UNI_B ((FLMUNICODE)66) -#define F_XML_UNI_C ((FLMUNICODE)67) -#define F_XML_UNI_D ((FLMUNICODE)68) -#define F_XML_UNI_E ((FLMUNICODE)69) -#define F_XML_UNI_F ((FLMUNICODE)70) -#define F_XML_UNI_G ((FLMUNICODE)71) -#define F_XML_UNI_H ((FLMUNICODE)72) -#define F_XML_UNI_I ((FLMUNICODE)73) -#define F_XML_UNI_J ((FLMUNICODE)74) -#define F_XML_UNI_K ((FLMUNICODE)75) -#define F_XML_UNI_L ((FLMUNICODE)76) -#define F_XML_UNI_M ((FLMUNICODE)77) -#define F_XML_UNI_N ((FLMUNICODE)78) -#define F_XML_UNI_O ((FLMUNICODE)79) -#define F_XML_UNI_P ((FLMUNICODE)80) -#define F_XML_UNI_Q ((FLMUNICODE)81) -#define F_XML_UNI_R ((FLMUNICODE)82) -#define F_XML_UNI_S ((FLMUNICODE)83) -#define F_XML_UNI_T ((FLMUNICODE)84) -#define F_XML_UNI_U ((FLMUNICODE)85) -#define F_XML_UNI_V ((FLMUNICODE)86) -#define F_XML_UNI_W ((FLMUNICODE)87) -#define F_XML_UNI_X ((FLMUNICODE)88) -#define F_XML_UNI_Y ((FLMUNICODE)89) -#define F_XML_UNI_Z ((FLMUNICODE)90) - -#define F_XML_UNI_LBRACKET ((FLMUNICODE)91) -#define F_XML_UNI_RBRACKET ((FLMUNICODE)93) -#define F_XML_UNI_UNDERSCORE ((FLMUNICODE)95) - -#define F_XML_UNI_a ((FLMUNICODE)97) -#define F_XML_UNI_b ((FLMUNICODE)98) -#define F_XML_UNI_c ((FLMUNICODE)99) -#define F_XML_UNI_d ((FLMUNICODE)100) -#define F_XML_UNI_e ((FLMUNICODE)101) -#define F_XML_UNI_f ((FLMUNICODE)102) -#define F_XML_UNI_g ((FLMUNICODE)103) -#define F_XML_UNI_h ((FLMUNICODE)104) -#define F_XML_UNI_i ((FLMUNICODE)105) -#define F_XML_UNI_j ((FLMUNICODE)106) -#define F_XML_UNI_k ((FLMUNICODE)107) -#define F_XML_UNI_l ((FLMUNICODE)108) -#define F_XML_UNI_m ((FLMUNICODE)109) -#define F_XML_UNI_n ((FLMUNICODE)110) -#define F_XML_UNI_o ((FLMUNICODE)111) -#define F_XML_UNI_p ((FLMUNICODE)112) -#define F_XML_UNI_q ((FLMUNICODE)113) -#define F_XML_UNI_r ((FLMUNICODE)114) -#define F_XML_UNI_s ((FLMUNICODE)115) -#define F_XML_UNI_t ((FLMUNICODE)116) -#define F_XML_UNI_u ((FLMUNICODE)117) -#define F_XML_UNI_v ((FLMUNICODE)118) -#define F_XML_UNI_w ((FLMUNICODE)119) -#define F_XML_UNI_x ((FLMUNICODE)120) -#define F_XML_UNI_y ((FLMUNICODE)121) -#define F_XML_UNI_z ((FLMUNICODE)122) - -#define F_XML_UNI_PIPE ((FLMUNICODE)124) -#define F_XML_UNI_TILDE ((FLMUNICODE)126) - -/**************************************************************************** -Desc: -****************************************************************************/ -typedef struct XMLCHAR -{ - FLMBYTE ucFlags; -} XMLCHAR; - -/**************************************************************************** -Desc: -****************************************************************************/ -class F_XML : public F_Base -{ -public: - - F_XML(); - - virtual ~F_XML(); - - FLMBOOL isPubidChar( - FLMUNICODE uChar); - - FLMBOOL isQuoteChar( - FLMUNICODE uChar); - - FLMBOOL isWhitespace( - FLMUNICODE uChar); - - FLMBOOL isExtender( - FLMUNICODE uChar); - - FLMBOOL isCombiningChar( - FLMUNICODE uChar); - - FLMBOOL isNameChar( - FLMUNICODE uChar); - - FLMBOOL isIdeographic( - FLMUNICODE uChar); - - FLMBOOL isBaseChar( - FLMUNICODE uChar); - - FLMBOOL isDigit( - FLMUNICODE uChar); - - FLMBOOL isLetter( - FLMUNICODE uChar); - - void setCharFlag( - FLMUNICODE uLowChar, - FLMUNICODE uHighChar, - FLMUINT16 ui16Flag); - - FLMBOOL isNameValid( - const FLMUNICODE * puzName, - const char * pszName); - - RCODE buildCharTable( void); - -protected: - - POOL m_tmpPool; - -private: - - XMLCHAR * m_pCharTable; -}; - -/**************************************************************************** -Desc: FLAIM's XML export class -****************************************************************************/ -class F_XMLExport : public F_XML -{ -public: - - F_XMLExport(); - - virtual ~F_XMLExport(); - - RCODE setup( void); - - // Methods - - RCODE exportRecord( - F_NameTable * pNameTable, - FlmRecord * pRec, - FLMUINT uiStartIndent, - FLMUINT uiIndentSize, - POOL * pPool, - char ** ppszXML, - FLMUINT * puiBytes); - -private: - - FLMBYTE m_szSpaces[ 256]; - FLMUINT m_uiTmpBufSize; - FLMBYTE * m_pszTmpBuf; - FCS_BIOS * m_pByteStream; - FLMBOOL m_bSetup; -}; - -typedef enum eFlmXMLTokenType -{ - FLM_XML_STAG, - FLM_XML_ETAG, - FLM_XML_COMMENT, - FLM_XML_CHAR_DATA -} FlmXMLTokenType; - -/**************************************************************************** -Desc: FLAIM's XML import class -****************************************************************************/ -class F_XMLImport: public F_XML -{ -public: - - F_XMLImport(); - - virtual ~F_XMLImport(); - - RCODE setup( void); - - RCODE importDocument( - HFDB hDb, - F_NameTable * pNameTable, - FCS_ISTM * pStream, - FLMBOOL bSubset, - FlmRecord ** ppRecord); - - void reset( void); - -private: - - RCODE getFieldTagAndType( - FLMUNICODE * puzName, - FLMUINT * puiTagNum, - FLMUINT * puiDataType); - - RCODE getByte( - FLMBYTE * pucByte); - - RCODE ungetByte( - FLMBYTE ucByte); - - RCODE ungetChar( - FLMUNICODE uChar); - - RCODE ungetChars( - FLMUNICODE * puChars, - FLMUINT uiChars); - - RCODE peekChar( - FLMUNICODE * puChar); - - RCODE getName( - FLMUNICODE * puzName, - FLMUINT * puiChars); - - RCODE getNmtoken( - FLMUNICODE * puzName, - FLMUINT * puiChars); - - RCODE getPubidLiteral( - FLMUNICODE * puBuf, - FLMUINT * puiMaxChars); - - RCODE getSystemLiteral( - FLMUNICODE * puBuf, - FLMUINT * puiMaxChars); - - RCODE getChar( - FLMUNICODE * pChar); - - RCODE getChars( - FLMUNICODE * uzChars, - FLMUINT * puiCount); - - RCODE getCharEntity( - FLMUNICODE * puChar); - - RCODE getElementValue( - FLMUNICODE * puBuf, - FLMUINT * puiMaxChars, - FLMBOOL * pbEntity); - - RCODE processEntityValue( - FlmRecord * pRec, - void * pvParent); - - RCODE getEntity( - FLMUNICODE * puBuf, - FLMUINT * puiChars, - FLMBOOL * pbTranslated, - FLMUNICODE * puTransChar); - - RCODE processReference( - FlmRecord * pRec, - void * pvParent, - FLMUNICODE * puChar = NULL); - - RCODE processCDATA( - FlmRecord * pRec, - void * pvParent); - - RCODE processAttributes( - HFDB hDb, - FlmRecord * pRec, - void * pvParent); - - RCODE processComment( - FlmRecord * pRec, - void * pvParent); - - RCODE processProlog( - FlmRecord * pRec, - void * pvParent); - - RCODE processXMLDecl( - FlmRecord * pRec, - void * pvParent); - - RCODE processVersion( - FlmRecord * pRec, - void * pvParent); - - RCODE processEncodingDecl( - FlmRecord * pRec, - void * pvParent); - - RCODE processSDDecl( - FlmRecord * pRec, - void * pvParent); - - RCODE processMisc( - FlmRecord * pRec, - void * pvParent); - - RCODE processDocTypeDecl( - FlmRecord * pRec, - void * pvParent); - - RCODE processPI( - FlmRecord * pRec, - void * pvParent); - - RCODE processElement( - FlmRecord * pRec, - void * pvParent); - - RCODE unicodeToNumber( - const FLMUNICODE * puzVal, - FLMUINT * puiVal, - FLMBOOL * pbNeg); - - RCODE setElementValue( - FlmRecord * pRec, - void * pvField, - const FLMUNICODE * puzValue); - - RCODE processAttributes( - FlmRecord * pRec, - void * pvParent); - - RCODE processMarkupDecl( - FlmRecord * pRec, - void * pvParent); - - RCODE processPERef( - FlmRecord * pRec, - void * pvParent); - - RCODE processElementDecl( - FlmRecord * pRec, - void * pvParent); - - RCODE processEntityDecl( - FlmRecord * pRec, - void * pvParent); - - RCODE processNotationDecl( - FlmRecord * pRec, - void * pvParent); - - RCODE processAttListDecl( - FlmRecord * pRec, - void * pvParent); - - RCODE processContentSpec( - FlmRecord * pRec, - void * pvParent); - - RCODE processMixedContent( - FlmRecord * pRec, - void * pvParent); - - RCODE processChildContent( - FlmRecord * pRec, - void * pvParent); - - RCODE processAttDef( - FlmRecord * pRec, - void * pvParent); - - RCODE processAttType( - FlmRecord * pRec, - void * pvParent); - - RCODE processAttValue( - FlmRecord * pRec, - void * pvParent); - - RCODE processDefaultDecl( - FlmRecord * pRec, - void * pvParent); - - RCODE processID( - FlmRecord * pRec, - void * pvParent, - FLMBOOL * pbPublicId); - - RCODE processSTag( - FlmRecord * pRec, - void * pvParent, - FLMBOOL * pbHasContent, - void ** ppvElementRoot); - - RCODE skipWhitespace( - void * pvParent, - FLMBOOL bRequired = FALSE); - - RCODE skipName( void); - - RCODE skipEntity( void); - - RCODE isXMLDecl( - FLMBOOL * pbIsXMLDecl); - - RCODE isDocTypeDecl( - FLMBOOL * pbIsDocTypeDecl); - - // Data - - FLMBOOL m_bSubset; - FLMUINT m_uiUngetPos; -#define F_XML_MAX_UNGET 32 - FLMUNICODE m_puUngetBuf[ F_XML_MAX_UNGET]; -#define F_XML_MAX_CHARS 128 - FLMUNICODE m_uChars[ F_XML_MAX_CHARS]; - FLMBYTE m_ucUngetByte; - FLMBOOL m_bSetup; - FCS_ISTM * m_pStream; - FLMUNICODE * m_puValBuf; - FLMUINT m_uiValBufSize; // Number of Unicode characters - F_NameTable * m_pNameTable; - HFDB m_hDb; -}; - -#include "fpackoff.h" - -#endif // FXML_H diff --git a/flaim/src/gdpool.cpp b/flaim/src/gdpool.cpp deleted file mode 100644 index e2d1446..0000000 --- a/flaim/src/gdpool.cpp +++ /dev/null @@ -1,381 +0,0 @@ -//------------------------------------------------------------------------- -// Desc: Memory pool routines. -// Tabs: 3 -// -// Copyright (c) 1992-2001,2003-2006 Novell, Inc. All Rights Reserved. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of version 2 of the GNU General Public -// License as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, contact Novell, Inc. -// -// To contact Novell about this file by physical or electronic mail, -// you may find current contact information at www.novell.com -// -// $Id: gdpool.cpp 12329 2006-01-20 17:49:30 -0700 (Fri, 20 Jan 2006) ahodgkinson $ -//------------------------------------------------------------------------- - -#include "flaimsys.h" - -#if defined( FLM_UNIX) || defined( FLM_NLM) || defined( FLM_WIN) - - #define PTR_IN_MBLK(p,bp,offs) (((FLMBYTE *)(p) > (FLMBYTE *)(bp)) && \ - ((FLMBYTE *)(p) <= (FLMBYTE *)(bp) + (offs))) -#else - #error Platform not supported -#endif - -FSTATIC RCODE GedPoolFreeToMark( - POOL * pPool, - void * markPtr); - -/**************************************************************************** -Desc: Initializes a memory pool -****************************************************************************/ -FLMEXP void FLMAPI GedPoolInit( - POOL * pPool, - FLMUINT uiBlkSize) -{ - pPool->uiBytesAllocated = 0; - pPool->lblk = NULL; - pPool->pPoolStats = NULL; - pPool->uiBlkSize = uiBlkSize; -} - -/**************************************************************************** -Desc: Returns a "marker" to the current offset in the memory pool -****************************************************************************/ -FLMEXP void * FLMAPI GedPoolMark( - POOL * pPool) -{ - return (void *)((pPool->lblk) - ? (FLMBYTE *) pPool->lblk + pPool->lblk->uiFreeOfs - : (FLMBYTE *)GedPoolAlloc( pPool, 1)); -} - -/**************************************************************************** -Desc: Determine what the initial block size should be for smart pools. -****************************************************************************/ -FINLINE void SetInitialSmartPoolBlkSize( - POOL * pPool) -{ - /* - Determine starting block size: - 1) average of bytes allocated / # of frees/resets (average size needed) - 2) add 10% - to minimize extra allocs - */ - pPool->uiBlkSize = (pPool->pPoolStats->uiAllocBytes / pPool->pPoolStats->uiCount); - - pPool->uiBlkSize += (pPool->uiBlkSize / 10); - - if( pPool->uiBlkSize < 512) - pPool->uiBlkSize = 512; -} - -/**************************************************************************** -Desc: Update the bytes allocated and alloc count for this pool's POOL_STATS -****************************************************************************/ -FINLINE void UpdateSmartPoolStats( - POOL * pPool) -{ - if( pPool->uiBytesAllocated) - { - POOL_STATS * pStats = pPool->pPoolStats; - if( (pStats->uiAllocBytes + pPool->uiBytesAllocated) >= 0xFFFF0000) - { - pStats->uiAllocBytes = (pStats->uiAllocBytes / pStats->uiCount) * 100; - pStats->uiCount = 100; - } - else - { - pStats->uiAllocBytes += pPool->uiBytesAllocated; - pStats->uiCount++; - } - pPool->uiBytesAllocated = 0; - } -} - -/************************************************************************* -Desc: Initialize a smart pool memory structure. A smart pool is one that - will adjust it's block allocation size based on statistics it - gathers within the POOL_STATS structure. For each pool that user - wants to use smart memory management a global POOL_STATS structure - should be declared. The POOL_STATS structure is used to track the - total bytes allocated and determine what the correct pool block - size should be. -*************************************************************************/ -void GedSmartPoolInit( - POOL * pPool, - POOL_STATS * pPoolStats) -{ - pPool->lblk = NULL; - pPool->uiBytesAllocated = 0; - pPool->pPoolStats = pPoolStats; - - if( pPoolStats && pPoolStats->uiCount) - { - SetInitialSmartPoolBlkSize( pPool); - } - else - { - pPool->uiBlkSize = 2048; - } -} - -/**************************************************************************** -Desc: Allocates a block of memory from a memory pool. -Note: If the number of bytes is more than the what is left in the - current block then a new block will be allocated and the lbkl element - of the PMS will be updated. -****************************************************************************/ -FLMEXP void * FLMAPI GedPoolAlloc( - POOL * pPool, - FLMUINT uiSize) -{ - MBLK * blk = pPool->lblk; - MBLK * old_lblk = blk; - FLMBYTE * freePtr; - FLMUINT uiBlkSize; - - // Adjust the size to a machine word boundary - // NOTE: ORed and ANDed 0x800.. & 0x7FFF to prevent partial - // stalls on Netware. - - if( uiSize & (FLM_ALLOC_ALIGN | 0x80000000)) - { - uiSize = ((uiSize + FLM_ALLOC_ALIGN) & (~(FLM_ALLOC_ALIGN) & 0x7FFFFFFF)); - } - - // Check if room in block - - if( ! blk || uiSize > blk->uiFreeSize) - { - // Check if previous block has space for allocation - - if( blk && blk->pPrevBlk != NULL && uiSize <= blk->pPrevBlk->uiFreeSize) - { - blk = blk->pPrevBlk; - goto Exit; - } - - /* Not enough memory in block - allocate new block */ - - /* Determine the block size: - 1) start with max of last block size, initial pool size, or alloc size - 2) if this is an extra block alloc then increase the size by 1/2 - 3) adjust size to include blk header */ - - uiBlkSize = (blk) ? blk->uiBlkSize : pPool->uiBlkSize; - uiBlkSize = f_max( uiSize, uiBlkSize); - - if( blk && (uiBlkSize == blk->uiBlkSize) && uiBlkSize <= 32769) - uiBlkSize += uiBlkSize / 2; - - uiBlkSize += sizeof( MBLK); - - if( RC_BAD( f_alloc( uiBlkSize, &blk))) - return( NULL); - - // Initialize the block elements - - blk->uiBlkSize = uiBlkSize; - blk->uiFreeOfs = sizeof( MBLK); - blk->uiFreeSize = uiBlkSize - sizeof( MBLK); - - pPool->lblk = blk; - blk->pPrevBlk = old_lblk; - } - -Exit: - freePtr = (FLMBYTE *) blk; - freePtr += blk->uiFreeOfs; - blk->uiFreeOfs += uiSize; - blk->uiFreeSize -= uiSize; - - pPool->uiBytesAllocated += uiSize; - return( (void *) freePtr); -} - -/************************************************************************ -Desc: Allocates memory from a pool and initializes all bytes to zero. -*END*********************************************************************/ -FLMEXP void * FLMAPI GedPoolCalloc( - POOL * pPool, - FLMUINT uiSize) -{ - void * ptr; - - if( (ptr = GedPoolAlloc( pPool, uiSize)) != NULL) - { - f_memset( ptr, 0, uiSize); - } - return ptr; -} - -/**************************************************************************** -Desc: Releases all memory allocated to a pool. -Note: All memory allocated to the pool is returned to the operating system. -****************************************************************************/ -FLMEXP RCODE FLMAPI GedPoolFree( - POOL * pPool) -{ - MBLK * blk = pPool->lblk; - MBLK * prevBlk; - - while( blk) - { - prevBlk = blk->pPrevBlk; - f_free( &blk); - blk = prevBlk; - } - - pPool->lblk = NULL; - - // For Smart Pools update pool statictics - - if( pPool->pPoolStats) - { - UpdateSmartPoolStats( pPool); - } - - return( FERR_OK); -} - -/**************************************************************************** -Desc: Resets memory blocks allocated to a pool. -Note: Will reset the free space in the first memory block, and if - any extra blocks exist they will be freed (destroyed). -****************************************************************************/ -FLMEXP RCODE FLMAPI GedPoolReset( - POOL * pPool, - void * markPtr) -{ - MBLK * blk = pPool->lblk; - MBLK * prevBlk; - - if( ! blk) - return( FERR_OK); - - // For Smart Pools update pool statictics - - if( pPool->pPoolStats) - { - UpdateSmartPoolStats( pPool); - } - - if( markPtr) - { - return( GedPoolFreeToMark( pPool, markPtr)); - } - - // Free all blocks except last one in chain -- which is really - // the first block allocated. This will help us keep memory from - // getting fragmented. - - while( blk->pPrevBlk) - { - prevBlk = blk->pPrevBlk; - f_free( &blk); - blk = prevBlk; - } - - if( (blk->uiBlkSize - sizeof(MBLK)) > pPool->uiBlkSize) - { - // The first block was not the default size, so FREE it - - f_free( &blk); - pPool->lblk = NULL; - } - else - { - // Reset the allocation pointers in the first block - - blk->uiFreeOfs = sizeof( MBLK); - blk->uiFreeSize = blk->uiBlkSize - sizeof( MBLK); - pPool->lblk = blk; - -#ifdef FLM_MEM_CHK - { - FLMBYTE * ptr = (FLMBYTE *) blk; - ptr += blk->uiFreeOfs; - f_memset( ptr, 'r', blk->uiFreeSize); - } -#endif - } - - // On smart pools, adjust the initial block size on pool resets - - if( pPool->pPoolStats) - { - SetInitialSmartPoolBlkSize( pPool); - } - - return( FERR_OK); -} - -/**************************************************************************** -Desc: Frees memory until the markPtr is found. -****************************************************************************/ -FSTATIC RCODE GedPoolFreeToMark( - POOL * pPool, - void * markPtr) -{ - MBLK * blk = pPool->lblk; - MBLK * prevBlk; - - pPool->lblk = NULL; /* Initialize PMS to no BLOCKS */ - - while( blk) /* Free all allocated blks in chain */ - { - prevBlk = blk->pPrevBlk; /* Save pointer to prev block */ - - /* Check for mark point */ - if( PTR_IN_MBLK( markPtr, blk, blk->uiBlkSize)) - { - FLMUINT uiOldFreeOfs = blk->uiFreeOfs; - - /* Reset freeOfs and freeSize variables */ - blk->uiFreeOfs = (FLMUINT)((FLMBYTE *)markPtr - (FLMBYTE *)blk); - blk->uiFreeSize = blk->uiBlkSize - blk->uiFreeOfs; - -#if defined( FLM_MEM_CHK) || defined( MEM_TEST) - { - /* memset the memory so someone pointing to it will get a error.*/ - FLMBYTE * ptr = (FLMBYTE *) blk; - ptr += blk->uiFreeOfs; - f_memset( ptr, 'r', blk->uiFreeSize); // Set memory to 'r' for Reset - } -#endif - - // For Smart Pools deduct the bytes allocated since pool mark - - if( pPool->pPoolStats) - { - flmAssert( uiOldFreeOfs >= blk->uiFreeOfs); - pPool->uiBytesAllocated -= (uiOldFreeOfs - blk->uiFreeOfs); - } - - break; - } - - if( pPool->pPoolStats) - { - pPool->uiBytesAllocated -= (blk->uiFreeOfs - sizeof( MBLK)); - } - - f_free( &blk); - blk = prevBlk; /* Point to previous block */ - } - - if( blk) - pPool->lblk = blk; - - return( FERR_OK); -} diff --git a/flaim/src/imonbase.cpp b/flaim/src/imonbase.cpp index 1a3f24e..f17f956 100644 --- a/flaim/src/imonbase.cpp +++ b/flaim/src/imonbase.cpp @@ -222,7 +222,7 @@ void F_WebPage::FormatTime( // Convert the timer units to milliseconds - FLM_TIMER_UNITS_TO_MILLI( uiTimerUnits, uiMilli); + uiMilli = FLM_TIMER_UNITS_TO_MILLI( uiTimerUnits); // Determine the number of days @@ -574,7 +574,7 @@ RCODE F_WebPage::getFormValueByName( bFreeFormData = TRUE; - if (fnRecvBuffer( m_pszFormData, (size_t*) &uiContentLength) != 0) + if (fnRecvBuffer( m_pszFormData, (FLMSIZET *) &uiContentLength) != 0) { rc = RC_SET( FERR_FAILURE); goto Exit; @@ -1241,7 +1241,7 @@ RCODE F_WebPage::acquireSession(void) uiSize = sizeof(szSessionKey); if (fnGetSessionValue( pvHttpSession, FLM_SESSION_ID_NAME, - (void*) szSessionKey, (size_t*) &uiSize) != 0) + (void*) szSessionKey, (FLMSIZET *) &uiSize) != 0) { CreateSession: diff --git a/flaim/src/imonchk.cpp b/flaim/src/imonchk.cpp index b88e147..1c19679 100644 --- a/flaim/src/imonchk.cpp +++ b/flaim/src/imonchk.cpp @@ -51,7 +51,7 @@ FSTATIC void freeCheckStatus( FLMBOOL bFreeStruct); FSTATIC void imonLogField( - F_FileHdl * pLogFile, + IF_FileHdl * pLogFile, F_NameTable * pNameTable, FlmRecord * pRecord, void * pvField, @@ -59,12 +59,12 @@ FSTATIC void imonLogField( FLMUINT uiLevelOffset); FSTATIC void imonLogKeyError( - F_FileHdl * pLogFile, + IF_FileHdl * pLogFile, F_NameTable * pNameTable, CORRUPT_INFO * pCorrupt); FSTATIC void imonLogCorruptError( - F_FileHdl * pLogFile, + IF_FileHdl * pLogFile, F_NameTable * pNameTable, CORRUPT_INFO * pCorrupt); @@ -75,10 +75,10 @@ FSTATIC RCODE CheckStatusCB( void * pvAppData); FSTATIC RCODE imonDoCheck( - F_Thread * pThread); + IF_Thread * pThread); FSTATIC void imonLogStr( - F_FileHdl * pLogFile, + IF_FileHdl * pLogFile, FLMUINT uiIndent, const char * pszStr); @@ -561,10 +561,11 @@ void F_CheckDbPage::outputCheckForm( F_NameTable * pNameTable, FLMUINT uiCheckThreadId) { - FLMBOOL bHighlight = FALSE; - char szTmp [128]; - char * pszTmp; - char * pszName; + FLMBOOL bHighlight = FALSE; + char szTmp [128]; + char * pszTmp; + char * pszName; + IF_FileHdl * pFileHdl = NULL; fnPrintf( m_pHRequest, "
bCheckRunning && pCheckStatus->bHaveCheckStatus && pCheckStatus->uiCorruptCount && pCheckStatus->pszLogFileName) { - F_FileHdl * pFileHdl; - fnPrintf( m_pHRequest, "

------LOG FILE CONTENTS------\n");
 
 		// Open the log file
 
-		if (RC_OK( gv_FlmSysData.pFileSystem->Open( pCheckStatus->pszLogFileName,
-											F_IO_RDWR | F_IO_SH_DENYNONE, &pFileHdl)))
+		if (RC_OK( gv_FlmSysData.pFileSystem->openFile( 
+			pCheckStatus->pszLogFileName, FLM_IO_RDWR | FLM_IO_SH_DENYNONE,
+			&pFileHdl)))
 		{
 			RCODE		rc;
 			FLMUINT	uiBytesRead;
@@ -848,9 +848,8 @@ void F_CheckDbPage::outputCheckForm(
 
 			for (;;)
 			{
-				if (RC_BAD( rc = pFileHdl->Read( F_IO_CURRENT_POS,
-						sizeof( szTmp) - 1,
-						&szTmp [0], &uiBytesRead)))
+				if (RC_BAD( rc = pFileHdl->read( FLM_IO_CURRENT_POS,
+						sizeof( szTmp) - 1, szTmp, &uiBytesRead)))
 				{
 					if (rc != FERR_IO_END_OF_FILE || !uiBytesRead)
 					{
@@ -867,14 +866,19 @@ void F_CheckDbPage::outputCheckForm(
 					break;
 				}
 			}
-			pFileHdl->Close();
+			
 			pFileHdl->Release();
+			pFileHdl = NULL;
 		}
+		
 		fnPrintf( m_pHRequest, "\n------END OF LOG FILE------\n");
 		fnPrintf( m_pHRequest, "
\n"); } - - //VISIT: Output detailed information, if we collected it. + + if( pFileHdl) + { + pFileHdl->Release(); + } } /**************************************************************************** @@ -942,17 +946,19 @@ FSTATIC void freeCheckStatus( { FlmDbClose( &pCheckStatus->hDb); } + if (pCheckStatus->pLogFile) { - pCheckStatus->pLogFile->Close(); pCheckStatus->pLogFile->Release(); pCheckStatus->pLogFile = NULL; } + if (pCheckStatus->pNameTable) { pCheckStatus->pNameTable->Release(); pCheckStatus->pNameTable = NULL; } + f_free( &pCheckStatus); } } @@ -975,7 +981,7 @@ RCODE F_CheckDbPage::runCheck( { RCODE rc = FERR_OK; CHECK_STATUS * pCheckStatus = NULL; - F_Thread * pThread; + IF_Thread * pThread; HFDB hDb = HFDB_NULL; FDB * pDb; @@ -1066,10 +1072,10 @@ RCODE F_CheckDbPage::runCheck( if (pCheckStatus->pszLogFileName) { - gv_FlmSysData.pFileSystem->Delete( pCheckStatus->pszLogFileName); - if (RC_BAD( gv_FlmSysData.pFileSystem->Create( - pCheckStatus->pszLogFileName, - F_IO_RDWR | F_IO_SH_DENYNONE, + gv_FlmSysData.pFileSystem->deleteFile( pCheckStatus->pszLogFileName); + + if (RC_BAD( gv_FlmSysData.pFileSystem->createFile( + pCheckStatus->pszLogFileName, FLM_IO_RDWR | FLM_IO_SH_DENYNONE, &pCheckStatus->pLogFile))) { f_free( &pCheckStatus->pszLogFileName); @@ -1097,12 +1103,12 @@ RCODE F_CheckDbPage::runCheck( // If browser does not check status at least every 15 seconds, we will // assume it has gone away and the thread will terminate itself. - FLM_SECS_TO_TIMER_UNITS( 15, pCheckStatus->uiCheckTimeout); + pCheckStatus->uiCheckTimeout = FLM_SECS_TO_TIMER_UNITS( 15); // Start a thread to do the check. if (RC_BAD( rc = f_threadCreate( &pThread, imonDoCheck, - "WEB DB CHECK", FLM_DB_THREAD_GROUP, 1, + "WEB DB CHECK", gv_uiDbThrdGrp, 1, (void *)pCheckStatus, (void *)hDb))) { goto Exit; @@ -1146,7 +1152,7 @@ void F_CheckDbPage::getCheckStatus( ) { FLMUINT uiThreadId; - F_Thread * pThread = NULL; + IF_Thread * pThread = NULL; CHECK_STATUS * pThreadCheckStatus; FLMBOOL bMutexLocked = FALSE; @@ -1162,7 +1168,7 @@ void F_CheckDbPage::getCheckStatus( for (;;) { if (RC_BAD( gv_FlmSysData.pThreadMgr->getNextGroupThread( &pThread, - FLM_DB_THREAD_GROUP, &uiThreadId))) + gv_uiDbThrdGrp, &uiThreadId))) { pCheckStatus->bCheckRunning = FALSE; goto Exit; @@ -1283,7 +1289,7 @@ Exit: Desc: Log a string to the log file. *********************************************************************/ FSTATIC void imonLogStr( - F_FileHdl * pLogFile, + IF_FileHdl * pLogFile, FLMUINT uiIndent, const char * pszStr) { @@ -1302,8 +1308,8 @@ FSTATIC void imonLogStr( { if (uiLoop == sizeof( szBuffer)) { - pLogFile->Write( F_IO_CURRENT_POS, - uiLoop, szBuffer, &uiBytesWritten); + pLogFile->write( FLM_IO_CURRENT_POS, uiLoop, + szBuffer, &uiBytesWritten); uiLoop = 0; } szBuffer [uiLoop++] = *pszStr; @@ -1312,21 +1318,21 @@ FSTATIC void imonLogStr( } if (uiLoop >= sizeof( szBuffer) - 2) { - pLogFile->Write( F_IO_CURRENT_POS, - uiLoop, szBuffer, &uiBytesWritten); + pLogFile->write( FLM_IO_CURRENT_POS, + uiLoop, szBuffer, &uiBytesWritten); uiLoop = 0; } szBuffer [uiLoop++] = '\r'; szBuffer [uiLoop++] = '\n'; - pLogFile->Write( F_IO_CURRENT_POS, - uiLoop, szBuffer, &uiBytesWritten); + pLogFile->write( FLM_IO_CURRENT_POS, + uiLoop, szBuffer, &uiBytesWritten); } /*************************************************************************** Desc: Log a field's data. *****************************************************************************/ FSTATIC void imonLogField( - F_FileHdl * pLogFile, + IF_FileHdl * pLogFile, F_NameTable * pNameTable, FlmRecord * pRecord, void * pvField, @@ -1414,10 +1420,9 @@ Exit: Desc: Log an index key corruption error. *********************************************************************/ FSTATIC void imonLogKeyError( - F_FileHdl * pLogFile, + IF_FileHdl * pLogFile, F_NameTable * pNameTable, - CORRUPT_INFO * pCorrupt - ) + CORRUPT_INFO * pCorrupt) { FLMUINT uiLogItem; FlmRecord * pRecord = NULL; @@ -1523,10 +1528,9 @@ FSTATIC void imonLogKeyError( Desc: Log corruptions to log file. *********************************************************************/ FSTATIC void imonLogCorruptError( - F_FileHdl * pLogFile, + IF_FileHdl * pLogFile, F_NameTable * pNameTable, - CORRUPT_INFO * pCorrupt - ) + CORRUPT_INFO * pCorrupt) { char szWhat [20]; char szTmpBuf [100]; @@ -1681,7 +1685,7 @@ FSTATIC void imonLogCorruptError( imonLogStr( pLogFile, 2, szTmpBuf); imonLogStr( pLogFile, 0, NULL); - pLogFile->Flush(); + pLogFile->flush(); } /*************************************************************************** @@ -1789,19 +1793,19 @@ Exit: Desc: Thread to perform a database check for a web page. ****************************************************************************/ FSTATIC RCODE imonDoCheck( - F_Thread * pThread) + IF_Thread * pThread) { RCODE rc; CHECK_STATUS * pCheckStatus = (CHECK_STATUS *)pThread->getParm1(); FLMUINT uiFlags; - POOL pool; + F_Pool pool; DB_CHECK_PROGRESS CheckProgress; FLMUINT uiCurrTime; pThread->setThreadStatus( FLM_THREAD_STATUS_INITIALIZING); pCheckStatus->pThread = pThread; - FLM_SECS_TO_TIMER_UNITS( 5, pCheckStatus->uiUpdateStatusInterval); + pCheckStatus->uiUpdateStatusInterval = FLM_SECS_TO_TIMER_UNITS( 5); uiFlags = FLM_CHK_FIELDS; if (pCheckStatus->bCheckingIndexes) @@ -1810,17 +1814,18 @@ FSTATIC RCODE imonDoCheck( } pThread->setThreadStatus( FLM_THREAD_STATUS_RUNNING); - GedPoolInit( &pool, 512); + pool.poolInit( 512); + rc = FlmDbCheck( pCheckStatus->hDb, NULL, NULL, NULL, uiFlags, &pool, &CheckProgress, CheckStatusCB, pCheckStatus); - GedPoolFree( &pool); + + pool.poolFree(); // Close the database and log file before doing anything else. FlmDbClose( &pCheckStatus->hDb); if (pCheckStatus->pLogFile) { - pCheckStatus->pLogFile->Close(); pCheckStatus->pLogFile->Release(); pCheckStatus->pLogFile = NULL; } diff --git a/flaim/src/imonerr.cpp b/flaim/src/imonerr.cpp index 3cda47a..bf732a3 100644 --- a/flaim/src/imonerr.cpp +++ b/flaim/src/imonerr.cpp @@ -55,52 +55,12 @@ RCODE F_ErrorPage::display( } fnPrintf( m_pHRequest, "

\n"); - - printRandomHaiku (); - fnPrintf( m_pHRequest, "\n"); - fnEmit(); return( rc); } - -/**************************************************************************** - Desc: Picks a haiku from a list and prints it on the error page -****************************************************************************/ - -static f_randomGenerator gen; -static bool bSeeded = FALSE; - -void F_ErrorPage::printRandomHaiku () -{ - -#define NUM_HAIKUS 3 - //The list of haikus... - char szHaikuList[NUM_HAIKUS][256] = { - " You step in the stream,\n But the water has moved on.\n This page is not here.\n -Unknown author\n", - " To have no errors\n Would be life without meaning.\n No struggle, no joy.\n -Unknown author\n", - " The code was willing,\n It considered your request,\n But the chips were weak.\n -Unknown author\n" - }; - - int uiNum; - - if (!bSeeded) - { - f_randomSetSeed (&gen, 1); - bSeeded = TRUE; - } - - uiNum = f_randomChoice (&gen, 0, (NUM_HAIKUS - 1)); - - fnPrintf( m_pHRequest, "
\n");
-	fnPrintf( m_pHRequest, szHaikuList[uiNum]);
-	fnPrintf( m_pHRequest, "
\n"); - - return; -} - /**************************************************************************** Desc: Page that is displayed when a URL is requested for a page requireing secure access but the Global security is not enabled or has expired. diff --git a/flaim/src/imonfact.cpp b/flaim/src/imonfact.cpp index 662f674..9236c4b 100644 --- a/flaim/src/imonfact.cpp +++ b/flaim/src/imonfact.cpp @@ -313,7 +313,7 @@ FLMBOOL F_WebPageFactory::isSecurePasswordEntered( flmAssert( pvSession); if (fnGetSessionValue( pvSession, FLM_SECURE_PASSWORD, (void *)szData, - (size_t *)&uiSize) == 0) + (FLMSIZET *)&uiSize) == 0) { szData[ uiSize] = '\0'; bResult = isValidSecurePassword( szData); @@ -340,7 +340,7 @@ FLMBOOL F_WebPageFactory::isValidSecurePassword( if (fnGetGblValue( FLM_SECURE_PASSWORD, szPassword, - (size_t *)&uiSize) == 0) + (FLMSIZET *)&uiSize) == 0) { szPassword[ uiSize] = '\0'; if (f_strcmp(pszData, szPassword) == 0) @@ -374,7 +374,7 @@ FLMBOOL F_WebPageFactory::isSecureAccessEnabled() // has not been set. if (fnGetGblValue( FLM_SECURE_EXPIRATION, szExpiration, - (size_t *)&uiExpSize) == 0) + (FLMSIZET *)&uiExpSize) == 0) { uiExpTime = f_atoud( szExpiration); @@ -395,228 +395,208 @@ FLMBOOL F_WebPageFactory::isSecureAccessEnabled() ****************************************************************************/ static F_WebPage * createErrorPage() { - return new F_ErrorPage; + return f_new F_ErrorPage; } static F_WebPage * createGblAccessPage() { - return new F_GblAccessPage; + return f_new F_GblAccessPage; } static F_WebPage * createSessionAccessPage() { - return new F_SessionAccessPage; + return f_new F_SessionAccessPage; } static F_WebPage * createSCacheBlockPage() { - return new F_SCacheBlockPage; + return f_new F_SCacheBlockPage; } static F_WebPage * createSCacheHashTablePage() { - return new F_SCacheHashTablePage; + return f_new F_SCacheHashTablePage; } static F_WebPage * createSCacheUseListPage() { - return new F_SCacheUseListPage; + return f_new F_SCacheUseListPage; } static F_WebPage * createSCacheNotifyListPage() { - return new F_SCacheNotifyListPage; + return f_new F_SCacheNotifyListPage; } static F_WebPage * createSCacheDataPage() { - return new F_SCacheDataPage; + return f_new F_SCacheDataPage; } static F_WebPage * createSCacheMgrPage() { - return new F_SCacheMgrPage; + return f_new F_SCacheMgrPage; } static F_WebPage * createQueriesPage() { - return new F_QueriesPage; + return f_new F_QueriesPage; } static F_WebPage * createQueryPage() { - return new F_QueryPage; + return f_new F_QueryPage; } static F_WebPage * createQueryStatsPage() { - return new F_QueryStatsPage; + return f_new F_QueryStatsPage; } static F_WebPage * createSysConfigPage() { - return new F_SysConfigPage; + return f_new F_SysConfigPage; } static F_WebPage * createStatsPage() { - return new F_StatsPage; + return f_new F_StatsPage; } static F_WebPage * createFlmSysDataPage() { - return new F_FlmSysDataPage; + return f_new F_FlmSysDataPage; } static F_WebPage * createHttpConfigParmsPage() { - return new F_HttpConfigParmsPage; + return f_new F_HttpConfigParmsPage; } static F_WebPage * createFlmThreadsPage() { - return new F_FlmThreadsPage; + return f_new F_FlmThreadsPage; } static F_WebPage * createFlmIndexPage() { - return new F_FlmIndexPage; + return f_new F_FlmIndexPage; } static F_WebPage * createIndexListPage() { - return new F_IndexListPage; + return f_new F_IndexListPage; } static F_WebPage * createSelectPage() { - return new F_SelectPage; + return f_new F_SelectPage; } static F_WebPage * createCheckDbPage() { - return new F_CheckDbPage; + return f_new F_CheckDbPage; } static F_WebPage * serveFile() { - return new F_HttpFile; + return f_new F_HttpFile; } static F_WebPage * createDbBackupPage() { - return new F_HttpDbBackup; + return f_new F_HttpDbBackup; } static F_WebPage * createFileHashTblPage() { - return new F_FileHashTblPage; + return f_new F_FileHashTblPage; } static F_WebPage * createFFilePage() { - return new F_FFilePage; -} - -static F_WebPage * createFileHdlMgrPage() -{ - return new F_FileHdlMgrPage; -} - -static F_WebPage * createFileHdlPage() -{ - return new F_FileHdlPage; + return f_new F_FFilePage; } static F_WebPage * createFDBPage() { - return new F_FDBPage; + return f_new F_FDBPage; } static F_WebPage * createRCacheMgrPage() { - return new F_RCacheMgrPage; + return f_new F_RCacheMgrPage; } static F_WebPage * createRCachePage() { - return new F_RCachePage; + return f_new F_RCachePage; } static F_WebPage * createRecordMgrPage() { - return new F_RecordMgrPage; + return f_new F_RecordMgrPage; } static F_WebPage * createRCHashBucketPage() { - return new F_RCHashBucketPage; + return f_new F_RCHashBucketPage; } // Frame pages static F_WebPage * createHeaderFrame() { - return new F_FrameHeader; + return f_new F_FrameHeader; } static F_WebPage * createMainFrame() { - return new F_FrameMain; + return f_new F_FrameMain; } static F_WebPage * createNavFrame() { - return new F_FrameNav; + return f_new F_FrameNav; } static F_WebPage * createWelcomeFrame() { - return new F_FrameWelcome; + return f_new F_FrameWelcome; } static F_WebPage * createSecureDbAccessPage() { - return new F_SecureDbAccess; + return f_new F_SecureDbAccess; } static F_WebPage * createSecureDbInfoPage() { - return new F_SecureDbInfo; -} - -static F_WebPage * createServerLockMgrPage() -{ - return new F_ServerLockMgrPage; + return f_new F_SecureDbInfo; } static F_WebPage * createDatabaseConfigPage() { - return new F_DatabaseConfigPage; -} - -static F_WebPage * createRCodeLookupPage() -{ - return new F_RCodeLookupPage; + return f_new F_DatabaseConfigPage; } static F_WebPage * createDatabasePage() { - return new F_DatabasePage; + return f_new F_DatabasePage; } static F_WebPage * createRecordPage() { - return new F_RecordPage; + return f_new F_RecordPage; } static F_WebPage * createProcessRecordPage() { - return new F_ProcessRecordPage; + return f_new F_ProcessRecordPage; } static F_WebPage * createLogHeaderPage() { - return new F_LogHeaderPage; + return f_new F_LogHeaderPage; } // Initialize the static variables in the class... @@ -629,8 +609,6 @@ RegistryEntry F_WebPageFactory::m_Registry[] = { {"FDB", createFDBPage, FALSE}, {"FFile", createFFilePage, FALSE}, {"FileHashTbl", createFileHashTblPage, FALSE}, - {"FileHdl", createFileHdlPage, FALSE}, - {"FileHdlMgr", createFileHdlMgrPage, FALSE}, {"FlmSysData", createFlmSysDataPage, FALSE}, {"Header.htm", createHeaderFrame, FALSE}, {"HttpConfigParms", createHttpConfigParmsPage, FALSE}, @@ -652,7 +630,6 @@ RegistryEntry F_WebPageFactory::m_Registry[] = { {"SCacheUseList", createSCacheUseListPage, FALSE}, {"SecureDbAccess", createSecureDbAccessPage, FALSE}, {"SecureDbInfo", createSecureDbInfoPage, FALSE}, - {"ServerLockManager", createServerLockMgrPage, FALSE}, {"Stats", createStatsPage, FALSE}, {"SysConfig", createSysConfigPage, TRUE}, {"Welcome.htm", createWelcomeFrame, FALSE}, @@ -663,7 +640,6 @@ RegistryEntry F_WebPageFactory::m_Registry[] = { {"file", serveFile, TRUE}, {"index", createFlmIndexPage, TRUE}, {"indexlist", createIndexListPage, TRUE}, - {"returncode", createRCodeLookupPage, FALSE}, {"recordmgr", createRecordMgrPage, TRUE}, {"select", createSelectPage, TRUE}, {"staticfile", serveFile, FALSE}, diff --git a/flaim/src/imonffil.cpp b/flaim/src/imonffil.cpp index 733fb16..facd899 100644 --- a/flaim/src/imonffil.cpp +++ b/flaim/src/imonffil.cpp @@ -999,28 +999,6 @@ void F_FFilePage::write_data( (bHighlight = ~bHighlight)); - - - // pFileIdList - Unique File List - f_sprintf( (char *)szTemp, - "%s/F_FileIdList?From=FFile?" - "Link=pFileIdList?" - "Address=%s?Bucket=%lu", - m_pszURLString, - szFFileAddress, - (unsigned long)pFile->uiBucket); - - printHTMLLink( - "pFileIdList", - "F_FileIdList *", - (void *)pFile, - (void *)&pFile->pFileIdList, - (void *)pFile->pFileIdList, - (char *)szTemp, - (bHighlight = ~bHighlight)); - - - // pBufferMgr f_sprintf( (char *)szTemp, "%s/F_IOBufferMgr?From=FFile?" @@ -1441,29 +1419,6 @@ void F_FFilePage::write_data( (char *)(pFile->bBackupActive ? "Yes" : "No"), (bHighlight = ~bHighlight)); - - - - // pECacheMgr - if (pFile->pECacheMgr) - { - f_sprintf( (char *)szTemp, - "%s/FlmECache?From=FFile?Link=pECacheMgr?Address=%s?Bucket=%lu", - m_pszURLString, - szFFileAddress, - (unsigned long)pFile->uiBucket); - } - - printHTMLLink( - "pECacheMgr", - "FlmECache *", - (void *)pFile, - (void *)&pFile->pECacheMgr, - (void *)pFile->pECacheMgr, - (char *)szTemp, - (bHighlight = ~bHighlight)); - - printTableEnd(); } diff --git a/flaim/src/imonfhdl.cpp b/flaim/src/imonfhdl.cpp deleted file mode 100644 index eaff34e..0000000 --- a/flaim/src/imonfhdl.cpp +++ /dev/null @@ -1,805 +0,0 @@ -//------------------------------------------------------------------------- -// Desc: Class for displaying an F_FileHdl class structure in HTML on a web page. -// Tabs: 3 -// -// Copyright (c) 2001-2003,2005-2006 Novell, Inc. All Rights Reserved. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of version 2 of the GNU General Public -// License as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, contact Novell, Inc. -// -// To contact Novell about this file by physical or electronic mail, -// you may find current contact information at www.novell.com -// -// $Id: imonfhdl.cpp 12329 2006-01-20 17:49:30 -0700 (Fri, 20 Jan 2006) ahodgkinson $ -//------------------------------------------------------------------------- - -#include "flaimsys.h" - -/**************************************************************************** -Desc: Implements the display function of the F_FileHdlPage -*****************************************************************************/ -RCODE F_FileHdlPage::display( - FLMUINT uiNumParams, - const char ** ppszParams) -{ - RCODE rc = FERR_OK; - char szFrom[20]; - char szFileId[20]; - FLMINT uiFileId; - char szList[10]; - FLMUINT uiList; - F_FileHdl * pFileHdl = NULL; - FLMBOOL bRefresh; - FLMUINT uiSize; - FLMUINT uiOffset; - FLMUINT uiListCount; - FLMBYTE szTemp[150]; - FLMBOOL bHadError = FALSE; - FLMBOOL bHighlight = FALSE; - FLMBYTE * pszTemp = NULL; - - if( RC_BAD( rc = f_alloc( 250, &pszTemp))) - { - printErrorPage( rc, TRUE, (char *)"Failed to allocate temporary buffer"); - goto Exit; - } - - //Let's first find out where we came from, then get the appropriate parameters. - - - szFrom[0] = '\0'; - szList[0] = '\0'; - - - //Get the "From" parameter - if (RC_BAD( rc = ExtractParameter( uiNumParams, - ppszParams, - "From", - sizeof( szFrom), - szFrom))) - { - goto Exit; - } - - - //If the source of this req uest is from the FileHdlMgr, then we will begin our search from there. - if (f_stricmp( szFrom, "FileHdlMgr") == 0) - { - - //Get the file id (index) and the list type. The parameters must be set! - - if (RC_BAD( rc = ExtractParameter( uiNumParams, - ppszParams, - "FileId", - sizeof( szFileId), - szFileId))) - { - goto Exit; - } - - uiFileId = f_atoud( szFileId); - if (RC_BAD( rc = ExtractParameter( uiNumParams, - ppszParams, - "List", - sizeof( szList), - szList))) - { - goto Exit; - } - - - if (f_stricmp( szList, "Used") == 0) - { - uiList = FHM_USED_LIST; - } - else if (f_stricmp( szList, "Avail") == 0) - { - uiList = FHM_AVAIL_LIST; - } - else //Invalid List option - { - rc = RC_SET( FERR_FAILURE); - goto Exit; - } - - - // Now get the file handle from the appropriate list, either the Used list or the Available list - f_mutexLock( gv_FlmSysData.hFileHdlMutex); - - uiListCount = gv_FlmSysData.pFileHdlMgr->GetListMgr()->GetCount(uiList); - if (uiListCount > 0) - { - pFileHdl = (F_FileHdl *)gv_FlmSysData.pFileHdlMgr->GetListMgr()->GetItem(uiList, uiFileId); - pFileHdl->AddRef(); - } - else - { - pFileHdl = NULL; - } - f_mutexUnlock( gv_FlmSysData.hFileHdlMutex); - - - } //FileHdlMgr - else - { - // Generate an error for now. (nothing else implemented) - rc = RC_SET( FERR_INVALID_PARM); - goto Exit; - } - - //Before we actually create the rest of the page, let's verify that the file handle - //we are about to display is still valid. - - stdHdr(); - - fnPrintf( m_pHRequest, HTML_DOCTYPE); - fnPrintf( m_pHRequest, "\n"); - - - if (pFileHdl) - { - - - //Check to see if we are to refresh this page automatically. - if ((bRefresh = DetectParameter( uiNumParams, - ppszParams, - "Refresh")) == TRUE) - { - //Send back the page with a refresh command in the header - - f_sprintf((char *)szTemp, - "%s/FileHdl?Refresh&From=%s&List=%s&FileId=%s", - m_pszURLString, - szFrom, szList, szFileId); - - fnPrintf( m_pHRequest, - "" - "" - "File Handle Structure\n", - szTemp); - - } - else - { - fnPrintf( m_pHRequest, - "File Handle Structure\n"); - } - printStyle(); - fnPrintf( m_pHRequest, "\n"); - - - fnPrintf( m_pHRequest, "\n"); - - // If we are not to refresh this page, then don't include the refresh meta command - if (!bRefresh) - { - f_sprintf( (char *)pszTemp, - "Start Auto-refresh (5 sec.)", - m_pszURLString, szFrom, szList, szFileId); - } - else - { - f_sprintf( (char *)pszTemp, - "Stop Auto-refresh", - m_pszURLString, szFrom, szList, szFileId); - } - // Prepare the refresh link. - f_sprintf( (char *)szTemp, - "Refresh", - m_pszURLString, szFrom, szList, szFileId); - - - - //Insert a new table into the page to display the FileHdl fields - printTableStart( "File Handle", 1, 100); - - printTableRowStart(); - printColumnHeading( "", JUSTIFY_LEFT, FLM_IMON_COLOR_PUTTY_1, 1, 1, FALSE); - fnPrintf( m_pHRequest, "%s, ", szTemp); - fnPrintf( m_pHRequest, "%s\n", pszTemp); - printColumnHeadingClose(); - printTableRowEnd(); - - printTableEnd(); - - - printTableStart( "File Handle - Methods", 2); - - // Write out the table headings. - printTableRowStart(); - printColumnHeading( "Method Name"); - printColumnHeading( "Value"); - printTableRowEnd(); - - - //File Size - printTableRowStart( bHighlight = ~bHighlight); - fnPrintf( m_pHRequest, TD_s, "Size"); - if (RC_BAD( rc = pFileHdl->Size(&uiSize))) - { - bHadError = TRUE; - goto Exit; - } - fnPrintf( m_pHRequest, TD_ui, uiSize); - printTableRowEnd(); - - - - //Current position - Tell - printTableRowStart( bHighlight = ~bHighlight); - fnPrintf( m_pHRequest, TD_s, "Tell (Current position)"); - if (RC_BAD( rc = pFileHdl->Tell(&uiOffset))) - { - bHadError = TRUE; - goto Exit; - } - fnPrintf( m_pHRequest, TD_ui, uiOffset); - printTableRowEnd(); - - // Write out a table showing the private data - write_data( (F_FileHdlImp *)pFileHdl); - - } - else - { - - fnPrintf( m_pHRequest, "\n"); - - fnPrintf( m_pHRequest, "Error - the File Header structure you are seeking is no longer valid. " - "This page will automatically redirect you to the File Handle Manager page after five seconds\n"); - - } - - - - fnPrintf( m_pHRequest, "\n"); - - fnEmit(); - -Exit: - - if (pFileHdl) - { - f_mutexLock( gv_FlmSysData.hFileHdlMutex); - pFileHdl->Release(); - f_mutexUnlock( gv_FlmSysData.hFileHdlMutex); - pFileHdl = NULL; - } - - - if (bHadError) - { - printTableRowEnd(); - printTableEnd(); - fnPrintf( m_pHRequest, "Error - An error has occured during processing." - " File handle could not be retrieved.\n"); - fnPrintf( m_pHRequest, "\n"); - fnEmit(); - bHadError = FALSE; - } - - if (pszTemp) - { - f_free( &pszTemp); - } - - return( rc); - -} - -/*************************************************************************** -Desc: Function to display the private data on a WIN32 platform -***************************************************************************/ -#ifdef FLM_WIN -void F_FileHdlPage::write_data( - F_FileHdlImp * pFileHdl) -{ - F_ListItem * pListItem; - F_FileHdlImpBase * pFileHdlBase; - char szAddress[20]; - FLMBOOL bHighlight = FALSE; - - if (!pFileHdl) - { - return; - } - - // Start the table - printTableStart( "File Handle - Fields", 4); - - - // Write out the table headings. - printTableRowStart(); - printColumnHeading( "Byte Offset (hex)"); - printColumnHeading( "Field Name"); - printColumnHeading( "Field Type"); - printColumnHeading( "Value"); - printTableRowEnd(); - - // m_FileHandle (HANDLE) - printAddress( &pFileHdl->m_FileHandle, szAddress); - printHTMLString( - "m_FileHandle", - "HANDLE", - (void *)pFileHdl, - (void *)&pFileHdl->m_FileHandle, - (char *)szAddress, - (bHighlight = ~bHighlight)); - - // m_uiBlockSize - printHTMLUint( - "m_uiBlockSize", - "FLMUINT", - (void *)pFileHdl, - (void *)&pFileHdl->m_uiBlockSize, - pFileHdl->m_uiBlockSize, - (bHighlight = ~bHighlight)); - - // m_uiBytesPerSector - printHTMLUint( - "m_uiBytesPerSector", - "FLMUINT", - (void *)pFileHdl, - (void *)&pFileHdl->m_uiBytesPerSector, - pFileHdl->m_uiBytesPerSector, - (bHighlight = ~bHighlight)); - - // m_uiNotOnSectorBoundMask - printHTMLUint( - "m_uiNotOnSectorBoundMask", - "FLMUINT", - (void *)pFileHdl, - (void *)&pFileHdl->m_uiNotOnSectorBoundMask, - pFileHdl->m_uiNotOnSectorBoundMask, - (bHighlight = ~bHighlight)); - - // m_uiGetSectorBoundMask - printHTMLUint( - "m_uiGetSectorBoundMask", - "FLMUINT", - (void *)pFileHdl, - (void *)&pFileHdl->m_uiGetSectorBoundMask, - pFileHdl->m_uiGetSectorBoundMask, - (bHighlight = ~bHighlight)); - - // m_bDoDirectIO - printHTMLString( - "m_bDoDirectIO", - "FLMBOOL", - (void *)pFileHdl, - (void *)&pFileHdl->m_bDoDirectIO, - (char *)(pFileHdl->m_bDoDirectIO ? "Yes" : "No"), - (bHighlight = ~bHighlight)); - - // m_uiExtendSize - printHTMLUint( - "m_uiExtendSize", - "FLMUINT", - (void *)pFileHdl, - (void *)&pFileHdl->m_uiExtendSize, - pFileHdl->m_uiExtendSize, - (bHighlight = ~bHighlight)); - - // m_uiMaxAutoExtendSize - printHTMLUint( - "m_uiMaxAutoExtendSize", - "FLMUINT", - (void *)pFileHdl, - (void *)&pFileHdl->m_uiMaxAutoExtendSize, - pFileHdl->m_uiMaxAutoExtendSize, - (bHighlight = ~bHighlight)); - - // m_pucAlignedBuff - printAddress( pFileHdl->m_pucAlignedBuff, szAddress); - printHTMLString( - "m_pucAlignedBuff", - "FLMBOOL", - (void *)pFileHdl, - (void *)&pFileHdl->m_pucAlignedBuff, - (char *)szAddress, - (bHighlight = ~bHighlight)); - - // m_uiAlignedBuffSize - printHTMLUint( - "m_uiAlignedBuffSize", - "FLMUINT", - (void *)pFileHdl, - (void *)&pFileHdl->m_uiAlignedBuffSize, - pFileHdl->m_uiAlignedBuffSize, - (bHighlight = ~bHighlight)); - - // m_uiCurrentPos - printHTMLUint( - "m_uiCurrentPos", - "FLMUINT", - (void *)pFileHdl, - (void *)&pFileHdl->m_uiCurrentPos, - pFileHdl->m_uiCurrentPos, - (bHighlight = ~bHighlight)); - - // m_bCanDoAsync - printHTMLString( - "m_bCanDoAsync", - "FLMBOOL", - (void *)pFileHdl, - (void *)&pFileHdl->m_bCanDoAsync, - (char *)(pFileHdl->m_bCanDoAsync ? "Yes" : "No"), - (bHighlight = ~bHighlight)); - - // m_Overlapped (OVERLAPPED) - printAddress( &pFileHdl->m_Overlapped, szAddress); - printHTMLString( - "m_Overlapped", - "OVERLAPPED", - (void *)pFileHdl, - (void *)&pFileHdl->m_Overlapped, - (char *)szAddress, - (bHighlight = ~bHighlight)); - - // Now we show private members of the base class F_FileHdlBase - - pFileHdlBase = (F_FileHdlImpBase *)pFileHdl; - - // m_LNode - printAddress( &pFileHdlBase->m_LNode[0], szAddress); - printHTMLString( - "F_FileHdlBase.m_LNode", - "LNODE", - (void *)pFileHdlBase, - (void *)&pFileHdlBase->m_LNode, - (char *)szAddress, - (bHighlight = ~bHighlight)); - - // m_bFileOpened - printHTMLString( - "F_FileHdlBase.m_bFileOpened", - "FLMBOOL", - (void *)pFileHdlBase, - (void *)&pFileHdlBase->m_bFileOpened, - (char *)(pFileHdlBase->m_bFileOpened ? "Yes" : "No"), - (bHighlight = ~bHighlight)); - - // m_uiAvailTime - printHTMLUint( - "F_FileHdlBase.m_uiAvailTime", - "FLMUINT", - (void *)pFileHdlBase, - (void *)&pFileHdlBase->m_uiAvailTime, - pFileHdlBase->m_uiAvailTime, - (bHighlight = ~bHighlight)); - - // m_uiFileId - printHTMLUint( - "F_FileHdlBase.m_uiFileId", - "FLMUINT", - (void *)pFileHdlBase, - (void *)&pFileHdlBase->m_uiFileId, - pFileHdlBase->m_uiFileId, - (bHighlight = ~bHighlight)); - - // m_bDeleteOnClose - printHTMLString( - "F_FileHdlBase.m_bDeleteOnClose", - "FLMBOOL", - (void *)pFileHdlBase, - (void *)&pFileHdlBase->m_bDeleteOnClose, - (char *)(pFileHdlBase->m_bDeleteOnClose ? "Yes" : "No"), - (bHighlight = ~bHighlight)); - - // m_bOpenedReadOnly - printHTMLString( - "F_FileHdlBase.m_bOpenedReadOnly", - "FLMBOOL", - (void *)pFileHdlBase, - (void *)&pFileHdlBase->m_bOpenedReadOnly, - (char *)(pFileHdlBase->m_bOpenedReadOnly ? "Yes" : "No"), - (bHighlight = ~bHighlight)); - - // m_bOpenedExclusive - printHTMLString( - "F_FileHdlBase.m_bOpenedExclusive", - "FLMBOOL", - (void *)pFileHdlBase, - (void *)&pFileHdlBase->m_bOpenedExclusive, - (char *)(pFileHdlBase->m_bOpenedExclusive ? "Yes" : "No"), - (bHighlight = ~bHighlight)); - - // m_pszIoPath - printHTMLString( - "F_FileHdlBase.m_pszIoPath", - "FLMBYTE *", - (void *)pFileHdlBase, - (void *)&pFileHdlBase->m_pszIoPath, - (char *)pFileHdlBase->m_pszIoPath, - (bHighlight = ~bHighlight)); - - // Now show the private members of the F_ListItem class - pListItem = (F_ListItem *)pFileHdlBase; - - // m_pListMgr - printAddress( pListItem->m_pListMgr, szAddress); - printHTMLString( - "F_ListItem.m_pListMgr", - "F_ListMgr *", - (void *)pListItem, - (void *)&pListItem->m_pListMgr, - (char *)szAddress, - (bHighlight = ~bHighlight)); - - // m_uiLNodeCnt - printHTMLUint( - "F_ListItem.m_uiLNodeCnt", - "FLMUINT", - (void *)pListItem, - (void *)&pListItem->m_uiLNodeCnt, - pListItem->m_uiLNodeCnt, - (bHighlight = ~bHighlight)); - - // m_pLNodes - printAddress( pListItem->m_pLNodes, szAddress); - printHTMLString( - "F_ListItem.m_pLNodes", - "LNODE *", - (void *)pListItem, - (void *)&pListItem->m_pLNodes, - (char *)szAddress, - (bHighlight = ~bHighlight)); - - // m_bInList - printHTMLString( - "F_ListItem.m_bInList", - "FLMBOOL", - (void *)pListItem, - (void *)&pListItem->m_bInList, - (char *)(pListItem->m_bInList ? "Yes" : "No"), - (bHighlight = ~bHighlight)); - - printTableEnd(); - -} - -#endif - -#ifdef FLM_UNIX -/*************************************************************************** -Desc: Function to display the private data on a UNIX platform -***************************************************************************/ -void F_FileHdlPage::write_data( - F_FileHdlImp * pFileHdl) -{ - FLMBOOL bHighlight = FALSE; - - if (!pFileHdl) - { - return; - } - - // Start the table - printTableStart( "File Handle Structure - Fields", 4); - - - // Write out the table headings. - printTableRowStart(); - printColumnHeading( "Byte Offset (hex)"); - printColumnHeading( "Field Name"); - printColumnHeading( "Field Type"); - printColumnHeading( "Value"); - printTableRowEnd(); - - - // m_fd (int) - printHTMLInt( - "m_fd", - "int", - (void *)pFileHdl, - (void *)&pFileHdl->m_fd, - pFileHdl->m_fd, - (bHighlight = ~bHighlight)); - - // m_uiCurrentPos - printHTMLUint( - "m_uiCurrentPos", - "FLMUINT", - (void *)pFileHdl, - (void *)&pFileHdl->m_uiCurrentPos, - pFileHdl->m_uiCurrentPos, - (bHighlight = ~bHighlight)); - - // m_bDoDirectIO - printHTMLString( - "m_bDoDirectIO", - "FLMBOOL", - (void *)pFileHdl, - (void *)&pFileHdl->m_bDoDirectIO, - (char *)(pFileHdl->m_bDoDirectIO ? "Yes" : "No"), - (bHighlight = ~bHighlight)); - - // m_uiMaxAutoExtendSize - printHTMLUint( - "m_uiMaxAutoExtendSize", - "FLMUINT", - (void *)pFileHdl, - (void *)&pFileHdl->m_uiMaxAutoExtendSize, - pFileHdl->m_uiMaxAutoExtendSize, - (bHighlight = ~bHighlight)); - - // m_bCanDoAsync - printHTMLString( - "m_bCanDoAsync", - "FLMUINT", - (void *)pFileHdl, - (void *)&pFileHdl->m_bCanDoAsync, - (char *)(pFileHdl->m_bCanDoAsync ? "Yes" : "No"), - (bHighlight = ~bHighlight)); - - printTableEnd(); -} -#endif - -/*************************************************************************** -Desc: Function to display the private data on a Netware platform -***************************************************************************/ -#ifdef FLM_NLM -void F_FileHdlPage::write_data( - F_FileHdlImp * pFileHdl) -{ - char szAddress[20]; - FLMBOOL bHighlight = FALSE; - - if (!pFileHdl) - { - return; - } - - // Start the table - printTableStart( "File Handle Structure - Fields", 4); - - - // Write out the table headings. - printTableRowStart(); - printColumnHeading( "Byte Offset (hex)"); - printColumnHeading( "Field Name"); - printColumnHeading( "Field Type"); - printColumnHeading( "Value"); - printTableRowEnd(); - - // m_lFileHandle (LONG) - printHTMLUlong( - "m_lFileHandle", - "LONG", - (void *)pFileHdl, - (void *)&pFileHdl->m_lFileHandle, - pFileHdl->m_lFileHandle, - (bHighlight = ~bHighlight)); - - // m_lOpenAttr - printHTMLUlong( - "m_lOpenAttr", - "LONG", - (void *)pFileHdl, - (void *)&pFileHdl->m_lOpenAttr, - pFileHdl->m_lOpenAttr, - (bHighlight = ~bHighlight)); - - // m_lVolumeID - printHTMLUlong( - "m_lVolumeID", - "LONG", - (void *)pFileHdl, - (void *)&pFileHdl->m_lVolumeID, - pFileHdl->m_lVolumeID, - (bHighlight = ~bHighlight)); - - // m_lLNamePathCount - printHTMLUlong( - "m_lLNamePathCount", - "LONG", - (void *)pFileHdl, - (void *)&pFileHdl->m_lLNamePathCount, - pFileHdl->m_lLNamePathCount, - (bHighlight = ~bHighlight)); - - // m_bDoSuballocation - printHTMLString( - "m_bDoSuballocation", - "FLMUINT", - (void *)pFileHdl, - (void *)&pFileHdl->m_bDoSuballocation, - (char *)(pFileHdl->m_bDoSuballocation ? "Yes" : "No"), - (bHighlight = ~bHighlight)); - - // m_uiExtendSize - printHTMLUint( - "m_uiExtendSize", - "FLMUINT", - (void *)pFileHdl, - (void *)&pFileHdl->m_uiExtendSize, - pFileHdl->m_uiExtendSize, - (bHighlight = ~bHighlight)); - - // m_uiMaxAutoExtendSize - printHTMLUint( - "m_uiMaxAutoExtendSize", - "FLMUINT", - (void *)pFileHdl, - (void *)&pFileHdl->m_uiMaxAutoExtendSize, - pFileHdl->m_uiMaxAutoExtendSize, - (bHighlight = ~bHighlight)); - - // m_bDoDirectIO - printHTMLString( - "m_bDoDirectIO", - "FLMUINT", - (void *)pFileHdl, - (void *)&pFileHdl->m_bDoDirectIO, - (char *)(pFileHdl->m_bDoDirectIO ? "Yes" : "No"), - (bHighlight = ~bHighlight)); - - // m_lSectorsPerBlock - printHTMLUlong( - "m_lSectorsPerBlock", - "LONG", - (void *)pFileHdl, - (void *)&pFileHdl->m_lSectorsPerBlock, - pFileHdl->m_lSectorsPerBlock, - (bHighlight = ~bHighlight)); - - // m_lMaxBlocks - printHTMLUlong( - "m_lMaxBlocks", - "LONG", - (void *)pFileHdl, - (void *)&pFileHdl->m_lMaxBlocks, - pFileHdl->m_lMaxBlocks); - - // m_uiCurrentPos - printHTMLUint( - "m_uiCurrentPos", - "FLMUINT", - (void *)pFileHdl, - (void *)&pFileHdl->m_uiCurrentPos, - pFileHdl->m_uiCurrentPos, - (bHighlight = ~bHighlight)); - - // m_bNSS - printHTMLString( - "m_bNSS", - "FLMUINT", - (void *)pFileHdl, - (void *)&pFileHdl->m_bNSS, - (char *)(pFileHdl->m_bNSS ? "Yes" : "No"), - (bHighlight = ~bHighlight)); - - // m_NssKey (Key_t) - printAddress( &pFileHdl->m_NssKey, szAddress); - printHTMLString( - "m_NssKey", - "Key_t", - (void *)pFileHdl, - (void *)&pFileHdl->m_NssKey, - (char *)szAddress, - (bHighlight = ~bHighlight)); - - // m_bNSSFileOpen - printHTMLString( - "m_bNSSFileOpen", - "FLMUINT", - (void *)pFileHdl, - (void *)&pFileHdl->m_bNSSFileOpen, - (char *)(pFileHdl->m_bNSSFileOpen ? "Yes" : "No"), - (bHighlight = ~bHighlight)); - - printTableEnd(); - -} - -#endif // FLM_NLM diff --git a/flaim/src/imonfmgr.cpp b/flaim/src/imonfmgr.cpp deleted file mode 100644 index 33c3b34..0000000 --- a/flaim/src/imonfmgr.cpp +++ /dev/null @@ -1,438 +0,0 @@ -//------------------------------------------------------------------------- -// Desc: Class for displaying a file handle manager in HTML on a web page. -// Tabs: 3 -// -// Copyright (c) 2001-2003,2005-2006 Novell, Inc. All Rights Reserved. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of version 2 of the GNU General Public -// License as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, contact Novell, Inc. -// -// To contact Novell about this file by physical or electronic mail, -// you may find current contact information at www.novell.com -// -// $Id: imonfmgr.cpp 12329 2006-01-20 17:49:30 -0700 (Fri, 20 Jan 2006) ahodgkinson $ -//------------------------------------------------------------------------- - -#include "flaimsys.h" - -/**************************************************************************** -Desc: This function implementd the display method of the FileHdlMgrPage web - page. -*****************************************************************************/ -RCODE F_FileHdlMgrPage::display( - FLMUINT uiNumParams, - const char ** ppszParams) -{ - RCODE rc = FERR_OK; - F_FileHdlMgr * pFileHdlMgr; - F_ListMgr * pListMgr; - FLMUINT uiNumAvailItems; - FLMUINT uiNumUsedItems; - char szTemp[20]; - FLMUINT uiLoop; - FLMBOOL bRefresh = FALSE; - char szAddress[20]; - FLMBOOL bHighlight = FALSE; - FLMBYTE * pszTemp = NULL; - FLMBYTE * pszTemp1 = NULL; - - if( RC_BAD( rc = f_alloc( 250, &pszTemp))) - { - printErrorPage( rc, TRUE, (char *)"Failed to allocate temporary buffer"); - goto Exit; - } - - if( RC_BAD( rc = f_alloc( 250, &pszTemp1))) - { - printErrorPage( rc, TRUE, (char *)"Failed to allocate temporary buffer"); - goto Exit; - } - - stdHdr(); - - fnPrintf( m_pHRequest, HTML_DOCTYPE); - fnPrintf( m_pHRequest, "\n"); - - // Determine if we are being requested to refresh this page or not. - - if ((bRefresh = DetectParameter( - uiNumParams, - ppszParams, - "Refresh")) == TRUE) - { - // Send back the page with a refresh command in the header - fnPrintf( m_pHRequest, - "" - "" - "gv_FlmSysData.pFileHdlMgr\n", - m_pszURLString); - } - else - { - fnPrintf( m_pHRequest, - "gv_FlmSysData.pFileHdlMgr\n"); - } - printStyle(); - fnPrintf( m_pHRequest, "\n"); - - - fnPrintf( m_pHRequest, "\n"); - - // If we are not to refresh this page, then don't include the - // refresh meta command - if (!bRefresh) - { - f_sprintf( (char *)pszTemp, - "Start Auto-refresh (5 sec.)", - m_pszURLString); - } - else - { - f_sprintf( (char *)pszTemp, - "Stop Auto-refresh", - m_pszURLString); - } - // Prepare the refresh link. - f_sprintf( (char *)pszTemp1, "Refresh", - m_pszURLString); - - - - if (gv_FlmSysData.pFileHdlMgr == NULL) - { - fnPrintf( m_pHRequest, - "
No File Handle Manager exists. " - "Please ensure that a database has been opened." - "
\n"); - } - else - { - // Lock the file handle manager Mutex and add a reference - // to it to hold it until we are done. - f_mutexLock( gv_FlmSysData.hFileHdlMutex); - pFileHdlMgr = gv_FlmSysData.pFileHdlMgr; - pFileHdlMgr->AddRef(); - f_mutexUnlock( gv_FlmSysData.hFileHdlMutex); - - printTableStart( "File Handle Manager", 1, 100); - - printTableRowStart(); - printColumnHeading( "", JUSTIFY_LEFT, FLM_IMON_COLOR_PUTTY_1, 4, 1, FALSE); - fnPrintf( m_pHRequest, "%s, ", pszTemp1); - fnPrintf( m_pHRequest, "%s\n", pszTemp); - printColumnHeadingClose(); - printTableRowEnd(); - - printTableEnd(); - - - printTableStart( "File Handle Manager - Methods", 2, 100); - - // Write out the table headings. - printTableRowStart(); - printColumnHeading( "Method Name"); - printColumnHeading( "Value"); - printTableRowEnd(); - - // GetOpenThreshold - method to return the file open threshold - printTableRowStart( bHighlight = ~bHighlight); - fnPrintf( m_pHRequest, TD_s, "GetOpenThreshold"); - fnPrintf( m_pHRequest, TD_ld, pFileHdlMgr->GetOpenThreshold()); - printTableRowEnd(); - - // GetOpenedFiles - Returns the number of opened files - printTableRowStart( bHighlight = ~bHighlight); - fnPrintf( m_pHRequest, TD_s, "GetOpenedFiles"); - fnPrintf( m_pHRequest, TD_ld, pFileHdlMgr->GetOpenedFiles()); - printTableRowEnd(); - - // GetMaxAvailTime - printTableRowStart( bHighlight = ~bHighlight); - fnPrintf( m_pHRequest, TD_s, "GetMaxAvailTime"); - FormatTime( pFileHdlMgr->GetMaxAvailTime(), szTemp); - fnPrintf( m_pHRequest, TD_s, szTemp); - fnPrintf( m_pHRequest, TR_END); - printTableRowEnd(); - - - // Introduce another table to show the private members - - printTableStart( "File Handle Manager - Fields", 4, 100); - - // Write out the table headings. - printTableRowStart(); - printColumnHeading( "Byte Offset (hex)"); - printColumnHeading( "Field Name"); - printColumnHeading( "Field Type"); - printColumnHeading( "Value"); - printTableRowEnd(); - - // m_phMutex (show the address) - printAddress( &pFileHdlMgr->m_phMutex, szAddress); - printHTMLString( - "m_phMutex", - "F_MUTEX", - (void *)pFileHdlMgr, - (void *)&pFileHdlMgr->m_phMutex, - (char *)szAddress, - (bHighlight = ~bHighlight)); - - // m_uiOpenThreshold - printHTMLUint( - "m_uiOpenThreshold", - "FLMUINT", - (void *)pFileHdlMgr, - (void *)&pFileHdlMgr->m_uiOpenThreshold, - pFileHdlMgr->m_uiOpenThreshold, - (bHighlight = ~bHighlight)); - - // m_uiMaxAvailTime - FormatTime( pFileHdlMgr->m_uiMaxAvailTime, szTemp); - printHTMLString( - "m_uiMaxAvailTime", - "FLMUINT", - (void *)pFileHdlMgr, - (void *)&pFileHdlMgr->m_uiMaxAvailTime, - (char *)szTemp, - (bHighlight = ~bHighlight)); - - // m_ListMgr (show address) - printAddress( &pFileHdlMgr->m_ListMgr, szAddress); - printHTMLString( - "m_ListMgr", - "F_ListMgr", - (void *)pFileHdlMgr, - (void *)&pFileHdlMgr->m_ListMgr, - (char *)szAddress, - (bHighlight = ~bHighlight)); - - // m_LNodes (show address) - printAddress( &pFileHdlMgr->m_LNodes[0], szAddress); - printHTMLString( - "m_LNodes", - "LNODE[]", - (void *)pFileHdlMgr, - (void *)&pFileHdlMgr->m_LNodes, - (char *)szAddress, - (bHighlight = ~bHighlight)); - - // m_bIsSetup - printHTMLString( - "m_bIsSetup", - "FLMBOOL", - (void *)pFileHdlMgr, - (void *)&pFileHdlMgr->m_bIsSetup, - (char *)(pFileHdlMgr->m_bIsSetup ? "Yes" : "No"), - (bHighlight = ~bHighlight)); - - // m_uiFileIdCounter - printHTMLUint( - "m_uiFileIdCounter", - "FLMUINT", - (void *)pFileHdlMgr, - (void *)&pFileHdlMgr->m_uiFileIdCounter, - pFileHdlMgr->m_uiFileIdCounter, - (bHighlight = ~bHighlight)); - - printTableEnd(); - - - fnPrintf( m_pHRequest, "
\n"); - fnPrintf( m_pHRequest, "
\n"); - fnPrintf( m_pHRequest, "Shown below are the AVAILABLE and the USED File " - "Handle Lists.
To select a File Handle to view, " - "you may click the appropriate \"NEXT FILE HANDLE\" " - "button or choose from the drop down selection list." - "\n"); - fnPrintf( m_pHRequest, "
\n"); - fnPrintf( m_pHRequest, "
\n"); - - // Define the form to present the File Handle Lists - // Begin with the Available List of File Handles - - - // Get a reference to the list manager, then find out - // how many items are in the Available List - pListMgr = pFileHdlMgr->GetListMgr(); - uiNumAvailItems = pListMgr->GetCount( FHM_AVAIL_LIST); - - if (uiNumAvailItems > 0) - { - fnPrintf( m_pHRequest, "\n", - m_pszURLString); - fnPrintf( m_pHRequest, "

Available List

\n"); - - fnPrintf( m_pHRequest, "
\n"); - - printButton( "Next File Handle", BT_Button, NULL, NULL, - "ONCLICK='nextAvailHdl(document.AvailSelection.AvailOption)'"); - fnPrintf( m_pHRequest, "  \n"); - fnPrintf( m_pHRequest, "or select a specific file handle to view\n"); - fnPrintf( m_pHRequest, "  \n"); - - fnPrintf( m_pHRequest, "\n"); - - fnPrintf( m_pHRequest, "  \n"); - - printButton( "Submit", BT_Submit); - fnPrintf( m_pHRequest, "
\n"); - - fnPrintf( m_pHRequest, "\n"); - fnPrintf( m_pHRequest, "\n"); - fnPrintf( m_pHRequest, "\n"); - - fnPrintf( m_pHRequest, "
\n"); - } - else - { - fnPrintf( m_pHRequest, "

Available List - " - "No Entries

\n"); - } - - - uiNumUsedItems = pListMgr->GetCount( FHM_USED_LIST); - - - if (uiNumUsedItems > 0) - { - fnPrintf( m_pHRequest, "
\n", - m_pszURLString); - fnPrintf( m_pHRequest, "

Used List

\n"); - - fnPrintf( m_pHRequest, "
\n"); - printButton( "Next File Handle", BT_Button, NULL, NULL, - "ONCLICK='nextUsedHdl(document.UsedSelection.UsedOption)'"); - fnPrintf( m_pHRequest, "  \n"); - fnPrintf( m_pHRequest, "or select a specific file handle to view\n"); - fnPrintf( m_pHRequest, "  \n"); - - fnPrintf( m_pHRequest, "\n"); - - fnPrintf( m_pHRequest, "  \n"); - - printButton( "Submit", BT_Submit); - fnPrintf( m_pHRequest, "
\n"); - - fnPrintf( m_pHRequest, "\n"); - fnPrintf( m_pHRequest, "\n"); - fnPrintf( m_pHRequest, "\n"); - - fnPrintf( m_pHRequest, "
\n"); - - } - else - { - fnPrintf( m_pHRequest, "

Used List - " - "No Entries

\n"); - } - - - fnPrintf( m_pHRequest, "\n"); - - // Now release the FileHdlMgr... - f_mutexLock( gv_FlmSysData.hFileHdlMutex); - pFileHdlMgr->Release(); - pFileHdlMgr = NULL; - f_mutexUnlock( gv_FlmSysData.hFileHdlMutex); - - - } // else - - fnPrintf( m_pHRequest, "\n"); - - fnEmit(); - -Exit: - - if (pszTemp) - { - f_free( &pszTemp); - } - - if (pszTemp1) - { - f_free( &pszTemp1); - } - - return( rc); -} diff --git a/flaim/src/imonfram.cpp b/flaim/src/imonfram.cpp index 5c95971..f52078f 100644 --- a/flaim/src/imonfram.cpp +++ b/flaim/src/imonfram.cpp @@ -272,8 +272,8 @@ RCODE F_FrameNav::display( if (DetectParameter( uiNumParams, ppszParams, "StopSecureDbAccess")) { - fnSetGblValue( FLM_SECURE_PASSWORD, "", (size_t)0); - fnSetGblValue( FLM_SECURE_EXPIRATION, "", (size_t )0); + fnSetGblValue( FLM_SECURE_PASSWORD, "", (FLMSIZET)0); + fnSetGblValue( FLM_SECURE_EXPIRATION, "", (FLMSIZET )0); uiSize = 0; } @@ -283,8 +283,8 @@ RCODE F_FrameNav::display( // We are going to ignore any error, as the password may not have been entered. uiSize = sizeof( szGblPassword); (void)fnGetGblValue( FLM_SECURE_PASSWORD, - (void *)&szGblPassword, - (size_t *)&uiSize); + (void *)szGblPassword, + (FLMSIZET *)&uiSize); } fnPrintf( m_pHRequest, "
Secure Control
\n" @@ -391,8 +391,8 @@ RCODE F_FrameNav::display( f_memset( szValue, 0, uiSize); (void)fnGetSessionValue( pvSession, FLM_SECURE_PASSWORD, - (void *)&szValue, - (size_t *)&uiSize); + (void *)szValue, + (FLMSIZET *)&uiSize); if (f_strlen( szValue) != 0) { @@ -405,8 +405,8 @@ RCODE F_FrameNav::display( // has been enabled uiSize = sizeof( szGblPassword); (void)fnGetGblValue( FLM_SECURE_PASSWORD, - (void *)&szGblPassword, - (size_t *)&uiSize); + (void *)szGblPassword, + (FLMSIZET *)&uiSize); if (f_strlen( szGblPassword) != 0) { fnPrintf( m_pHRequest, "
"); @@ -615,11 +615,11 @@ RCODE F_SecureDbInfo::display( // Now store the data... if (gv_FlmSysData.HttpConfigParms.fnSetGblValue) { - if (fnSetGblValue( FLM_SECURE_PASSWORD, pszPassword, (size_t)uiPwdLen)) + if (fnSetGblValue( FLM_SECURE_PASSWORD, pszPassword, (FLMSIZET)uiPwdLen)) { flmAssert( 0); } - if (fnSetGblValue( FLM_SECURE_EXPIRATION, pszExpiration, (size_t)uiExpLen)) + if (fnSetGblValue( FLM_SECURE_EXPIRATION, pszExpiration, (FLMSIZET)uiExpLen)) { flmAssert( 0); } diff --git a/flaim/src/imonfsys.cpp b/flaim/src/imonfsys.cpp index a8d1127..997d931 100644 --- a/flaim/src/imonfsys.cpp +++ b/flaim/src/imonfsys.cpp @@ -217,33 +217,6 @@ void F_FlmSysDataPage::write_data( - // hServerLockMgrMutex - Server lock manager mutex - printAddress( (void *)&gv_FlmSysData.hServerLockMgrMutex, szAddress); - printHTMLString( - "hServerLockMgrMutex", - "F_MUTEX", - (void *)&gv_FlmSysData, - (void *)&gv_FlmSysData.hServerLockMgrMutex, - (char *)szAddress, - (bHighlight = !bHighlight)); - - - - // pFileHdlMgr - File handle manager - f_sprintf( (char *)pszTemp, "%s/FileHdlMgr", - m_pszURLString); - - printHTMLLink( - "pFileHdlMgr", - "FFILE *", - (void *)&gv_FlmSysData, - (void *)&gv_FlmSysData.pFileHdlMgr, - (void *)gv_FlmSysData.pFileHdlMgr, - (char *)pszTemp, - (bHighlight = !bHighlight)); - - - // pFileSystem - File system printAddress( (void *)gv_FlmSysData.pFileSystem, szAddress); printHTMLString( @@ -280,17 +253,6 @@ void F_FlmSysDataPage::write_data( - // bOkToUseESM - printHTMLString( - "bOkToUseESM", - "FLMBOOL", - (void *)&gv_FlmSysData, - (void *)&gv_FlmSysData.bOkToUseESM, - (char *)(gv_FlmSysData.bOkToUseESM ? "Yes" : "No"), - (bHighlight = !bHighlight)); - - - // bCheckCache - Check cache printHTMLString( "bCheckCache", @@ -300,22 +262,7 @@ void F_FlmSysDataPage::write_data( (char *)(gv_FlmSysData.bCheckCache ? "Yes" : "No"), (bHighlight = !bHighlight)); - // pServerLockMgr - Server lock Manager - f_sprintf( (char *)pszTemp, - "%s/ServerLockManager", - m_pszURLString); - printHTMLLink( - "pServerLockMgr", - "ServerLockManager_p", - (void *)&gv_FlmSysData, - (void *)&gv_FlmSysData.pServerLockMgr, - (void *)gv_FlmSysData.pServerLockMgr, - (char *)pszTemp, - (bHighlight = !bHighlight)); - - - // uiMaxCPInterval - Maximum checkpoint interval printHTMLUint( @@ -674,216 +621,6 @@ void F_FlmSysDataPage::write_data( (char *)pszTemp, (bHighlight = !bHighlight)); - -#ifdef FLM_DEBUG - // Variables for memory allocation tracking. - - // bTrackLeaks - printHTMLString( - "bTrackLeaks", - "FLMBOOL", - (void *)&gv_FlmSysData, - (void *)&gv_FlmSysData.bTrackLeaks, - (char *)(gv_FlmSysData.bTrackLeaks ? "Yes" : "No"), - (bHighlight = !bHighlight)); - - - - - // bLogLeaks - printHTMLString( - "bLogLeaks", - "FLMBOOL", - (void *)&gv_FlmSysData, - (void *)&gv_FlmSysData.bLogLeaks, - (char *)(gv_FlmSysData.bLogLeaks ? "Yes" : "No"), - (bHighlight = !bHighlight)); - - - - - // bStackWalk - printHTMLString( - "bStackWalk", - "FLMBOOL", - (void *)&gv_FlmSysData, - (void *)&gv_FlmSysData.bStackWalk, - (char *)(gv_FlmSysData.bStackWalk ? "Yes" : "No"), - (bHighlight = !bHighlight)); - - - - - // bMemTrackingInitialized - printHTMLString( - "bMemTrackingInitialized", - "FLMBOOL", - (void *)&gv_FlmSysData, - (void *)&gv_FlmSysData.bMemTrackingInitialized, - (char *)(gv_FlmSysData.bMemTrackingInitialized ? "Yes" : "No"), - (bHighlight = !bHighlight)); - - - - - // uiInitThreadId - printHTMLUint( - "uiInitThreadId", - "FLMUINT", - (void *)&gv_FlmSysData, - (void *)&gv_FlmSysData.uiInitThreadId, - gv_FlmSysData.uiInitThreadId, - (bHighlight = !bHighlight)); - - - - - // hMemTrackingmutex - printAddress( (void *)&gv_FlmSysData.hMemTrackingMutex, szAddress); - printHTMLString( - "hMemTrackingMutex", - "F_MUTEX", - (void *)&gv_FlmSysData, - (void *)&gv_FlmSysData.hMemTrackingMutex, - (char *)szAddress, - (bHighlight = !bHighlight)); - - - - - // ppvMemTrackingPtrs - printAddress( (void *)gv_FlmSysData.ppvMemTrackingPtrs, szAddress); - printHTMLString( - "ppvMemTrackingPtrs", - "void **", - (void *)&gv_FlmSysData, - (void *)&gv_FlmSysData.ppvMemTrackingPtrs, - (char *)szAddress, - (bHighlight = !bHighlight)); - - - - - - // uiMemTrackingPtrArraySize - printHTMLUint( - "uiMemTrackingPtrArraySize", - "FLMUINT", - (void *)&gv_FlmSysData, - (void *)&gv_FlmSysData.uiMemTrackingPtrArraySize, - gv_FlmSysData.uiMemTrackingPtrArraySize, - (bHighlight = !bHighlight)); - - - - - // uiMemNumPtrs - printHTMLUint( - "uiMemNumPtrs", - "FLMUINT", - (void *)&gv_FlmSysData, - (void *)&gv_FlmSysData.uiMemNumPtrs, - gv_FlmSysData.uiMemNumPtrs, - (bHighlight = !bHighlight)); - - - - - // uiMemNextPtrSlotToUse - printHTMLUint( - "uiMemNextPtrSlotToUse", - "FLMUINT", - (void *)&gv_FlmSysData, - (void *)&gv_FlmSysData.uiMemNextPtrSlotToUse, - gv_FlmSysData.uiMemNextPtrSlotToUse, - (bHighlight = !bHighlight)); - - - - - // uiAllocCnt - printHTMLUint( - "uiAllocCnt", - "FLMUINT", - (void *)&gv_FlmSysData, - (void *)&gv_FlmSysData.uiAllocCnt, - gv_FlmSysData.uiAllocCnt, - (bHighlight = !bHighlight)); - - -#if defined( FLM_WIN) - - - // hMemProcess - printHTMLUint( - "hMemProcess", - "HANDLE", - (void *)&gv_FlmSysData, - (void *)&gv_FlmSysData.hMemProcess, - (FLMUINT)gv_FlmSysData.hMemProcess, - (bHighlight = !bHighlight)); - - -#endif - -#ifdef DEBUG_SIM_OUT_OF_MEM - - // uiOutOfMemSimEnabledFlag - printHTMLUint( - "uiOutOfMemSimEnabledFlag", - "FLMUINT", - (void *)&gv_FlmSysData, - (void *)&gv_FlmSysData.uiOutOfMemSimEnabledFlag, - gv_FlmSysData.uiOutOfMemSimEnabledFlag, - (bHighlight = !bHighlight)); - - - - // memSimRandomGen - printAddress( (void *)&gv_FlmSysData.memSimRandomGen, szAddress); - printHTMLString( - "memSimRandomGen", - "f_randomGenerator", - (void *)&gv_FlmSysData, - (void *)&gv_FlmSysData.memSimRandomGen, - (char *)szAddress, - (bHighlight = !bHighlight)); - - - - // uiSimOutOfMemFailTotal - printHTMLUint( - "uiSimOutOfMemFailTotal", - "FLMUINT", - (void *)&gv_FlmSysData, - (void *)&gv_FlmSysData.uiSimOutOfMemFailTotal, - gv_FlmSysData.uiSimOutOfMemFailTotal, - (bHighlight = !bHighlight)); - - - - // uiSimOutOfMemFailSequence - printHTMLUint( - "uiSimOutOfMemFailSequence", - "FLMUINT", - (void *)&gv_FlmSysData, - (void *)&gv_FlmSysData.uiSimOutOfMemFailSequence, - gv_FlmSysData.uiSimOutOfMemFailSequence, - (bHighlight = !bHighlight)); - -#endif //#ifdef DEBUG_SIM_OUT_OF_MEM -#endif - - // pThreadMgr - printAddress( (void *)gv_FlmSysData.pThreadMgr, szAddress); - printHTMLString( - "pThreadMgr", - "F_ThreadMgr *", - (void *)&gv_FlmSysData, - (void *)&gv_FlmSysData.pThreadMgr, - (char *)szAddress, - (bHighlight = !bHighlight)); - printTableEnd(); Exit: @@ -901,6 +638,9 @@ Exit: return; } +/**************************************************************************** +Desc: +*****************************************************************************/ RCODE F_HttpConfigParmsPage::display( FLMUINT uiNumParams, const char ** ppszParams) diff --git a/flaim/src/imonix.cpp b/flaim/src/imonix.cpp index 90fdc89..db6b1d9 100644 --- a/flaim/src/imonix.cpp +++ b/flaim/src/imonix.cpp @@ -50,7 +50,7 @@ FSTATIC void copyIndexListStatus( FLMBOOL bTransferKeyList); FSTATIC RCODE imonDoIndexList( - F_Thread * pThread); + IF_Thread * pThread); /**************************************************************************** Desc: Prints the web page for listing index keys. @@ -1083,7 +1083,7 @@ RCODE F_IndexListPage::runIndexList( { RCODE rc = FERR_OK; IXLIST_STATUS * pIndexListStatus = NULL; - F_Thread * pThread; + IF_Thread * pThread; FDB * pDb = NULL; // Open the database for the thread - so it doesn't have @@ -1130,13 +1130,13 @@ RCODE F_IndexListPage::runIndexList( // If browser does not check query status at least every 15 seconds, we will // assume it has gone away and the thread will terminate itself. - FLM_SECS_TO_TIMER_UNITS( 15, pIndexListStatus->uiIndexListTimeout); + pIndexListStatus->uiIndexListTimeout = FLM_SECS_TO_TIMER_UNITS( 15); // Start a thread to do the query. if( RC_BAD( rc = f_threadCreate( &pThread, imonDoIndexList, "WEB INDEX LIST", - FLM_DB_THREAD_GROUP, 1, + gv_uiDbThrdGrp, 1, (void *)pIndexListStatus, (void *)hDb))) { goto Exit; @@ -1270,7 +1270,7 @@ void F_IndexListPage::getIndexListStatus( IXLIST_STATUS * pIndexListStatus) { FLMUINT uiThreadId; - F_Thread * pThread = NULL; + IF_Thread * pThread = NULL; IXLIST_STATUS * pThreadIndexListStatus; FLMBOOL bMutexLocked = FALSE; @@ -1284,7 +1284,7 @@ void F_IndexListPage::getIndexListStatus( for (;;) { if (RC_BAD( gv_FlmSysData.pThreadMgr->getNextGroupThread( &pThread, - FLM_DB_THREAD_GROUP, &uiThreadId))) + gv_uiDbThrdGrp, &uiThreadId))) { pIndexListStatus->bIndexListRunning = FALSE; goto Exit; @@ -1402,7 +1402,7 @@ Exit: Desc: Thread to perform a query for a web page. ****************************************************************************/ FSTATIC RCODE imonDoIndexList( - F_Thread * pThread) + IF_Thread * pThread) { RCODE rc; IXLIST_STATUS * pIndexListStatus = (IXLIST_STATUS *)pThread->getParm1(); @@ -1424,8 +1424,7 @@ FSTATIC RCODE imonDoIndexList( char * pszEndStatus = &pIndexListStatus->szEndStatus [0]; pThread->setThreadStatus( FLM_THREAD_STATUS_RUNNING); - - FLM_SECS_TO_TIMER_UNITS( 20, ui20SecsTime); + ui20SecsTime = FLM_SECS_TO_TIMER_UNITS( 20); // Start a transaction. diff --git a/flaim/src/imonqury.cpp b/flaim/src/imonqury.cpp index cea6842..120539d 100644 --- a/flaim/src/imonqury.cpp +++ b/flaim/src/imonqury.cpp @@ -24,7 +24,7 @@ #include "flaimsys.h" -#define Q_FIELD_COLOR FLM_PURPLE +#define Q_FIELD_COLOR FLM_MAGENTA #define Q_LABEL_COLOR FLM_BLACK #define Q_VALUE_COLOR FLM_GREEN #define Q_PARAM_COLOR FLM_BLUE @@ -64,12 +64,12 @@ private: const char * pszStr); void changeColor( - FlmColorType eColor, + eColorType eColor, FLMBOOL bForceColor = FALSE); void appendString( const char * pszStr, - FlmColorType eColor = FLM_CURRENT_COLOR, + eColorType eColor = FLM_CURRENT_COLOR, FLMBOOL bForceColor = FALSE); void newline( void); @@ -99,12 +99,12 @@ private: void outputBinary( FLMBYTE * pucBuf, FLMUINT uiBufLen, - FlmColorType eValueColor = Q_VALUE_COLOR); + eColorType eValueColor = Q_VALUE_COLOR); void outputText( FLMBYTE * pucBuf, FLMUINT uiBufLen, - FlmColorType eColor = Q_VALUE_COLOR); + eColorType eColor = Q_VALUE_COLOR); void outputPredicate( FLMUINT uiIndent, @@ -123,37 +123,37 @@ private: void outputLabel( const char * pszLabel, - FlmColorType eLabelColor = Q_LABEL_COLOR); + eColorType eLabelColor = Q_LABEL_COLOR); void outputStringRow( const char * pszLabel, const char * pszValue, - FlmColorType eLabelColor = Q_LABEL_COLOR, - FlmColorType eValueColor = Q_VALUE_COLOR); + eColorType eLabelColor = Q_LABEL_COLOR, + eColorType eValueColor = Q_VALUE_COLOR); void outputYesNoRow( const char * pszLabel, FLMBOOL bYesNo, - FlmColorType eLabelColor = Q_LABEL_COLOR, - FlmColorType eYesColor = Q_YES_COLOR, - FlmColorType eNoColor = Q_NO_COLOR); + eColorType eLabelColor = Q_LABEL_COLOR, + eColorType eYesColor = Q_YES_COLOR, + eColorType eNoColor = Q_NO_COLOR); void outputUINTRow( const char * pszLabel, FLMUINT uiValue, - FlmColorType eLabelColor = Q_LABEL_COLOR, - FlmColorType eValueColor = Q_VALUE_COLOR); + eColorType eLabelColor = Q_LABEL_COLOR, + eColorType eValueColor = Q_VALUE_COLOR); void outputBinaryRow( const char * pszLabel, FLMBYTE * pucValue, FLMUINT uiValueLen, - FlmColorType eLabelColor, - FlmColorType eValueColor); + eColorType eLabelColor, + eColorType eValueColor); HRequest * m_pHRequest; F_WebPage * m_pWebPage; - FlmColorType m_eCurrColor; + eColorType m_eCurrColor; FLMBOOL m_bSingleLineOnly; FLMUINT m_uiMaxChars; FLMUINT m_uiVisibleChars; @@ -337,7 +337,7 @@ void F_QueryFormatter::outputStr( Desc: Output a new color code, but only if the color has changed. ****************************************************************************/ void F_QueryFormatter::changeColor( - FlmColorType eColor, + eColorType eColor, FLMBOOL bForceColor) { const char * pszColor; @@ -384,7 +384,7 @@ void F_QueryFormatter::changeColor( case FLM_RED: pszColor = ""; break; - case FLM_PURPLE: + case FLM_MAGENTA: pszColor = ""; break; case FLM_BROWN: @@ -414,7 +414,7 @@ void F_QueryFormatter::changeColor( //VISIT: Redo this one pszColor = ""; break; - case FLM_LIGHTPURPLE: + case FLM_LIGHTMAGENTA: //VISIT: Redo this one pszColor = ""; break; @@ -444,7 +444,7 @@ Desc: Append a string to the output buffer. ****************************************************************************/ void F_QueryFormatter::appendString( const char * pszStr, - FlmColorType eColor, + eColorType eColor, FLMBOOL bForceColor) { char szTmpBuf [80]; @@ -678,7 +678,7 @@ Desc: This routine outputs a buffer of binary bytes as ASCII hex. void F_QueryFormatter::outputBinary( FLMBYTE * pucBuf, FLMUINT uiBufLen, - FlmColorType eValueColor) + eColorType eValueColor) { FLMUINT uiLoop; FLMUINT uiOffset; @@ -795,8 +795,7 @@ Desc: This routine outputs text data. void F_QueryFormatter::outputText( FLMBYTE * pucBuf, FLMUINT uiBufLen, - FlmColorType eColor - ) + eColorType eColor) { FLMUINT uiLoop; FLMUINT uiOffset; @@ -924,7 +923,7 @@ void F_QueryFormatter::outputPredicate( for (;;) { - FlmColorType eSaveCurrColor; + eColorType eSaveCurrColor; eCurrentOp = GET_QNODE_TYPE( pQNode); if (IS_OP( eCurrentOp)) @@ -1555,7 +1554,7 @@ Desc: This routine outputs a label in its own column. ****************************************************************************/ void F_QueryFormatter::outputLabel( const char * pszLabel, - FlmColorType eLabelColor) + eColorType eLabelColor) { // Label goes in a column by itself @@ -1577,8 +1576,8 @@ Desc: This routine outputs a row that has a label in column one and a void F_QueryFormatter::outputStringRow( const char * pszLabel, const char * pszValue, - FlmColorType eLabelColor, - FlmColorType eValueColor) + eColorType eLabelColor, + eColorType eValueColor) { // Start a new row in the table @@ -1615,9 +1614,9 @@ Desc: This routine outputs a row that has a label in column one and a void F_QueryFormatter::outputYesNoRow( const char * pszLabel, FLMBOOL bYesNo, - FlmColorType eLabelColor, - FlmColorType eYesColor, - FlmColorType eNoColor) + eColorType eLabelColor, + eColorType eYesColor, + eColorType eNoColor) { // Start a new row in the table @@ -1654,8 +1653,8 @@ Desc: This routine outputs a row that has a label in column one and a void F_QueryFormatter::outputUINTRow( const char * pszLabel, FLMUINT uiValue, - FlmColorType eLabelColor, - FlmColorType eValueColor) + eColorType eLabelColor, + eColorType eValueColor) { char szTmp [20]; @@ -1689,8 +1688,8 @@ void F_QueryFormatter::outputBinaryRow( const char * pszLabel, FLMBYTE * pucValue, FLMUINT uiValueLen, - FlmColorType eLabelColor, - FlmColorType eValueColor) + eColorType eLabelColor, + eColorType eValueColor) { // Start a new row in the table diff --git a/flaim/src/imonscfg.cpp b/flaim/src/imonscfg.cpp index 4773c7d..fde2d83 100644 --- a/flaim/src/imonscfg.cpp +++ b/flaim/src/imonscfg.cpp @@ -296,8 +296,6 @@ void F_SysConfigPage::outputParams( void) outputUINT( FLM_QUERY_MAX, "Max Queries To Save"); - outputBOOL( FLM_USE_ESM, "Use Extended Memory"); - outputBOOL( FLM_CACHE_CHECK, "Cache Checking"); outputBOOL( FLM_SCACHE_DEBUG, "Cache debugging"); @@ -613,7 +611,6 @@ RCODE F_SysConfigPage::doConfig( break; case FLM_SCACHE_DEBUG: case FLM_CACHE_CHECK: - case FLM_USE_ESM: rc = configBOOL( eConfigType, uiNumParams, ppszParams); break; case FLM_BLOB_EXT: diff --git a/flaim/src/imonsel.cpp b/flaim/src/imonsel.cpp index df7749b..dd34d48 100644 --- a/flaim/src/imonsel.cpp +++ b/flaim/src/imonsel.cpp @@ -39,7 +39,7 @@ FSTATIC RCODE queryStatusCB( void * pvUserData); FSTATIC RCODE imonDoQuery( - F_Thread * pThread); + IF_Thread * pThread); /**************************************************************************** Desc: Prints the web page for running queries. @@ -163,7 +163,7 @@ RCODE F_SelectPage::display( fnSetSessionValue( pvHttpSession, QUERY_CRITERIA_LEN, &uiCriteriaLen, sizeof( uiCriteriaLen)); fnSetSessionValue( pvHttpSession, - QUERY_CRITERIA, pszQueryCriteria, (size_t)uiCriteriaLen); + QUERY_CRITERIA, pszQueryCriteria, (FLMSIZET)uiCriteriaLen); fnReleaseSession( pvHttpSession); } } @@ -178,7 +178,7 @@ RCODE F_SelectPage::display( uiSize = sizeof( uiCriteriaLen); if (fnGetSessionValue( pvHttpSession, QUERY_CRITERIA_LEN, (void *)&uiCriteriaLen, - (size_t *)&uiSize) == 0) + (FLMSIZET *)&uiSize) == 0) { if (uiCriteriaLen <= sizeof( szQueryCriteria)) { @@ -195,7 +195,7 @@ RCODE F_SelectPage::display( { if (fnGetSessionValue( pvHttpSession, QUERY_CRITERIA, pszQueryCriteria, - (size_t *)&uiCriteriaLen) != 0) + (FLMSIZET *)&uiCriteriaLen) != 0) { if (pszQueryCriteria != &szQueryCriteria [0]) { @@ -781,7 +781,7 @@ RCODE F_SelectPage::runQuery( { RCODE rc = FERR_OK; QUERY_STATUS * pQueryStatus = NULL; - F_Thread * pThread; + IF_Thread * pThread; FDB * pDb = NULL; // Open the database for the thread - so it doesn't have @@ -815,13 +815,13 @@ RCODE F_SelectPage::runQuery( // If browser does not check query status at least every 15 seconds, we will // assume it has gone away and the thread will terminate itself. - FLM_SECS_TO_TIMER_UNITS( 15, pQueryStatus->uiQueryTimeout); + pQueryStatus->uiQueryTimeout = FLM_SECS_TO_TIMER_UNITS( 15); // Start a thread to do the query. if( RC_BAD( rc = f_threadCreate( &pThread, imonDoQuery, "WEB QUERY", - FLM_DB_THREAD_GROUP, 1, + gv_uiDbThrdGrp, 1, (void *)pQueryStatus, (void *)hDb))) { goto Exit; @@ -871,7 +871,7 @@ void F_SelectPage::getQueryStatus( ) { FLMUINT uiThreadId; - F_Thread * pThread = NULL; + IF_Thread * pThread = NULL; QUERY_STATUS * pThreadQueryStatus; FLMBOOL bMutexLocked = FALSE; @@ -887,7 +887,7 @@ void F_SelectPage::getQueryStatus( for (;;) { if (RC_BAD( gv_FlmSysData.pThreadMgr->getNextGroupThread( &pThread, - FLM_DB_THREAD_GROUP, &uiThreadId))) + gv_uiDbThrdGrp, &uiThreadId))) { pQueryStatus->bQueryRunning = FALSE; goto Exit; @@ -1048,7 +1048,7 @@ Exit: Desc: Thread to perform a query for a web page. ****************************************************************************/ FSTATIC RCODE imonDoQuery( - F_Thread * pThread) + IF_Thread * pThread) { RCODE rc; QUERY_STATUS * pQueryStatus = (QUERY_STATUS *)pThread->getParm1(); @@ -1062,8 +1062,7 @@ FSTATIC RCODE imonDoQuery( FLMBOOL bTransStarted = FALSE; pThread->setThreadStatus( FLM_THREAD_STATUS_INITIALIZING); - - FLM_SECS_TO_TIMER_UNITS( 5, ui5SecsTime); + ui5SecsTime = FLM_SECS_TO_TIMER_UNITS( 5); // Start a transaction. diff --git a/flaim/src/imonslmg.cpp b/flaim/src/imonslmg.cpp deleted file mode 100644 index 163f83e..0000000 --- a/flaim/src/imonslmg.cpp +++ /dev/null @@ -1,190 +0,0 @@ -//------------------------------------------------------------------------- -// Desc: Class for displaying lock manager information in HTML on a web page. -// Tabs: 3 -// -// Copyright (c) 2002-2003,2005-2006 Novell, Inc. All Rights Reserved. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of version 2 of the GNU General Public -// License as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, contact Novell, Inc. -// -// To contact Novell about this file by physical or electronic mail, -// you may find current contact information at www.novell.com -// -// $Id: imonslmg.cpp 12329 2006-01-20 17:49:30 -0700 (Fri, 20 Jan 2006) ahodgkinson $ -//------------------------------------------------------------------------- - -#include "flaimsys.h" - -/**************************************************************************** -Desc: Implements the display function of the F_ServerLockMgrPage -*****************************************************************************/ -RCODE F_ServerLockMgrPage::display( - FLMUINT uiNumParams, - const char ** ppszParams) -{ - RCODE rc = FERR_OK; - ServerLockManager_p pServerLockMgr; - FLMBOOL bHighlight = FALSE; - FLMBOOL bRefresh; - char szAddress[20]; - char * pszTemp = NULL; - - if( RC_BAD( rc = f_alloc( 150, &pszTemp))) - { - printErrorPage( rc, TRUE, "Failed to allocate temporary buffer"); - goto Exit; - } - - stdHdr(); - - fnPrintf( m_pHRequest, HTML_DOCTYPE); - fnPrintf( m_pHRequest, "\n"); - - // Get the pointer to the ServerLockManager - pServerLockMgr = gv_FlmSysData.pServerLockMgr; - - if (!pServerLockMgr) - { - rc = RC_SET(FERR_NOT_FOUND); - printErrorPage( rc, TRUE, "No ServerLockManager exists"); - goto Exit; - } - - //Check to see if we are to refresh this page automatically. - if ((bRefresh = DetectParameter( uiNumParams, - ppszParams, - "Refresh")) == TRUE) - { - //Send back the page with a refresh command in the header - - char szTemp[100]; - - f_sprintf(szTemp, "%s/ServerLockManager?Refresh", - m_pszURLString); - - fnPrintf( m_pHRequest, - "" - "" - "Server Lock Manager\n", - szTemp); - - } - else - { - fnPrintf( m_pHRequest, - "Server Lock Manager\n"); - } - printStyle(); - fnPrintf( m_pHRequest, "\n"); - - - fnPrintf( m_pHRequest, "\n"); - - printTableStart( "ServerLockManager", 4, 100); - - // If we are not to refresh this page, then don't include the refresh meta command - if (!bRefresh) - { - f_sprintf( pszTemp, - "Start Auto-refresh (5 sec.)", - m_pszURLString); - } - else - { - f_sprintf( pszTemp, - "Stop Auto-refresh", - m_pszURLString); - } - - printTableRowStart(); - printColumnHeading( "", JUSTIFY_LEFT, FLM_IMON_COLOR_PUTTY_1, 4, 1, FALSE); - fnPrintf( m_pHRequest, "Refresh, ", - m_pszURLString); - fnPrintf( m_pHRequest, "%s\n", pszTemp); - printColumnHeadingClose(); - - printTableRowStart(); - printColumnHeading( "Byte Offset (hex)"); - printColumnHeading( "Field Name"); - printColumnHeading( "Field Type"); - printColumnHeading( "Value"); - printTableRowEnd(); - - - - // m_phMutex - printAddress( pServerLockMgr->m_phMutex, szAddress); - printHTMLString( - "m_phMutex", - "F_MUTEX", - (void *)pServerLockMgr, - (void *)&pServerLockMgr->m_phMutex, - szAddress, - (bHighlight = ~bHighlight)); - - // m_pHashTbl - printAddress( pServerLockMgr->m_pHashTbl, szAddress); - printHTMLString( - "m_pHashTbl", - "FBUCKET *", - (void *)pServerLockMgr, - (void *)&pServerLockMgr->m_pHashTbl, - szAddress, - (bHighlight = ~bHighlight)); - - // m_pFirstLockWaiter - printAddress( pServerLockMgr->m_pFirstLockWaiter, szAddress); - printHTMLString( - "m_pFirstLockWaiter", - "LOCK_WAITER", - (void *)pServerLockMgr, - (void *)&pServerLockMgr->m_pFirstLockWaiter, - szAddress, - (bHighlight = ~bHighlight)); - - // m_uiNumAvail - printHTMLUint( - "m_uiNumAvail", - "FLMUINT", - (void *)pServerLockMgr, - (void *)&pServerLockMgr->m_uiNumAvail, - pServerLockMgr->m_uiNumAvail, - (bHighlight = ~bHighlight)); - - // m_pAvailLockList - printAddress( pServerLockMgr->m_pAvailLockList, szAddress); - printHTMLString( - "m_pAvailLockList", - "ServerLockObject *", - (void *)pServerLockMgr, - (void *)&pServerLockMgr->m_pAvailLockList, - szAddress, - (bHighlight = ~bHighlight)); - - printTableEnd(); - - - printDocEnd(); - - fnEmit(); - -Exit: - - if (pszTemp) - { - f_free( &pszTemp); - } - - return( rc); -} - - diff --git a/flaim/src/imonstat.cpp b/flaim/src/imonstat.cpp index 9e21237..9e00e82 100644 --- a/flaim/src/imonstat.cpp +++ b/flaim/src/imonstat.cpp @@ -199,12 +199,14 @@ void F_StatsPage::gatherDbStats( } // Gather lock statistics - flmUpdateCountTimeStats( &pStatGather->NoLocks, - &pDbStats->NoLocks); - flmUpdateCountTimeStats( &pStatGather->WaitingForLock, - &pDbStats->WaitingForLock); - flmUpdateCountTimeStats( &pStatGather->HeldLock, - &pDbStats->HeldLock); + flmUpdateCountTimeStats( &pStatGather->LockStats.NoLocks, + &pDbStats->LockStats.NoLocks); + + flmUpdateCountTimeStats( &pStatGather->LockStats.WaitingForLock, + &pDbStats->LockStats.WaitingForLock); + + flmUpdateCountTimeStats( &pStatGather->LockStats.HeldLock, + &pDbStats->LockStats.HeldLock); for (uiLoop = 0; uiLoop < pDbStats->uiNumLFileStats; uiLoop++) { @@ -378,7 +380,7 @@ RCODE F_StatsPage::display( if (fnGetSessionValue( pvSession, STAT_DISPLAY_ORDER, (void *)szStatOrder, - (size_t *)&uiSize) != 0) + (FLMSIZET *)&uiSize) != 0) { // If we could not get display order, then set the default. f_strcpy( szStatOrder, DEFAULT_STAT_ORDER); @@ -389,7 +391,7 @@ RCODE F_StatsPage::display( if (fnGetSessionValue( pvSession, STAT_FOCUS, (void *)szFocus, - (size_t *)&uiSize) == 0) + (FLMSIZET *)&uiSize) == 0) { szFocus[ uiSize] = '\0'; if (RC_BAD( setFocus( szFocus))) @@ -491,7 +493,7 @@ RCODE F_StatsPage::display( (void)fnSetSessionValue( pvSession, STAT_DISPLAY_ORDER, szStatNewOrder, - (size_t)(f_strlen( szStatNewOrder) + 1)); + (FLMSIZET)(f_strlen( szStatNewOrder) + 1)); } if (RC_BAD( rc = f_calloc( sizeof( STAT_GATHER), &pStatGather))) @@ -517,7 +519,7 @@ RCODE F_StatsPage::display( if (fnGetSessionValue( pvSession, SAVED_STATS, (void *)pOldStatGather, - (size_t *)&uiSize) != 0) + (FLMSIZET *)&uiSize) != 0) { // If we could not get any former stats, then just copy the current one. f_memcpy( pOldStatGather, pStatGather, sizeof( STAT_GATHER)); @@ -806,11 +808,11 @@ void F_StatsPage::printIORow( Desc: Outputs count/time statistics for a particular category. ****************************************************************************/ void F_StatsPage::printCountTimeRow( - FLMBOOL bHighlight, - const char * pszCategory, - COUNT_TIME_STAT * pStat, - COUNT_TIME_STAT * pOldStat, - FLMBOOL bPrintCountOnly) + FLMBOOL bHighlight, + const char * pszCategory, + F_COUNT_TIME_STAT * pStat, + F_COUNT_TIME_STAT * pOldStat, + FLMBOOL bPrintCountOnly) { char szTemp[ 30]; @@ -976,11 +978,10 @@ Desc: Gets the LOCK_USER information for the specified pFile. ****************************************************************************/ void F_StatsPage::gatherLockStats( STAT_GATHER * pStatGather, - FFILE * pFile - ) + FFILE * pFile) { - LOCK_USER_HEADER_p pTmp; - RCODE rc; + LOCK_USER_HEADER_p pTmp; + RCODE rc; flmAssert( pStatGather); flmAssert( pFile); @@ -1009,7 +1010,8 @@ void F_StatsPage::gatherLockStats( // two locks - Write locks (tx) and Wait locks (db). if (pFile->pFileLockObj) { - if (RC_BAD( rc = pFile->pFileLockObj->GetLockInfo( TRUE, (void *)&pTmp->pDbLockUser))) + if (RC_BAD( rc = pFile->pFileLockObj->getLockQueue( + &pTmp->pDbLockUser))) { pTmp->pDbLockUser = NULL; } @@ -1021,7 +1023,8 @@ void F_StatsPage::gatherLockStats( if (pFile->pWriteLockObj) { - if (RC_BAD( rc = pFile->pWriteLockObj->GetLockInfo( TRUE, (void *)&pTmp->pTxLockUser))) + if (RC_BAD( rc = pFile->pWriteLockObj->getLockQueue( + &pTmp->pTxLockUser))) { pTmp->pTxLockUser = NULL; } @@ -1037,14 +1040,12 @@ Exit: return; } - /**************************************************************************** Desc: Gets the CHECKPOINT_INFO information for the specified pFile. ****************************************************************************/ void F_StatsPage::gatherCPStats( STAT_GATHER * pStatGather, - FFILE * pFile - ) + FFILE * pFile) { CP_INFO_HEADER_p pTmp; RCODE rc = FERR_OK; @@ -1285,8 +1286,8 @@ void F_StatsPage::printOperationStats( STAT_GATHER * pStatGather, STAT_GATHER * pOldStatGather) { - COUNT_TIME_STAT Stat; - COUNT_TIME_STAT OldStat; + F_COUNT_TIME_STAT Stat; + F_COUNT_TIME_STAT OldStat; FLMBOOL bHighlight; if (pStatGather->uiStartTime) @@ -1391,6 +1392,8 @@ void F_StatsPage::printLockStats( STAT_GATHER * pStatGather, STAT_GATHER * pOldStatGather) { + FLMUINT uiLen; + if (pStatGather->uiStartTime) { LOCK_USER_HEADER_p pLckHdr; @@ -1410,14 +1413,16 @@ void F_StatsPage::printLockStats( printTableRowEnd(); printCountTimeRow( TRUE, "Time No Locks Held", - &pStatGather->NoLocks, - &pOldStatGather->NoLocks); + &pStatGather->LockStats.NoLocks, + &pOldStatGather->LockStats.NoLocks); + printCountTimeRow( FALSE, "Time Waiting for Locks", - &pStatGather->WaitingForLock, - &pOldStatGather->WaitingForLock); + &pStatGather->LockStats.WaitingForLock, + &pOldStatGather->LockStats.WaitingForLock); + printCountTimeRow( TRUE, "Time Locks Held", - &pStatGather->HeldLock, - &pOldStatGather->HeldLock); + &pStatGather->LockStats.HeldLock, + &pOldStatGather->LockStats.HeldLock); printTableEnd(); @@ -1429,7 +1434,7 @@ void F_StatsPage::printLockStats( char szTitle[ 128]; FLMBOOL bHighlight = FALSE; FLMBOOL bLocked = TRUE; - LOCK_USER * pLckUsr; + F_LOCK_USER * pLckUsr; FLMUINT uiTxWaiters; FLMUINT uiDbWaiters; @@ -1488,17 +1493,9 @@ void F_StatsPage::printLockStats( printTableDataEnd(); printTableDataStart( TRUE, JUSTIFY_RIGHT); -#ifdef FLM_NLM - if( kGetThreadName( pLckUsr->uiThreadId, (char *)szThreadName, - sizeof( szThreadName)) !=0) - { - f_sprintf( (char *)szThreadName, "N/A"); - } -#else - // Get the thread name from the thread manager -// gv_FlmSysData.pThreadMgr->getThreadName( pLckUsr->uiThreadId, szThreadName); - f_sprintf( (char *)szThreadName, "N/A"); // VISIT: Remove this when you get the function above working -#endif + uiLen = sizeof( szThreadName); + gv_FlmSysData.pThreadMgr->getThreadName( + pLckUsr->uiThreadId, szThreadName, &uiLen); fnPrintf( m_pHRequest, "%s", szThreadName); printTableDataEnd(); // Status @@ -1531,17 +1528,9 @@ void F_StatsPage::printLockStats( printTableDataEnd(); printTableDataStart( TRUE, JUSTIFY_RIGHT); -#ifdef FLM_NLM - if( kGetThreadName( pLckUsr->uiThreadId, (char *)szThreadName, - sizeof( szThreadName)) !=0) - { - f_sprintf( (char *)szThreadName, "N/A"); - } -#else - // Get the thread name from the thread manager -// gv_FlmSysData.pThreadMgr->getThreadName( pLckUsr->uiThreadId, szThreadName); - f_sprintf( (char *)szThreadName, "N/A"); // VISIT: Remove this when you get the function above working -#endif + uiLen = sizeof( szThreadName); + gv_FlmSysData.pThreadMgr->getThreadName( pLckUsr->uiThreadId, + szThreadName, &uiLen); fnPrintf( m_pHRequest, "%s", szThreadName); printTableDataEnd(); // Status @@ -2048,7 +2037,7 @@ void F_StatsPage::displayFocus( if (fnSetSessionValue( pvSession, STAT_FOCUS, (void *)szTemp, - (size_t)f_strlen(szTemp)) != 0) + (FLMSIZET)f_strlen(szTemp)) != 0) { flmAssert( 0); goto Exit; diff --git a/flaim/src/imonutil.cpp b/flaim/src/imonutil.cpp index 70d2eab..3bf3c43 100644 --- a/flaim/src/imonutil.cpp +++ b/flaim/src/imonutil.cpp @@ -1886,9 +1886,9 @@ RCODE F_FlmThreadsPage::display( FLMUINT uiCurrentTime; FLMUINT uiNumThreads; F_THREAD_INFO * pThreadInfo = NULL; - POOL pool; + F_Pool pool; - GedPoolInit( &pool, 1024); + pool.poolInit( 1024); printDocStart( "Threads", FALSE); @@ -2018,7 +2018,6 @@ RCODE F_FlmThreadsPage::display( Exit: fnEmit(); - GedPoolFree( &pool); return( FERR_OK); } @@ -2030,9 +2029,10 @@ RCODE F_HttpFile::display( const char ** ppszParams) { FlmStaticFile * pStaticFile; - F_FileHdl * pSrcFile = NULL; - F_DirHdl * pDirHdl = NULL; + IF_FileHdl * pSrcFile = NULL; + IF_DirHdl * pDirHdl = NULL; FLMUINT uiSize; + FLMUINT64 ui64FileSize; FLMUINT uiBytesRead; FLMUINT uiOffset; FLMBYTE * pucBuf = NULL; @@ -2151,9 +2151,9 @@ RCODE F_HttpFile::display( // See if a directory listing has been requested. - if( gv_FlmSysData.pFileSystem->IsDir( szPath)) + if( gv_FlmSysData.pFileSystem->isDir( szPath)) { - if (RC_BAD( rc = gv_FlmSysData.pFileSystem->OpenDir( + if (RC_BAD( rc = gv_FlmSysData.pFileSystem->openDir( szPath, "*", &pDirHdl))) { goto ReportErrorExit; @@ -2182,7 +2182,8 @@ RCODE F_HttpFile::display( // Output the parent directory bHaveParent = FALSE; - if( RC_BAD( rc = f_pathReduce( szPath, szTmp, NULL))) + if( RC_BAD( rc = gv_FlmSysData.pFileSystem->pathReduce( + szPath, szTmp, NULL))) { if( rc == FERR_IO_AT_PATH_ROOT) { @@ -2205,7 +2206,7 @@ RCODE F_HttpFile::display( { if( !bHaveParent) { - if (RC_BAD( rc = pDirHdl->Next())) + if (RC_BAD( rc = pDirHdl->next())) { if (rc == FERR_IO_NO_MORE_FILES) { @@ -2217,7 +2218,7 @@ RCODE F_HttpFile::display( goto Exit; } } - pDirHdl->CurrentItemPath( szTmp); + pDirHdl->currentItemPath( szTmp); } printTableRowStart( (uiCount & 0x00000001) ? FALSE : TRUE); @@ -2231,14 +2232,14 @@ RCODE F_HttpFile::display( fnPrintf( m_pHRequest, "\">"); printEncodedString( bHaveParent ? ".. " - : pDirHdl->CurrentItemName(), HTML_ENCODING); + : pDirHdl->currentItemName(), HTML_ENCODING); fnPrintf( m_pHRequest, "\n"); printTableDataEnd(); // File type printTableDataStart(); - if( bHaveParent || pDirHdl->CurrentItemIsDir()) + if( bHaveParent || pDirHdl->currentItemIsDir()) { fnPrintf( m_pHRequest, "Dir"); } @@ -2251,9 +2252,9 @@ RCODE F_HttpFile::display( // File size printTableDataStart(); - if( !bHaveParent && !pDirHdl->CurrentItemIsDir()) + if( !bHaveParent && !pDirHdl->currentItemIsDir()) { - fnPrintf( m_pHRequest, "%u", pDirHdl->CurrentItemSize()); + fnPrintf( m_pHRequest, "%u", pDirHdl->currentItemSize()); } else { @@ -2268,7 +2269,7 @@ RCODE F_HttpFile::display( { FLMUINT uiTimestamp; - if( RC_BAD( gv_FlmSysData.pFileSystem->GetTimeStamp( + if( RC_BAD( gv_FlmSysData.pFileSystem->getFileTimeStamp( szTmp, &uiTimestamp))) { uiTimestamp = 0; @@ -2285,8 +2286,8 @@ RCODE F_HttpFile::display( printTableDataStart(); if( !bHaveParent && - (f_strstr( pDirHdl->CurrentItemName(), ".db") != NULL || - f_strstr( pDirHdl->CurrentItemName(), ".DB") != NULL)) + (f_strstr( pDirHdl->currentItemName(), ".db") != NULL || + f_strstr( pDirHdl->currentItemName(), ".DB") != NULL)) { fnPrintf( m_pHRequest, "Open( szPath, - F_IO_RDONLY | F_IO_SH_DENYNONE, &pSrcFile))) + if( RC_BAD( rc = gv_FlmSysData.pFileSystem->openFile( szPath, + FLM_IO_RDONLY | FLM_IO_SH_DENYNONE, &pSrcFile))) { if( rc == FERR_IO_PATH_NOT_FOUND) { @@ -2339,10 +2340,12 @@ RCODE F_HttpFile::display( // Get the file size - if( RC_BAD( rc = pSrcFile->Size( &uiSize))) + if( RC_BAD( rc = pSrcFile->size( &ui64FileSize))) { goto ReportErrorExit; } + + uiSize = (FLMUINT)ui64FileSize; // Allocate a buffer for streaming the data back to the client @@ -2363,7 +2366,7 @@ RCODE F_HttpFile::display( uiOffset = 0; for( ;;) { - if( RC_BAD( rc = pSrcFile->Read( uiOffset, uiBufSize, + if( RC_BAD( rc = pSrcFile->read( uiOffset, uiBufSize, pucBuf, &uiBytesRead))) { if( rc == FERR_IO_END_OF_FILE) @@ -3093,138 +3096,6 @@ ReportErrorExit: goto Exit; } -/**************************************************************************** -Desc: Displays information about return codes -****************************************************************************/ -RCODE F_RCodeLookupPage::display( - FLMUINT uiNumParams, - const char ** ppszParams) -{ - char szCode[ 128]; - FLMUINT uiLow; - FLMUINT uiCount; - FLMUINT uiHigh; - FLMUINT uiLoop; - - // Extract the lookup parameter - - szCode[ 0] = 0; - if( RC_BAD( ExtractParameter( uiNumParams, ppszParams, - "rc", sizeof( szCode), szCode))) - { - if( f_strnicmp( ppszParams[ 0], "returncode/", 11) == 0 && - f_strlen( ppszParams[ 0]) > 11) - { - f_strcpy( szCode, &ppszParams[ 0][ 11]); - } - } - else if( !szCode[ 0]) - { - f_strcpy( szCode, "all"); - } - - // Document - - printDocStart( (char *)"Return Code Lookup"); - - // Insert a form into the page to get the file path - - fnPrintf( m_pHRequest, "
\n", - m_pszURLString); - fnPrintf( m_pHRequest, "
\n
\nReturn Code
\n" - "
\n"); - printButton( "Submit", BT_Submit); - fnPrintf( m_pHRequest, "
\n
\n
\n"); - - // Done? - - if( !szCode[ 0]) - { - printDocEnd(); - goto Exit; - } - - // Translate any escaped characters in the path - - fcsDecodeHttpString( szCode); - - // Get the value of the RCODE - - if( f_stricmp( szCode, "all") != 0) - { - if( (uiLow = f_atoud( szCode)) < (FLMUINT)FIRST_FLAIM_ERROR) - { - uiLow = (FLMUINT)FIRST_FLAIM_ERROR; - } - - if( (uiHigh = uiLow + 100) > (FLMUINT)LAST_FLAIM_ERROR) - { - uiHigh = (FLMUINT)LAST_FLAIM_ERROR; - } - } - else - { - uiLow = (FLMUINT)FIRST_FLAIM_ERROR; - uiHigh = (FLMUINT)LAST_FLAIM_ERROR; - } - - // Put a little space between the form and the table - - fnPrintf( m_pHRequest, "
\n"); - - // Table - - printTableStart( (char *)"Return Code(s)", 3); - - // Table column headers - - printTableRowStart(); - printColumnHeading( "Hex"); - printColumnHeading( "Decimal"); - printColumnHeading( "Name"); - printTableRowEnd(); - - uiCount = 0; - for( uiLoop = uiLow; uiLoop <= uiHigh; uiLoop++) - { - const char * pszName = flmErrorString( (RCODE)uiLoop); - - if( pszName) - { - printTableRowStart( ((uiCount++) & 0x00000001) ? FALSE : TRUE); - - // Hex - - printTableDataStart(); - fnPrintf( m_pHRequest, "0x%04X", (unsigned)uiLoop); - printTableDataEnd(); - - // Decimal - - printTableDataStart(); - fnPrintf( m_pHRequest, "%u", (unsigned)uiLoop); - printTableDataEnd(); - - // Name - - printTableDataStart(); - fnPrintf( m_pHRequest, "%s", pszName); - printTableDataEnd(); - - printTableRowEnd(); - } - } - - printTableEnd(); - printDocEnd(); - -Exit: - - fnEmit(); - return( FERR_OK); -} - /**************************************************************************** Desc: ****************************************************************************/ @@ -3853,12 +3724,12 @@ void F_DatabasePage::printSessionDatabaseList( F_SessionDb * pSessionDb; FLMBOOL bChecked; FLMUINT uiTransType; - FLOCK_TYPE lockType; - FLMBOOL bImplicit; + FLMBOOL bImplicit = FALSE; FLMBOOL bAllowLock; FLMBOOL bAllowUnlock; char * pszDbKey; char szDbOption [80]; + eLockType lockType; // Table @@ -4190,11 +4061,11 @@ RCODE F_RecordMgrPage::display( FLMBOOL bUpdateSelected = FALSE; FLMBOOL bDeleteSelected = FALSE; FLMBOOL bReserveDrnSelected = FALSE; - POOL pool; + F_Pool pool; // Initialize a pool for XML parsing - GedPoolInit( &pool, 1024); + pool.poolInit( 1024); // Check the session @@ -4307,12 +4178,12 @@ RCODE F_RecordMgrPage::display( fcsDecodeHttpString( pszXmlInRec); } - if( pszXmlInRec && *pszXmlInRec && hDb != HFDB_NULL) - { - FCS_BUFISTM bufIStream( (FLMBYTE *)pszXmlInRec, f_strlen( pszXmlInRec)); - (void)pFlmSession->getXmlImport()->importDocument( - hDb, pNameTable, &bufIStream, TRUE, &pInRec); - } +// if( pszXmlInRec && *pszXmlInRec && hDb != HFDB_NULL) +// { +// FCS_BUFISTM bufIStream( (FLMBYTE *)pszXmlInRec, f_strlen( pszXmlInRec)); +// (void)pFlmSession->getXmlImport()->importDocument( +// hDb, pNameTable, &bufIStream, TRUE, &pInRec); +// } if( hDb == HFDB_NULL) { @@ -4565,20 +4436,20 @@ RCODE F_RecordMgrPage::display( // Record - if( pRec || pInRec) - { - if( !pRec) - { - pRec = pInRec; - pInRec = NULL; - } - - if( RC_BAD( rc = pFlmSession->getXmlExport()->exportRecord( - pNameTable, pRec, 0, 3, &pool, &pszXmlOutRec, NULL))) - { - goto Exit; - } - } +// if( pRec || pInRec) +// { +// if( !pRec) +// { +// pRec = pInRec; +// pInRec = NULL; +// } +// +// if( RC_BAD( rc = pFlmSession->getXmlExport()->exportRecord( +// pNameTable, pRec, 0, 3, &pool, &pszXmlOutRec, NULL))) +// { +// goto Exit; +// } +// } printTableRowStart( bHighlight); bHighlight = !bHighlight; @@ -4630,7 +4501,6 @@ Exit: f_free( &pszXmlInRec); } - GedPoolFree( &pool); return( FERR_OK); ReportErrorExit: @@ -4977,7 +4847,7 @@ void F_DatabaseConfigPage::outputValue( case FDB_GET_DEFAULT_LANG: if( RC_OK( rc = FlmDbGetConfig( hDb, (eDbGetConfigType)uiType, &uiValue1))) { - FlmGetLanguage( uiValue1, (char *)szValue); + f_languageToStr( uiValue1, (char *)szValue); fnPrintf( m_pHRequest, TD_s, szValue); } break; @@ -5224,9 +5094,9 @@ void F_WebPage::printLanguagePulldown( fnPrintf( m_pHRequest, "