diff --git a/Makefile b/Makefile
index f86bf0e71b469ee178da82f38b0fdccb1b94b651..a200219eb05ef2e964066d6a9835de4994d1e7e9 100644
--- a/Makefile
+++ b/Makefile
@@ -93,9 +93,12 @@ endif
 ifeq ($(BUILDODBC),yes)
 MODULES      += odbc
 endif
-ifeq ($(BUILDSHIFT),yes)
+ifeq ($(BUILDRFIO),yes)
 MODULES      += rfio
 endif
+ifeq ($(BUILDCASTOR),yes)
+MODULES      += castor
+endif
 ifeq ($(BUILDDCAP),yes)
 MODULES      += dcache
 endif
@@ -207,7 +210,7 @@ endif
 -include MyModules.mk   # allow local modules
 
 ifneq ($(findstring $(MAKECMDGOALS),distclean maintainer-clean),)
-MODULES      += unix winnt x11 x11ttf win32gdk gl rfio thread \
+MODULES      += unix winnt x11 x11ttf win32gdk gl rfio castor thread \
                 pythia pythia6 venus table mysql pgsql sapdb srputils x3d \
                 rootx rootd proofd proof dcache chirp hbook alien asimage \
                 ldap mlp krb5auth rpdutils globusauth pyroot ruby gfal \
