Project

General

Profile

Statistics
| Branch: | Revision:

gdp-if / tensorflow / gdpfs_tf.cc @ master

History | View | Annotate | Download (13.7 KB)

1 3c340135 Nitesh Mor
#include "gdpfs_tf.h"
2
3 a531ea78 Nitesh Mor
#include <unistd.h>
4
#include <stdio.h>
5 3c340135 Nitesh Mor
#include <errno.h>
6
#include <string.h>
7
#include <sys/stat.h>
8
#include <cstdlib>
9
#include <string>
10 a531ea78 Nitesh Mor
#include <iostream>
11
#include <map>
12
13
#include "tensorflow/core/lib/core/error_codes.pb.h"
14
#include "tensorflow/core/lib/core/status.h"
15
#include "tensorflow/core/lib/strings/strcat.h"
16
#include "tensorflow/core/platform/env.h"
17
#include "tensorflow/core/platform/file_system_helper.h"
18
#include "tensorflow/core/platform/logging.h"
19
20 98b0e081 Nitesh Mor
#include "gdpfs.h"
21 a531ea78 Nitesh Mor
22
namespace tensorflow {
23
24 33678164 Nitesh Mor
static EP_DBG Dbg = EP_DBG_INIT("gdpfs.tf",
25
                                                "GDP FileSystem: Tensorflow Extensions");
26 a531ea78 Nitesh Mor
27
28
/*
29
**        First, we implement a few classes that conform to
30
**  the behavior expected by the filesystem users.
31
**
32
**  These classes are thin wrappers around the classes
33 98b0e081 Nitesh Mor
**  provided by the gdpfs. Note that the WritableFile
34 a531ea78 Nitesh Mor
**  and AppendableFile are implemented by the same class.
35
*/
36
37
/*
38
** RandomAccessFile implementation based on GDPFileRO
39 98b0e081 Nitesh Mor
** (provided by gdpfs).
40 a531ea78 Nitesh Mor
*/
41
class GDPRandomAccessFile : public RandomAccessFile
42
{
43
44
        public:
45 6740856c Nitesh Mor
        GDPRandomAccessFile(const string& fname)
46 a531ea78 Nitesh Mor
        {
47 ee860b9f Nitesh Mor
                ep_dbg_cprintf(Dbg, 4, "New RandomAccessFile(%s)\n",
48
                                                                                        fname.c_str());
49
                _myname = fname;
50 6b980dad Nitesh Mor
                _file = new GDPFileRO(fname);
51 a531ea78 Nitesh Mor
        }
52
53
        ~GDPRandomAccessFile() override { delete _file; }
54
55
        Status Read(uint64 offset, size_t n, StringPiece* result,
56
                                                        char* scratch) const override
57
        {
58 9f162415 Nitesh Mor
                ep_dbg_cprintf(Dbg, 24, "Reading [%lld +(%ld)] bytes\n", offset, n);
59 3c340135 Nitesh Mor
                size_t read = _file->Read(offset, n, scratch);
60 a531ea78 Nitesh Mor
                *result = StringPiece(scratch, read);
61
                if (read == n)
62
                        return Status::OK();
63
                else
64
                {
65 3c340135 Nitesh Mor
                        ep_dbg_cprintf(Dbg, 11,
66
                                                        "Read only %ld bytes (asked for %ld)\n", read, n);
67
                        return Status(error::OUT_OF_RANGE,
68
                                                        "Read less bytes than requested");
69 a531ea78 Nitesh Mor
                }
70
        }
71
72
        private:
73
        GDPFileRO* _file;
74 ee860b9f Nitesh Mor
        string _myname;
75 a531ea78 Nitesh Mor
};
76
77
78
/*
79
** WritableFile implementation based on GDPFileWO
80 98b0e081 Nitesh Mor
** (provided by gdpfs).
81 a531ea78 Nitesh Mor
*/
82
83
class GDPWritableFile : public WritableFile
84
{
85
86
        public:
87 6740856c Nitesh Mor
        GDPWritableFile(const string& fname)
88 a531ea78 Nitesh Mor
        {
89 ee860b9f Nitesh Mor
                ep_dbg_cprintf(Dbg, 4, "New WritableFile(%s)\n",
90
                                                                                        fname.c_str());
91
                _myname = fname;
92 6b980dad Nitesh Mor
                _file = new GDPFileWO(fname);
93 a531ea78 Nitesh Mor
        }
94
95
        ~GDPWritableFile() override { delete _file; }
96
97
        Status Append(const StringPiece& data) override
98
        {
99 ee860b9f Nitesh Mor
                string s(data.data(), data.size());
100 70b43258 Nitesh Mor
                _file->Append(s);
101 a531ea78 Nitesh Mor
                return Status::OK();
102
        }
103
104 ee860b9f Nitesh Mor
        Status Close() override
105
        { 
106
                ep_dbg_cprintf(Dbg, 6, "Close(%s)\n", _myname.c_str());
107
                return Status::OK();
108
        }
109
        Status Flush() override
110
        {
111
                ep_dbg_cprintf(Dbg, 6, "Flush(%s)\n", _myname.c_str());
112
                return Status::OK();
113
        }
114
        Status Sync() override
115
        {
116
                ep_dbg_cprintf(Dbg, 6, "Sync(%s)\n", _myname.c_str());
117
                return Status::OK();
118
        }
119 a531ea78 Nitesh Mor
120
        private:
121 ee860b9f Nitesh Mor
        GDPFileWO* _file;
122
        string _myname;
123 a531ea78 Nitesh Mor
124
};
125
126
/*
127
** MemoryMapped implementation based on GDPFileROMemMap
128 98b0e081 Nitesh Mor
** (provided by gdpfs).
129 a531ea78 Nitesh Mor
*/
130
class GDPReadOnlyMemoryRegion : public ReadOnlyMemoryRegion
131
{
132
        public:
133 6740856c Nitesh Mor
        GDPReadOnlyMemoryRegion(const string& fname)
134 a531ea78 Nitesh Mor
        {
135 ee860b9f Nitesh Mor
                ep_dbg_cprintf(Dbg, 4, "New ReadOnlyMemoryRegion(%s)\n",
136
                                                                                        fname.c_str());
137
                _myname = fname;
138 6b980dad Nitesh Mor
                _file = new GDPFileROMemMap(fname);
139 a531ea78 Nitesh Mor
        }
140
141
        ~GDPReadOnlyMemoryRegion() override { delete _file; }
142
143
        const void* data() override
144
        {
145 9f162415 Nitesh Mor
                ep_dbg_cprintf(Dbg, 9, "%s.data()\n", _myname.c_str());
146 a531ea78 Nitesh Mor
                return (const char*) _file->data();
147
        }
148
149
        uint64 length() override
150
        {
151 9f162415 Nitesh Mor
                ep_dbg_cprintf(Dbg, 9, "%s.length()\n", _myname.c_str());
152 a531ea78 Nitesh Mor
                return (uint64) _file->length();
153
        }
154
155
        private:
156
        GDPFileROMemMap* _file;
157 ee860b9f Nitesh Mor
        string _myname;
158 a531ea78 Nitesh Mor
159
};
160
161
/**********************************************************/
162
/******** Implementation of GDPFileSystem below ***********/
163
/**********************************************************/
164
165
166 6740856c Nitesh Mor
GDPFileSystem::GDPFileSystem()
167 a531ea78 Nitesh Mor
{
168
        // nothing to see here.
169 418bfd3f Nitesh Mor
        GDPfsInit(GDP_MODE_RA);
170 a531ea78 Nitesh Mor
        ep_dbg_cprintf(Dbg, 2, "Initializing file system\n");
171
}
172
173
GDPFileSystem::~GDPFileSystem()
174
{
175
        ep_dbg_cprintf(Dbg, 2, "Freeing file system\n");
176
177
        // we close the directories in _open_root_dirs
178
        std::map<string, GDPDir*>::iterator it;
179
        for (it=_open_root_dirs.begin(); it!=_open_root_dirs.end(); it++)
180
        {
181
                ep_dbg_cprintf(Dbg, 15, "Freeing up open dir %s\n",
182
                                                                                        it->first.c_str());
183
                delete it->second;
184
        }
185
}
186
187
GDPDir* GDPFileSystem::get_root_dir(const string& dirname)
188
{
189
190 b89919ec Nitesh Mor
        ep_dbg_cprintf(Dbg, 14, "get_root_dir(%s)\n", dirname.c_str());
191 a531ea78 Nitesh Mor
192
        std::map<string, GDPDir*>::iterator it;
193
        it = _open_root_dirs.find(dirname);
194
        if (it == _open_root_dirs.end())
195
        {
196
                // open the directory, and return the pointer
197
                // dirname is also the logname for the topmost
198
                // directory; this is intentional.
199 b89919ec Nitesh Mor
                ep_dbg_cprintf(Dbg, 14, "Opening log/dir %s\n", dirname.c_str());
200 6b980dad Nitesh Mor
                GDPDir *ptr = new GDPDir(dirname, GDP_MODE_RA);
201 a531ea78 Nitesh Mor
                _open_root_dirs[dirname] = ptr;
202
                return ptr;
203
        }
204
        else
205
        {
206 b89919ec Nitesh Mor
                ep_dbg_cprintf(Dbg, 14, "Returning alredy open log/dir %s\n",
207 a531ea78 Nitesh Mor
                                                                                                        dirname.c_str());
208
                return it->second;
209
        }
210
}
211
212
Status GDPFileSystem::NewRandomAccessFile(
213
                const string& fname,
214 6740856c Nitesh Mor
                std::unique_ptr<RandomAccessFile>*result)
215 a531ea78 Nitesh Mor
{
216
        ep_dbg_cprintf(Dbg, 4, "NewRandomAccessFile(%s)\n", fname.c_str());
217
218
        string rootlog, path, logname;
219
        GDPDir *ptr;
220 6c1b37e9 Nitesh Mor
        assert (ParsePath(fname, &rootlog, &path) == kSuccess);
221 a531ea78 Nitesh Mor
        ptr = get_root_dir(rootlog);
222
223 418bfd3f Nitesh Mor
        if (ptr->NameExists(path))
224 a531ea78 Nitesh Mor
        {
225 418bfd3f Nitesh Mor
                ptr->GetEntryLogname(path, &logname);
226 a531ea78 Nitesh Mor
227
                ep_dbg_cprintf(Dbg, 7, "[%s]/[%s] => [%s]\n",
228
                                                                rootlog.c_str(), path.c_str(),
229
                                                                logname.c_str());
230
231
                result->reset(new GDPRandomAccessFile(logname));
232
                return Status::OK();
233
        }
234
        else
235
        {
236
                ep_dbg_cprintf(Dbg, 7, "[%s]/[%s] Does NOT Exist\n",
237
                                                                rootlog.c_str(), path.c_str());
238
                result->reset(NULL);
239
                return errors::NotFound("File doesn't exist\n");
240
        }
241
}
242
243
Status GDPFileSystem::NewReadOnlyMemoryRegionFromFile(
244
                                const string& fname,
245
                                std::unique_ptr<ReadOnlyMemoryRegion>* result)
246
{
247
        ep_dbg_cprintf(Dbg, 4, "NewReadOnlyMemoryRegionFromFile(%s)\n",
248
                                                                                                        fname.c_str());
249
        GDPDir *ptr;
250
        string rootlog, path, logname;
251 6c1b37e9 Nitesh Mor
        assert (ParsePath(fname, &rootlog, &path) == kSuccess);
252 a531ea78 Nitesh Mor
        ptr = get_root_dir(rootlog);
253
254 418bfd3f Nitesh Mor
        if (ptr->NameExists(path))
255 a531ea78 Nitesh Mor
        {
256 418bfd3f Nitesh Mor
                ptr->GetEntryLogname(path, &logname);
257 a531ea78 Nitesh Mor
258
                ep_dbg_cprintf(Dbg, 7, "[%s]/[%s] => [%s]\n",
259
                                                                rootlog.c_str(), path.c_str(),
260
                                                                logname.c_str());
261
262
                result->reset(new GDPReadOnlyMemoryRegion(logname));
263
                return Status::OK();
264
        }
265
        else
266
        {
267
                ep_dbg_cprintf(Dbg, 7, "[%s]/[%s] Does NOT Exist\n",
268
                                                                rootlog.c_str(), path.c_str());
269
                result->reset(NULL);
270
                return errors::NotFound("File doesn't exist\n");
271
        }
272
}
273
274
Status GDPFileSystem::NewWritableFile(
275
                const string& fname,
276 6740856c Nitesh Mor
                std::unique_ptr<WritableFile>* result)
277 a531ea78 Nitesh Mor
{
278
        ep_dbg_cprintf(Dbg, 4, "NewWritableFile(%s)\n", fname.c_str());
279
280
        GDPDir *ptr;
281
        string rootlog, path, logname;
282 6c1b37e9 Nitesh Mor
        assert (ParsePath(fname, &rootlog, &path) == kSuccess);
283 a531ea78 Nitesh Mor
        ptr = get_root_dir(rootlog);
284
285 418bfd3f Nitesh Mor
        if (ptr->NameExists(path))
286 a531ea78 Nitesh Mor
        {
287
                ep_dbg_cprintf(Dbg, 7, "Opening existing log as writable file\n");
288 418bfd3f Nitesh Mor
                ptr->GetEntryLogname(path, &logname);
289 a531ea78 Nitesh Mor
        }
290
        else
291
        {
292
                ep_dbg_cprintf(Dbg, 7, "Creating new log as writable file\n");
293 418bfd3f Nitesh Mor
                ptr->NewFile(path, &logname);
294 a531ea78 Nitesh Mor
        }
295
296
        result->reset(new GDPWritableFile(logname));
297
        ep_dbg_cprintf(Dbg, 7, "[%s]/[%s] => [%s]\n",
298
                                                                rootlog.c_str(), path.c_str(),
299
                                                                logname.c_str());
300
        return Status::OK();
301
}
302
303
Status GDPFileSystem::NewAppendableFile(
304
                                const string& fname,
305
                                std::unique_ptr<WritableFile>* result)
306
{
307
        ep_dbg_cprintf(Dbg, 4, "NewAppendableFile(%s)\n", fname.c_str());
308
        return NewWritableFile(fname, result);
309
}
310
311
312
Status GDPFileSystem::FileExists(const string& fname)
313
{
314
        ep_dbg_cprintf(Dbg, 4, "FileExists(%s)\n", fname.c_str());
315
        string rootlog, path;
316
        GDPDir *ptr;
317
318 6c1b37e9 Nitesh Mor
        assert (ParsePath(fname, &rootlog, &path) == kSuccess);
319 a531ea78 Nitesh Mor
        ptr = get_root_dir(rootlog);
320
321 418bfd3f Nitesh Mor
        if (ptr->NameExists(path))
322 a531ea78 Nitesh Mor
        {
323
                ep_dbg_cprintf(Dbg, 7, "[%s]/[%s] Exists\n",
324
                                                                rootlog.c_str(), path.c_str());
325
                return Status::OK();
326
        }
327
        else
328
        {
329
                ep_dbg_cprintf(Dbg, 7, "[%s]/[%s] Does NOT Exist\n",
330
                                                                rootlog.c_str(), path.c_str());
331
                return errors::NotFound("Not found\n");
332
        }
333
}
334
335
Status GDPFileSystem::GetChildren(
336
                                const string& dir,
337
                                std::vector<string>* result)
338
{
339
        ep_dbg_cprintf(Dbg, 4, "GetChildren(%s)\n", dir.c_str());
340 b89919ec Nitesh Mor
341
        string rootlog, path;
342
        GDPDir *ptr;
343 1e31523e Nitesh Mor
        std::vector<string> tmp;
344
        std::vector<string>::iterator it;
345
        string s;
346 b89919ec Nitesh Mor
347 6c1b37e9 Nitesh Mor
        assert (ParsePath(dir, &rootlog, &path) == kSuccess);
348 b89919ec Nitesh Mor
        ptr = get_root_dir(rootlog);
349
350 1e31523e Nitesh Mor
        ptr->GetChildren(path, &tmp);
351
352
        // Make sure we translate the names back to full path
353
        for (it=tmp.begin(); it!=tmp.end(); it++)
354
        {
355
                s.assign("gdp://");
356
                s.append(rootlog);
357
                s.append("/");
358
                s.append(*it);
359
                result->push_back(s);
360
        }
361
362 adceff07 Nitesh Mor
        return Status::OK();
363
364
        /*
365
        // XXX This should be removed after testing GDPDir's GetChildren
366

367 ebd8f911 Nitesh Mor
        for (it=ptr->dentries_.begin(); it!= ptr->dentries_.end(); it++)
368 b89919ec Nitesh Mor
        {
369 418bfd3f Nitesh Mor
                BaseDirName(it->first, &dirname, &basename);
370 b89919ec Nitesh Mor
                fulldirname.assign("gdp://");
371
                fulldirname.append(rootlog);
372
                fulldirname.append("/");
373
                fulldirname.append(dirname);
374

375 9f162415 Nitesh Mor
                ep_dbg_cprintf(Dbg, 15, "comparing %s with %s\n",
376 b89919ec Nitesh Mor
                                                                fulldirname.c_str(), dir.c_str());
377
                if (fulldirname.compare(dir) == 0)
378
                {
379 9f162415 Nitesh Mor
                        ep_dbg_cprintf(Dbg, 12, "child => %s\n", basename.c_str());
380 b89919ec Nitesh Mor
                        result->push_back(basename);
381
                }
382
        }
383

384
        return Status::OK();
385 adceff07 Nitesh Mor
        */
386 a531ea78 Nitesh Mor
}
387
388
389
Status GDPFileSystem::Stat(const string& fname, FileStatistics* stat)
390
{
391
        ep_dbg_cprintf(Dbg, 4, "Stat(%s)\n", fname.c_str());
392 ca58f4e8 Nitesh Mor
        string rootlog, path;
393 b89919ec Nitesh Mor
        GDPDir *ptr;
394 ca58f4e8 Nitesh Mor
        GdpStat tmp;
395 b89919ec Nitesh Mor
396 6c1b37e9 Nitesh Mor
        assert (ParsePath(fname, &rootlog, &path) == kSuccess);
397 b89919ec Nitesh Mor
        ptr = get_root_dir(rootlog);
398
399 ca58f4e8 Nitesh Mor
        ptr->Stat(path, &tmp);
400
401
        stat->is_directory = tmp.is_directory;
402
        stat->length = tmp.length;
403
        stat->mtime_nsec = tmp.mtime_nsec;
404
        
405
        /*
406

407 418bfd3f Nitesh Mor
        stat->is_directory = (ptr->GetEntryType(path) == GDPfs::DIR);
408 b89919ec Nitesh Mor
        if (!stat->is_directory)
409
        {
410
                GetFileSize(fname, &size);
411
                stat->length = size;
412 c2dabd24 Nitesh Mor

413
                // getting last update time
414 418bfd3f Nitesh Mor
                ptr->GetEntryLogname(path, &logname);
415 6b980dad Nitesh Mor
                GDPFileLowLevel f(logname, GDP_MODE_RO);
416 ebd8f911 Nitesh Mor
                stat->mtime_nsec = f.GetMTime();
417 b89919ec Nitesh Mor
        }
418 c2dabd24 Nitesh Mor
        else
419
        {
420
                stat->length = 0;
421 418bfd3f Nitesh Mor
                stat->mtime_nsec = TimeNS();        // XXX: fix this
422 c2dabd24 Nitesh Mor
        }
423

424 ca58f4e8 Nitesh Mor
        */
425 c2dabd24 Nitesh Mor
        ep_dbg_cprintf(Dbg, 4, "Stat(%s)=%lld, %lld\n", fname.c_str(),
426
                                                                        stat->length, stat->mtime_nsec);
427 6740856c Nitesh Mor
        return Status::OK();
428 a531ea78 Nitesh Mor
}
429
430
Status GDPFileSystem::GetMatchingPaths(
431
                                const string& pattern,
432
                                std::vector<string>* results)
433
{
434
        ep_dbg_cprintf(Dbg, 4, "GetMatchingPaths(%s)\n", pattern.c_str());
435 a48a4a87 Nitesh Mor
        ep_dbg_cprintf(Dbg, 1, "Note that this isn't fully implemented yet.\n");
436 2a8c143d Nitesh Mor
437 8dce4a9a Nitesh Mor
        string rootlog, path;
438
        GDPDir *ptr;
439 1e31523e Nitesh Mor
        std::vector<string> tmp;
440
        std::vector<string>::iterator it;
441
        string s;
442 8dce4a9a Nitesh Mor
443 6c1b37e9 Nitesh Mor
        assert (ParsePath(pattern, &rootlog, &path) == kSuccess);
444 8dce4a9a Nitesh Mor
        ptr = get_root_dir(rootlog);
445
446 1e31523e Nitesh Mor
        ptr->GetMatchingPaths(path, &tmp);
447
448
        // Make sure we translate the names back to full path
449
        for (it=tmp.begin(); it!= tmp.end(); it++)
450
        {
451
                s.assign("gdp://");
452
                s.append(rootlog);
453
                s.append("/");
454
                s.append(*it);
455
                results->push_back(s);
456
        }
457
458 8dce4a9a Nitesh Mor
        return Status::OK();
459
460
        /*
461

462
        // XXX: this should be removed once GDPDir GetMatchingPaths is tested.
463

464 2a8c143d Nitesh Mor
        if (pattern.find('*')!=string::npos)
465
                return errors::Unimplemented(" '*' Not yet implemented\n");
466
        if (pattern.find('?')!=string::npos)
467
                return errors::Unimplemented(" '?' Not yet implemented\n");
468
        if (pattern.find('[')!=string::npos)
469
                return errors::Unimplemented(" '[' Not yet implemented\n");
470
        if (pattern.find(']')!=string::npos)
471
                return errors::Unimplemented(" ']' Not yet implemented\n");
472 9f162415 Nitesh Mor
        if (pattern.find("\\\\")!=string::npos)
473
                return errors::Unimplemented(" ds Not yet implemented\n");
474 2a8c143d Nitesh Mor
        
475
        size_t pos;
476
        string rootlog, path;
477
        GDPDir *ptr;
478
        std::map<string, string>::iterator it;
479

480 6c1b37e9 Nitesh Mor
        assert (ParsePath(pattern, &rootlog, &path) == kSuccess);
481 2a8c143d Nitesh Mor
        ptr = get_root_dir(rootlog);
482

483 ebd8f911 Nitesh Mor
        for (it=ptr->dentries_.begin(); it!=ptr->dentries_.end(); it++)
484 2a8c143d Nitesh Mor
        {
485
                ep_dbg_cprintf(Dbg, 30, "Matching %s against: %s\n",
486
                                                                        path.c_str(), it->first.c_str());
487
                pos = it->first.find(path);
488
                if (pos == 0)
489
                {
490
                        ep_dbg_cprintf(Dbg, 22, "Found match %s\n", it->first.c_str());
491
                        results->push_back(it->first);
492
                }
493
        }
494

495
        return Status::OK();
496 8dce4a9a Nitesh Mor
        */
497 a531ea78 Nitesh Mor
}
498
499
Status GDPFileSystem::DeleteFile(const string& fname)
500
{
501
        ep_dbg_cprintf(Dbg, 4, "DeleteFile(%s)\n", fname.c_str());
502
        string rootlog, path;
503
        GDPDir *ptr;
504
505 6c1b37e9 Nitesh Mor
        assert (ParsePath(fname, &rootlog, &path) == kSuccess);
506 a531ea78 Nitesh Mor
        ptr = get_root_dir(rootlog);
507
508
        ep_dbg_cprintf(Dbg, 7, "Deleting file [%s]/[%s]\n",
509
                                                        rootlog.c_str(), path.c_str());
510
511 2651f137 Nitesh Mor
        ptr->DeleteFile(path);
512 6740856c Nitesh Mor
        return Status::OK();
513 a531ea78 Nitesh Mor
}
514
515
Status GDPFileSystem::CreateDir(const string& name)
516
{
517
        ep_dbg_cprintf(Dbg, 4, "CreateDir(%s)\n", name.c_str());
518 b6438f0c Nitesh Mor
        string rootlog, path;
519 a531ea78 Nitesh Mor
        GDPDir *ptr;
520
521 6c1b37e9 Nitesh Mor
        assert (ParsePath(name, &rootlog, &path) == kSuccess);
522 a531ea78 Nitesh Mor
        ptr = get_root_dir(rootlog);
523
524 2651f137 Nitesh Mor
        ptr->CreateDir(path);
525 b6438f0c Nitesh Mor
        ep_dbg_cprintf(Dbg, 7, "New dir [%s]/[%s] => [X]\n",
526
                                                        rootlog.c_str(), path.c_str());
527 a531ea78 Nitesh Mor
528 6740856c Nitesh Mor
        return Status::OK();
529 a531ea78 Nitesh Mor
}
530
531
532
Status GDPFileSystem::DeleteDir(const string& name)
533
{
534
        ep_dbg_cprintf(Dbg, 4, "DeleteDir(%s)\n", name.c_str());
535
        string rootlog, path;
536
        GDPDir *ptr;
537
538 6c1b37e9 Nitesh Mor
        assert (ParsePath(name, &rootlog, &path) == kSuccess);
539 a531ea78 Nitesh Mor
        ptr = get_root_dir(rootlog);
540
541
        ep_dbg_cprintf(Dbg, 7, "Deleting dir [%s]/[%s]\n",
542
                                                        rootlog.c_str(), path.c_str());
543
544 2651f137 Nitesh Mor
        ptr->DeleteDir(path);
545 6740856c Nitesh Mor
        return Status::OK();
546 a531ea78 Nitesh Mor
}
547
548
549
Status GDPFileSystem::GetFileSize(const string& fname, uint64* size)
550
{
551
        ep_dbg_cprintf(Dbg, 4, "GetFileSize(%s)\n", fname.c_str());
552
        string rootlog, path, logname;
553
        GDPDir *ptr;
554
555 6c1b37e9 Nitesh Mor
        assert (ParsePath(fname, &rootlog, &path) == kSuccess);
556 a531ea78 Nitesh Mor
        ptr = get_root_dir(rootlog);
557 418bfd3f Nitesh Mor
        assert (ptr->GetEntryType(path) == GDPfs::FILE);
558 a531ea78 Nitesh Mor
559 418bfd3f Nitesh Mor
        ptr->GetEntryLogname(path, &logname);
560 6b980dad Nitesh Mor
        GDPFile f(logname, GDP_MODE_RO);
561 418bfd3f Nitesh Mor
        *size = (uint64) f.GetFileSize();
562 a531ea78 Nitesh Mor
563 6740856c Nitesh Mor
        return Status::OK();
564 a531ea78 Nitesh Mor
}
565
566
567
Status GDPFileSystem::RenameFile(const string& src, const string& target)
568
{
569
        ep_dbg_cprintf(Dbg, 4, "RenameFile(%s=>%s)\n",
570
                                                                src.c_str(), target.c_str());
571 beec3457 Nitesh Mor
572
        string rootlog1, path1, rootlog2, path2;
573
        GDPDir *ptr;
574
575 6c1b37e9 Nitesh Mor
        assert (ParsePath(src, &rootlog1, &path1) == kSuccess);
576
        assert (ParsePath(target, &rootlog2, &path2) == kSuccess);
577 beec3457 Nitesh Mor
578
        // we don't support copying across different root
579
        // directories.
580
        assert (rootlog1.compare(rootlog2) == 0);
581
582
        ptr = get_root_dir(rootlog1);
583
584 418bfd3f Nitesh Mor
        ptr->RenameFile(path1, path2);
585 beec3457 Nitesh Mor
        return Status::OK();
586 a531ea78 Nitesh Mor
}
587
588
REGISTER_FILE_SYSTEM("gdp", GDPFileSystem);
589
590
}        // namespace tensorflow