XRootD
Loading...
Searching...
No Matches
XrdSsiDir.cc
Go to the documentation of this file.
1/******************************************************************************/
2/* */
3/* X r d S s i D i r . c c */
4/* */
5/* (c) 2015 by the Board of Trustees of the Leland Stanford, Jr., University */
6/* Produced by Andrew Hanushevsky for Stanford University under contract */
7/* DE-AC02-76-SFO0515 with the Department of Energy */
8/* */
9/* This file is part of the XRootD software suite. */
10/* */
11/* XRootD is free software: you can redistribute it and/or modify it under */
12/* the terms of the GNU Lesser General Public License as published by the */
13/* Free Software Foundation, either version 3 of the License, or (at your */
14/* option) any later version. */
15/* */
16/* XRootD is distributed in the hope that it will be useful, but WITHOUT */
17/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
18/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
19/* License for more details. */
20/* */
21/* You should have received a copy of the GNU Lesser General Public License */
22/* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
23/* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
24/* */
25/* The copyright holder's institutional names and contributor's names may not */
26/* be used to endorse or promote products derived from this software without */
27/* specific prior written permission of the institution or contributor. */
28/******************************************************************************/
29
30#include <cerrno>
31#include <cstring>
32
33#include "XrdOuc/XrdOucPList.hh"
34#include "XrdSsi/XrdSsiDir.hh"
35#include "XrdSsi/XrdSsiUtils.hh"
36
37/******************************************************************************/
38/* G l o b a l s */
39/******************************************************************************/
40
41namespace XrdSsi
42{
43extern XrdSfsFileSystem *theFS;
44extern XrdOucPListAnchor FSPath;
45extern bool fsChk;
46};
47
48using namespace XrdSsi;
49
50/******************************************************************************/
51/* o p e n */
52/******************************************************************************/
53
54int XrdSsiDir::open(const char *dir_path, // In
55 const XrdSecEntity *client, // In
56 const char *info) // In
57/*
58 Function: Open the directory `path' and prepare for reading.
59
60 Input: path - The fully qualified name of the directory to open.
61 client - Authentication credentials, if any.
62 info - Opaque information to be used as seen fit.
63
64 Output: Returns SFS_OK upon success, otherwise SFS_ERROR.
65*/
66{
67 static const char *epname = "opendir";
68
69// Verify that this object is not already associated with an open file
70//
71 if (dirP)
72 return XrdSsiUtils::Emsg(epname,EADDRINUSE,"open directory",dir_path,error);
73
74// Open a regular file if this is wanted
75//
76 if (fsChk && FSPath.Find(dir_path))
77 {if (!(dirP = theFS->newDir((char *)tident, error.getErrMid())))
78 return XrdSsiUtils::Emsg(epname, ENOMEM, epname, dir_path, error);
79 dirP->error = error;
80 return dirP->open(dir_path, client, info);
81 }
82
83// All done
84//
85 if (fsChk) error.setErrInfo(ENOTSUP, "Directory operations not "
86 "supported on given path.");
87 else error.setErrInfo(ENOTSUP, "Directory operations not supported.");
88 return SFS_ERROR;
89}
90
91/******************************************************************************/
92/* n e x t E n t r y */
93/******************************************************************************/
94
96/*
97 Function: Read the next directory entry.
98
99 Input: n/a
100
101 Output: Upon success, returns the contents of the next directory entry as
102 a null terminated string. Returns a null pointer upon EOF or an
103 error. To differentiate the two cases, getErrorInfo will return
104 0 upon EOF and an actual error code (i.e., not 0) on error.
105*/
106{
107 const char *epname = "readdir";
108
109// Get next directory entry if we can
110//
111 if (dirP) return dirP->nextEntry();
112 XrdSsiUtils::Emsg(epname, EBADF, epname, "???", error);
113 return 0;
114}
115
116/******************************************************************************/
117/* c l o s e */
118/******************************************************************************/
119
121/*
122 Function: Close the directory object.
123
124 Input: n/a
125
126 Output: Returns SFS_OK upon success and SFS_ERROR upon failure.
127*/
128{
129 const char *epname = "closedir";
130
131// Close as needed
132//
133 if (dirP) return dirP->close();
134 return XrdSsiUtils::Emsg(epname, EBADF, epname, "???", error);
135}
136
137/******************************************************************************/
138/* a u t o S t a t */
139/******************************************************************************/
140
141int XrdSsiDir::autoStat(struct stat *buf)
142/*
143 Function: Set stat buffer to automaticaly return stat information
144
145 Input: Pointer to stat buffer which will be filled in on each
146 nextEntry() and represent stat information for that entry.
147
148 Output: Upon success, returns zero. Upon error returns SFS_ERROR and sets
149 the error object to contain the reason.
150*/
151{
152 const char *epname = "autoStat";
153
154// Check if this directory is actually open
155//
156 if (dirP) return dirP->autoStat(buf);
157 return XrdSsiUtils::Emsg(epname, EBADF, epname, "???", error);
158}
159
160/******************************************************************************/
161/* F N a m e */
162/******************************************************************************/
163
164const char *XrdSsiDir::FName()
165{
166 const char *epname = "fname";
167
168// Check if this directory is actually open
169//
170 if (dirP) return dirP->FName();
171 XrdSsiUtils::Emsg(epname, EBADF, epname, "???", error);
172 return "";
173}
#define stat(a, b)
Definition XrdPosix.hh:101
#define SFS_ERROR
XrdOucErrInfo & error
const char * nextEntry()
Definition XrdSsiDir.cc:95
int autoStat(struct stat *buf)
Definition XrdSsiDir.cc:141
int open(const char *dirName, const XrdSecEntity *client, const char *opaque=0)
Definition XrdSsiDir.cc:54
const char * FName()
Definition XrdSsiDir.cc:164
int close()
Definition XrdSsiDir.cc:120
static int Emsg(const char *pfx, int ecode, const char *op, const char *path, XrdOucErrInfo &eDest)
XrdSfsFileSystem * theFS
Definition XrdSsiFile.cc:54
bool fsChk
Definition XrdSsiFile.cc:56
XrdOucPListAnchor FSPath
Definition XrdSsiFile.cc:55