diff --git a/castor/Module.mk b/castor/Module.mk
new file mode 100644
index 0000000000000000000000000000000000000000..7ef3375ff7c1b79012ce188f5c5a5846b1e21da2
--- /dev/null
+++ b/castor/Module.mk
@@ -0,0 +1,71 @@
+# Module.mk for castor module
+# Copyright (c) 2000 Rene Brun and Fons Rademakers
+#
+# Author: Fons Rademakers, 29/2/2000
+
+MODDIR       := castor
+MODDIRS      := $(MODDIR)/src
+MODDIRI      := $(MODDIR)/inc
+
+CASTORDIR    := $(MODDIR)
+CASTORDIRS   := $(CASTORDIR)/src
+CASTORDIRI   := $(CASTORDIR)/inc
+
+##### libRCastor #####
+CASTORL      := $(MODDIRI)/LinkDef.h
+CASTORDS     := $(MODDIRS)/G__CASTOR.cxx
+CASTORDO     := $(CASTORDS:.cxx=.o)
+CASTORDH     := $(CASTORDS:.cxx=.h)
+
+CASTORH      := $(filter-out $(MODDIRI)/LinkDef%,$(wildcard $(MODDIRI)/*.h))
+CASTORS      := $(filter-out $(MODDIRS)/G__%,$(wildcard $(MODDIRS)/*.cxx))
+CASTORO      := $(CASTORS:.cxx=.o)
+
+CASTORDEP    := $(CASTORO:.o=.d) $(CASTORDO:.o=.d)
+
+CASTORLIB    := $(LPATH)/libRCastor.$(SOEXT)
+
+# used in the main Makefile
+ALLHDRS     += $(patsubst $(MODDIRI)/%.h,include/%.h,$(CASTORH))
+ALLLIBS     += $(CASTORLIB)
+
+# include all dependency files
+INCLUDEFILES += $(CASTORDEP)
+
+##### local rules #####
+include/%.h:    $(CASTORDIRI)/%.h
+		cp $< $@
+
+$(CASTORLIB):   $(CASTORO) $(CASTORDO) $(ORDER_) $(MAINLIBS)
+		@$(MAKELIB) $(PLATFORM) $(LD) "$(LDFLAGS)" \
+		   "$(SOFLAGS)" libRCastor.$(SOEXT) $@ \
+		   "$(CASTORO) $(CASTORDO)" "$(CASTORLIBDIR) $(CASTORCLILIB)"
+
+$(CASTORDS):    $(CASTORH) $(CASTORL) $(ROOTCINTTMPEXE)
+		@echo "Generating dictionary $@..."
+		$(ROOTCINTTMP) -f $@ -c $(CASTORH) $(CASTORL)
+
+all-castor:     $(CASTORLIB)
+
+map-castor:     $(RLIBMAP)
+		$(RLIBMAP) -r $(ROOTMAP) -l $(CASTORLIB) \
+		   -d $(CASTORLIBDEP) -c $(CASTORL)
+
+map::           map-castor
+
+clean-castor:
+		@rm -f $(CASTORO) $(CASTORDO)
+
+clean::         clean-castor
+
+distclean-castor: clean-castor
+		@rm -f $(CASTORDEP) $(CASTORDS) $(CASTORDH) $(CASTORLIB)
+
+distclean::     distclean-castor
+
+##### extra rules ######
+ifeq ($(PLATFORM),win32)
+$(CASTORO): CXXFLAGS += $(CASTORCFLAGS) $(CASTORINCDIR:%=-I%) -DNOGDI -D__INSIDE_CYGWIN__
+else
+$(CASTORO): CXXFLAGS += $(CASTORCFLAGS) $(CASTORINCDIR:%=-I%)
+endif
diff --git a/castor/inc/LinkDef.h b/castor/inc/LinkDef.h
new file mode 100644
index 0000000000000000000000000000000000000000..a52d33aad56046091a7e57abe1175156338cd52f
--- /dev/null
+++ b/castor/inc/LinkDef.h
@@ -0,0 +1,19 @@
+/* @(#)root/castor:$Name:  $:$Id: LinkDef.h,v 1.3 2003/09/21 21:38:30 rdm Exp $ */
+
+/*************************************************************************
+ * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
+ * All rights reserved.                                                  *
+ *                                                                       *
+ * For the licensing terms see $ROOTSYS/LICENSE.                         *
+ * For the list of contributors see $ROOTSYS/README/CREDITS.             *
+ *************************************************************************/
+
+#ifdef __CINT__
+
+#pragma link off all globals;
+#pragma link off all classes;
+#pragma link off all functions;
+
+#pragma link C++ class TCastorFile;
+
+#endif
diff --git a/rfio/inc/TCastorFile.h b/castor/inc/TCastorFile.h
similarity index 97%
rename from rfio/inc/TCastorFile.h
rename to castor/inc/TCastorFile.h
index 8d7125bdaa44828c6206f75bfe330e524f8d5a2d..06ac39cdb01c88dbaa360e5daea4f1334e517e1f 100644
--- a/rfio/inc/TCastorFile.h
+++ b/castor/inc/TCastorFile.h
@@ -1,4 +1,4 @@
-// @(#)root/rfio:$Name:  $:$Id: TCastorFile.h,v 1.3 2006/07/10 13:01:12 rdm Exp $
+// @(#)root/castor:$Name:  $:$Id: TCastorFile.h,v 1.4 2006/07/24 16:26:28 rdm Exp $
 // Author: Fons Rademakers  17/09/2003 + Giulia Taurelli  29/06/2006
 
 /*************************************************************************
diff --git a/rfio/src/TCastorFile.cxx b/castor/src/TCastorFile.cxx
similarity index 99%
rename from rfio/src/TCastorFile.cxx
rename to castor/src/TCastorFile.cxx
index c3ecaded4cba209f6bfc341c2859c1b9f33ff0eb..b31117c12352e418fb2d044025d13f06062f1313 100644
--- a/rfio/src/TCastorFile.cxx
+++ b/castor/src/TCastorFile.cxx
@@ -1,4 +1,4 @@
-// @(#)root/net:$Name:  $:$Id: TCastorFile.cxx,v 1.13 2006/07/10 13:01:12 rdm Exp $
+// @(#)root/castor:$Name:  $:$Id: TCastorFile.cxx,v 1.14 2006/07/24 16:26:28 rdm Exp $
 // Author: Fons Rademakers + Jean-Damien Durand 17/09/2003 + Ben Couturier 31/05/2005
 // + Giulia Taurelli 26/04/2006
 
diff --git a/config/Makefile.in b/config/Makefile.in
index fff2639296378ccf2db5d2a0cc8d9cae8c9a95aa..1f5902e1280bb9c74f44a12d6b2cf33fa91a949a 100644
--- a/config/Makefile.in
+++ b/config/Makefile.in
@@ -101,12 +101,18 @@ QTLIB          := @qtlib@
 QTINCDIR       := $(filter-out /usr/include, @qtincdir@)
 QTMOCEXE       := @qtmocexe@
 
-BUILDSHIFT     := @buildshift@
+BUILDRFIO      := @buildrfio@
 SHIFTLIBDIR    := @shiftlibdir@
 SHIFTLIB       := @shiftlib@
 SHIFTINCDIR    := $(filter-out /usr/include, @shiftincdir@)
 SHIFTCFLAGS    := @shiftcflags@
 
+BUILDCASTOR    := @buildcastor@
+CASTORLIBDIR   := @castorlibdir@
+CASTORCLILIB   := @castorlib@
+CASTORINCDIR   := $(filter-out /usr/include, @castorincdir@)
+CASTORCFLAGS   := @castorcflags@
+
 BUILDDCAP      := @builddcap@
 DCAPLIBDIR     := @dcaplibdir@
 DCAPLIB        := @dcaplib@
diff --git a/config/rootrc.in b/config/rootrc.in
index b1fda2720e4a030c8e75b37c885ab91590a576bc..d015988883784f180d810646ccb9ca44606f8799 100644
--- a/config/rootrc.in
+++ b/config/rootrc.in
@@ -1,4 +1,4 @@
-# @(#)root/config:$Name:  $:$Id: rootrc.in,v 1.144 2006/06/20 13:21:24 brun Exp $
+# @(#)root/config:$Name:  $:$Id: rootrc.in,v 1.145 2006/06/21 16:18:26 rdm Exp $
 # Author: Fons Rademakers  22/09/95
 
 # ROOT Environment settings are handled via the class TEnv. To see
@@ -429,7 +429,7 @@ XProof.Debug:  0
 
 # Plugin library handlers.
 Plugin.TFile:        ^rfio:    TRFIOFile     RFIO    "TRFIOFile(const char*,Option_t*,const char*,Int_t)"
-+Plugin.TFile:       ^castor:  TCastorFile   RFIO    "TCastorFile(const char*,Option_t*,const char*,Int_t,Int_t)"
++Plugin.TFile:       ^castor:  TCastorFile   RCastor "TCastorFile(const char*,Option_t*,const char*,Int_t,Int_t)"
 +Plugin.TFile:       ^dcache:  TDCacheFile   DCache  "TDCacheFile(const char*,Option_t*,const char*,Int_t)"
 +Plugin.TFile:       ^dcap:    TDCacheFile   DCache  "TDCacheFile(const char*,Option_t*,const char*,Int_t)"
 +Plugin.TFile:       ^gfal:    TGFALFile     GFAL    "TGFALFile(const char*,Option_t*,const char*,Int_t)"
diff --git a/configure b/configure
index 61ec608fb67dd8df16e23e93585ca5d97d78baa4..85f3e50adc55c493f070f2cd2f8d402cc53c6795 100755
--- a/configure
+++ b/configure
@@ -32,6 +32,7 @@ options="                    \
    enable_builtin_freetype   \
    enable_builtin_pcre       \
    enable_builtin_zlib       \
+   enable_castor             \
    enable_cern               \
    enable_chirp              \
    enable_cintex             \
@@ -117,6 +118,7 @@ PGSQL            \
 QTDIR            \
 SAPDB            \
 RFIO             \
+CASTOR           \
 GFAL             \
 GSL              \
 CERNLIB          \
@@ -823,6 +825,7 @@ enable/disable options, prefix with either --enable- or --disable-
   builtin-freetype   Built included libfreetype, or use system libfreetype
   builtin-pcre       Built included libpcre, or use system libpcre
   builtin-zlib       Built included libz, or use system libz
+  castor             CASTOR support, requires libshift from CASTOR >= 1.5.2
   cern               CERNLIB usage, build h2root and g2root
   chirp              Chirp support (Condor remote I/O), requires libchirp_client
   cintex             Build the libCintex Reflex interface library
@@ -852,7 +855,7 @@ enable/disable options, prefix with either --enable- or --disable-
   qt                 Qt graphics backend, requires libqt >= 3
   qtgsi              GSI's Qt integration, requires libqt >= 3
   reflex             Build the libReflex dictionary library
-  rfio               CASTOR support, requires libshift from CASTOR >= 1.5.2
+  rfio               RFIO support, requires libshift from CASTOR >= 1.5.2
   roofit             Build the libRooFit advanced fitting package
   rpath              Set run-time library load path on executables
   ruby               Ruby ROOT bindings, requires ruby >= 1.8
@@ -874,6 +877,8 @@ with options, prefix with --with-, enables corresponding support
   afs                AFS support, location of AFS distribution
   alien-incdir       AliEn support, location of gapiUI.h
   alien-libdir       AliEn support, location of libapiUI
+  castor-incdir      CASTOR support, location of stager_api.h
+  castor-libdir      CASTOR support, location of libshift
   cern-libdir        HBOOK converter, location of CERNLIB libraries
   chirp-incdir       Chirp support, location of chirp_client.h
   chirp-libdir       Chirp support, location of libchirp_client
@@ -916,8 +921,8 @@ with options, prefix with --with-, enables corresponding support
   ruby-libdir        Ruby support, location of libruby
   sapdb-incdir       SapDB support, location of sql.h
   sapdb-libdir       SapDB support, location of libsqlod
-  shift-incdir       CASTOR support, location of stager_api.h
-  shift-libdir       CASTOR support, location of libshift
+  shift-incdir       RFIO support, location of rfio_api.h
+  shift-libdir       RFIO support, location of libshift
   srp                Secure Remote Passwd support, location of SRP distribution
   srp-incdir         SRP support, location header of t_server.h
   srp-libdir         SRP support, location header of libsrp.a
@@ -1054,6 +1059,8 @@ if test $# -gt 0 ; then
       --with-alien-libdir=*)   alienlibdir=$optarg   ; enable_alien="yes"   ;;
       --with-afterimage-incdir=*) afterimageincdir=$optarg; enable_builtin_afterimage=no ;;
       --with-afterimage-libdir=*) afterimagelibdir=$optarg; enable_builtin_afterimage=no ;;
+      --with-castor-incdir=*)  castorsincdir=$optarg ; enable_castor="yes"  ;;
+      --with-castor-libdir=*)  castorlibdir=$optarg  ; enable_castor="yes"  ;;
       --with-cern-libdir=*)    cernlibdir=$optarg    ; enable_cern="yes"    ;;
       --with-chirp-incdir=*)   chirpincdir=$optarg   ; enable_chirp="yes"   ;;
       --with-chirp-libdir=*)   chirplibdir=$optarg   ; enable_chirp="yes"   ;;
@@ -1782,11 +1789,11 @@ check_explicit "$enable_qt" "$enable_qt_explicit" \
 
 ######################################################################
 #
-### echo %%% CASTOR Support - Third party libraries
+### echo %%% RFIO Support - Third party libraries
 #
 # (See http://castor.web.cern.ch/castor/)
 #
-# Check for rfio_api.h, stager_api.h for CASTOR 2 and libshift.a
+# Check for rfio_api.h of CASTOR 2 and libshift.a
 #
 shiftold=""
 if test ! "x$enable_rfio" = "xno" ; then
@@ -1812,25 +1819,6 @@ if test ! "x$enable_rfio" = "xno" ; then
         fi
     fi
 
-    check_header "stager_api.h" "$keepincdir" $RFIO $RFIO/include $RFIO/h \
-	/cern/pro/include /cern/new/include /cern/old/include \
-	/opt/shift/include /usr/local/shift/inlcude /usr/include/shift \
-	/usr/local/include/shift /usr/include /usr/local/include
-    stagerinc=$found_hdr
-
-    if test ! "x$stagerinc" = "x"; then
-        shiftcflags=-DR__CASTOR2
-        # check for Castor >= 2.1
-        message "Checking for Castor version >= 2.1"
-        castor_version=`grep "define BASEVERSION" $shiftincdir/patchlevel.h | sed 's/^.*"\([0-9]\.[0-9]\.[0-9]\)"/\1/' | awk 'BEGIN { FS="." } { printf "%d", $1 * 1000 + $2 }'`
-        if test $castor_version -lt 2001; then
-            shiftincdir=""
-            result "no"
-        else
-            result "ok"
-        fi
-    fi
-
     check_library "libshift shiftmd shift" "$enable_shared" "$shiftlibdir" \
 	$RFIO $RFIO/lib /cern/pro/lib /cern/new/lib /cern/old/lib \
 	/opt/shift/lib /usr/local/shift/lib /usr/lib/shift \
@@ -1867,6 +1855,93 @@ fi
 check_explicit "$enable_rfio" "$enable_rfio_explicit" \
      "Explicitly required Castor dependencies not fulfilled"
 
+######################################################################
+#
+### echo %%% CASTOR Support - Third party libraries
+#
+# (See http://castor.web.cern.ch/castor/)
+#
+# Check for rfio_api.h, stager_api.h for CASTOR 2 and libshift.a
+#
+castorold=""
+if test ! "x$enable_castor" = "xno" ; then
+    # Check for Castor include and library
+    keepincdir=$castorincdir
+    check_header "rfio_api.h" "$castorincdir" $CASTOR $CASTOR/include $CASTOR/h \
+	/cern/pro/include /cern/new/include /cern/old/include \
+	/opt/shift/include /usr/local/shift/inlcude /usr/include/shift \
+	/usr/local/include/shift /usr/include /usr/local/include
+    castorinc=$found_hdr
+    castorincdir=$found_dir
+
+    if test ! "x$castorincdir" = "x"; then
+        message "Checking whether rfio_fchmod declared in $castorinc"
+	logmsg "grep rfio_fchmod $castorincdir/$castorinc"
+        if `grep rfio_fchmod $castorincdir/$castorinc >> $logfile 2>&1` ; then
+            result "yes"
+        else
+            castorincdir=""
+            castorold="yes"
+            result "no"
+            result "### Found old version of libshift, please uprade to >=1.5.2"
+        fi
+    fi
+
+    check_header "stager_api.h" "$keepincdir" $CASTOR $CASTOR/include $CASTOR/h \
+	/cern/pro/include /cern/new/include /cern/old/include \
+	/opt/shift/include /usr/local/shift/inlcude /usr/include/shift \
+	/usr/local/include/shift /usr/include /usr/local/include
+    stagerinc=$found_hdr
+
+    if test ! "x$stagerinc" = "x"; then
+        castorcflags=-DR__CASTOR2
+        # check for Castor >= 2.1
+        message "Checking for Castor version >= 2.1"
+        castor_version=`grep "define BASEVERSION" $castorincdir/patchlevel.h | sed 's/^.*"\([0-9]\.[0-9]\.[0-9]\)"/\1/' | awk 'BEGIN { FS="." } { printf "%d", $1 * 1000 + $2 }'`
+        if test $castor_version -lt 2001; then
+            castorincdir=""
+            result "no"
+        else
+            result "ok"
+        fi
+    fi
+
+    check_library "libshift shiftmd shift" "$enable_shared" "$castorlibdir" \
+	$CASTOR $CASTOR/lib /cern/pro/lib /cern/new/lib /cern/old/lib \
+	/opt/shift/lib /usr/local/shift/lib /usr/lib/shift \
+	/usr/local/lib/shift /usr/lib /usr/local/lib
+    castorlib=$found_lib
+    castorlibdir=$found_dir
+
+    if test "x$castorincdir" = "x" || test "x$castorlib" = "x"; then
+        enable_castor="no"
+    else
+        case $platform in
+           linux)      castorlib="$castorlib -lnsl"
+		for i in "" -ladns ; do
+		    echo "extern rfio_fchmod(); int main() { rfio_fchmod(); return 0; }" > conftest.c
+		    logmsg "Checking if we can link against $castorlib"
+		    logmsg "gcc conftest.c $castorlibdir $castorlib $i -o conftest"
+		    gcc conftest.c $castorlibdir $castorlib $i -o conftest >> $logfile 2>&1
+		    if test $? -eq 0 ; then
+			castorlib="$castorlib $i" ;
+			break ;
+		    else
+			logmsg "Failed program was:"
+			cat conftest.c >> $logfile
+		    fi
+		done
+		rm -f conftest.c conftest
+		;;
+           solaris)    castorlib="$castorlib -lposix4" ;;
+           win32)      castorincdir="$castorincdir $castorincdir/../win32"
+                       castorlib="$castorlib WSock32.lib Ws2_32.lib" ;;
+        esac
+    fi
+fi
+check_explicit "$enable_castor" "$enable_castor_explicit" \
+     "Explicitly required Castor dependencies not fulfilled"
+
 ######################################################################
 #
 ### echo %%% GFAL Support - Third party libraries
@@ -3704,6 +3779,7 @@ fi
 if test "x$show_pkglist" = "xyes" ; then
     test "x$enable_alien"   = "xyes" && pkglist="$pkglist root-plugin-alien"
     test "x$enable_asimage" = "xyes" && pkglist="$pkglist root-plugin-asimage"
+    test "x$enable_castor"  = "xyes" && pkglist="$pkglist root-plugin-castor"
     test "x$enable_cern"    = "xyes" && pkglist="$pkglist root-plugin-hbook"
     test "x$enable_chirp"   = "xyes" && pkglist="$pkglist root-plugin-chirp"
     test "x$enable_clarens" = "xyes" && pkglist="$pkglist libroot-clarens"
@@ -3728,7 +3804,7 @@ if test "x$show_pkglist" = "xyes" ; then
     test "x$enable_qt"      = "xyes" && pkglist="$pkglist root-plugin-qt"
     test "x$enable_roofit"  = "xyes" && pkglist="$pkglist libroot-roofit"
     test "x$enable_ruby"    = "xyes" && pkglist="$pkglist libroot-ruby"
-    test "x$enable_rfio"    = "xyes" && pkglist="$pkglist root-plugin-castor"
+    test "x$enable_rfio"    = "xyes" && pkglist="$pkglist root-plugin-rfio"
     test "x$enable_sapdb"   = "xyes" && pkglist="$pkglist root-plugin-maxdb"
     test "x$enable_srp"     = "xyes" && pkglist="$pkglist root-plugin-srp"
     test "x$enable_venus"   = "xyes" && pkglist="$pkglist root-plugin-venus"
@@ -3965,6 +4041,10 @@ sed -e "s|@aclocaldir@|$aclocaldir|"            \
     -e "s|@buildxrd@|$buildxrd|"                \
     -e "s|@cernlibdir@|$cernlibdir|"            \
     -e "s|@cernlibs@|$cernlib|"                 \
+    -e "s|@castorincdir@|$castorincdir|"        \
+    -e "s|@castorlib@|$castorlib|"              \
+    -e "s|@castorlibdir@|$castorlibdir|"        \
+    -e "s|@castorcflags@|$castorcflags|"        \
     -e "s|@chirpincdir@|$chirpincdir|"          \
     -e "s|@chirplib@|$chirplib|"                \
     -e "s|@chirplibdir@|$chirplibdir|"          \
@@ -4122,7 +4202,8 @@ sed -e "s|@srcdir@|$srcdir|"                    \
     -e "s|@buildsapdb@|$enable_sapdb|"          \
     -e "s|@buildqt@|$enable_qt|"                \
     -e "s|@buildqtgsi@|$enable_qtgsi|"          \
-    -e "s|@buildshift@|$enable_rfio|"           \
+    -e "s|@buildrfio@|$enable_rfio|"            \
+    -e "s|@buildcastor@|$enable_castor|"        \
     -e "s|@builddcap@|$enable_dcache|"          \
     -e "s|@buildfftw3@|$enable_fftw3|"          \
     -e "s|@buildgfal@|$enable_gfal|"            \