XRootD
Loading...
Searching...
No Matches
XrdClFS.cc
Go to the documentation of this file.
1//------------------------------------------------------------------------------
2// Copyright (c) 2011-2014 by European Organization for Nuclear Research (CERN)
3// Author: Lukasz Janyst <ljanyst@cern.ch>
4//------------------------------------------------------------------------------
5// This file is part of the XRootD software suite.
6//
7// XRootD is free software: you can redistribute it and/or modify
8// it under the terms of the GNU Lesser General Public License as published by
9// the Free Software Foundation, either version 3 of the License, or
10// (at your option) any later version.
11//
12// XRootD is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15// GNU General Public License for more details.
16//
17// You should have received a copy of the GNU Lesser General Public License
18// along with XRootD. If not, see <http://www.gnu.org/licenses/>.
19//
20// In applying this licence, CERN does not waive the privileges and immunities
21// granted to it by virtue of its status as an Intergovernmental Organization
22// or submit itself to any jurisdiction.
23//------------------------------------------------------------------------------
24
30#include "XrdCl/XrdClFile.hh"
34#include "XrdCl/XrdClLog.hh"
36#include "XrdCl/XrdClStatus.hh"
37#include "XrdCl/XrdClURL.hh"
38#include "XrdCl/XrdClUtils.hh"
41#include "XrdSys/XrdSysE2T.hh"
42
43#include <algorithm>
44#include <cctype>
45#include <getopt.h>
46#include <iterator>
47#include <cmath>
48#include <cstdio>
49#include <cstdlib>
50#include <iomanip>
51#include <iostream>
52#include <memory>
53#include <unistd.h>
54
55#ifdef HAVE_READLINE
56#include <readline/history.h>
57#include <readline/readline.h>
58#endif
59
60using namespace XrdCl;
61
62namespace
63{
64 enum URLCommandResult
65 {
66 NotURLCommand,
67 ValidURLCommand,
68 InvalidURLCommand
69 };
70
71 bool SupportsFullURLs( const std::string &command )
72 {
73 static const char *commands[] = {
74 "cache", "cat", "chmod", "locate", "ls", "mkdir", "mv",
75 "prepare", "rm", "rmdir", "spaceinfo", "stat", "statvfs",
76 "tail", "truncate", "xattr"
77 };
78
79 return std::find( std::begin( commands ), std::end( commands ), command )
80 != std::end( commands );
81 }
82
83 // XrdCl::URL also accepts bare hosts and local paths. Keep this small check
84 // to distinguish explicit URL operands from those shorthand forms and from
85 // values such as "name=https://example.org".
86 bool HasExplicitURLScheme( const std::string &argument )
87 {
88 std::string::size_type separator = argument.find( "://" );
89 if( separator == std::string::npos || separator == 0
90 || !std::isalpha( static_cast<unsigned char>( argument[0] ) ) )
91 return false;
92
93 for( std::string::size_type i = 1; i < separator; ++i )
94 {
95 unsigned char character = static_cast<unsigned char>( argument[i] );
96 if( !std::isalnum( character ) && character != '+'
97 && character != '-' && character != '.' )
98 return false;
99 }
100
101 return true;
102 }
103
104 URLCommandResult ParseURLCommand( FSExecutor::CommandParams &arguments,
105 URL &endpoint, std::string &error )
106 {
107 if( arguments.empty() )
108 return NotURLCommand;
109
110 if( arguments[0] == "query" )
111 {
112 for( std::size_t i = 1; i < arguments.size(); ++i )
113 {
114 if( HasExplicitURLScheme( arguments[i] ) )
115 {
116 error = "command-first full URLs are not supported for 'query'";
117 return InvalidURLCommand;
118 }
119 }
120 return NotURLCommand;
121 }
122
123 if( !SupportsFullURLs( arguments[0] ) )
124 return NotURLCommand;
125
126 bool foundURL = false;
127 for( std::size_t i = 1; i < arguments.size(); ++i )
128 {
129 if( !HasExplicitURLScheme( arguments[i] ) )
130 continue;
131
132 URL operand( arguments[i] );
133 if( !operand.IsValid() || operand.GetProtocol() == "file"
134 || operand.GetProtocol() == "stdio" )
135 {
136 error = "invalid remote URL operand";
137 return InvalidURLCommand;
138 }
139
140 if( !foundURL )
141 {
142 endpoint = operand;
143 endpoint.SetPath( "" );
144 endpoint.SetParams( URL::ParamsMap() );
145 foundURL = true;
146 }
147 else if( endpoint.GetProtocol() != operand.GetProtocol()
148 || endpoint.GetHostId() != operand.GetHostId() )
149 {
150 error = "all URL operands must use the same endpoint";
151 return InvalidURLCommand;
152 }
153
154 arguments[i] = operand.GetPathWithParams();
155 if( arguments[i].empty() || arguments[i][0] != '/' )
156 arguments[i].insert( arguments[i].begin(), '/' );
157 }
158
159 return foundURL ? ValidURLCommand : NotURLCommand;
160 }
161}
162
163//------------------------------------------------------------------------------
164// Build a path
165//------------------------------------------------------------------------------
166XRootDStatus BuildPath( std::string &newPath, Env *env,
167 const std::string &path,
168 const char *op = nullptr )
169{
170 Log *log = DefaultEnv::GetLog();
171
172 if( path.empty() )
173 {
174 const std::string msg = "A path is required.";
175 log->Error( AppMsg, "%s", msg.c_str() );
176 return XRootDStatus( stError, errInvalidArgs, 0, msg );
177 }
178
179 int noCwd = 0;
180 env->GetInt( "NoCWD", noCwd );
181
182 if( path[0] == '/' )
183 {
184 newPath = path;
185 return XRootDStatus();
186 }
187 else if( noCwd )
188 {
189 std::string msg;
190 if( op )
191 msg = std::string( op ) + " relative path '" + path + "' is disallowed.";
192 else
193 msg = "Relative path '" + path + "' is disallowed.";
194 log->Error( AppMsg, "%s", msg.c_str() );
195 return XRootDStatus( stError, errInvalidArgs, 0, msg );
196 }
197
198 std::string cwd = "/";
199 env->GetString( "CWD", cwd );
200 newPath = cwd;
201 newPath += "/";
202 newPath += path;
203
204 //----------------------------------------------------------------------------
205 // Collapse the dots
206 //----------------------------------------------------------------------------
207 std::list<std::string> pathComponents;
208 std::list<std::string>::iterator it;
209 XrdCl::Utils::splitString( pathComponents, newPath, "/" );
210 newPath = "/";
211 for( it = pathComponents.begin(); it != pathComponents.end(); )
212 {
213 if( *it == "." )
214 {
215 it = pathComponents.erase( it );
216 continue;
217 }
218
219 if( *it == ".." )
220 {
221 if( it == pathComponents.begin() )
222 {
223 const std::string msg = "Path '" + path + "' escapes above root.";
224 log->Error( AppMsg, "%s", msg.c_str() );
225 return XRootDStatus( stError, errInvalidArgs, 0, msg );
226 }
227 std::list<std::string>::iterator it1 = it;
228 --it1;
229 it = pathComponents.erase( it1 );
230 it = pathComponents.erase( it );
231 continue;
232 }
233 ++it;
234 }
235
236 newPath = "/";
237 for( it = pathComponents.begin(); it != pathComponents.end(); ++it )
238 {
239 newPath += *it;
240 newPath += "/";
241 }
242 if( newPath.length() > 1 )
243 newPath.erase( newPath.length()-1, 1 );
244
245 return XRootDStatus();
246}
247
248//------------------------------------------------------------------------------
249// Convert mode string to uint16_t
250//------------------------------------------------------------------------------
251XRootDStatus ConvertMode( Access::Mode &mode, const std::string &modeStr )
252{
253 if( modeStr.length() != 9 )
255
256 mode = Access::None;
257 for( int i = 0; i < 3; ++i )
258 {
259 if( modeStr[i] == 'r' )
260 mode |= Access::UR;
261 else if( modeStr[i] == 'w' )
262 mode |= Access::UW;
263 else if( modeStr[i] == 'x' )
264 mode |= Access::UX;
265 else if( modeStr[i] != '-' )
267 }
268 for( int i = 3; i < 6; ++i )
269 {
270 if( modeStr[i] == 'r' )
271 mode |= Access::GR;
272 else if( modeStr[i] == 'w' )
273 mode |= Access::GW;
274 else if( modeStr[i] == 'x' )
275 mode |= Access::GX;
276 else if( modeStr[i] != '-' )
278 }
279 for( int i = 6; i < 9; ++i )
280 {
281 if( modeStr[i] == 'r' )
282 mode |= Access::OR;
283 else if( modeStr[i] == 'w' )
284 mode |= Access::OW;
285 else if( modeStr[i] == 'x' )
286 mode |= Access::OX;
287 else if( modeStr[i] != '-' )
289 }
290 return XRootDStatus();
291}
292
293//------------------------------------------------------------------------------
294// Perform a cache operation
295//------------------------------------------------------------------------------
297 Env *env,
298 const FSExecutor::CommandParams &args )
299{
300 //----------------------------------------------------------------------------
301 // Check up the args
302 //----------------------------------------------------------------------------
303 Log *log = DefaultEnv::GetLog();
304 uint32_t argc = args.size();
305
306 if( argc != 3 )
307 {
308 log->Error( AppMsg, "Wrong number of arguments." );
310 "Wrong number of arguments." );
311 }
312
313 if( args[1] != "evict" && args[1] != "fevict")
314 {
315 log->Error( AppMsg, "Invalid cache operation." );
316 return XRootDStatus( stError, errInvalidArgs, 0, "Invalid cache operation." );
317 }
318
319 std::string fullPath;
320 XRootDStatus pathSt = BuildPath( fullPath, env, args[2], "Caching" );
321 if( !pathSt.IsOK() )
322 return pathSt;
323
324 //----------------------------------------------------------------------------
325 // Create the command
326 //----------------------------------------------------------------------------
327 std::string cmd = args[1];
328 cmd.append(" ");
329 cmd.append(fullPath);
330
331 //----------------------------------------------------------------------------
332 // Run the operation
333 //----------------------------------------------------------------------------
334 Buffer *response = 0;
335 XRootDStatus st = fs->SendCache( cmd, response );
336 if( !st.IsOK() )
337 {
338 log->Error( AppMsg, "Unable set cache %s: %s",
339 fullPath.c_str(),
340 st.ToStr().c_str() );
341 return st;
342 }
343
344 if( response )
345 {
346 std::cout << response->ToString() << '\n';
347 }
348
349 delete response;
350
351 return XRootDStatus();
352}
353//------------------------------------------------------------------------------
354// Change current working directory
355//------------------------------------------------------------------------------
357 Env *env,
358 const FSExecutor::CommandParams &args )
359{
360 //----------------------------------------------------------------------------
361 // Check up the args
362 //----------------------------------------------------------------------------
363 Log *log = DefaultEnv::GetLog();
364 if( args.size() != 2 )
365 {
366 log->Error( AppMsg, "Invalid arguments. Expected a path." );
368 }
369
370 //----------------------------------------------------------------------------
371 // cd excludes NoCWD
372 //----------------------------------------------------------------------------
373 env->PutInt( "NoCWD", 0 );
374
375 std::string newPath;
376 XRootDStatus pathSt = BuildPath( newPath, env, args[1], "Changing" );
377 if( !pathSt.IsOK() )
378 return pathSt;
379
380 //----------------------------------------------------------------------------
381 // Check if the path exist and is not a directory
382 //----------------------------------------------------------------------------
383 StatInfo *info;
384 XRootDStatus st = fs->Stat( newPath, info );
385 if( !st.IsOK() )
386 {
387 log->Error( AppMsg, "Unable to stat the path: %s", st.ToStr().c_str() );
388 return st;
389 }
390
391 if( !info->TestFlags( StatInfo::IsDir ) )
392 {
393 log->Error( AppMsg, "%s is not a directory.", newPath.c_str() );
395 }
396
397 env->PutString( "CWD", newPath );
398 delete info;
399 return XRootDStatus();
400}
401
402//------------------------------------------------------------------------------
403// Helper function to calculate number of digits in a number
404//------------------------------------------------------------------------------
405uint32_t nbDigits( uint64_t nb )
406{
407 if( nb == 0 ) return 1;
408 return uint32_t( log10( double(nb) ) + 1);
409}
410
411std::string getSizeStr(uint64_t size, bool human, uint64_t base) {
412 std::ostringstream oss;
413 if (!human) {
414 oss << size;
415 } else {
416 oss << XrdOucUtils::genHumanSize(size,base);
417 }
418 return oss.str();
419}
420
421void PrintDirListStatInfo( StatInfo *info, bool hascks = false, uint32_t ownerwidth = 0, uint32_t groupwidth = 0, uint32_t sizewidth = 0, bool human = false, uint64_t base = 1000 )
422{
423 if( info->ExtendedFormat() )
424 {
425 if( info->TestFlags( StatInfo::IsDir ) )
426 std::cout << "d";
427 else
428 std::cout << "-";
429 std::cout << info->GetModeAsOctString();
430
431 std::cout << " " << std::setw( ownerwidth ) << info->GetOwner();
432 std::cout << " " << std::setw( groupwidth ) << info->GetGroup();
433 std::cout << " " << std::setw( sizewidth ) << getSizeStr(info->GetSize(),human, base);
434 if( hascks && info->HasChecksum() )
435 std::cout << " " << std::setw( sizewidth ) << info->GetChecksum();
436 std::cout << " " << info->GetModTimeAsString() << " ";
437 }
438 else
439 {
440 if( info->TestFlags( StatInfo::IsDir ) )
441 std::cout << "d";
442 else
443 std::cout << "-";
444
445 if( info->TestFlags( StatInfo::IsReadable ) )
446 std::cout << "r";
447 else
448 std::cout << "-";
449
450 if( info->TestFlags( StatInfo::IsWritable ) )
451 std::cout << "w";
452 else
453 std::cout << "-";
454
455 if( info->TestFlags( StatInfo::XBitSet ) )
456 std::cout << "x";
457 else
458 std::cout << "-";
459
460 std::cout << " " << info->GetModTimeAsString();
461
462 uint64_t size = info->GetSize();
463 std::string displaySize = getSizeStr(size,human,base);
464 int width = displaySize.size() + 2;
465 if (width < 12) {
466 width = 12;
467 }
468 std::cout << std::setw( width ) << displaySize << " ";
469 }
470}
471
472//------------------------------------------------------------------------------
473// List a directory
474//------------------------------------------------------------------------------
476 Env *env,
477 const FSExecutor::CommandParams &args )
478{
479 //----------------------------------------------------------------------------
480 // Check up the args
481 //----------------------------------------------------------------------------
482 Log *log = DefaultEnv::GetLog();
483 uint32_t argc = args.size();
484 bool stats = false;
485 bool showUrls = false;
486 bool hascks = false;
487 bool human = false;
488 uint64_t base = 1024;
489 std::string path;
491
492 if( argc > 6 )
493 {
494 log->Error( AppMsg, "Too many arguments." );
496 }
497
498 for( uint32_t i = 1; i < args.size(); ++i )
499 {
500 if( args[i] == "-l" )
501 {
502 stats = true;
503 flags |= DirListFlags::Stat;
504 }
505 else if( args[i] == "-u" )
506 showUrls = true;
507 else if( args[i] == "-R" )
508 {
510 }
511 else if( args[i] == "-D" )
512 {
513 // show duplicates
514 flags &= ~DirListFlags::Merge;
515 }
516 else if( args[i] == "-Z" )
517 {
518 // check if file is a ZIP archive if yes list content
519 flags |= DirListFlags::Zip;
520 }
521 else if( args[i] == "-C" )
522 {
523 // query checksum for each entry in the directory
524 hascks = true;
525 stats = true;
526 flags |= DirListFlags::Cksm;
527 }
528 else if ( args [i] == "-h" )
529 {
530 human = true;
531 }
532 else
533 path = args[i];
534 }
535
536 if( showUrls )
537 // we don't merge the duplicate entries
538 // in case we print the full URL
539 flags &= ~DirListFlags::Merge;
540
541 std::string newPath = "/";
542 if( path.empty() )
543 env->GetString( "CWD", newPath );
544 else
545 {
546 XRootDStatus pathSt = BuildPath( newPath, env, path, "Listing" );
547 if( !pathSt.IsOK() )
548 return pathSt;
549 }
550
551 //----------------------------------------------------------------------------
552 // Stat the entry so we know if it is a file or a directory
553 //----------------------------------------------------------------------------
554 log->Debug( AppMsg, "Attempting to stat: %s", newPath.c_str() );
555
556 StatInfo *info = 0;
557 XRootDStatus st = fs->Stat( newPath, info );
558 std::unique_ptr<StatInfo> ptr( info );
559 if( !st.IsOK() )
560 {
561 log->Error( AppMsg, "Unable to stat the path: %s", st.ToStr().c_str() );
562 return st;
563 }
564
565 if( !info->TestFlags( StatInfo::IsDir ) &&
566 !( flags & DirListFlags::Zip ) )
567 {
568 if( stats )
569 PrintDirListStatInfo( info, false, 0, 0, 0, human, base );
570
571 if( showUrls )
572 {
573 std::string url;
574 fs->GetProperty( "LastURL", url );
575 std::cout << url;
576 }
577 std::cout << newPath << std::endl;
578 return XRootDStatus();
579 }
580
581
582 //----------------------------------------------------------------------------
583 // Ask for the list
584 //----------------------------------------------------------------------------
585 log->Debug( AppMsg, "Attempting to list: %s", newPath.c_str() );
586
587 DirectoryList *list;
588 st = fs->DirList( newPath, flags, list );
589 if( !st.IsOK() )
590 {
591 log->Error( AppMsg, "Unable to list the path: %s", st.ToStr().c_str() );
592 return st;
593 }
594
595 if( st.code == suPartial )
596 {
597 std::cerr << "[!] Some of the requests failed. The result may be ";
598 std::cerr << "incomplete." << std::endl;
599 }
600
601 uint32_t ownerwidth = 0, groupwidth = 0, sizewidth = 0, ckswidth = 0;
603 for( it = list->Begin(); it != list->End() && stats; ++it )
604 {
605 StatInfo *info = (*it)->GetStatInfo();
606
607 std::string size = getSizeStr(info->GetSize(),human,base);
608 uint32_t sizeWidthComp;
609 if (human) {
610 sizeWidthComp = size.size();
611 } else {
612 sizeWidthComp = nbDigits( info->GetSize());
613 }
614
615 if( ownerwidth < info->GetOwner().size() )
616 ownerwidth = info->GetOwner().size();
617 if( groupwidth < info->GetGroup().size() )
618 groupwidth = info->GetGroup().size();
619 if( sizewidth < sizeWidthComp )
620 sizewidth = sizeWidthComp;
621 if( ckswidth < info->GetChecksum().size() )
622 ckswidth = info->GetChecksum().size();
623 }
624
625 //----------------------------------------------------------------------------
626 // Print the results
627 //----------------------------------------------------------------------------
628 for( it = list->Begin(); it != list->End(); ++it )
629 {
630 if( stats )
631 {
632 StatInfo *info = (*it)->GetStatInfo();
633 if( !info )
634 std::cout << "---- 0000-00-00 00:00:00 ? ";
635 else
636 PrintDirListStatInfo( info, hascks, ownerwidth, groupwidth, sizewidth, human, base );
637 }
638 if( showUrls )
639 std::cout << "root://" << (*it)->GetHostAddress() << "/";
640 std::cout << list->GetParentName() << (*it)->GetName() << std::endl;
641 }
642 delete list;
643 return XRootDStatus();
644}
645
646//------------------------------------------------------------------------------
647// Create a directory
648//------------------------------------------------------------------------------
650 Env *env,
651 const FSExecutor::CommandParams &args )
652{
653 //----------------------------------------------------------------------------
654 // Check up the args
655 //----------------------------------------------------------------------------
656 Log *log = DefaultEnv::GetLog();
657 uint32_t argc = args.size();
658
659 if( argc < 2 || argc > 4 )
660 {
661 log->Error( AppMsg, "Too few arguments." );
663 }
664
667 std::string modeStr = "rwxr-x---";
668 std::string path = "";
669
670 for( uint32_t i = 1; i < args.size(); ++i )
671 {
672 if( args[i] == "-p" )
673 flags |= MkDirFlags::MakePath;
674 else if( !args[i].compare( 0, 2, "-m" ) )
675 modeStr = args[i].substr( 2, 9 );
676 else
677 path = args[i];
678 }
679
680 XRootDStatus st = ConvertMode( mode, modeStr );
681 if( !st.IsOK() )
682 {
683 log->Error( AppMsg, "Invalid mode string." );
684 return st;
685 }
686
687 std::string newPath;
688 XRootDStatus pathSt = BuildPath( newPath, env, path, "Creating" );
689 if( !pathSt.IsOK() )
690 return pathSt;
691
692 //----------------------------------------------------------------------------
693 // Run the query
694 //----------------------------------------------------------------------------
695 st = fs->MkDir( newPath, flags, mode );
696 if( !st.IsOK() )
697 {
698 log->Error( AppMsg, "Unable create directory %s: %s",
699 newPath.c_str(),
700 st.ToStr().c_str() );
701 return st;
702 }
703
704 return XRootDStatus();
705}
706
707//------------------------------------------------------------------------------
708// Remove a directory
709//------------------------------------------------------------------------------
711 Env *env,
712 const FSExecutor::CommandParams &args )
713{
714 //----------------------------------------------------------------------------
715 // Check up the args
716 //----------------------------------------------------------------------------
717 Log *log = DefaultEnv::GetLog();
718 uint32_t argc = args.size();
719
720 if( argc != 2 )
721 {
722 log->Error( AppMsg, "Wrong number of arguments." );
724 }
725
726 std::string fullPath;
727 XRootDStatus pathSt = BuildPath( fullPath, env, args[1], "Removing" );
728 if( !pathSt.IsOK() )
729 return pathSt;
730
731 //----------------------------------------------------------------------------
732 // Run the query
733 //----------------------------------------------------------------------------
734 XRootDStatus st = query->RmDir( fullPath );
735 if( !st.IsOK() )
736 {
737 log->Error( AppMsg, "Unable remove directory %s: %s",
738 fullPath.c_str(),
739 st.ToStr().c_str() );
740 return st;
741 }
742
743 return XRootDStatus();
744}
745
746//------------------------------------------------------------------------------
747// Move a file or directory
748//------------------------------------------------------------------------------
750 Env *env,
751 const FSExecutor::CommandParams &args )
752{
753 //----------------------------------------------------------------------------
754 // Check up the args
755 //----------------------------------------------------------------------------
756 Log *log = DefaultEnv::GetLog();
757 uint32_t argc = args.size();
758
759 if( argc != 3 )
760 {
761 log->Error( AppMsg, "Wrong number of arguments." );
763 }
764
765 std::string fullPath1;
766 XRootDStatus pathSt = BuildPath( fullPath1, env, args[1], "Renaming" );
767 if( !pathSt.IsOK() )
768 return pathSt;
769
770 std::string fullPath2;
771 pathSt = BuildPath( fullPath2, env, args[2], "Renaming to" );
772 if( !pathSt.IsOK() )
773 return pathSt;
774
775 if( is_subdirectory(fullPath1, fullPath2) )
777 "cannot move directory to a subdirectory of itself." );
778
779 //----------------------------------------------------------------------------
780 // Run the query
781 //----------------------------------------------------------------------------
782 XRootDStatus st = fs->Mv( fullPath1, fullPath2 );
783 if( !st.IsOK() )
784 {
785 log->Error( AppMsg, "Unable move %s to %s: %s",
786 fullPath1.c_str(), fullPath2.c_str(),
787 st.ToStr().c_str() );
788 return st;
789 }
790
791 return XRootDStatus();
792}
793
794//------------------------------------------------------------------------------
795// Remove a file
796//------------------------------------------------------------------------------
798 Env *env,
799 const FSExecutor::CommandParams &args )
800{
801 //----------------------------------------------------------------------------
802 // Check up the args
803 //----------------------------------------------------------------------------
804 Log *log = DefaultEnv::GetLog();
805 uint32_t argc = args.size();
806
807 if( argc < 2 )
808 {
809 log->Error( AppMsg, "Wrong number of arguments." );
811 }
812
813 struct print_t
814 {
815 void print( const std::string &msg )
816 {
817 std::unique_lock<std::mutex> lck( mtx );
818 std::cout << msg << '\n';
819 }
820 std::mutex mtx;
821 };
822 std::shared_ptr<print_t> print;
823 if( argc - 1 > 0 )
824 print = std::make_shared<print_t>();
825
826 std::vector<Pipeline> rms;
827 rms.reserve( argc - 1 );
828 for( size_t i = 1; i < argc; ++i )
829 {
830 std::string fullPath;
831 XRootDStatus pathSt = BuildPath( fullPath, env, args[i], "Removing" );
832 if( !pathSt.IsOK() )
833 return pathSt;
834 rms.emplace_back( Rm( fs, fullPath ) >>
835 [log, fullPath, print]( XRootDStatus &st )
836 {
837 if( !st.IsOK() )
838 {
839 log->Error( AppMsg, "Unable remove %s: %s",
840 fullPath.c_str(),
841 st.ToStr().c_str() );
842 }
843 if( print )
844 {
845 print->print( "rm " + fullPath + " : " + st.ToString() );
846 }
847 } );
848 }
849
850 //----------------------------------------------------------------------------
851 // Run the query:
852 // Parallel() will take the vector of Pipeline by reference and empty the
853 // vector, so rms.size() will change after the call.
854 //----------------------------------------------------------------------------
855 const size_t rs = rms.size();
856 XRootDStatus st = WaitFor( Parallel( rms ).AtLeast( rs ) );
857 if( !st.IsOK() )
858 return st;
859
860 return XRootDStatus();
861}
862
863//------------------------------------------------------------------------------
864// Truncate a file
865//------------------------------------------------------------------------------
867 Env *env,
868 const FSExecutor::CommandParams &args )
869{
870 //----------------------------------------------------------------------------
871 // Check up the args
872 //----------------------------------------------------------------------------
873 Log *log = DefaultEnv::GetLog();
874 uint32_t argc = args.size();
875
876 if( argc != 3 )
877 {
878 log->Error( AppMsg, "Wrong number of arguments." );
880 }
881
882 std::string fullPath;
883 XRootDStatus pathSt = BuildPath( fullPath, env, args[1], "Truncating" );
884 if( !pathSt.IsOK() )
885 return pathSt;
886
887 char *result;
888 uint64_t size = ::strtoll( args[2].c_str(), &result, 0 );
889 if( *result != 0 )
890 {
891 log->Error( AppMsg, "Size parameter needs to be an integer" );
893 }
894
895 //----------------------------------------------------------------------------
896 // Run the query
897 //----------------------------------------------------------------------------
898 XRootDStatus st = fs->Truncate( fullPath, size );
899 if( !st.IsOK() )
900 {
901 log->Error( AppMsg, "Unable truncate %s: %s",
902 fullPath.c_str(),
903 st.ToStr().c_str() );
904 return st;
905 }
906
907 return XRootDStatus();
908}
909
910//------------------------------------------------------------------------------
911// Change the access rights to a file
912//------------------------------------------------------------------------------
914 Env *env,
915 const FSExecutor::CommandParams &args )
916{
917 //----------------------------------------------------------------------------
918 // Check up the args
919 //----------------------------------------------------------------------------
920 Log *log = DefaultEnv::GetLog();
921 uint32_t argc = args.size();
922
923 if( argc != 3 )
924 {
925 log->Error( AppMsg, "Wrong number of arguments." );
927 }
928
929 std::string fullPath;
930 XRootDStatus pathSt = BuildPath( fullPath, env, args[1], "Modifying" );
931 if( !pathSt.IsOK() )
932 return pathSt;
933
935 XRootDStatus st = ConvertMode( mode, args[2] );
936 if( !st.IsOK() )
937 {
938 log->Error( AppMsg, "Invalid mode string." );
939 return st;
940 }
941
942 //----------------------------------------------------------------------------
943 // Run the query
944 //----------------------------------------------------------------------------
945 st = fs->ChMod( fullPath, mode );
946 if( !st.IsOK() )
947 {
948 log->Error( AppMsg, "Unable change mode of %s: %s",
949 fullPath.c_str(),
950 st.ToStr().c_str() );
951 return st;
952 }
953
954 return XRootDStatus();
955}
956
957//------------------------------------------------------------------------------
958// Locate a path
959//------------------------------------------------------------------------------
961 Env *env,
962 const FSExecutor::CommandParams &args )
963{
964 //----------------------------------------------------------------------------
965 // Check up the args
966 //----------------------------------------------------------------------------
967 Log *log = DefaultEnv::GetLog();
968 uint32_t argc = args.size();
969
970 if( argc > 4 )
971 {
972 log->Error( AppMsg, "Wrong number of arguments." );
974 }
975
977 std::string path;
978 bool hasPath = false;
979 bool doDeepLocate = false;
980 for( uint32_t i = 1; i < argc; ++i )
981 {
982 if( args[i] == "-n" )
983 flags |= OpenFlags::NoWait;
984 else if( args[i] == "-r" )
985 flags |= OpenFlags::Refresh;
986 else if( args[i] == "-m" || args[i] == "-h" )
987 flags |= OpenFlags::PrefName;
988 else if( args[i] == "-i" )
989 flags |= OpenFlags::Force;
990 else if( args[i] == "-d" )
991 doDeepLocate = true;
992 else if( args[i] == "-p" )
993 {
994 Env *env = DefaultEnv::GetEnv();
995 env->PutInt( "PreserveLocateTried", 0 );
996 }
997 else if( !hasPath )
998 {
999 path = args[i];
1000 hasPath = true;
1001 }
1002 else
1003 {
1004 log->Error( AppMsg, "Invalid argument: %s.", args[i].c_str() );
1006 }
1007 }
1008
1009 std::string fullPath;
1010 if( path[0] == '*' )
1011 fullPath = path;
1012 else
1013 {
1014 XRootDStatus pathSt = BuildPath( fullPath, env, path, "Locating" );
1015 if( !pathSt.IsOK() )
1016 return pathSt;
1017 }
1018
1019 //----------------------------------------------------------------------------
1020 // Run the query
1021 //----------------------------------------------------------------------------
1022 LocationInfo *info = 0;
1023 XRootDStatus st;
1024 if( doDeepLocate )
1025 st = fs->DeepLocate( fullPath, flags, info );
1026 else
1027 st = fs->Locate( fullPath, flags, info );
1028
1029 if( !st.IsOK() )
1030 {
1031 log->Error( AppMsg, "Unable locate %s: %s",
1032 fullPath.c_str(),
1033 st.ToStr().c_str() );
1034 return st;
1035 }
1036
1037 //----------------------------------------------------------------------------
1038 // Print the result
1039 //----------------------------------------------------------------------------
1040 if( st.code == suPartial )
1041 {
1042 std::cerr << "[!] Some of the requests failed. The result may be ";
1043 std::cerr << "incomplete." << std::endl;
1044 }
1045
1047 for( it = info->Begin(); it != info->End(); ++it )
1048 {
1049 std::cout << it->GetAddress() << " ";
1050 switch( it->GetType() )
1051 {
1053 std::cout << "Manager ";
1054 break;
1056 std::cout << "ManagerPending ";
1057 break;
1059 std::cout << "Server ";
1060 break;
1062 std::cout << "ServerPending ";
1063 break;
1064 default:
1065 std::cout << "Unknown ";
1066 };
1067
1068 switch( it->GetAccessType() )
1069 {
1070 case LocationInfo::Read:
1071 std::cout << "Read";
1072 break;
1074 std::cout << "ReadWrite ";
1075 break;
1076 default:
1077 std::cout << "Unknown ";
1078 };
1079 std::cout << std::endl;
1080 }
1081
1082 delete info;
1083 return XRootDStatus();
1084}
1085
1086//------------------------------------------------------------------------------
1087// Process stat query
1088//------------------------------------------------------------------------------
1089XRootDStatus ProcessStatQuery( StatInfo &info, const std::string &query )
1090{
1091 Log *log = DefaultEnv::GetLog();
1092
1093 //----------------------------------------------------------------------------
1094 // Process the query
1095 //----------------------------------------------------------------------------
1096 bool isOrQuery = false;
1097 bool status = true;
1098 if( query.find( '|' ) != std::string::npos )
1099 {
1100 isOrQuery = true;
1101 status = false;
1102 }
1103 std::vector<std::string> queryFlags;
1104 if( isOrQuery )
1105 Utils::splitString( queryFlags, query, "|" );
1106 else
1107 Utils::splitString( queryFlags, query, "&" );
1108
1109 //----------------------------------------------------------------------------
1110 // Initialize flag translation map and check the input flags
1111 //----------------------------------------------------------------------------
1112 std::map<std::string, StatInfo::Flags> flagMap;
1113 flagMap["XBitSet"] = StatInfo::XBitSet;
1114 flagMap["IsDir"] = StatInfo::IsDir;
1115 flagMap["Other"] = StatInfo::Other;
1116 flagMap["Offline"] = StatInfo::Offline;
1117 flagMap["POSCPending"] = StatInfo::POSCPending;
1118 flagMap["IsReadable"] = StatInfo::IsReadable;
1119 flagMap["IsWritable"] = StatInfo::IsWritable;
1120 flagMap["BackUpExists"] = StatInfo::BackUpExists;
1121
1122 std::vector<std::string>::iterator it;
1123 for( it = queryFlags.begin(); it != queryFlags.end(); ++it )
1124 if( flagMap.find( *it ) == flagMap.end() )
1125 {
1126 log->Error( AppMsg, "Flag '%s' is not recognized.", it->c_str() );
1128 }
1129
1130 //----------------------------------------------------------------------------
1131 // Process the query
1132 //----------------------------------------------------------------------------
1133 if( isOrQuery )
1134 {
1135 for( it = queryFlags.begin(); it != queryFlags.end(); ++it )
1136 if( info.TestFlags( flagMap[*it] ) )
1137 return XRootDStatus();
1138 }
1139 else
1140 {
1141 for( it = queryFlags.begin(); it != queryFlags.end(); ++it )
1142 if( !info.TestFlags( flagMap[*it] ) )
1144 }
1145
1146 if( status )
1147 return XRootDStatus();
1149}
1150
1151//------------------------------------------------------------------------------
1152// Stat a path
1153//------------------------------------------------------------------------------
1155 Env *env,
1156 const FSExecutor::CommandParams &args )
1157{
1158 //----------------------------------------------------------------------------
1159 // Check up the args
1160 //----------------------------------------------------------------------------
1161 Log *log = DefaultEnv::GetLog();
1162 uint32_t argc = args.size();
1163
1164 if( argc < 2 )
1165 {
1166 log->Error( AppMsg, "Wrong number of arguments." );
1168 }
1169
1170 std::vector<std::string> paths;
1171 std::string query;
1172
1173 for( uint32_t i = 1; i < args.size(); ++i )
1174 {
1175 if( args[i] == "-q" )
1176 {
1177 if( i < args.size()-1 )
1178 {
1179 query = args[i+1];
1180 ++i;
1181 }
1182 else
1183 {
1184 log->Error( AppMsg, "Parameter '-q' requires an argument." );
1186 }
1187 }
1188 else
1189 paths.emplace_back( args[i] );
1190 }
1191
1192 std::vector<XrdCl::Pipeline> stats;
1193 std::vector<std::tuple<std::future<StatInfo>, std::string>> results;
1194 for( auto &path : paths )
1195 {
1196 std::string fullPath;
1197 XRootDStatus pathSt = BuildPath( fullPath, env, path, "Stating" );
1198 if( !pathSt.IsOK() )
1199 return pathSt;
1200 std::future<XrdCl::StatInfo> ftr;
1201 stats.emplace_back( XrdCl::Stat( fs, fullPath ) >> ftr );
1202 results.emplace_back( std::move( ftr ), std::move( fullPath ) );
1203 }
1204
1205 //----------------------------------------------------------------------------
1206 // Run the query
1207 //----------------------------------------------------------------------------
1208 XrdCl::Async( XrdCl::Parallel( stats ) );
1209
1210 //----------------------------------------------------------------------------
1211 // Print the result
1212 //----------------------------------------------------------------------------
1214 for( auto &tpl : results )
1215 {
1216 auto &ftr = std::get<0>( tpl );
1217 auto &fullPath = std::get<1>( tpl );
1218 std::cout << std::endl;
1219 try
1220 {
1221 XrdCl::StatInfo info( ftr.get() );
1222 std::string flags;
1223
1224 if( info.TestFlags( StatInfo::XBitSet ) )
1225 flags += "XBitSet|";
1226 if( info.TestFlags( StatInfo::IsDir ) )
1227 flags += "IsDir|";
1228 if( info.TestFlags( StatInfo::Other ) )
1229 flags += "Other|";
1230 if( info.TestFlags( StatInfo::Offline ) )
1231 flags += "Offline|";
1232 if( info.TestFlags( StatInfo::POSCPending ) )
1233 flags += "POSCPending|";
1234 if( info.TestFlags( StatInfo::IsReadable ) )
1235 flags += "IsReadable|";
1236 if( info.TestFlags( StatInfo::IsWritable ) )
1237 flags += "IsWritable|";
1238 if( info.TestFlags( StatInfo::BackUpExists ) )
1239 flags += "BackUpExists|";
1240
1241 if( !flags.empty() )
1242 flags.erase( flags.length()-1, 1 );
1243
1244 std::cout << "Path: " << fullPath << std::endl;
1245 std::cout << "Id: " << info.GetId() << std::endl;
1246 std::cout << "Size: " << info.GetSize() << std::endl;
1247 std::cout << "MTime: " << info.GetModTimeAsString() << std::endl;
1248 // if extended stat information is available we can print also
1249 // change time and access time
1250 if( info.ExtendedFormat() )
1251 {
1252 std::cout << "CTime: " << info.GetChangeTimeAsString() << std::endl;
1253 std::cout << "ATime: " << info.GetAccessTimeAsString() << std::endl;
1254 }
1255 std::cout << "Flags: " << info.GetFlags() << " (" << flags << ")";
1256
1257 // check if extended stat information is available
1258 if( info.ExtendedFormat() )
1259 {
1260 std::cout << "\nMode: " << info.GetModeAsString() << std::endl;
1261 std::cout << "Owner: " << info.GetOwner() << std::endl;
1262 std::cout << "Group: " << info.GetGroup();
1263 }
1264
1265 std::cout << std::endl;
1266
1267 if( query.length() != 0 )
1268 {
1269 XRootDStatus s = ProcessStatQuery( info, query );
1270 if( !s.IsOK() )
1271 st = s;
1272 std::cout << "Query: " << query << " " << std::endl;
1273 }
1274 }
1275 catch( XrdCl::PipelineException &ex )
1276 {
1277 st = ex.GetError();
1278 log->Error( AppMsg, "Unable stat %s: %s", fullPath.c_str(), st.ToStr().c_str() );
1279 }
1280 }
1281
1282 return st;
1283}
1284
1285//------------------------------------------------------------------------------
1286// Stat a VFS
1287//------------------------------------------------------------------------------
1289 Env *env,
1290 const FSExecutor::CommandParams &args )
1291{
1292 //----------------------------------------------------------------------------
1293 // Check up the args
1294 //----------------------------------------------------------------------------
1295 Log *log = DefaultEnv::GetLog();
1296 uint32_t argc = args.size();
1297
1298 if( argc != 2 )
1299 {
1300 log->Error( AppMsg, "Wrong number of arguments." );
1302 }
1303
1304 std::string fullPath;
1305 XRootDStatus pathSt = BuildPath( fullPath, env, args[1], "Stating" );
1306 if( !pathSt.IsOK() )
1307 return pathSt;
1308
1309 //----------------------------------------------------------------------------
1310 // Run the query
1311 //----------------------------------------------------------------------------
1312 StatInfoVFS *info = 0;
1313 XRootDStatus st = fs->StatVFS( fullPath, info );
1314
1315 if( !st.IsOK() )
1316 {
1317 log->Error( AppMsg, "Unable stat VFS at %s: %s",
1318 fullPath.c_str(),
1319 st.ToStr().c_str() );
1320 return st;
1321 }
1322
1323 //----------------------------------------------------------------------------
1324 // Print the result
1325 //----------------------------------------------------------------------------
1326 std::cout << "Path: ";
1327 std::cout << fullPath << std::endl;
1328 std::cout << "Nodes with RW space: ";
1329 std::cout << info->GetNodesRW() << std::endl;
1330 std::cout << "Size of largest RW space (MB): ";
1331 std::cout << info->GetFreeRW() << std::endl;
1332 std::cout << "Utilization of RW space (%): ";
1333 std::cout << (uint16_t)info->GetUtilizationRW() << std::endl;
1334 std::cout << "Nodes with staging space: ";
1335 std::cout << info->GetNodesStaging() << std::endl;
1336 std::cout << "Size of largest staging space (MB): ";
1337 std::cout << info->GetFreeStaging() << std::endl;
1338 std::cout << "Utilization of staging space (%): ";
1339 std::cout << (uint16_t)info->GetUtilizationStaging() << std::endl;
1340
1341 delete info;
1342 return XRootDStatus();
1343}
1344
1345//------------------------------------------------------------------------------
1346// Query the server
1347//------------------------------------------------------------------------------
1349 Env *env,
1350 const FSExecutor::CommandParams &args )
1351{
1352 //----------------------------------------------------------------------------
1353 // Check up the args
1354 //----------------------------------------------------------------------------
1355 Log *log = DefaultEnv::GetLog();
1356 uint32_t argc = args.size();
1357
1358 if( !( argc >= 3 ) )
1359 {
1360 log->Error( AppMsg, "Wrong number of arguments." );
1362 }
1363
1364 QueryCode::Code qCode;
1365 if( args[1] == "config" )
1366 qCode = QueryCode::Config;
1367 else if( args[1] == "checksumcancel" )
1369 else if( args[1] == "checksum" )
1370 qCode = QueryCode::Checksum;
1371 else if( args[1] == "opaque" )
1372 qCode = QueryCode::Opaque;
1373 else if( args[1] == "opaquefile" )
1374 qCode = QueryCode::OpaqueFile;
1375 else if( args[1] == "prepare" )
1376 qCode = QueryCode::Prepare;
1377 else if( args[1] == "space" )
1378 qCode = QueryCode::Space;
1379 else if( args[1] == "stats" )
1380 qCode = QueryCode::Stats;
1381 else if( args[1] == "xattr" )
1382 qCode = QueryCode::XAttr;
1383 else
1384 {
1385 log->Error( AppMsg, "Invalid query code." );
1387 }
1388
1389 if( !( qCode & QueryCode::Prepare ) && argc != 3 )
1390 {
1391 log->Error( AppMsg, "Wrong number of arguments." );
1393 }
1394
1395 std::string strArg = args[2];
1396 if( qCode & QueryCode::Prepare )
1397 {
1398 // strArg is supposed to contain already the request ID
1399
1400 for( size_t i = 3; i < args.size(); ++i )
1401 {
1402 std::string path = args[i];
1403 XRootDStatus pathSt = BuildPath( path, env, path, "Preparing" );
1404 if( !pathSt.IsOK() )
1405 return pathSt;
1406 // we use new line character as delimiter
1407 strArg += '\n';
1408 strArg += path;
1409 }
1410 }
1411 else
1412 {
1413 std::string strArg = args[2];
1414 if( qCode == QueryCode::ChecksumCancel ||
1415 qCode == QueryCode::Checksum ||
1416 qCode == QueryCode::XAttr )
1417 {
1418 XRootDStatus pathSt = BuildPath( strArg, env, args[2], "Querying" );
1419 if( !pathSt.IsOK() )
1420 return pathSt;
1421 }
1422 }
1423
1424 //----------------------------------------------------------------------------
1425 // Run the query
1426 //----------------------------------------------------------------------------
1427 Buffer arg( strArg.size() );
1428 arg.FromString( strArg );
1429 Buffer *response = 0;
1430 XRootDStatus st = fs->Query( qCode, arg, response );
1431
1432 if( !st.IsOK() )
1433 {
1434 log->Error( AppMsg, "Unable run query %s: %s",
1435 args[1].c_str(),
1436 st.ToStr().c_str() );
1437 return st;
1438 }
1439
1440 //----------------------------------------------------------------------------
1441 // Print the result
1442 //----------------------------------------------------------------------------
1443 std::cout << response->ToString() << std::endl;
1444 delete response;
1445 return XRootDStatus();
1446}
1447
1448//------------------------------------------------------------------------------
1449// Query the server
1450//------------------------------------------------------------------------------
1452 Env *env,
1453 const FSExecutor::CommandParams &args )
1454{
1455 //----------------------------------------------------------------------------
1456 // Check up the args
1457 //----------------------------------------------------------------------------
1458 Log *log = DefaultEnv::GetLog();
1459 uint32_t argc = args.size();
1460
1461 if( argc < 2 )
1462 {
1463 log->Error( AppMsg, "Wrong number of arguments." );
1465 }
1466
1468 std::vector<std::string> files;
1469 uint8_t priority = 0;
1470 std::string reqid;
1471
1472 for( uint32_t i = 1; i < args.size(); ++i )
1473 {
1474 if( args[i] == "-p" )
1475 {
1476 if( i < args.size()-1 )
1477 {
1478 char *result;
1479 int32_t param = ::strtol( args[i+1].c_str(), &result, 0 );
1480 if( *result != 0 || param > 3 || param < 0 )
1481 {
1482 log->Error( AppMsg, "Size priotiry needs to be an integer between 0 "
1483 "and 3" );
1485 }
1486 priority = (uint8_t)param;
1487 ++i;
1488 }
1489 else
1490 {
1491 log->Error( AppMsg, "Parameter '-p' requires an argument." );
1493 }
1494 }
1495 else if( args[i] == "-c" )
1496 flags |= PrepareFlags::Colocate;
1497 else if( args[i] == "-f" )
1498 flags |= PrepareFlags::Fresh;
1499 else if( args[i] == "-s" )
1500 flags |= PrepareFlags::Stage;
1501 else if( args[i] == "-w" )
1502 flags |= PrepareFlags::WriteMode;
1503 else if( args[i] == "-e" )
1504 flags |= PrepareFlags::Evict;
1505 else if( args[i] == "-a" )
1506 {
1507 flags |= PrepareFlags::Cancel;
1508 if( i < args.size()-1 )
1509 {
1510 // by convention the request ID appears as the the first token
1511 // in the list of files
1512 files.push_back( args[i+1] );
1513 ++i;
1514 }
1515 else
1516 {
1517 log->Error( AppMsg, "Parameter '-a' requires an argument." );
1519 }
1520 }
1521 else
1522 files.push_back( args[i] );
1523 }
1524
1525 if( files.empty() )
1526 {
1527 log->Error( AppMsg, "Filename missing." );
1529 }
1530
1531 //----------------------------------------------------------------------------
1532 // Run the command
1533 //----------------------------------------------------------------------------
1534 Buffer *response = 0;
1535 XRootDStatus st = fs->Prepare( files, flags, priority, response );
1536 if( !st.IsOK() )
1537 {
1538 log->Error( AppMsg, "Prepare request failed: %s", st.ToStr().c_str() );
1539 return st;
1540 }
1541
1542 if( ( flags & PrepareFlags::Stage ) && response )
1543 {
1544 std::cout << response->ToString() << '\n';
1545 }
1546
1547 delete response;
1548 return XRootDStatus();
1549}
1550
1551//------------------------------------------------------------------------------
1552// Copy progress handler
1553//------------------------------------------------------------------------------
1555{
1556 public:
1557 //--------------------------------------------------------------------------
1558 // Constructor
1559 //--------------------------------------------------------------------------
1560 ProgressDisplay(): pBytesProcessed(0), pBytesTotal(0), pPrevious(0)
1561 {}
1562
1563 //--------------------------------------------------------------------------
1564 // End job
1565 //--------------------------------------------------------------------------
1566 virtual void EndJob( uint32_t jobNum, const XrdCl::PropertyList *results )
1567 {
1568 JobProgress( jobNum, pBytesProcessed, pBytesTotal );
1569 std::cerr << std::endl;
1570 }
1571
1572 //--------------------------------------------------------------------------
1573 // Job progress
1574 //--------------------------------------------------------------------------
1575 virtual void JobProgress( uint32_t jobNum,
1576 uint64_t bytesProcessed,
1577 uint64_t bytesTotal )
1578 {
1579 pBytesProcessed = bytesProcessed;
1580 pBytesTotal = bytesTotal;
1581
1582 time_t now = time(0);
1583 if( (now - pPrevious < 1) && (bytesProcessed != bytesTotal) )
1584 return;
1585 pPrevious = now;
1586
1587 std::cerr << "\r";
1588 std::cerr << "Progress: ";
1589 std::cerr << XrdCl::Utils::BytesToString(bytesProcessed) << "B ";
1590
1591 if( bytesTotal )
1592 std::cerr << "(" << bytesProcessed*100/bytesTotal << "%)";
1593
1594 std::cerr << std::flush;
1595 }
1596
1597 private:
1598 uint64_t pBytesProcessed;
1599 uint64_t pBytesTotal;
1600 time_t pPrevious;
1601};
1602
1603//------------------------------------------------------------------------------
1604// Cat a file
1605//------------------------------------------------------------------------------
1607 Env *env,
1608 const FSExecutor::CommandParams &args )
1609{
1610 //----------------------------------------------------------------------------
1611 // Check up the args
1612 //----------------------------------------------------------------------------
1613 Log *log = DefaultEnv::GetLog();
1614 uint32_t argc = args.size();
1615
1616 if( argc < 2 )
1617 {
1618 log->Error( AppMsg, "Wrong number of arguments." );
1620 }
1621
1622 std::string server;
1623 env->GetString( "ServerURL", server );
1624 if( server.empty() )
1625 {
1626 log->Error( AppMsg, "Invalid address: \"%s\".", server.c_str() );
1628 }
1629
1630 std::vector<std::string> remotes;
1631 std::string local;
1632
1633 for( uint32_t i = 1; i < args.size(); ++i )
1634 {
1635 if( args[i] == "-o" )
1636 {
1637 if( i < args.size()-1 )
1638 {
1639 local = args[i+1];
1640 ++i;
1641 }
1642 else
1643 {
1644 log->Error( AppMsg, "Parameter '-o' requires an argument." );
1646 }
1647 }
1648 else
1649 remotes.emplace_back( args[i] );
1650 }
1651
1652 if( !local.empty() && remotes.size() > 1 )
1653 {
1654 log->Error( AppMsg, "If '-o' is used only can be used with only one remote file." );
1656 }
1657
1658 // a file URL needs an absolute path, else the path becomes its host
1659 if( !local.empty() && local[0] != '/' )
1660 {
1661 std::unique_ptr<char, decltype( &free )> cwd( getcwd( nullptr, 0 ), free );
1662 if( !cwd )
1663 {
1664 int err = errno;
1665 log->Error( AppMsg, "Unable to get the current directory: %s",
1666 XrdSysE2T( err ) );
1667 return XRootDStatus( stError, errOSError, err );
1668 }
1669 local = std::string( cwd.get() ) + "/" + local;
1670 }
1671
1672 std::vector<URL> remoteUrls;
1673 remoteUrls.reserve( remotes.size() );
1674 for( auto &remote : remotes )
1675 {
1676 std::string remoteFile;
1677 XRootDStatus pathSt = BuildPath( remoteFile, env, remote, "Opening" );
1678 if( !pathSt.IsOK() )
1679 return pathSt;
1680
1681 remoteUrls.emplace_back( server );
1682 remoteUrls.back().SetPath( remoteFile );
1683 }
1684
1685 //----------------------------------------------------------------------------
1686 // Fetch the data
1687 //----------------------------------------------------------------------------
1688 CopyProgressHandler *handler = 0; ProgressDisplay d;
1689 CopyProcess process;
1690 std::vector<PropertyList> props( remoteUrls.size() ), results( remoteUrls.size() );
1691
1692 for( size_t i = 0; i < remoteUrls.size(); ++i )
1693 {
1694 props[i].Set( "source", remoteUrls[i].GetURL() );
1695 if( !local.empty() )
1696 {
1697 props[i].Set( "target", std::string( "file://" ) + local );
1698 handler = &d;
1699 }
1700 else
1701 props[i].Set( "target", "stdio://-" );
1702
1703 props[i].Set( "dynamicSource", true );
1704
1705 XRootDStatus st = process.AddJob( props[i], &results[i] );
1706 if( !st.IsOK() )
1707 {
1708 log->Error( AppMsg, "Job adding failed: %s.", st.ToStr().c_str() );
1709 return st;
1710 }
1711 }
1712
1713 XRootDStatus st = process.Prepare();
1714 if( !st.IsOK() )
1715 {
1716 log->Error( AppMsg, "Copy preparation failed: %s.", st.ToStr().c_str() );
1717 return st;
1718 }
1719
1720 st = process.Run(handler);
1721 if( !st.IsOK() )
1722 {
1723 log->Error( AppMsg, "Cope process failed: %s.", st.ToStr().c_str() );
1724 return st;
1725 }
1726
1727 return XRootDStatus();
1728}
1729
1730//------------------------------------------------------------------------------
1731// Tail a file
1732//------------------------------------------------------------------------------
1734 Env *env,
1735 const FSExecutor::CommandParams &args )
1736{
1737 //----------------------------------------------------------------------------
1738 // Check up the args
1739 //----------------------------------------------------------------------------
1740 Log *log = DefaultEnv::GetLog();
1741 uint32_t argc = args.size();
1742
1743 if( argc < 2 || argc > 5 )
1744 {
1745 log->Error( AppMsg, "Wrong number of arguments." );
1747 }
1748
1749 std::string server;
1750 env->GetString( "ServerURL", server );
1751 if( server.empty() )
1752 {
1753 log->Error( AppMsg, "Invalid address: \"%s\".", server.c_str() );
1755 }
1756
1757 std::string remote;
1758 bool followMode = false;
1759 uint32_t offset = 512;
1760
1761 for( uint32_t i = 1; i < args.size(); ++i )
1762 {
1763 if( args[i] == "-f" )
1764 followMode = true;
1765 else if( args[i] == "-c" )
1766 {
1767 if( i < args.size()-1 )
1768 {
1769 char *result;
1770 offset = ::strtol( args[i+1].c_str(), &result, 0 );
1771 if( *result != 0 )
1772 {
1773 log->Error( AppMsg, "Offset from the end needs to be a number: %s",
1774 args[i+1].c_str() );
1776 }
1777 ++i;
1778 }
1779 else
1780 {
1781 log->Error( AppMsg, "Parameter '-n' requires an argument." );
1783 }
1784 }
1785 else
1786 remote = args[i];
1787 }
1788
1789 std::string remoteFile;
1790 XRootDStatus pathSt = BuildPath( remoteFile, env, remote, "Opening" );
1791 if( !pathSt.IsOK() )
1792 return pathSt;
1793
1794 URL remoteUrl( server );
1795 remoteUrl.SetPath( remoteFile );
1796
1797 //----------------------------------------------------------------------------
1798 // Fetch the data
1799 //----------------------------------------------------------------------------
1800 File file;
1801 XRootDStatus st = file.Open( remoteUrl.GetURL(), OpenFlags::Read );
1802 if( !st.IsOK() )
1803 {
1804 log->Error( AppMsg, "Unable to open file %s: %s",
1805 remoteUrl.GetObfuscatedURL().c_str(), st.ToStr().c_str() );
1806 return st;
1807 }
1808
1809 StatInfo *info = 0;
1810 uint64_t size = 0;
1811 st = file.Stat( false, info );
1812 if (st.IsOK()) size = info->GetSize();
1813
1814 if( size < offset )
1815 offset = 0;
1816 else
1817 offset = size - offset;
1818
1819 uint32_t chunkSize = 1*1024*1024;
1820 char *buffer = new char[chunkSize];
1821 uint32_t bytesRead = 0;
1822 while(1)
1823 {
1824 st = file.Read( offset, chunkSize, buffer, bytesRead );
1825 if( !st.IsOK() )
1826 {
1827 log->Error( AppMsg, "Unable to read from %s: %s",
1828 remoteUrl.GetObfuscatedURL().c_str(), st.ToStr().c_str() );
1829 delete [] buffer;
1830 return st;
1831 }
1832
1833 offset += bytesRead;
1834 int ret = write( 1, buffer, bytesRead );
1835 if( ret == -1 )
1836 {
1837 log->Error( AppMsg, "Unable to write to stdout: %s",
1838 XrdSysE2T(errno) );
1839 delete [] buffer;
1840 return st;
1841 }
1842
1843 if( bytesRead < chunkSize )
1844 {
1845 if( !followMode )
1846 break;
1847 sleep(1);
1848 }
1849 }
1850 delete [] buffer;
1851
1852 XRootDStatus stC = file.Close();
1853
1854 return XRootDStatus();
1855}
1856
1857//------------------------------------------------------------------------------
1858// Print statistics concerning given space
1859//------------------------------------------------------------------------------
1861 Env *env,
1862 const FSExecutor::CommandParams &args )
1863{
1864 using namespace XrdCl;
1865
1866 //----------------------------------------------------------------------------
1867 // Check up the args
1868 //----------------------------------------------------------------------------
1869 Log *log = DefaultEnv::GetLog();
1870 uint32_t argc = args.size();
1871
1872 if( argc != 2 )
1873 {
1874 log->Error( AppMsg, "Wrong number of arguments." );
1876 }
1877
1879
1880 XRootDStatus st = FileSystemUtils::GetSpaceInfo( i, fs, args[1] );
1881 if( !st.IsOK() )
1882 return st;
1883
1884 if( st.code == suPartial )
1885 {
1886 std::cerr << "[!] Some of the requests failed. The result may be ";
1887 std::cerr << "incomplete." << std::endl;
1888 }
1889
1890 std::cout << "Path: " << args[1] << std::endl;
1891 std::cout << "Total: " << i->GetTotal() << std::endl;
1892 std::cout << "Free: " << i->GetFree() << std::endl;
1893 std::cout << "Used: " << i->GetUsed() << std::endl;
1894 std::cout << "Largest free chunk: " << i->GetLargestFreeChunk() << std::endl;
1895
1896 delete i;
1897 return XRootDStatus();
1898}
1899
1900//------------------------------------------------------------------------------
1901// Carry out xattr operation
1902//------------------------------------------------------------------------------
1904 Env *env,
1905 const FSExecutor::CommandParams &args )
1906{
1907 //----------------------------------------------------------------------------
1908 // Check up the args
1909 //----------------------------------------------------------------------------
1910 Log *log = DefaultEnv::GetLog();
1911 uint32_t argc = args.size();
1912
1913 if( argc < 3 )
1914 {
1915 log->Error( AppMsg, "Wrong number of arguments." );
1917 }
1918
1919 kXR_char code = 0;
1920 if( args[2] == "set")
1921 code = kXR_fattrSet;
1922 else if( args[2] == "get" )
1923 code = kXR_fattrGet;
1924 else if( args[2] == "del" )
1925 code = kXR_fattrDel;
1926 else if( args[2] == "list" )
1927 code = kXR_fattrList;
1928 else
1929 {
1930 log->Error( AppMsg, "Invalid xattr code." );
1932 }
1933
1934 std::string path;
1935 XRootDStatus pathSt = BuildPath( path, env, args[1], "Accessing" );
1936 if( !pathSt.IsOK() )
1937 return pathSt;
1938
1939 //----------------------------------------------------------------------------
1940 // Issue the xattr operation
1941 //----------------------------------------------------------------------------
1942 XRootDStatus status;
1943 switch( code )
1944 {
1945 case kXR_fattrSet:
1946 {
1947 if( argc != 4 )
1948 {
1949 log->Error( AppMsg, "Wrong number of arguments." );
1951 }
1952
1953 std::string key_value = args[3];
1954 size_t pos = key_value.find( '=' );
1955 std::string key = key_value.substr( 0, pos );
1956 std::string value = key_value.substr( pos + 1 );
1957 std::vector<xattr_t> attrs;
1958 attrs.push_back( std::make_tuple( key, value ) );
1959
1960 std::vector<XAttrStatus> result;
1961 XRootDStatus status = fs->SetXAttr( path, attrs, result );
1962 XAttrStatus xst = status.IsOK() ? result.front() : XAttrStatus( key, status );
1963
1964 if( !xst.status.IsOK() )
1965 status = xst.status;
1966
1967 if( !status.IsOK() )
1968 log->Error( AppMsg, "Unable to xattr set %s %s: %s",
1969 key.c_str(), value.c_str(),
1970 status.ToStr().c_str() );
1971 return status;
1972 }
1973
1974 case kXR_fattrGet:
1975 {
1976 if( argc != 4 )
1977 {
1978 log->Error( AppMsg, "Wrong number of arguments." );
1980 }
1981
1982 std::string key = args[3];
1983 std::vector<std::string> attrs;
1984 attrs.push_back( key );
1985
1986 std::vector<XAttr> result;
1987 XRootDStatus status = fs->GetXAttr( path, attrs, result );
1988 XAttr xattr = status.IsOK() ? result.front() : XAttr( key, status );
1989
1990 if( !xattr.status.IsOK() )
1991 status = xattr.status;
1992
1993 if( !status.IsOK() )
1994 log->Error( AppMsg, "Unable to xattr get %s : %s",
1995 key.c_str(),
1996 status.ToStr().c_str() );
1997 else
1998 {
1999 std::cout << "# file: " << path << '\n';
2000 std::cout << xattr.name << "=\"" << xattr.value << "\"\n";
2001 }
2002
2003 return status;
2004 }
2005
2006 case kXR_fattrDel:
2007 {
2008 if( argc != 4 )
2009 {
2010 log->Error( AppMsg, "Wrong number of arguments." );
2012 }
2013
2014 std::string key = args[3];
2015 std::vector<std::string> attrs;
2016 attrs.push_back( key );
2017
2018 std::vector<XAttrStatus> result ;
2019 XRootDStatus status = fs->DelXAttr( path, attrs, result );
2020 XAttrStatus xst = status.IsOK() ? result.front() : XAttrStatus( key, status );
2021
2022 if( !xst.status.IsOK() )
2023 status = xst.status;
2024
2025 if( !status.IsOK() )
2026 log->Error( AppMsg, "Unable to xattr del %s : %s",
2027 key.c_str(),
2028 status.ToStr().c_str() );
2029 return status;
2030 }
2031
2032 case kXR_fattrList:
2033 {
2034 if( argc != 3 )
2035 {
2036 log->Error( AppMsg, "Wrong number of arguments." );
2038 }
2039
2040 std::vector<XAttr> result;
2041 XRootDStatus status = fs->ListXAttr( path, result );
2042
2043 if( !status.IsOK() )
2044 log->Error( AppMsg, "Unable to xattr list : %s",
2045 status.ToStr().c_str() );
2046 else
2047 {
2048 std::cout << "# file: " << path << '\n';
2049 auto itr = result.begin();
2050 for( ; itr != result.end(); ++itr )
2051 std::cout << itr->name << "=\"" << itr->value << "\"\n";
2052 }
2053
2054 return status;
2055 }
2056
2057 default:
2059 }
2060}
2061
2062//------------------------------------------------------------------------------
2063// Print help
2064//------------------------------------------------------------------------------
2067{
2068 printf( "Usage:\n" );
2069 printf( " xrdfs [options] host[:port] - interactive mode\n" );
2070 printf( " xrdfs [options] host[:port] command args - server-first batch\n" );
2071 printf( " xrdfs [options] command args-with-URLs - command-first batch\n\n" );
2072
2073 printf( "The two batch forms cannot be mixed.\n\n" );
2074
2075 printf( "Available options:\n\n" );
2076
2077 printf( " -4, --ipv4 use only the IPv4 network stack\n" );
2078 printf( " -6, --ipv6 use only the IPv6 network stack\n" );
2079 printf( " -d, --debug <level> set debug level: 0 off, 1 low, 2 medium,\n" );
2080 printf( " 3 high\n" );
2081 printf( " -h, --help show this help\n" );
2082 printf( " --no-cwd do not preset a CWD in interactive mode\n\n" );
2083
2084 printf( "Available commands:\n\n" );
2085
2086 printf( " exit\n" );
2087 printf( " Exits from the program.\n\n" );
2088
2089 printf( " help\n" );
2090 printf( " This help screen.\n\n" );
2091
2092 printf( " cache {evict | fevict} <path>\n" );
2093 printf( " Evict a file from a cache if not in use; while fevict\n" );
2094 printf( " forcibly evicts the file causing any current uses of the\n" );
2095 printf( " file to get read failures on a subsequent read\n\n" );
2096
2097 printf( " cd <path>\n" );
2098 printf( " Change the current working directory\n\n" );
2099
2100 printf( " chmod <path> <user><group><other>\n" );
2101 printf( " Modify permissions. Permission string example:\n" );
2102 printf( " rwxr-x--x\n\n" );
2103
2104 printf( " ls [-l] [-u] [-R] [-D] [-Z] [-C] [dirname]\n" );
2105 printf( " Get directory listing.\n" );
2106 printf( " -l stat every entry and print long listing\n" );
2107 printf( " -u print paths as URLs\n" );
2108 printf( " -R list subdirectories recursively\n" );
2109 printf( " -D show duplicate entries\n" );
2110 printf( " -Z if a ZIP archive list its content\n" );
2111 printf( " -C checksum every entry\n\n" );
2112
2113 printf( " locate [-n] [-r] [-d] [-m] [-i] [-p] <path>\n" );
2114 printf( " Get the locations of the path.\n" );
2115 printf( " -r refresh, don't use cached locations\n" );
2116 printf( " -n make the server return the response immediately even\n" );
2117 printf( " though it may be incomplete\n" );
2118 printf( " -d do a recursive (deep) locate\n" );
2119 printf( " -m|-h prefer host names to IP addresses\n" );
2120 printf( " -i ignore network dependencies\n" );
2121 printf( " -p be passive: ignore tried/triedrc cgi opaque info\n\n" );
2122
2123 printf( " mkdir [-p] [-m<user><group><other>] <dirname>\n" );
2124 printf( " Creates a directory/tree of directories.\n\n" );
2125
2126 printf( " mv <path1> <path2>\n" );
2127 printf( " Move path1 to path2 locally on the same server.\n\n" );
2128
2129 printf( " stat [-q query] <path>\n" );
2130 printf( " Get info about the file or directory.\n" );
2131 printf( " -q query optional flag query parameter that makes\n" );
2132 printf( " xrdfs return error code to the shell if the\n" );
2133 printf( " requested flag combination is not present;\n" );
2134 printf( " flags may be combined together using '|' or '&'\n" );
2135 printf( " Available flags:\n" );
2136 printf( " XBitSet, IsDir, Other, Offline, POSCPending,\n" );
2137 printf( " IsReadable, IsWritable\n\n" );
2138
2139 printf( " statvfs <path>\n" );
2140 printf( " Get info about a virtual file system.\n\n" );
2141
2142 printf( " query <code> <parameters>\n" );
2143 printf( " Obtain server information. Query codes:\n\n" );
2144
2145 printf( " config <what> Server configuration; <what> is\n" );
2146 printf( " one of the following:\n" );
2147 printf( " bind_max - the maximum number of parallel streams\n" );
2148 printf( " chksum - the supported checksum\n" );
2149 printf( " cms - the status of the cmsd\n" );
2150 printf( " pio_max - maximum number of parallel I/O requests\n" );
2151 printf( " readv_ior_max - maximum size of a readv element\n" );
2152 printf( " readv_iov_max - maximum number of readv entries\n" );
2153 printf( " role - the role in a cluster\n" );
2154 printf( " sitename - the site name\n" );
2155 printf( " tpc - support for third party copies\n" );
2156 printf( " version - the version of the server\n" );
2157 printf( " wan_port - the port to use for wan copies\n" );
2158 printf( " wan_window - the wan_port window size\n" );
2159 printf( " window - the tcp window size\n" );
2160 printf( " checksumcancel <path> File checksum cancellation\n" );
2161 printf( " checksum <path> File checksum\n" );
2162 printf( " opaque <arg> Implementation dependent\n" );
2163 printf( " opaquefile <arg> Implementation dependent\n" );
2164 printf( " space <space> Logical space stats\n" );
2165 printf( " stats <what> Server stats; <what> is a list\n" );
2166 printf( " of letters indicating information\n");
2167 printf( " to be returned:\n" );
2168 printf( " a - all statistics\n" );
2169 printf( " p - protocol statistics\n" );
2170 printf( " b - buffer usage statistics\n" );
2171 printf( " s - scheduling statistics\n" );
2172 printf( " d - device polling statistics\n" );
2173 printf( " u - usage statistics\n" );
2174 printf( " i - server identification\n" );
2175 printf( " z - synchronized statistics\n" );
2176 printf( " l - connection statistics\n" );
2177 printf( " xattr <path> Extended attributes\n" );
2178 printf( " prepare <reqid> [filenames] Prepare request status\n\n" );
2179
2180 printf( " rm <filename>\n" );
2181 printf( " Remove a file.\n\n" );
2182
2183 printf( " rmdir <dirname>\n" );
2184 printf( " Remove a directory.\n\n" );
2185
2186 printf( " truncate <filename> <length>\n" );
2187 printf( " Truncate a file.\n\n" );
2188
2189 printf( " prepare [-c] [-f] [-s] [-w] [-e] [-p priority] [-a requestid] filenames\n" );
2190 printf( " Prepare one or more files for access.\n" );
2191 printf( " -c co-locate staged files if possible\n" );
2192 printf( " -f refresh file access time even if the location is known\n" );
2193 printf( " -s stage the files to disk if they are not online\n" );
2194 printf( " -w the files will be accessed for modification\n" );
2195 printf( " -p priority of the request, 0 (lowest) - 3 (highest)\n" );
2196 printf( " -a abort stage request\n" );
2197 printf( " -e evict the file from disk cache\n\n" );
2198
2199 printf( " cat [-o local file] files\n" );
2200 printf( " Print contents of one or more files to stdout.\n" );
2201 printf( " -o print to the specified local file\n\n" );
2202
2203 printf( " tail [-c bytes] [-f] file\n" );
2204 printf( " Output last part of files to stdout.\n" );
2205 printf( " -c num_bytes out last num_bytes\n" );
2206 printf( " -f output appended data as file grows\n\n" );
2207
2208 printf( " spaceinfo path\n" );
2209 printf( " Get space statistics for given path.\n\n" );
2210
2211 printf( " xattr <path> <code> <params> \n" );
2212 printf( " Operation on extended attributes. Codes:\n\n" );
2213 printf( " set <attr> Set extended attribute; <attr> is\n" );
2214 printf( " string of form name=value\n" );
2215 printf( " get <name> Get extended attribute\n" );
2216 printf( " del <name> Delete extended attribute\n" );
2217 printf( " list List extended attributes\n\n" );
2218
2219 return XRootDStatus();
2220}
2221
2222//------------------------------------------------------------------------------
2223// Create the executor object
2224//------------------------------------------------------------------------------
2226{
2227 Env *env = new Env();
2228 env->PutString( "CWD", "/" );
2229 FSExecutor *executor = new FSExecutor( url, env );
2230 executor->AddCommand( "cache", DoCache );
2231 executor->AddCommand( "cd", DoCD );
2232 executor->AddCommand( "chmod", DoChMod );
2233 executor->AddCommand( "ls", DoLS );
2234 executor->AddCommand( "help", PrintHelp );
2235 executor->AddCommand( "stat", DoStat );
2236 executor->AddCommand( "statvfs", DoStatVFS );
2237 executor->AddCommand( "locate", DoLocate );
2238 executor->AddCommand( "mv", DoMv );
2239 executor->AddCommand( "mkdir", DoMkDir );
2240 executor->AddCommand( "rm", DoRm );
2241 executor->AddCommand( "rmdir", DoRmDir );
2242 executor->AddCommand( "query", DoQuery );
2243 executor->AddCommand( "truncate", DoTruncate );
2244 executor->AddCommand( "prepare", DoPrepare );
2245 executor->AddCommand( "cat", DoCat );
2246 executor->AddCommand( "tail", DoTail );
2247 executor->AddCommand( "spaceinfo", DoSpaceInfo );
2248 executor->AddCommand( "xattr", DoXAttr );
2249 return executor;
2250}
2251
2252//------------------------------------------------------------------------------
2253// Execute command
2254//------------------------------------------------------------------------------
2256{
2257 XRootDStatus st = ex->Execute( args );
2258 if( !st.IsOK() )
2259 std::cerr << st.ToStr() << std::endl;
2260 return st.GetShellCode();
2261}
2262
2263//------------------------------------------------------------------------------
2264// Define some functions required to function when build without readline
2265//------------------------------------------------------------------------------
2266#ifndef HAVE_READLINE
2267char *readline(const char *prompt)
2268{
2269 std::cout << prompt << std::flush;
2270 std::string input;
2271 std::getline( std::cin, input );
2272
2273 if( !std::cin.good() )
2274 return 0;
2275
2276 char *linebuf = (char *)malloc( input.size()+1 );
2277 strncpy( linebuf, input.c_str(), input.size()+1 );
2278
2279 return linebuf;
2280}
2281
2282void add_history( const char * )
2283{
2284}
2285
2286void rl_bind_key( char, uint16_t )
2287{
2288}
2289
2290uint16_t rl_insert = 0;
2291
2292int read_history( const char * )
2293{
2294 return 0;
2295}
2296
2297int write_history( const char * )
2298{
2299 return 0;
2300}
2301#endif
2302
2303//------------------------------------------------------------------------------
2304// Build the command prompt
2305//------------------------------------------------------------------------------
2306std::string BuildPrompt( Env *env, const URL &url )
2307{
2308 std::ostringstream prompt;
2309 std::string cwd = "/";
2310 env->GetString( "CWD", cwd );
2311 prompt << "[" << url.GetHostId() << "] " << cwd << " > ";
2312 return prompt.str();
2313}
2314
2315//------------------------------------------------------------------------
2321//------------------------------------------------------------------------
2322bool getArguments (std::vector<std::string> & result, const std::string &input)
2323{
2324 // the delimiter (space in the case of command line)
2325 static const char delimiter = ' ';
2326 // two types of quotes: single and double quotes
2327 const char singleQuote = '\'', doubleQuote = '\"';
2328 // if the current character of the command has been
2329 // quoted 'currentQuote' holds the type of quote,
2330 // otherwise it holds the null character
2331 char currentQuote = '\0';
2332
2333 std::string tmp;
2334 for (std::string::const_iterator it = input.begin (); it != input.end (); ++it)
2335 {
2336 // if we encountered a quote character ...
2337 if (*it == singleQuote || *it == doubleQuote)
2338 {
2339 // if we are not within quoted text ...
2340 if (!currentQuote)
2341 {
2342 currentQuote = *it; // set the type of quote
2343 continue; // and continue, the quote character itself is not a part of the parameter
2344 }
2345 // otherwise if it is the closing quote character ...
2346 else if (currentQuote == *it)
2347 {
2348 currentQuote = '\0'; // reset the current quote type
2349 continue; // and continue, the quote character itself is not a part of the parameter
2350 }
2351 }
2352 // if we are within quoted text or the character is not a delimiter ...
2353 if (currentQuote || *it != delimiter)
2354 {
2355 // concatenate it
2356 tmp += *it;
2357 }
2358 else
2359 {
2360 // otherwise add a parameter and erase the tmp string
2361 if (!tmp.empty ())
2362 {
2363 result.push_back(tmp);
2364 tmp.erase ();
2365 }
2366 }
2367 }
2368 // if the there are some remainders of the command add them
2369 if (!tmp.empty())
2370 {
2371 result.push_back(tmp);
2372 }
2373 // return true if the quotation has been closed
2374 return currentQuote == '\0';
2375}
2376
2377//------------------------------------------------------------------------------
2378// Execute interactive
2379//------------------------------------------------------------------------------
2380int ExecuteInteractive( const URL &url, bool noCwd = false )
2381{
2382 //----------------------------------------------------------------------------
2383 // Set up the environment
2384 //----------------------------------------------------------------------------
2385 std::string historyFile = getenv( "HOME" );
2386 historyFile += "/.xrdquery.history";
2387 rl_bind_key( '\t', rl_insert );
2388 read_history( historyFile.c_str() );
2389 FSExecutor *ex = CreateExecutor( url );
2390
2391 if( noCwd )
2392 ex->GetEnv()->PutInt( "NoCWD", 1 );
2393
2394 //----------------------------------------------------------------------------
2395 // Execute the commands
2396 //----------------------------------------------------------------------------
2397 std::string cmdline;
2398 while(1)
2399 {
2400 char *linebuf = 0;
2401 // print new prompt only if the previous line was complete
2402 // (a line is considered not to be complete if a quote has
2403 // been opened but it has not been closed)
2404 linebuf = readline( cmdline.empty() ? BuildPrompt( ex->GetEnv(), url ).c_str() : "> " );
2405 if( !linebuf || !strncmp( linebuf, "exit", 4 ) || !strncmp( linebuf, "quit", 4 ) )
2406 {
2407 std::cout << "Goodbye." << std::endl << std::endl;
2408 break;
2409 }
2410 if( !*linebuf)
2411 {
2412 free( linebuf );
2413 continue;
2414 }
2415 std::vector<std::string> args;
2416 cmdline += linebuf;
2417 free( linebuf );
2418 if (getArguments( args, cmdline ))
2419 {
2420 XRootDStatus st = ex->Execute( args );
2421 add_history( cmdline.c_str() );
2422 cmdline.erase();
2423 if( !st.IsOK() )
2424 std::cerr << st.ToStr() << std::endl;
2425 }
2426 }
2427
2428 //----------------------------------------------------------------------------
2429 // Cleanup
2430 //----------------------------------------------------------------------------
2431 delete ex;
2432 write_history( historyFile.c_str() );
2433 return 0;
2434}
2435
2436//------------------------------------------------------------------------------
2437// Execute command
2438//------------------------------------------------------------------------------
2439int ExecuteCommand( const URL &url, const FSExecutor::CommandParams &args )
2440{
2441 FSExecutor *ex = CreateExecutor( url );
2442 ex->GetEnv()->PutInt( "NoCWD", 1 );
2443 int st = ExecuteCommand( ex, args );
2444 delete ex;
2445 return st;
2446}
2447
2448//------------------------------------------------------------------------------
2449// Start the show
2450//------------------------------------------------------------------------------
2451int main( int argc, char **argv )
2452{
2454 enum { NoCwdOption = 256 };
2455 static const option options[] = {
2456 { "ipv4", no_argument, 0, '4' },
2457 { "ipv6", no_argument, 0, '6' },
2458 { "debug", required_argument, 0, 'd' },
2459 { "help", no_argument, 0, 'h' },
2460 { "no-cwd", no_argument, 0, NoCwdOption },
2461 { 0, 0, 0, 0 }
2462 };
2463
2464 bool noCwd = false;
2465 int debugLevel = 0;
2466 std::string networkStack;
2467 opterr = 0;
2468 int option = 0;
2469 while( (option = getopt_long( argc, argv, "+46d:h", options, 0 )) != -1 )
2470 {
2471 switch( option )
2472 {
2473 case '4':
2474 if( networkStack == "IPv6" )
2475 {
2476 std::cerr << "xrdfs: -4 and -6 are mutually exclusive" << std::endl;
2477 return 1;
2478 }
2479 networkStack = "IPv4";
2480 break;
2481 case '6':
2482 if( networkStack == "IPv4" )
2483 {
2484 std::cerr << "xrdfs: -4 and -6 are mutually exclusive" << std::endl;
2485 return 1;
2486 }
2487 networkStack = "IPv6";
2488 break;
2489 case 'd':
2490 {
2491 char *end = 0;
2492 long level = std::strtol( optarg, &end, 10 );
2493 if( !*optarg || *end || level < 0 || level > 3 )
2494 {
2495 std::cerr << "xrdfs: invalid debug level '" << optarg
2496 << "' (expected 0-3)" << std::endl;
2497 return 1;
2498 }
2499 debugLevel = static_cast<int>( level );
2500 break;
2501 }
2502 case 'h':
2503 PrintHelp( 0, 0, params );
2504 return 0;
2505 case NoCwdOption:
2506 noCwd = true;
2507 break;
2508 default:
2509 PrintHelp( 0, 0, params );
2510 return 1;
2511 }
2512 }
2513
2514 if( !networkStack.empty() )
2515 DefaultEnv::GetEnv()->PutString( "NetworkStack", networkStack );
2516
2517 if( debugLevel )
2518 {
2519 Log *log = DefaultEnv::GetLog();
2520 if( debugLevel == 1 )
2521 log->SetLevel( Log::InfoMsg );
2522 else if( debugLevel == 2 )
2523 log->SetLevel( Log::DebugMsg );
2524 else
2525 log->SetLevel( Log::DumpMsg );
2526 }
2527
2528 if( optind == argc )
2529 {
2530 PrintHelp( 0, 0, params );
2531 return 1;
2532 }
2533
2534 FSExecutor::CommandParams arguments( argv + optind, argv + argc );
2535 URL url;
2536 std::string error;
2537 URLCommandResult result = ParseURLCommand( arguments, url, error );
2538 if( result == InvalidURLCommand )
2539 {
2540 std::cerr << "xrdfs: " << error << std::endl;
2541 return 1;
2542 }
2543
2544 if( result == ValidURLCommand )
2545 return ExecuteCommand( url, arguments );
2546
2547 url = URL( arguments[0] );
2548 if( !url.IsValid() )
2549 {
2550 PrintHelp( 0, 0, params );
2551 return 1;
2552 }
2553
2554 if( arguments.size() == 1 )
2555 return ExecuteInteractive( url, noCwd );
2556
2557 arguments.erase( arguments.begin() );
2558
2559 // Raw query parameters are implementation-dependent and may themselves look
2560 // like URLs, so query intentionally remains server-first only.
2561 if( arguments[0] != "query" )
2562 {
2563 URL inferredEndpoint;
2564 result = ParseURLCommand( arguments, inferredEndpoint, error );
2565 if( result == InvalidURLCommand )
2566 {
2567 std::cerr << "xrdfs: " << error << std::endl;
2568 return 1;
2569 }
2570
2571 if( result == ValidURLCommand )
2572 {
2573 std::cerr << "xrdfs: cannot mix a leading endpoint with full URL "
2574 "operands; use either server-first or command-first syntax"
2575 << std::endl;
2576 return 1;
2577 }
2578 }
2579
2580 return ExecuteCommand( url, arguments );
2581}
@ kXR_fattrDel
Definition XProtocol.hh:300
@ kXR_fattrSet
Definition XProtocol.hh:303
@ kXR_fattrList
Definition XProtocol.hh:302
@ kXR_fattrGet
Definition XProtocol.hh:301
unsigned char kXR_char
Definition XPtypes.hh:65
void PrintDirListStatInfo(StatInfo *info, bool hascks=false, uint32_t ownerwidth=0, uint32_t groupwidth=0, uint32_t sizewidth=0, bool human=false, uint64_t base=1000)
Definition XrdClFS.cc:421
uint32_t nbDigits(uint64_t nb)
Definition XrdClFS.cc:405
XRootDStatus DoQuery(FileSystem *fs, Env *env, const FSExecutor::CommandParams &args)
Definition XrdClFS.cc:1348
XRootDStatus DoLocate(FileSystem *fs, Env *env, const FSExecutor::CommandParams &args)
Definition XrdClFS.cc:960
int write_history(const char *)
Definition XrdClFS.cc:2297
XRootDStatus DoMkDir(FileSystem *fs, Env *env, const FSExecutor::CommandParams &args)
Definition XrdClFS.cc:649
void add_history(const char *)
Definition XrdClFS.cc:2282
XRootDStatus DoRmDir(FileSystem *query, Env *env, const FSExecutor::CommandParams &args)
Definition XrdClFS.cc:710
XRootDStatus DoRm(FileSystem *fs, Env *env, const FSExecutor::CommandParams &args)
Definition XrdClFS.cc:797
XRootDStatus DoTail(FileSystem *fs, Env *env, const FSExecutor::CommandParams &args)
Definition XrdClFS.cc:1733
int ExecuteInteractive(const URL &url, bool noCwd=false)
Definition XrdClFS.cc:2380
void rl_bind_key(char, uint16_t)
Definition XrdClFS.cc:2286
XRootDStatus DoStat(FileSystem *fs, Env *env, const FSExecutor::CommandParams &args)
Definition XrdClFS.cc:1154
XRootDStatus ProcessStatQuery(StatInfo &info, const std::string &query)
Definition XrdClFS.cc:1089
XRootDStatus DoCat(FileSystem *fs, Env *env, const FSExecutor::CommandParams &args)
Definition XrdClFS.cc:1606
XRootDStatus BuildPath(std::string &newPath, Env *env, const std::string &path, const char *op=nullptr)
Definition XrdClFS.cc:166
std::string BuildPrompt(Env *env, const URL &url)
Definition XrdClFS.cc:2306
XRootDStatus DoMv(FileSystem *fs, Env *env, const FSExecutor::CommandParams &args)
Definition XrdClFS.cc:749
XRootDStatus DoPrepare(FileSystem *fs, Env *env, const FSExecutor::CommandParams &args)
Definition XrdClFS.cc:1451
XRootDStatus DoChMod(FileSystem *fs, Env *env, const FSExecutor::CommandParams &args)
Definition XrdClFS.cc:913
FSExecutor * CreateExecutor(const URL &url)
Definition XrdClFS.cc:2225
XRootDStatus DoLS(FileSystem *fs, Env *env, const FSExecutor::CommandParams &args)
Definition XrdClFS.cc:475
bool getArguments(std::vector< std::string > &result, const std::string &input)
Definition XrdClFS.cc:2322
XRootDStatus DoCD(FileSystem *fs, Env *env, const FSExecutor::CommandParams &args)
Definition XrdClFS.cc:356
XRootDStatus DoXAttr(FileSystem *fs, Env *env, const FSExecutor::CommandParams &args)
Definition XrdClFS.cc:1903
char * readline(const char *prompt)
Definition XrdClFS.cc:2267
XRootDStatus DoStatVFS(FileSystem *fs, Env *env, const FSExecutor::CommandParams &args)
Definition XrdClFS.cc:1288
XRootDStatus DoCache(FileSystem *fs, Env *env, const FSExecutor::CommandParams &args)
Definition XrdClFS.cc:296
XRootDStatus DoSpaceInfo(FileSystem *fs, Env *env, const FSExecutor::CommandParams &args)
Definition XrdClFS.cc:1860
int read_history(const char *)
Definition XrdClFS.cc:2292
XRootDStatus ConvertMode(Access::Mode &mode, const std::string &modeStr)
Definition XrdClFS.cc:251
int ExecuteCommand(FSExecutor *ex, const FSExecutor::CommandParams &args)
Definition XrdClFS.cc:2255
uint16_t rl_insert
Definition XrdClFS.cc:2290
std::string getSizeStr(uint64_t size, bool human, uint64_t base)
Definition XrdClFS.cc:411
XRootDStatus DoTruncate(FileSystem *fs, Env *env, const FSExecutor::CommandParams &args)
Definition XrdClFS.cc:866
XRootDStatus PrintHelp(FileSystem *, Env *, const FSExecutor::CommandParams &)
Definition XrdClFS.cc:2065
int main(int argc, char *argv[])
Definition XrdMain.cc:161
int optind
#define write(a, b, c)
Definition XrdPosix.hh:121
const char * XrdSysE2T(int errcode)
Definition XrdSysE2T.cc:101
virtual void EndJob(uint32_t jobNum, const XrdCl::PropertyList *results)
Definition XrdClFS.cc:1566
virtual void JobProgress(uint32_t jobNum, uint64_t bytesProcessed, uint64_t bytesTotal)
Job progress.
Definition XrdClCopy.cc:224
Binary blob representation.
void FromString(const std::string str)
Fill the buffer from a string.
std::string ToString() const
Convert the buffer to a string.
Copy the data from one point to another.
XRootDStatus Run(CopyProgressHandler *handler)
Run the copy jobs.
XRootDStatus AddJob(const PropertyList &properties, PropertyList *results)
Interface for copy progress notification.
static Log * GetLog()
Get default log.
static Env * GetEnv()
Get default client environment.
const std::string & GetParentName() const
Get parent directory name.
DirList::iterator Iterator
Directory listing iterator.
Iterator End()
Get the end iterator.
Iterator Begin()
Get the begin iterator.
bool PutInt(const std::string &key, int value)
Definition XrdClEnv.cc:136
bool PutString(const std::string &key, const std::string &value)
Definition XrdClEnv.cc:52
bool GetString(const std::string &key, std::string &value)
Definition XrdClEnv.cc:31
bool GetInt(const std::string &key, int &value)
Definition XrdClEnv.cc:115
Execute queries given as a commandline.
std::vector< std::string > CommandParams
Definition of command argument list.
FSExecutor(const URL &url, Env *env=0)
XRootDStatus Execute(const CommandParams &args)
bool AddCommand(const std::string &name, Command command)
Env * GetEnv()
Get the environment.
Container for space information.
uint64_t GetUsed() const
Amount of used space in MB.
uint64_t GetLargestFreeChunk() const
Largest single chunk of free space.
uint64_t GetTotal() const
Amount of total space in MB.
uint64_t GetFree() const
Amount of free space in MB.
static XRootDStatus GetSpaceInfo(SpaceInfo *&result, FileSystem *fs, const std::string &path)
Recursively get space information for given path.
Send file/filesystem queries to an XRootD cluster.
XRootDStatus Mv(const std::string &source, const std::string &dest, ResponseHandler *handler, time_t timeout=0) XRD_WARN_UNUSED_RESULT
XRootDStatus DirList(const std::string &path, DirListFlags::Flags flags, ResponseHandler *handler, time_t timeout=0) XRD_WARN_UNUSED_RESULT
XRootDStatus Locate(const std::string &path, OpenFlags::Flags flags, ResponseHandler *handler, time_t timeout=0) XRD_WARN_UNUSED_RESULT
XRootDStatus SendCache(const std::string &info, ResponseHandler *handler, time_t timeout=0) XRD_WARN_UNUSED_RESULT
XRootDStatus Truncate(const std::string &path, uint64_t size, ResponseHandler *handler, time_t timeout=0) XRD_WARN_UNUSED_RESULT
XRootDStatus RmDir(const std::string &path, ResponseHandler *handler, time_t timeout=0) XRD_WARN_UNUSED_RESULT
XRootDStatus ListXAttr(const std::string &path, ResponseHandler *handler, time_t timeout=0)
XRootDStatus Stat(const std::string &path, ResponseHandler *handler, time_t timeout=0) XRD_WARN_UNUSED_RESULT
XRootDStatus StatVFS(const std::string &path, ResponseHandler *handler, time_t timeout=0) XRD_WARN_UNUSED_RESULT
XRootDStatus GetXAttr(const std::string &path, const std::vector< std::string > &attrs, ResponseHandler *handler, time_t timeout=0)
XRootDStatus ChMod(const std::string &path, Access::Mode mode, ResponseHandler *handler, time_t timeout=0) XRD_WARN_UNUSED_RESULT
XRootDStatus DelXAttr(const std::string &path, const std::vector< std::string > &attrs, ResponseHandler *handler, time_t timeout=0)
XRootDStatus Prepare(const std::vector< std::string > &fileList, PrepareFlags::Flags flags, uint8_t priority, ResponseHandler *handler, time_t timeout=0) XRD_WARN_UNUSED_RESULT
XRootDStatus MkDir(const std::string &path, MkDirFlags::Flags flags, Access::Mode mode, ResponseHandler *handler, time_t timeout=0) XRD_WARN_UNUSED_RESULT
XRootDStatus Query(QueryCode::Code queryCode, const Buffer &arg, ResponseHandler *handler, time_t timeout=0) XRD_WARN_UNUSED_RESULT
XRootDStatus SetXAttr(const std::string &path, const std::vector< xattr_t > &attrs, ResponseHandler *handler, time_t timeout=0)
bool GetProperty(const std::string &name, std::string &value) const
XRootDStatus DeepLocate(const std::string &path, OpenFlags::Flags flags, ResponseHandler *handler, time_t timeout=0) XRD_WARN_UNUSED_RESULT
A file.
Definition XrdClFile.hh:52
XRootDStatus Open(const std::string &url, OpenFlags::Flags flags, Access::Mode mode, ResponseHandler *handler, time_t timeout=0) XRD_WARN_UNUSED_RESULT
Definition XrdClFile.cc:125
XRootDStatus Read(uint64_t offset, uint32_t size, void *buffer, ResponseHandler *handler, time_t timeout=0) XRD_WARN_UNUSED_RESULT
Definition XrdClFile.cc:265
XRootDStatus Close(ResponseHandler *handler, time_t timeout=0) XRD_WARN_UNUSED_RESULT
Definition XrdClFile.cc:210
XRootDStatus Stat(bool force, ResponseHandler *handler, time_t timeout=0) XRD_WARN_UNUSED_RESULT
Definition XrdClFile.cc:236
Path location info.
Iterator Begin()
Get the location begin iterator.
@ Read
read access is allowed
@ ReadWrite
write access is allowed
@ ServerPending
server node where the file is pending to be online
@ ManagerOnline
manager node where the file is online
@ ServerOnline
server node where the file is online
@ ManagerPending
manager node where the file is pending to be online
LocationList::iterator Iterator
Iterator over locations.
Iterator End()
Get the location end iterator.
Handle diagnostics.
Definition XrdClLog.hh:101
@ InfoMsg
print info
Definition XrdClLog.hh:111
@ DebugMsg
print debug info
Definition XrdClLog.hh:112
@ DumpMsg
print details of the request and responses
Definition XrdClLog.hh:113
void SetLevel(LogLevel level)
Set the level of the messages that should be sent to the destination.
Definition XrdClLog.hh:193
void Error(uint64_t topic, const char *format,...)
Report an error.
Definition XrdClLog.cc:231
void Debug(uint64_t topic, const char *format,...)
Print a debug message.
Definition XrdClLog.cc:282
Pipeline exception, wrapps an XRootDStatus.
const XRootDStatus & GetError() const
A key-value pair map storing both keys and values as strings.
uint64_t GetFreeRW() const
Get size of the largest contiguous area of free r/w space (in MB).
uint64_t GetNodesStaging() const
Get number of nodes that can provide staging space.
uint8_t GetUtilizationStaging() const
Get percentage of the partition utilization represented by FreeStaging.
uint64_t GetFreeStaging() const
Get size of the largest contiguous area of free staging space (in MB).
uint8_t GetUtilizationRW() const
Get percentage of the partition utilization represented by FreeRW.
uint64_t GetNodesRW() const
Get number of nodes that can provide read/write space.
Object stat info.
std::string GetChangeTimeAsString() const
Get change time.
std::string GetModTimeAsString() const
Get modification time.
bool HasChecksum() const
Has checksum.
bool TestFlags(uint32_t flags) const
Test flags.
uint64_t GetSize() const
Get size (in bytes).
const std::string GetModeAsOctString() const
Get mode.
const std::string & GetOwner() const
Get owner.
@ IsReadable
Read access is allowed.
@ IsDir
This is a directory.
@ Other
Neither a file nor a directory.
@ BackUpExists
Back up copy exists.
@ XBitSet
Executable/searchable bit set.
@ Offline
File is not online (ie. on disk).
@ IsWritable
Write access is allowed.
uint32_t GetFlags() const
Get flags.
bool ExtendedFormat() const
Has extended stat information.
const std::string & GetModeAsString() const
Get mode.
const std::string & GetId() const
Get id.
const std::string & GetGroup() const
Get group.
std::string GetAccessTimeAsString() const
Get change time.
const std::string & GetChecksum() const
Get checksum.
URL representation.
Definition XrdClURL.hh:31
std::string GetHostId() const
Get the host part of the URL (user:password@host:port).
Definition XrdClURL.hh:99
std::map< std::string, std::string > ParamsMap
Definition XrdClURL.hh:33
void SetParams(const std::string &params)
Set params.
Definition XrdClURL.cc:378
URL()
Default constructor.
Definition XrdClURL.cc:36
std::string GetURL() const
Get the URL.
Definition XrdClURL.hh:86
std::string GetObfuscatedURL() const
Get the URL with authz information obfuscated.
Definition XrdClURL.cc:474
void SetPath(const std::string &path)
Set the path.
Definition XrdClURL.hh:225
const std::string & GetProtocol() const
Get the protocol.
Definition XrdClURL.hh:118
bool IsValid() const
Is the url valid.
Definition XrdClURL.cc:428
static void splitString(Container &result, const std::string &input, const std::string &delimiter)
Split a string.
Definition XrdClUtils.hh:56
static std::string BytesToString(uint64_t bytes)
Convert bytes to a human readable string.
XRootDStatus(uint16_t st=0, uint16_t code=0, uint32_t errN=0, const std::string &message="")
Constructor.
std::string ToStr() const
Convert to string.
static std::string genHumanSize(size_t size, uint64_t base)
const uint16_t suPartial
const uint16_t errInvalidAddr
RmImpl< false > Rm
const uint16_t stError
An error occurred that could potentially be retried.
const uint64_t AppMsg
const uint16_t errResponseNegative
Query response was negative.
StatImpl< false > Stat(Ctx< File > file, Arg< bool > force, time_t timeout=0)
const uint16_t errOSError
const uint16_t errInvalidArgs
XRootDStatus WaitFor(Pipeline pipeline, time_t timeout=0)
std::future< XRootDStatus > Async(Pipeline pipeline, time_t timeout=0)
ParallelOperation< false > Parallel(Container &&container)
Factory function for creating parallel operation from a vector.
@ OX
world executable/browsable
@ OW
world writeable
@ UR
owner readable
@ GR
group readable
@ UW
owner writable
@ GX
group executable/browsable
@ GW
group writable
@ UX
owner executable/browsable
@ OR
world readable
@ Stat
Stat each entry.
@ Merge
Merge duplicates.
@ Zip
List content of ZIP files.
@ Recursive
Do a recursive listing.
@ Cksm
Get checksum for every entry.
@ None
Nothing special.
@ MakePath
create the entire directory tree if it doesn't exist
Flags
Open flags, may be or'd when appropriate.
@ Read
Open only for reading.
@ Cancel
cancel staging request
@ Colocate
co-locate staged files, if possible
Code
XRootD query request codes.
@ OpaqueFile
Implementation dependent.
@ XAttr
Query file extended attributes.
@ Opaque
Implementation dependent.
@ Config
Query server configuration.
@ Stats
Query server stats.
@ ChecksumCancel
Query file checksum cancellation.
@ Checksum
Query file checksum.
@ Space
Query logical space stats.
@ Prepare
Query prepare status.
uint16_t code
Error type, or additional hints on what to do.
bool IsOK() const
We're fine.
std::string ToString() const
Create a string representation.
int GetShellCode() const
Get the status code that may be returned to the shell.
Extended attribute operation status.
XAttrStatus(const std::string &name, const XRootDStatus &status)
Extended attributes with status.
XAttr(const std::string &name, const XRootDStatus &status)