2017-01-20 01:54:49 +00:00
|
|
|
/* mbed Microcontroller Library
|
|
|
|
* Copyright (c) 2006-2013 ARM Limited
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
Build with external tool fails: missing includes
When building with VisualGDB the compilation fails due to the lack of required include files Dir.h and File.h.
Compiler report:
1>------ Build started: Project: exported-mbed-STM32F429-nucleo, Configuration: Debug VisualGDB ------
1> FileSystem.cpp
1> mbed-os/features/filesystem/FileSystem.cpp: In instantiation of 'class Managed<mbed::File>':
1> mbed-os\features\filesystem\FileSystem.cpp(141,19): note : required from here
1>mbed-os\features\filesystem\FileSystem.cpp(130,7): error : invalid use of incomplete type 'class mbed::File'
1> class Managed : public F {
1> ^~~~~~~
1> mbed-os\features\filesystem\FileSystem.cpp(18):
1> mbed-os\features\filesystem\FileSystem.h(39,7): note : forward declaration of 'class mbed::File'
1> class File;
1> ^~~~
1> mbed-os/features/filesystem/FileSystem.cpp: In member function 'virtual int mbed::FileSystem::open(mbed::FileHandle**, const char*, int)':
1>mbed-os\features\filesystem\FileSystem.cpp(141,19): error : cannot convert 'Managed<mbed::File>*' to 'mbed::File*' in initialization
1> File *f = new Managed<File>;
1> ^~~~~~~~~~~~~
1>mbed-os\features\filesystem\FileSystem.cpp(142,16): error : invalid use of incomplete type 'class mbed::File'
1> int err = f->open(this, path, flags);
1> ^~
1> mbed-os\features\filesystem\FileSystem.cpp(18):
1> mbed-os\features\filesystem\FileSystem.h(39,7): note : forward declaration of 'class mbed::File'
1> class File;
1> ^~~~
1>mbed-os\features\filesystem\FileSystem.cpp(144,16): warning : possible problem detected in invocation of delete operator: [-Wdelete-incomplete]
1> delete f;
1> ^
1>mbed-os\features\filesystem\FileSystem.cpp(141,11): warning : 'f' has incomplete type
1> File *f = new Managed<File>;
1> ^
1> mbed-os\features\filesystem\FileSystem.cpp(18):
1> mbed-os\features\filesystem\FileSystem.h(39,7): note : forward declaration of 'class mbed::File'
1> class File;
1> ^~~~
1> mbed-os\features\filesystem\FileSystem.cpp(144,16): note : neither the destructor nor the class-specific operator delete will be called, even if they are declared when the class is defined
1> delete f;
1> ^
1>mbed-os\features\filesystem\FileSystem.cpp(148,13): error : cannot convert 'mbed::File*' to 'mbed::FileHandle*' in assignment
1> *file = f;
1> ^
1> mbed-os\features\filesystem\FileSystem.cpp(18):
1> mbed-os\features\filesystem\FileSystem.h(39,7): note : class type 'mbed::File' is incomplete
1> class File;
1> ^~~~
1> mbed-os/features/filesystem/FileSystem.cpp: In instantiation of 'class Managed<mbed::Dir>':
1> mbed-os\features\filesystem\FileSystem.cpp(153,18): note : required from here
1>mbed-os\features\filesystem\FileSystem.cpp(130,7): error : invalid use of incomplete type 'class mbed::Dir'
1> class Managed : public F {
1> ^~~~~~~
1> mbed-os\features\filesystem\FileSystem.cpp(18):
1> mbed-os\features\filesystem\FileSystem.h(38,7): note : forward declaration of 'class mbed::Dir'
1> class Dir;
1> ^~~
1> mbed-os/features/filesystem/FileSystem.cpp: In member function 'virtual int mbed::FileSystem::open(mbed::DirHandle**, const char*)':
1>mbed-os\features\filesystem\FileSystem.cpp(153,18): error : cannot convert 'Managed<mbed::Dir>*' to 'mbed::Dir*' in initialization
1> Dir *d = new Managed<Dir>;
1> ^~~~~~~~~~~~
1>mbed-os\features\filesystem\FileSystem.cpp(154,16): error : invalid use of incomplete type 'class mbed::Dir'
1> int err = d->open(this, path);
1> ^~
1> mbed-os\features\filesystem\FileSystem.cpp(18):
1> mbed-os\features\filesystem\FileSystem.h(38,7): note : forward declaration of 'class mbed::Dir'
1> class Dir;
1> ^~~
1>mbed-os\features\filesystem\FileSystem.cpp(156,16): warning : possible problem detected in invocation of delete operator: [-Wdelete-incomplete]
1> delete d;
1> ^
1>mbed-os\features\filesystem\FileSystem.cpp(153,10): warning : 'd' has incomplete type
1> Dir *d = new Managed<Dir>;
1> ^
1> mbed-os\features\filesystem\FileSystem.cpp(18):
1> mbed-os\features\filesystem\FileSystem.h(38,7): note : forward declaration of 'class mbed::Dir'
1> class Dir;
1> ^~~
1> mbed-os\features\filesystem\FileSystem.cpp(156,16): note : neither the destructor nor the class-specific operator delete will be called, even if they are declared when the class is defined
1> delete d;
1> ^
1>mbed-os\features\filesystem\FileSystem.cpp(160,12): error : cannot convert 'mbed::Dir*' to 'mbed::DirHandle*' in assignment
1> *dir = d;
1> ^
1> mbed-os\features\filesystem\FileSystem.cpp(18):
1> mbed-os\features\filesystem\FileSystem.h(38,7): note : class type 'mbed::Dir' is incomplete
1> class Dir;
1> ^~~
1> mbed-os/features/filesystem/FileSystem.cpp: In instantiation of 'int Managed<F>::close() [with F = mbed::Dir]':
1> mbed-os\features\filesystem\FileSystem.cpp(162,1): note : required from here
1>mbed-os\features\filesystem\FileSystem.cpp(133,27): error : incomplete type 'mbed::Dir' used in nested name specifier
1> int err = F::close();
1> ~~~~~~~~^~
1> mbed-os/features/filesystem/FileSystem.cpp: In instantiation of 'int Managed<F>::close() [with F = mbed::File]':
1> mbed-os\features\filesystem\FileSystem.cpp(162,1): note : required from here
1>mbed-os\features\filesystem\FileSystem.cpp(133,27): error : incomplete type 'mbed::File' used in nested name specifier
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
2017-08-30 15:21:53 +00:00
|
|
|
#include "filesystem/Dir.h"
|
|
|
|
#include "filesystem/File.h"
|
2017-01-20 01:54:49 +00:00
|
|
|
#include "filesystem/FileSystem.h"
|
2017-02-13 23:49:57 +00:00
|
|
|
#include <errno.h>
|
2017-01-20 01:54:49 +00:00
|
|
|
|
2018-07-31 15:30:00 +00:00
|
|
|
namespace mbed {
|
2017-01-20 01:54:49 +00:00
|
|
|
|
2017-02-13 19:19:57 +00:00
|
|
|
FileSystem::FileSystem(const char *name)
|
2017-03-30 19:36:21 +00:00
|
|
|
: FileSystemLike(name)
|
2017-02-13 19:19:57 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-08-14 22:05:40 +00:00
|
|
|
int FileSystem::reformat(BlockDevice *bd)
|
|
|
|
{
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
|
2017-03-30 19:39:54 +00:00
|
|
|
int FileSystem::remove(const char *path)
|
|
|
|
{
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
|
|
|
|
int FileSystem::rename(const char *path, const char *newpath)
|
|
|
|
{
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
|
|
|
|
int FileSystem::stat(const char *path, struct stat *st)
|
|
|
|
{
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
|
|
|
|
int FileSystem::mkdir(const char *path, mode_t mode)
|
|
|
|
{
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
|
2017-12-28 22:38:20 +00:00
|
|
|
int FileSystem::statvfs(const char *path, struct statvfs *buf)
|
|
|
|
{
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
|
2017-01-20 01:54:49 +00:00
|
|
|
int FileSystem::file_sync(fs_file_t file)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-02-13 19:19:57 +00:00
|
|
|
int FileSystem::file_isatty(fs_file_t file)
|
2017-01-20 01:54:49 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
off_t FileSystem::file_tell(fs_file_t file)
|
|
|
|
{
|
|
|
|
return file_seek(file, 0, SEEK_CUR);
|
|
|
|
}
|
|
|
|
|
|
|
|
void FileSystem::file_rewind(fs_file_t file)
|
|
|
|
{
|
|
|
|
file_seek(file, 0, SEEK_SET);
|
|
|
|
}
|
|
|
|
|
2017-03-28 13:23:00 +00:00
|
|
|
off_t FileSystem::file_size(fs_file_t file)
|
2017-01-20 01:54:49 +00:00
|
|
|
{
|
|
|
|
off_t off = file_tell(file);
|
2017-03-28 13:23:00 +00:00
|
|
|
off_t size = file_seek(file, 0, SEEK_END);
|
2017-01-20 01:54:49 +00:00
|
|
|
file_seek(file, off, SEEK_SET);
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:14:21 +00:00
|
|
|
int FileSystem::file_truncate(fs_file_t file, off_t length)
|
|
|
|
{
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
|
2017-01-20 01:54:49 +00:00
|
|
|
int FileSystem::dir_open(fs_dir_t *dir, const char *path)
|
|
|
|
{
|
2017-02-13 23:49:57 +00:00
|
|
|
return -ENOSYS;
|
2017-01-20 01:54:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int FileSystem::dir_close(fs_dir_t dir)
|
|
|
|
{
|
2017-02-13 23:49:57 +00:00
|
|
|
return -ENOSYS;
|
2017-01-20 01:54:49 +00:00
|
|
|
}
|
|
|
|
|
2017-02-23 02:14:50 +00:00
|
|
|
ssize_t FileSystem::dir_read(fs_dir_t dir, struct dirent *ent)
|
2017-01-20 01:54:49 +00:00
|
|
|
{
|
2017-02-13 23:49:57 +00:00
|
|
|
return -ENOSYS;
|
2017-01-20 01:54:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FileSystem::dir_seek(fs_dir_t dir, off_t offset)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
off_t FileSystem::dir_tell(fs_dir_t dir)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FileSystem::dir_rewind(fs_dir_t dir)
|
|
|
|
{
|
|
|
|
// Note, the may not satisfy rewind on all filesystems
|
|
|
|
dir_seek(dir, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t FileSystem::dir_size(fs_dir_t dir)
|
|
|
|
{
|
|
|
|
off_t off = dir_tell(dir);
|
|
|
|
size_t size = 0;
|
2017-02-23 02:14:50 +00:00
|
|
|
struct dirent *ent = new struct dirent;
|
2017-01-20 01:54:49 +00:00
|
|
|
|
|
|
|
dir_rewind(dir);
|
|
|
|
while (true) {
|
2017-02-23 02:14:50 +00:00
|
|
|
int res = dir_read(dir, ent);
|
2017-01-20 01:54:49 +00:00
|
|
|
if (res <= 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
size += 1;
|
|
|
|
}
|
|
|
|
dir_seek(dir, off);
|
|
|
|
|
2017-02-23 02:14:50 +00:00
|
|
|
delete ent;
|
2017-01-20 01:54:49 +00:00
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2017-03-30 19:40:36 +00:00
|
|
|
// Internally used file wrapper that manages memory on close
|
2017-03-30 19:36:21 +00:00
|
|
|
template <typename F>
|
|
|
|
class Managed : public F {
|
|
|
|
public:
|
2018-10-30 14:57:42 +00:00
|
|
|
virtual int close()
|
|
|
|
{
|
2017-03-30 19:36:21 +00:00
|
|
|
int err = F::close();
|
|
|
|
delete this;
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
int FileSystem::open(FileHandle **file, const char *path, int flags)
|
|
|
|
{
|
|
|
|
File *f = new Managed<File>;
|
|
|
|
int err = f->open(this, path, flags);
|
|
|
|
if (err) {
|
|
|
|
delete f;
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
*file = f;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-10-30 14:57:42 +00:00
|
|
|
int FileSystem::open(DirHandle **dir, const char *path)
|
|
|
|
{
|
2017-03-30 19:36:21 +00:00
|
|
|
Dir *d = new Managed<Dir>;
|
|
|
|
int err = d->open(this, path);
|
|
|
|
if (err) {
|
|
|
|
delete d;
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
*dir = d;
|
|
|
|
return 0;
|
|
|
|
}
|
2018-07-31 15:30:00 +00:00
|
|
|
|
|
|
|
} // namespace mbed
|