From d9fb90a6e3ec5de387e55fc5647f0932ac766934 Mon Sep 17 00:00:00 2001
From: Daniele Kruse <dkruse@cern.ch>
Date: Thu, 12 Feb 2015 16:44:52 +0100
Subject: [PATCH] First example of xrdcp usage

---
 xroot_clients/CTACopyCmd.cpp       |  5 +-
 xroot_plugins/XrdProFile.cpp       | 76 +++++++++++++-----------------
 xroot_plugins/XrdProFile.hpp       |  4 +-
 xroot_plugins/XrdProFilesystem.cpp | 18 +++----
 xroot_plugins/xrd.cf.fst           |  5 +-
 5 files changed, 52 insertions(+), 56 deletions(-)

diff --git a/xroot_clients/CTACopyCmd.cpp b/xroot_clients/CTACopyCmd.cpp
index 33a07fe5ae..8b827d8b8d 100644
--- a/xroot_clients/CTACopyCmd.cpp
+++ b/xroot_clients/CTACopyCmd.cpp
@@ -49,8 +49,9 @@ int CTACopyCmd::main(const int argc, char **argv) throw() {
 //------------------------------------------------------------------------------
 int CTACopyCmd::executeCommand(const int argc, char **argv)  {
   XrdCl::PropertyList properties;
-  properties.Set("source", "/afs/cern.ch/user/d/dkruse/vmgrlisttape.txt2");
-  properties.Set("target", "/afs/cern.ch/user/d/dkruse/vmgrlisttape.txt3");  
+  properties.Set("source", "root://localhost//himama");
+  properties.Set("target", "/afs/cern.ch/user/d/dkruse/lola.txt"); 
+  properties.Set("force", true);
   XrdCl::PropertyList results;
   XrdCl::CopyProcess copyProcess;
   
diff --git a/xroot_plugins/XrdProFile.cpp b/xroot_plugins/XrdProFile.cpp
index 744ed012ba..74f10ef353 100644
--- a/xroot_plugins/XrdProFile.cpp
+++ b/xroot_plugins/XrdProFile.cpp
@@ -1,28 +1,26 @@
 #include "XrdProFile.hpp"
 
+#include <iostream>
+
 //------------------------------------------------------------------------------
 // open
 //------------------------------------------------------------------------------
-int XrdProFile::open(const char *fileName, XrdSfsFileOpenMode openMode, mode_t createMode, const XrdSecEntity *client, const char *opaque){
-  
-  error.setErrInfo(ENOTSUP, "Not supported.");
-  return SFS_ERROR;
+int XrdProFile::open(const char *fileName, XrdSfsFileOpenMode openMode, mode_t createMode, const XrdSecEntity *client, const char *opaque) {
+  m_data = "Hello this is my data";
+  return SFS_OK;
 }
 
 //------------------------------------------------------------------------------
 // close
 //------------------------------------------------------------------------------
-int XrdProFile::close(){
-  
-  error.setErrInfo(ENOTSUP, "Not supported.");
-  return SFS_ERROR;
+int XrdProFile::close() {
+  return SFS_OK;
 }
 
 //------------------------------------------------------------------------------
 // fctl
 //------------------------------------------------------------------------------
-int XrdProFile::fctl(const int cmd, const char *args, XrdOucErrInfo &eInfo){
-  
+int XrdProFile::fctl(const int cmd, const char *args, XrdOucErrInfo &eInfo) {  
   error.setErrInfo(ENOTSUP, "Not supported.");
   return SFS_ERROR;
 }
@@ -30,8 +28,7 @@ int XrdProFile::fctl(const int cmd, const char *args, XrdOucErrInfo &eInfo){
 //------------------------------------------------------------------------------
 // FName
 //------------------------------------------------------------------------------
-const char* XrdProFile::FName(){
-  
+const char* XrdProFile::FName() {
   error.setErrInfo(ENOTSUP, "Not supported.");
   return NULL;
 }
@@ -39,17 +36,15 @@ const char* XrdProFile::FName(){
 //------------------------------------------------------------------------------
 // getMmap
 //------------------------------------------------------------------------------
-int XrdProFile::getMmap(void **Addr, off_t &Size){
-  
-  error.setErrInfo(ENOTSUP, "Not supported.");
+int XrdProFile::getMmap(void **Addr, off_t &Size) {
+  *Addr = const_cast<char *>(m_data.c_str()); Size = m_data.length();
   return SFS_ERROR;
 }
 
 //------------------------------------------------------------------------------
 // read
 //------------------------------------------------------------------------------
-XrdSfsXferSize XrdProFile::read(XrdSfsFileOffset offset, XrdSfsXferSize size){
-  
+XrdSfsXferSize XrdProFile::read(XrdSfsFileOffset offset, XrdSfsXferSize size) {
   error.setErrInfo(ENOTSUP, "Not supported.");
   return 0;
 }
@@ -57,17 +52,21 @@ XrdSfsXferSize XrdProFile::read(XrdSfsFileOffset offset, XrdSfsXferSize size){
 //------------------------------------------------------------------------------
 // read
 //------------------------------------------------------------------------------
-XrdSfsXferSize XrdProFile::read(XrdSfsFileOffset offset, char *buffer, XrdSfsXferSize size){
-  
-  error.setErrInfo(ENOTSUP, "Not supported.");
-  return 0;
+XrdSfsXferSize XrdProFile::read(XrdSfsFileOffset offset, char *buffer, XrdSfsXferSize size) {
+  if((unsigned long)offset<m_data.length()) {
+    strncpy(buffer, m_data.c_str()+offset, size);
+    return m_data.length()-offset;
+  }
+  else {
+    buffer = NULL;
+    return 0;
+  }
 }
 
 //------------------------------------------------------------------------------
 // read
 //------------------------------------------------------------------------------
-XrdSfsXferSize XrdProFile::read(XrdSfsAio *aioparm){
-  
+XrdSfsXferSize XrdProFile::read(XrdSfsAio *aioparm) {
   error.setErrInfo(ENOTSUP, "Not supported.");
   return 0;
 }
@@ -75,8 +74,7 @@ XrdSfsXferSize XrdProFile::read(XrdSfsAio *aioparm){
 //------------------------------------------------------------------------------
 // write
 //------------------------------------------------------------------------------
-XrdSfsXferSize XrdProFile::write(XrdSfsFileOffset offset, const char *buffer, XrdSfsXferSize size){
-  
+XrdSfsXferSize XrdProFile::write(XrdSfsFileOffset offset, const char *buffer, XrdSfsXferSize size) {
   error.setErrInfo(ENOTSUP, "Not supported.");
   return 0;
 }
@@ -84,8 +82,7 @@ XrdSfsXferSize XrdProFile::write(XrdSfsFileOffset offset, const char *buffer, Xr
 //------------------------------------------------------------------------------
 // write
 //------------------------------------------------------------------------------
-int XrdProFile::write(XrdSfsAio *aioparm){
-  
+int XrdProFile::write(XrdSfsAio *aioparm) {
   error.setErrInfo(ENOTSUP, "Not supported.");
   return SFS_ERROR;
 }
@@ -93,17 +90,15 @@ int XrdProFile::write(XrdSfsAio *aioparm){
 //------------------------------------------------------------------------------
 // stat
 //------------------------------------------------------------------------------
-int XrdProFile::stat(struct stat *buf){
-  
-  error.setErrInfo(ENOTSUP, "Not supported.");
-  return SFS_ERROR;
+int XrdProFile::stat(struct stat *buf) {
+  buf->st_size=m_data.length();
+  return SFS_OK;
 }
 
 //------------------------------------------------------------------------------
 // sync
 //------------------------------------------------------------------------------
-int XrdProFile::sync(){
-  
+int XrdProFile::sync() {
   error.setErrInfo(ENOTSUP, "Not supported.");
   return SFS_ERROR;
 }
@@ -111,8 +106,7 @@ int XrdProFile::sync(){
 //------------------------------------------------------------------------------
 // sync
 //------------------------------------------------------------------------------
-int XrdProFile::sync(XrdSfsAio *aiop){
-  
+int XrdProFile::sync(XrdSfsAio *aiop) {
   error.setErrInfo(ENOTSUP, "Not supported.");
   return SFS_ERROR;
 }
@@ -120,8 +114,7 @@ int XrdProFile::sync(XrdSfsAio *aiop){
 //------------------------------------------------------------------------------
 // truncate
 //------------------------------------------------------------------------------
-int XrdProFile::truncate(XrdSfsFileOffset fsize){
-  
+int XrdProFile::truncate(XrdSfsFileOffset fsize) {
   error.setErrInfo(ENOTSUP, "Not supported.");
   return SFS_ERROR;
 }
@@ -129,8 +122,7 @@ int XrdProFile::truncate(XrdSfsFileOffset fsize){
 //------------------------------------------------------------------------------
 // getCXinfo
 //------------------------------------------------------------------------------
-int XrdProFile::getCXinfo(char cxtype[4], int &cxrsz){
-  
+int XrdProFile::getCXinfo(char cxtype[4], int &cxrsz) {
   error.setErrInfo(ENOTSUP, "Not supported.");
   return SFS_ERROR;
 }
@@ -138,13 +130,11 @@ int XrdProFile::getCXinfo(char cxtype[4], int &cxrsz){
 //------------------------------------------------------------------------------
 // Constructor
 //------------------------------------------------------------------------------
-XrdProFile::XrdProFile(const char *user, int MonID): error(user, MonID){
-  
+XrdProFile::XrdProFile(const char *user, int MonID): error(user, MonID) {  
 }
 
 //------------------------------------------------------------------------------
 // Destructor
 //------------------------------------------------------------------------------
-XrdProFile::~XrdProFile(){
-  
+XrdProFile::~XrdProFile() {  
 }
\ No newline at end of file
diff --git a/xroot_plugins/XrdProFile.hpp b/xroot_plugins/XrdProFile.hpp
index 0f2122f376..3caaf2d3ef 100644
--- a/xroot_plugins/XrdProFile.hpp
+++ b/xroot_plugins/XrdProFile.hpp
@@ -2,6 +2,8 @@
 
 #include "XrdSfs/XrdSfsInterface.hh"
 
+#include <string>
+
 class XrdProFile : public XrdSfsFile {
 public:
   XrdOucErrInfo  error;
@@ -23,5 +25,5 @@ public:
   XrdProFile(const char *user=0, int MonID=0);
   ~XrdProFile();
 protected:
-  
+  std::string m_data;
 };
\ No newline at end of file
diff --git a/xroot_plugins/XrdProFilesystem.cpp b/xroot_plugins/XrdProFilesystem.cpp
index 37bc369b61..9ee4b34b24 100644
--- a/xroot_plugins/XrdProFilesystem.cpp
+++ b/xroot_plugins/XrdProFilesystem.cpp
@@ -1,4 +1,5 @@
 #include "XrdProFilesystem.hpp"
+#include "XrdProFile.hpp"
 
 #include "XrdOuc/XrdOucString.hh"
 #include "XrdSec/XrdSecEntity.hh"
@@ -1001,6 +1002,14 @@ int XrdProFilesystem::FSctl(const int cmd, XrdSfsFSctl &args, XrdOucErrInfo &eIn
   }
 }
 
+//------------------------------------------------------------------------------
+// newFile
+//------------------------------------------------------------------------------
+XrdSfsFile * XrdProFilesystem::newFile(char *user, int MonID)
+{  
+  return new XrdProFile(user, MonID);
+}
+
 //------------------------------------------------------------------------------
 // fsctl
 //------------------------------------------------------------------------------
@@ -1127,15 +1136,6 @@ XrdSfsDirectory * XrdProFilesystem::newDir(char *user, int MonID)
   return NULL;
 }
 
-//------------------------------------------------------------------------------
-// newFile
-//------------------------------------------------------------------------------
-XrdSfsFile * XrdProFilesystem::newFile(char *user, int MonID)
-{
-  (void)user; (void)MonID;
-  return NULL;
-}
-
 //------------------------------------------------------------------------------
 // chksum
 //------------------------------------------------------------------------------
diff --git a/xroot_plugins/xrd.cf.fst b/xroot_plugins/xrd.cf.fst
index 6b882ee175..f1c8f18078 100644
--- a/xroot_plugins/xrd.cf.fst
+++ b/xroot_plugins/xrd.cf.fst
@@ -1,4 +1,7 @@
 xrootd.fslib /home/dkruse/CTA/build/xroot_plugins/libXrdProFst.so
 xrootd.seclib libXrdSec.so
 sec.protocol krb5 /etc/krb5.keytab.dkruse host/<host>@CERN.CH
-sec.protbind * only krb5
\ No newline at end of file
+sec.protbind * only krb5
+all.export /
+xrootd.async off
+
-- 
GitLab