[prettyprint commit] r527 - Namespacify filesystem better

0 views
Skip to first unread message

codesite...@google.com

unread,
May 6, 2009, 7:16:18 PM5/6/09
to pp-d...@googlegroups.com
Author: thockin
Date: Wed May 6 16:10:05 2009
New Revision: 527

Modified:
trunk/drivers/cpu/cpu_driver.cpp
trunk/drivers/io/io_binding.cpp
trunk/drivers/io/io_binding.h
trunk/drivers/mem/mem_binding.cpp
trunk/drivers/mem/mem_binding.h
trunk/drivers/msr/msr_binding.cpp
trunk/drivers/msr/msr_binding.h
trunk/drivers/msr/tests/msr_io_test.cpp
trunk/drivers/pci/pci_binding.cpp
trunk/drivers/pci/pci_binding.h
trunk/filesystem.h
trunk/tests/filesystem_test.cpp

Log:
Namespacify filesystem better

Modified: trunk/drivers/cpu/cpu_driver.cpp
==============================================================================
--- trunk/drivers/cpu/cpu_driver.cpp (original)
+++ trunk/drivers/cpu/cpu_driver.cpp Wed May 6 16:10:05 2009
@@ -203,9 +203,9 @@
void
cpu_driver::enumerate(const string &path, std::vector<cpu_address>
*addresses)
{
- fs::directory_ptr dir = fs::directory::open(path);
+ filesystem::DirectoryPtr dir = filesystem::Directory::open(path);

- fs::direntry_ptr de;
+ filesystem::DirentryPtr de;
while ((de = dir->read())) {
// each CPU gets a dir
if (!de->is_dir())

Modified: trunk/drivers/io/io_binding.cpp
==============================================================================
--- trunk/drivers/io/io_binding.cpp (original)
+++ trunk/drivers/io/io_binding.cpp Wed May 6 16:10:05 2009
@@ -85,7 +85,7 @@
if (device == "")
device = IO_DEVICE;

- m_file = fs::file::open(device, O_RDONLY);
+ m_file = filesystem::File::open(device, O_RDONLY);
return;
}


Modified: trunk/drivers/io/io_binding.h
==============================================================================
--- trunk/drivers/io/io_binding.h (original)
+++ trunk/drivers/io/io_binding.h Wed May 6 16:10:05 2009
@@ -57,7 +57,7 @@

private:
io_address m_address;
- fs::file_ptr m_file;
+ filesystem::FilePtr m_file;

void
do_io_error(const string &str) const;

Modified: trunk/drivers/mem/mem_binding.cpp
==============================================================================
--- trunk/drivers/mem/mem_binding.cpp (original)
+++ trunk/drivers/mem/mem_binding.cpp Wed May 6 16:10:05 2009
@@ -97,11 +97,11 @@
if (device == "")
device = MEM_DEVICE;

- m_file = fs::file::open(device, O_RDONLY | O_SYNC);
+ m_file = filesystem::File::open(device, O_RDONLY | O_SYNC);
return;
}

