embkernel
 All Classes Functions Variables Typedefs Groups Pages
FsDir.cpp
1 //------------------------------------------------------------------------------
2 //This file is part of embKernel.
3 //See license.txt for the full license governing this code.
4 //------------------------------------------------------------------------------
5 
6 #include "FsDir.hpp"
7 #include "Fs.hpp"
8 #include <stdlib.h>
9 
10 FsDir::FsDir() {
11 }
12 
13 FsDir::~FsDir() {
14 }
15 
16 FsDefs::RESULT FsDir::open(const char* path) {
17  return FsEntry::open(path, false, false, true);
18 }
19 
20 FsDefs::RESULT FsDir::create(const char* path) {
21  return FsEntry::open(path, false, false, true);
22 }
23 
24 FsDefs::RESULT FsDir::close() {
25  if (!mSector) {
26  return FsDefs::RES_ENTRY_NOT_OPEN;
27  }
28  free(mSector);
29  mSector = 0;
30  return FsDefs::RES_SUCCESS;
31 }
32 
33 FsDefs::RESULT FsDir::del(const char* path) {
34  return FsEntry::del(path, true);
35 }
36 
37 FsDefs::RESULT FsDir::rewind() {
38  if (!mSector) {
39  return FsDefs::RES_ENTRY_NOT_OPEN;
40  }
41  mPosition = 0;
42  uint32_t lba = mPartition->getClusterBeginLba(mClusterBegin);
43  if (mCurrentLba != lba) {
44  mFlags.bits.sectorCacheInvalid = true;
45  }
46  mCurrentLba = lba;
47  return FsDefs::RES_SUCCESS;
48 }
49 
50 FsDefs::RESULT FsDir::getNextEntry(ENTRY_INFO* entryInfo) {
51  if (entryInfo->longFileName) {
52  free((void*) entryInfo->longFileName);
53  entryInfo->longFileName = 0;
54  }
55  if (!mSector) {
56  return FsDefs::RES_ENTRY_NOT_OPEN;
57  }
58  return Fs::getNextEntry(this, entryInfo);
59 }
60