diff --git a/configure b/configure
index b2d9f1b34f8ce9121763d5672911964e0e519f79..02ee6c5a0e4b4a95e08a869444dbcdf7ac4a1bfa 100755
--- a/configure
+++ b/configure
@@ -685,7 +685,7 @@ enable/disable options, prefix with either --enable- or --disable-
   python             Python ROOT bindings, requires python >= 2.1
   qt                 Qt graphics backend, requires libqt >= 3
   reflex             Build the libReflex dictionary library
-  rfio               CASTOR support, requires libshift from CASTOR >= 2.0.0
+  rfio               CASTOR 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
@@ -1387,18 +1387,41 @@ fi
 #
 # (See http://castor.web.cern.ch/castor/)
 #
-# Check for stager_api.h and libshift.a
+# Check for rfio_api.h, stager_api.h for CASTOR 2 and libshift.a
 #
 shiftold=""
 if test ! "x$enable_rfio" = "xno" ; then
     # Check for RFIO include and library
-    check_header "stager_api.h" "$shiftincdir" $RFIO $RFIO/include $RFIO/h \
+    keepincdir=$shiftincdir
+    check_header "rfio_api.h" "$shiftincdir" $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
     shiftinc=$found_hdr
     shiftincdir=$found_dir
 
+    if test ! "x$shiftincdir" = "x"; then
+        message "Checking whether rfio_fchmod declared in $shiftinc"
+        if `grep rfio_fchmod $shiftincdir/$shiftinc > /dev/null 2>&1` ; then
+            echo "yes"
+        else
+            shiftincdir=""
+            shiftold="yes"
+            echo "no"
+            echo "### Found old version of libshift, please uprade to >=1.5.2"
+        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
+    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 \
@@ -1406,12 +1429,6 @@ if test ! "x$enable_rfio" = "xno" ; then
     shiftlib=$found_lib
     shiftlibdir=$found_dir
 
-    if test ! "x$shiftlib" = "x" && test "x$shiftincdir" = "x"; then
-         shiftlib=""
-         shiftold="yes"
-         echo "### Found old version of libshift, please uprade to >=2.0.0"
-    fi
-
     if test "x$shiftincdir" = "x" || test "x$shiftlib" = "x"; then
         enable_rfio="no"
     else
@@ -1464,7 +1481,7 @@ if test ! "x$enable_cern" = "xno"; then
             if test  $found_symbol -eq 0 ; then
                 echo "### Need libshift with this version of $packlib"
                 if test "x$shiftold" = "xyes"; then
-                    echo "### Found old version of libshift, please uprade to >=2.0.0"
+                    echo "### Found old version of libshift, please uprade to >=1.5.2"
                 else
                     echo "### Run configure with --enable-rfio or set --with-shift-libdir"
                 fi
@@ -1878,7 +1895,7 @@ if test ! "x$enable_xml" = "xno" ; then
     else
        echo "not found"
        # fall back in case xml2-config is not found
-       keepinc=$xmlincdir
+       keepincdir=$xmlincdir
        check_header "libxml/tree.h" "$xmlincdir" $XMLDIR $XMLDIR/include \
            /opt/libxml2/include /usr/local/include/libxml2 /usr/include/libxml2
        xmlincdir=$found_dir
@@ -1890,7 +1907,7 @@ if test ! "x$enable_xml" = "xno" ; then
        xmllibdir=$found_dir
 
        if test "x$platform" = "xwin32"; then
-          check_header "iconv.h" "$keepinc" $ICONVDIR $ICONVDIR/include \
+          check_header "iconv.h" "$keepincdir" $ICONVDIR $ICONVDIR/include \
               $XMLDIR $XMLDIR/include \
               /opt/libxml2/include /usr/local/include/libxml2 /usr/include/libxml2
           iconvincdir=$found_dir
@@ -3214,6 +3231,7 @@ sed -e "s|@ldflags@||"                          \
     -e "s|@shiftincdir@|$shiftincdir|"          \
     -e "s|@shiftlib@|$shiftlib|"                \
     -e "s|@shiftlibdir@|$shiftlibdir|"          \
+    -e "s|@shiftcflags@|$shiftcflags|"          \
     -e "s|@srcdir@|$srcdir|"                    \
     -e "s|@srpincdir@|$srpincdir|"              \
     -e "s|@srplib@|$srplib|"                    \