-fs::file_mapping_ptr
+filesystem::FileMappingPtr
mem_io::map(const pp_value &offset, size_t length) const
{
if (offset.get_uint()+length > m_address.size) {
@@ -139,7 +139,7 @@
pp_value
mem_io::do_read(const pp_value &offset) const
{
- fs::file_mapping_ptr mapping = map(offset, sizeof(Tdata));
+ filesystem::FileMappingPtr mapping = map(offset, sizeof(Tdata));
Tdata *ptr = (Tdata *)mapping->address();
Tdata data = *ptr;
return pp_value(data);
@@ -154,7 +154,7 @@
m_file->reopen(O_RDWR | O_SYNC);
}

- fs::file_mapping_ptr mapping = map(offset, sizeof(Tdata));
+ filesystem::FileMappingPtr mapping = map(offset, sizeof(Tdata));
Tdata *ptr = (Tdata *)mapping->address();
Tdata data = value.get_uint();
*ptr = data;

Modified: trunk/drivers/mem/mem_binding.h
==============================================================================
--- trunk/drivers/mem/mem_binding.h (original)
+++ trunk/drivers/mem/mem_binding.h Wed May 6 16:10:05 2009
@@ -57,7 +57,7 @@

private:
mem_address m_address;
- fs::file_ptr m_file;
+ filesystem::FilePtr m_file;

void
do_io_error(const string &str) const;
@@ -65,7 +65,7 @@
void
open_device(string device);

- fs::file_mapping_ptr
+ filesystem::FileMappingPtr
map(const pp_value &offset, std::size_t length) const;

void

Modified: trunk/drivers/msr/msr_binding.cpp
==============================================================================
--- trunk/drivers/msr/msr_binding.cpp (original)
+++ trunk/drivers/msr/msr_binding.cpp Wed May 6 16:10:05 2009
@@ -97,16 +97,16 @@
/* try to open it through /dev */
filename = sprintfxx("%s/%d/msr", devdir, m_address.cpu);
try {
- m_file = fs::file::open(filename, O_RDONLY);
+ m_file = filesystem::File::open(filename, O_RDONLY);
return;
} catch (syserr::not_found &e) {
/* do nothing yet */
}

/* fall back on a self-made device node */
- filename = fs::file::tempname();
- fs::device::mkdev(filename, 0600, S_IFCHR, major, minor);
- m_file = fs::device::open(filename, O_RDONLY);
+ filename = filesystem::File::tempname();
+ filesystem::Device::mkdev(filename, 0600, S_IFCHR, major, minor);
+ m_file = filesystem::Device::open(filename, O_RDONLY);
return;
}


Modified: trunk/drivers/msr/msr_binding.h
==============================================================================
--- trunk/drivers/msr/msr_binding.h (original)
+++ trunk/drivers/msr/msr_binding.h Wed May 6 16:10:05 2009
@@ -57,7 +57,7 @@

private:
msr_address m_address;
- fs::file_ptr m_file;
+ filesystem::FilePtr m_file;

void
do_io_error(const string &str) const;

Modified: trunk/drivers/msr/tests/msr_io_test.cpp
==============================================================================
--- trunk/drivers/msr/tests/msr_io_test.cpp (original)
+++ trunk/drivers/msr/tests/msr_io_test.cpp Wed May 6 16:10:05 2009
@@ -51,7 +51,8 @@
TEST_ASSERT(io2.read(0x0, BITS64) == pp_value(0x0),
"msr_io::msr_io()");
} catch (syserr::operation_not_permitted &e) {
- TEST_WARN("must be root to call fs::device::mkdev()");
+ TEST_WARN("must be root to call "
+ "filesystem::device::mkdev()");
}
} catch (std::exception &e) {
system("rm -rf test_data");

Modified: trunk/drivers/pci/pci_binding.cpp
==============================================================================
--- trunk/drivers/pci/pci_binding.cpp (original)
+++ trunk/drivers/pci/pci_binding.cpp Wed May 6 16:10:05 2009
@@ -94,9 +94,9 @@
void
pci_io::enumerate(std::vector<pci_address> *addresses)
{
- if (fs::direntry::is_dir(PCI_SYSFS_DIR)) {
+ if (filesystem::Direntry::is_dir(PCI_SYSFS_DIR)) {
enumerate_sysfs(addresses);
- } else if (fs::direntry::is_dir(PCI_PROCFS_DIR)) {
+ } else if (filesystem::Direntry::is_dir(PCI_PROCFS_DIR)) {
enumerate_procfs(addresses);
}
std::sort(addresses->begin(), addresses->end());
@@ -125,7 +125,7 @@
m_address.segment, m_address.bus,
m_address.device, m_address.function);
try {
- m_file = fs::file::open(filename, O_RDONLY);
+ m_file = filesystem::File::open(filename, O_RDONLY);
return;
} catch (std::exception &e) {
/* do nothing yet */
@@ -138,7 +138,7 @@
/* fall back on /proc */
filename = sprintfxx("%s/%02x/%02x.%x", devdir, m_address.bus,
m_address.device, m_address.function);
- m_file = fs::file::open(filename, O_RDONLY);
+ m_file = filesystem::File::open(filename, O_RDONLY);
return;
}

@@ -175,9 +175,10 @@
static void
enumerate_sysfs(std::vector<pci_address> *addresses)
{
- fs::directory_ptr dir = fs::directory::open(PCI_SYSFS_DIR);
+ filesystem::DirectoryPtr dir
+ = filesystem::Directory::open(PCI_SYSFS_DIR);

- fs::direntry_ptr de;
+ filesystem::DirentryPtr de;
while ((de = dir->read())) {
/* skip dotfiles */
if (de->name()[0] == '.')
@@ -204,9 +205,10 @@
static void
enumerate_procfs(std::vector<pci_address> *addresses)
{
- fs::directory_ptr dir = fs::directory::open(PCI_PROCFS_DIR);
+ filesystem::DirectoryPtr dir
+ = filesystem::Directory::open(PCI_PROCFS_DIR);

- fs::direntry_ptr de;
+ filesystem::DirentryPtr de;
while ((de = dir->read())) {
/* skip dotfiles */
if (de->name()[0] == '.')
@@ -216,10 +218,10 @@
string name(string(PCI_PROCFS_DIR)
+ "/" + de->name());

- fs::directory_ptr subdir
- = fs::directory::open(name);
+ filesystem::DirectoryPtr subdir
+ = filesystem::Directory::open(name);

- fs::direntry_ptr subde;
+ filesystem::DirentryPtr subde;
while ((subde = subdir->read())) {
/* skip dotfiles */
if (subde->name()[0] == '.')

Modified: trunk/drivers/pci/pci_binding.h
==============================================================================
--- trunk/drivers/pci/pci_binding.h (original)
+++ trunk/drivers/pci/pci_binding.h Wed May 6 16:10:05 2009
@@ -79,7 +79,7 @@

private:
pci_address m_address;
- fs::file_ptr m_file;
+ filesystem::FilePtr m_file;

void
do_io_error(const string &str) const;

Modified: trunk/filesystem.h
==============================================================================
--- trunk/filesystem.h (original)
+++ trunk/filesystem.h Wed May 6 16:10:05 2009
@@ -26,51 +26,51 @@
#include "pp.h"
#include "syserror.h"

-namespace fs {
+namespace filesystem {

using std::size_t;
using ::off_t;

// a file
-class file;
-typedef boost::shared_ptr<file> file_ptr;
-typedef boost::shared_ptr<const file> const_file_ptr;
-typedef boost::weak_ptr<file> weak_file_ptr;
+class File;
+typedef boost::shared_ptr<File> FilePtr;
+typedef boost::shared_ptr<const File> ConstFilePtr;
+typedef boost::weak_ptr<File> WeakFilePtr;

// a memory-mapped area of a file
-class file_mapping;
-typedef boost::shared_ptr<file_mapping> file_mapping_ptr;
+class FileMapping;
+typedef boost::shared_ptr<FileMapping> FileMappingPtr;

// a directory
-class directory;
-typedef boost::shared_ptr<directory> directory_ptr;
+class Directory;
+typedef boost::shared_ptr<Directory> DirectoryPtr;

// a directory entry
-class direntry;
-typedef boost::shared_ptr<direntry> direntry_ptr;
+class Direntry;
+typedef boost::shared_ptr<Direntry> DirentryPtr;


//
-// file_mapping
+// FileMapping
//
// This class tracks an individual mmap() of a file. When this class is
// destructed, the mapping is munmap()ed.
//
// Users can not create instances of this class. To create a mapping call
-// fs::file::mmap(), which returns a smart pointer to one of these.
+// filesystem::File::mmap(), which returns a smart pointer to one of these.
//
-class file_mapping
+class FileMapping
{
- friend class file;
+ friend class File;

private:
// constructors - private to prevent abuse, defined later
- file_mapping(const const_file_ptr &file, off_t offset, size_t length,
+ FileMapping(const ConstFilePtr &file, off_t offset, size_t length,
int prot = PROT_READ, int flags = MAP_SHARED);

public:
// destructor
- ~file_mapping()
+ ~FileMapping()
{
unmap();
}
@@ -87,7 +87,7 @@
int r = munmap(m_real_address, m_real_length);
if (r < 0) {
syserr::throw_errno_error(errno,
- "fs::file_mapping::unmap()");
+ "filesystem::FileMapping::unmap()");
}
m_address = m_real_address = NULL;
m_length = m_real_length = 0;
@@ -130,7 +130,7 @@
}

private:
- const_file_ptr m_file;
+ ConstFilePtr m_file;
// these are the file offset and map length that were requested
off_t m_offset;
size_t m_length;
@@ -151,21 +151,21 @@
// destructed, the file descriptor is close()d.
//
// Users can not create instances of this class. To open a file call
-// fs::file::open(), which returns a smart pointer to one of these.
+// filesystem::File::open(), which returns a smart pointer to one of these.
//
-class file
+class File
{
private:
// constructors - private to prevent abuse
- file(): m_path(""), m_flags(-1), m_fd(-1)
+ File(): m_path(""), m_flags(-1), m_fd(-1)
{
}
- file(const file &that)
+ File(const File &that)
: m_path(that.m_path), m_flags(that.m_flags), m_fd(that.m_fd)
{
}
- file &
- operator=(const file &that)
+ File &
+ operator=(const File &that)
{
m_path = that.m_path;
m_flags = that.m_flags;
@@ -175,17 +175,17 @@

public:
// destructor
- ~file()
+ ~File()
{
if (m_fd >= 0) {
close();
}
}

- static file_ptr
+ static FilePtr
open(const std::string &path, int flags)
{
- file_ptr f(new file());
+ FilePtr f(new File());

f->m_this_ptr = f;
f->m_path = path;
@@ -193,16 +193,16 @@
f->m_fd = ::open(path.c_str(), flags);
if (f->m_fd < 0) {
syserr::throw_errno_error(errno,
- "fs::file::open(" + path + ")");
+ "filesystem::File::open(" + path + ")");
}

return f;
}

- static file_ptr
+ static FilePtr
fdopen(int fd, const std::string &path = "", int flags = -1)
{
- file_ptr f(new file());
+ FilePtr f(new File());

f->m_this_ptr = f;
f->m_path = path;
@@ -212,7 +212,7 @@
return f;
}

- static file_ptr
+ static FilePtr
tempfile(std::string path_template = "")
{
if (path_template == "") {
@@ -228,7 +228,7 @@
r = ::mkstemp(buf);
if (r < 0) {
syserr::throw_errno_error(errno,
- "fs::file::tempfile(" + path_template + ")");
+ "filesystem::File::tempfile("+path_template+")");
}

return fdopen(r, buf, O_RDWR);
@@ -238,7 +238,8 @@
static std::string
tempname(std::string path_template = "")
{
- fs::file_ptr f = fs::file::tempfile(path_template);
+ filesystem::FilePtr f
+ = filesystem::File::tempfile(path_template);
std::string filename = f->path();
f->close();
unlink(filename);
@@ -253,7 +254,7 @@
new_fd = ::open(m_path.c_str(), new_flags);
if (new_fd < 0) {
syserr::throw_errno_error(errno,
- "fs::file::open(" + m_path + ")");
+ "filesystem::File::open(" + m_path + ")");
}

int tmp = m_fd;
@@ -261,7 +262,7 @@
m_fd = new_fd;
if (::close(tmp) < 0) {
syserr::throw_errno_error(errno,
- "fs::file::close(" + m_path + ")");
+ "filesystem::File::close(" + m_path + ")");
}
}

@@ -274,7 +275,7 @@
//
if (::close(m_fd) < 0) {
syserr::throw_errno_error(errno,
- "fs::file::close(" + m_path + ")");
+ "filesystem::File::close(" + m_path + ")");
}
m_fd = -1;
}
@@ -287,7 +288,7 @@
r = ::unlink(path.c_str());
if (r < 0) {
syserr::throw_errno_error(errno,
- "fs::file::unlink(" + path + ")");
+ "filesystem::File::unlink(" + path + ")");
}
}

@@ -305,7 +306,7 @@
r = ::read(m_fd, buf, size);
if (r < 0) {
syserr::throw_errno_error(errno,
- "fs::file::read(" + m_path + ")");
+ "filesystem::File::read(" + m_path + ")");
}

return r;
@@ -340,13 +341,13 @@
r = ::write(m_fd, buf, size);
if (r < 0) {
syserr::throw_errno_error(errno,
- "fs::file::write(" + m_path + ")");
+ "filesystem::File::write(" + m_path + ")");
}

return r;
}

- file_mapping_ptr
+ FileMappingPtr
mmap(off_t offset, size_t length, int prot = -1,
int flags = MAP_SHARED) const
{
@@ -360,8 +361,8 @@
}
}

- return file_mapping_ptr(new file_mapping(
- const_file_ptr(m_this_ptr),
+ return FileMappingPtr(new FileMapping(
+ ConstFilePtr(m_this_ptr),
offset, length, prot, flags));
}

@@ -373,7 +374,7 @@
r = ::lseek(m_fd, offset, whence);
if (r == (off_t)-1) {
syserr::throw_errno_error(errno,
- "fs::file::seek(" + m_path + ")");
+ "filesystem::File::seek(" + m_path + ")");
}

// convert off_t (signed) to size_t (unsigned)
@@ -389,7 +390,7 @@
r = ::stat(path.c_str(), &st);
if (r < 0) {
syserr::throw_errno_error(errno,
- "fs::file::size(" + path + ")");
+ "filesystem::File::size(" + path + ")");
}

// convert off_t (signed) to size_t (unsigned)
@@ -405,7 +406,7 @@
r = ::fstat(m_fd, &st);
if (r < 0) {
syserr::throw_errno_error(errno,
- "fs::file::size(" + m_path + ")");
+ "filesystem::File::size(" + m_path + ")");
}

// convert off_t (signed) to size_t (unsigned)
@@ -455,7 +456,7 @@
}

private:
- weak_file_ptr m_this_ptr;
+ WeakFilePtr m_this_ptr;
std::string m_path;
int m_flags;
int m_fd;
@@ -481,7 +482,7 @@
};

inline
-file_mapping::file_mapping(const const_file_ptr &file,
+FileMapping::FileMapping(const ConstFilePtr &file,
off_t offset, size_t length, int prot, int flags)
: m_file(file),
m_offset(offset), m_length(length), m_address(NULL),
@@ -503,21 +504,21 @@
flags, m_file->fd(), m_real_offset);
if (!m_real_address || m_real_address == MAP_FAILED) {
syserr::throw_errno_error(errno,
- "fs::file_mapping::file_mapping()");
+ "filesystem::FileMapping::FileMapping()");
}

m_address = m_real_address + ptr_off;
}

//
-// device
+// Device
//
// This class represents a single device node.
//
// Users can not create instances of this class. To open a device call
-// fs::device::open(), which returns a smart pointer to one of these.
+// filesystem::Device::open(), which returns a smart pointer to one of
these.
//
-class device: public file
+class Device: public File
{
public:
static void
@@ -530,32 +531,33 @@
::makedev(major, minor));
if (r < 0) {
syserr::throw_errno_error(errno,
- "fs::device::mkdev(" + path + ")");
+ "filesystem::Device::mkdev(" + path + ")");
}
}
};