diff --git a/rfio/Module.mk b/rfio/Module.mk
index e779d36f8063c967810deef024da21afc65cfc28..c449a8beaf3c86fea1b1cb65c9e4b345b25bc1d7 100644
--- a/rfio/Module.mk
+++ b/rfio/Module.mk
@@ -69,8 +69,9 @@ distclean::     distclean-rfio
 ##### extra rules ######
 $(RFIOO): %.o: %.cxx
 ifeq ($(PLATFORM),win32)
-	$(CXX) $(OPT) $(CXXFLAGS) -D__INSIDE_CYGWIN__ $(SHIFTINCDIR:%=-I%) \
-	   -o $@ -c $<
+	$(CXX) $(OPT) $(CXXFLAGS) $(SHIFTCFLAGS) -D__INSIDE_CYGWIN__ \
+	   $(SHIFTINCDIR:%=-I%) -o $@ -c $<
 else
-	$(CXX) $(OPT) $(CXXFLAGS) $(SHIFTINCDIR:%=-I%) -o $@ -c $<
+	$(CXX) $(OPT) $(CXXFLAGS) $(SHIFTCFLAGS) $(SHIFTINCDIR:%=-I%) \
+	   -o $@ -c $<
 endif
diff --git a/rfio/src/TCastorFile.cxx b/rfio/src/TCastorFile.cxx
index 2a017351066b48233eb5f0c3925891dfff9caee9..7790924fd562b1bee2f7b27e5ecdc71adef73be2 100644
--- a/rfio/src/TCastorFile.cxx
+++ b/rfio/src/TCastorFile.cxx
@@ -1,4 +1,4 @@
-// @(#)root/net:$Name:  $:$Id: TCastorFile.cxx,v 1.5 2003/11/29 01:47:13 rdm Exp $
+// @(#)root/net:$Name:  $:$Id: TCastorFile.cxx,v 1.8 2005/08/17 12:58:40 rdm Exp $
 // Author: Fons Rademakers + Jean-Damien Durand 17/09/2003 + Ben Couturier 31/05/2005
 
 /*************************************************************************
@@ -28,6 +28,7 @@
 //////////////////////////////////////////////////////////////////////////
 
 #include "TCastorFile.h"
+#include "TError.h"
 
 #include <stdlib.h>
 #include <errno.h>
@@ -37,7 +38,9 @@
 #include <WinSock2.h>
 #endif
 
-#include <stager_api.h>       // For the new CASTOR Stager
+#ifdef R__CASTOR2
+#include <stager_api.h>       // For the new CASTOR 2 Stager
+#endif
 #define RFIO_KERNEL           // Get access to extra symbols in the headers
 #include <stage_api.h>        // Dial with CASTOR stager
 #include <rfio_api.h>         // Util routines from rfio
@@ -50,18 +53,28 @@ extern "C" { char *getconfent(char *, char *, int); }
 //______________________________________________________________________________
 static int UseCastor2API()
 {
-   // Function that checks whetehr we should use the old or new stager API.
+   // Function that checks whether we should use the old or new stager API.
 
    char *p;
 
    if (((p = getenv(RFIO_USE_CASTOR_V2)) == 0) &&
        ((p = getconfent("RFIO","USE_CASTOR_V2",0)) == 0)) {
       // Variable not set: compat mode
-      return(0);
+      return 0;
    }
    if ((strcmp(p,"YES") == 0) || (strcmp(p,"yes") == 0) || (atoi(p) == 1)) {
+#ifdef R__CASTOR2
       // Variable set to yes or 1 : new mode
       return 1;
+#else
+      // Variable set to yes or 1 but old CASTOR 1: compat mode + warning
+      static int once = 0;
+      if (!once) {
+         ::Warning("UseCastor2API", "asked to use CASTOR 2, but linked with CASTOR 1");
+         once = 1;
+      }
+      return 0;
+#endif
    }
    // Variable set but not to 1 : compat mode
    return 0;
@@ -250,7 +263,10 @@ void TCastorFile::FindServerAndPath()
       // server 'host', e.g. it is fDiskServer:fInternalPath
       fInternalPath = stcp_output->ipath;
       free(stcp_output);
+
    } else {
+
+#ifdef R__CASTOR2
       // We use the new stager API
       int flags = O_RDONLY;
       int rc;
@@ -318,6 +334,8 @@ void TCastorFile::FindServerAndPath()
       if (response) free(response);
       if (url) free(url);
       if (requestId) free(requestId);
+#endif
+
    }
 
    fIsCastor = kTRUE;