//
-// direntry
+// Direntry
//
// This class represents a single directory entry.
//
// Users can not create instances of this class. To access a direntry, use
-// fs::directory::read(), which returns a smart pointer to one of these.
+// filesystem::Directory::read(), which returns a smart pointer to one of
+// these.
//
-class direntry
+class Direntry
{
- friend class directory;
+ friend class Directory;

private:
// constructor - implicit conversion from ::dirent
- direntry(struct ::dirent *de): m_dirent(de)
+ Direntry(struct ::dirent *de): m_dirent(de)
{
}

public:
// destructor
- ~direntry()
+ ~Direntry()
{
}

@@ -684,27 +686,28 @@
};

//
-// directory
+// Directory
//
// This class represents a single directory. When this class is
destructed,
// the directory is closedir()d.
//
// Users can not create instances of this class. To access a direntry, use
-// fs::directory::open(), which returns a smart pointer to one of these.
+// filesystem::Directory::open(), which returns a smart pointer to one of
+// these.
//
-class directory
+class Directory
{
private:
// constructors - private to prevent abuse
- directory(): m_path(""), m_dir(NULL)
+ Directory(): m_path(""), m_dir(NULL)
{
}
- directory(const directory &that)
+ Directory(const Directory &that)
: m_path(that.m_path), m_dir(that.m_dir)
{
}
- directory &
- operator=(const directory &that)
+ Directory &
+ operator=(const Directory &that)
{
m_path = that.m_path;
m_dir = that.m_dir;
@@ -713,22 +716,22 @@

public:
// destructor
- ~directory()
+ ~Directory()
{
if (m_dir) {
close();
}
}

- static directory_ptr
+ static DirectoryPtr
open(const std::string &path)
{
- directory_ptr d(new directory());
+ DirectoryPtr d(new Directory());

d->m_dir = ::opendir(path.c_str());
if (!d->m_dir) {
syserr::throw_errno_error(errno,
- "fs::directory::open(" + path + ")");
+ "filesystem::Directory::open(" + path + ")");
}

return d;
@@ -745,14 +748,14 @@
//FIXME: remove
//FIXME: mkdtemp => tempname() and tempdir()

- direntry_ptr
+ DirentryPtr
read() const
{
struct ::dirent *de = ::readdir(m_dir);
if (de) {
- return direntry_ptr(new direntry(de));
+ return DirentryPtr(new Direntry(de));
}
- return direntry_ptr();
+ return DirentryPtr();
}

void
@@ -794,7 +797,7 @@
#ifdef _GNU_SOURCE
char *p = ::get_current_dir_name();
if (p == NULL) {
- syserr::throw_errno_error(errno, "fs::getcwd()");
+ syserr::throw_errno_error(errno, "filesystem::getcwd()");
}
string cwd(p);
free(p);
@@ -803,7 +806,7 @@
char buf[4096];
char *p = ::getcwd(buf, sizeof(buf));
if (p == NULL) {
- syserr::throw_errno_error(errno, "fs::getcwd()");
+ syserr::throw_errno_error(errno, "filesystem::getcwd()");
}
return p;
#endif

Modified: trunk/tests/filesystem_test.cpp
==============================================================================
--- trunk/tests/filesystem_test.cpp (original)
+++ trunk/tests/filesystem_test.cpp Wed May 6 16:10:05 2009
@@ -3,6 +3,8 @@
#include <set>
#include "pp_test.h"

+namespace filesystem {
+
#define FILE_EXISTS_NAME "file.exists"
#define FILE_EXISTS_PATH TEST_TMP_DIR "/" FILE_EXISTS_NAME
#define FILE_EXISTS_DATA "data.exists"
@@ -34,52 +36,52 @@

TEST(test_file)
{
- if (fs::direntry::exists(FILE_NOT_EXISTS_PATH)) {
- TEST_FAIL("fs::direntry::exists()");
+ if (Direntry::exists(FILE_NOT_EXISTS_PATH)) {
+ TEST_FAIL("filesystem::Direntry::exists()");
}

- if (!fs::direntry::exists(FILE_EXISTS_PATH)) {
- TEST_FAIL("fs::direntry::exists()");
+ if (!Direntry::exists(FILE_EXISTS_PATH)) {
+ TEST_FAIL("filesystem::Direntry::exists()");
}

- if (fs::file::size(FILE_EXISTS_PATH) != FILE_EXISTS_SIZE) {
- TEST_FAIL("fs::file::size(std::string)");
+ if (File::size(FILE_EXISTS_PATH) != FILE_EXISTS_SIZE) {
+ TEST_FAIL("filesystem::File::size(std::string)");
}

- fs::file_ptr f = fs::file::open(FILE_EXISTS_PATH, O_RDONLY);
+ FilePtr f = File::open(FILE_EXISTS_PATH, O_RDONLY);
if (!f->is_open()) {
- TEST_FAIL("fs::direntry::is_open()");
+ TEST_FAIL("filesystem::Direntry::is_open()");
}

if (f->size() != FILE_EXISTS_SIZE) {
- TEST_FAIL("fs::file::size()");
+ TEST_FAIL("filesystem::File::size()");
}

if (f->tell() != 0) {
- TEST_FAIL("fs::file::tell()");
+ TEST_FAIL("filesystem::File::tell()");
}

f->seek(2, SEEK_SET);
if (f->tell() != 2) {
- TEST_FAIL("fs::file::seek()");
+ TEST_FAIL("filesystem::File::seek()");
}
f->seek(2, SEEK_CUR);
if (f->tell() != 4) {
- TEST_FAIL("fs::file::seek()");
+ TEST_FAIL("filesystem::File::seek()");
}
f->seek(-3, SEEK_END);
if (f->tell() != FILE_EXISTS_SIZE-3) {
- TEST_FAIL("fs::file::seek()");
+ TEST_FAIL("filesystem::File::seek()");
}

f->seek(FILE_EXISTS_SIZE+1, SEEK_SET);
if (!f->is_eof()) {
- TEST_FAIL("fs::file::is_eof()");
+ TEST_FAIL("filesystem::File::is_eof()");
}

f->seek(0, SEEK_SET);
if (f->tell() != 0) {
- TEST_FAIL("fs::file::seek()");
+ TEST_FAIL("filesystem::File::seek()");
}

char buf[16];
@@ -87,58 +89,58 @@
r = f->read(buf, 16);
buf[r] = '\0';
if (std::string(buf) != FILE_EXISTS_DATA) {
- TEST_FAIL("fs::file::read()");
+ TEST_FAIL("filesystem::File::read()");
}

f->unlink();
- if (fs::direntry::exists(FILE_EXISTS_PATH)) {
- TEST_FAIL("fs::file::unlink()");
+ if (Direntry::exists(FILE_EXISTS_PATH)) {
+ TEST_FAIL("filesystem::File::unlink()");
}

f->close();
if (f->is_open()) {
- TEST_FAIL("fs::file::is_open()");
+ TEST_FAIL("filesystem::File::is_open()");
}

- f = fs::file::tempfile(TEMPFILE_TEMPLATE);
+ f = File::tempfile(TEMPFILE_TEMPLATE);
if (!f->is_open()) {
- TEST_FAIL("fs::file::tempfile()");
+ TEST_FAIL("filesystem::File::tempfile()");
}
f->close();
if (f->is_open()) {
- TEST_FAIL("fs::file::is_open()");
+ TEST_FAIL("filesystem::File::is_open()");
}

- std::string tempname = fs::file::tempname(TEMPFILE_TEMPLATE);
- if (fs::direntry::exists(tempname)) {
- TEST_FAIL("fs::file::tempname()");
+ std::string tempname = File::tempname(TEMPFILE_TEMPLATE);
+ if (Direntry::exists(tempname)) {
+ TEST_FAIL("filesystem::File::tempname()");
}
}

TEST(test_file_mapping)
{
- fs::file_ptr f = fs::file::open(FILE_EXISTS_PATH, O_RDONLY);
- fs::file_mapping_ptr map = f->mmap(1, 4, PROT_READ, MAP_SHARED);
+ FilePtr f = File::open(FILE_EXISTS_PATH, O_RDONLY);
+ FileMappingPtr map = f->mmap(1, 4, PROT_READ, MAP_SHARED);
char *p = (char *)map->address();
if (strncmp(p, &FILE_EXISTS_DATA[1], 4)) {
- TEST_FAIL("fs::file::mmap()");
+ TEST_FAIL("filesystem::File::mmap()");
}

map = f->mmap(2, 4);
p = (char *)map->address();
if (strncmp(p, &FILE_EXISTS_DATA[2], 4)) {
- TEST_FAIL("fs::file::mmap()");
+ TEST_FAIL("filesystem::File::mmap()");
}
}

TEST(test_dir)
{
- if (fs::direntry::exists(DIR_NOT_EXISTS_PATH)) {
- TEST_FAIL("fs::direntry::exists()");
+ if (Direntry::exists(DIR_NOT_EXISTS_PATH)) {
+ TEST_FAIL("filesystem::Direntry::exists()");
}

- if (!fs::direntry::exists(DIR_EXISTS_PATH)) {
- TEST_FAIL("fs::direntry::exists()");
+ if (!Direntry::exists(DIR_EXISTS_PATH)) {
+ TEST_FAIL("filesystem::Direntry::exists()");
}

std::set<std::string> expected;
@@ -148,27 +150,27 @@
expected.insert("..");
expected.insert(FILE_EXISTS_NAME);

- fs::directory_ptr d = fs::directory::open(DIR_EXISTS_PATH);
+ DirectoryPtr d = Directory::open(DIR_EXISTS_PATH);

- fs::direntry_ptr de;
+ DirentryPtr de;
de = d->read();
it = expected.find(de->name());
if (it == expected.end()) {
- TEST_FAIL("fs::directory::read()");
+ TEST_FAIL("filesystem::Directory::read()");
}
// don't erase this, save it for rewind()

de = d->read();
it = expected.find(de->name());
if (it == expected.end()) {
- TEST_FAIL("fs::directory::read()");
+ TEST_FAIL("filesystem::Directory::read()");
}
expected.erase(it);

de = d->read();
it = expected.find(de->name());
if (it == expected.end()) {
- TEST_FAIL("fs::directory::read()");
+ TEST_FAIL("filesystem::Directory::read()");
}
expected.erase(it);

@@ -176,28 +178,30 @@
de = d->read();
it = expected.find(de->name());
if (it == expected.end()) {
- TEST_FAIL("fs::directory::read()");
+ TEST_FAIL("filesystem::Directory::read()");
}
expected.erase(it);

if (!expected.empty()) {
- TEST_FAIL("fs::directory::read()");
+ TEST_FAIL("filesystem::Directory::read()");
}
}

TEST(test_dev)
{
- std::string tempname = fs::file::tempname(TEMPFILE_TEMPLATE);
- if (fs::direntry::exists(tempname)) {
- TEST_FAIL("fs::file::tempname()");
+ std::string tempname = File::tempname(TEMPFILE_TEMPLATE);
+ if (Direntry::exists(tempname)) {
+ TEST_FAIL("filesystem::File::tempname()");
}
try {
// major 1, minor 3 = /dev/null
- fs::device::mkdev(tempname, 0600, S_IFCHR, 1, 3);
- if (!fs::direntry::exists(tempname)) {
- TEST_FAIL("fs::file::tempname()");
+ Device::mkdev(tempname, 0600, S_IFCHR, 1, 3);
+ if (!Direntry::exists(tempname)) {
+ TEST_FAIL("filesystem::File::tempname()");
}
} catch (syserr::operation_not_permitted &e) {
- TEST_WARN("must be root to call fs::device::mkdev()");
+ TEST_WARN("must be root to call filesystem::Device::mkdev()");
}
}
+
+} // namespace filesystem

Reply all
Reply to author
Forward
0 new messages