15460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao//===- FileSystem.h -------------------------------------------------------===// 25460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao// 35460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao// The MCLinker Project 45460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao// 55460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao// This file is distributed under the University of Illinois Open Source 65460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao// License. See LICENSE.TXT for details. 75460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao// 85460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao//===----------------------------------------------------------------------===// 95460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao// This file declares the mcld::sys::fs:: namespace. It follows TR2/boost 105460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao// filesystem (v3), but modified to remove exception handling and the 115460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao// path class. 125460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao//===----------------------------------------------------------------------===// 1337b74a387bb3993387029859c2d9d051c41c724eStephen Hines#ifndef MCLD_SUPPORT_FILESYSTEM_H_ 1437b74a387bb3993387029859c2d9d051c41c724eStephen Hines#define MCLD_SUPPORT_FILESYSTEM_H_ 155460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 1637b74a387bb3993387029859c2d9d051c41c724eStephen Hines#include "mcld/Config/Config.h" 175460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao#include "mcld/Support/PathCache.h" 1837b74a387bb3993387029859c2d9d051c41c724eStephen Hines 195460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao#include <iosfwd> 205460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao#include <locale> 2137b74a387bb3993387029859c2d9d051c41c724eStephen Hines#include <string> 225460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 235460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liaonamespace mcld { 245460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liaonamespace sys { 25affc150dc44fab1911775a49636d0ce85333b634Zonr Chang 265460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liaonamespace fs { 275460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 2837b74a387bb3993387029859c2d9d051c41c724eStephen Hinesenum FileType { 295460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao StatusError, 305460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao StatusUnknown = StatusError, 315460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao FileNotFound, 325460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao RegularFile, 335460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao DirectoryFile, 345460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao SymlinkFile, 355460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao BlockFile, 365460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao CharacterFile, 375460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao FifoFile, 385460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao SocketFile, 395460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao ReparseFile, 405460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao TypeUnknown, 415460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao StatusKnown, 425460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao IsSymLink 435460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao}; 445460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 455460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao/** \class FileStatus 465460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao * \brief FileStatus 475460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao */ 4837b74a387bb3993387029859c2d9d051c41c724eStephen Hinesclass FileStatus { 4937b74a387bb3993387029859c2d9d051c41c724eStephen Hines public: 5037b74a387bb3993387029859c2d9d051c41c724eStephen Hines FileStatus() : m_Value(StatusError) {} 515460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 5237b74a387bb3993387029859c2d9d051c41c724eStephen Hines explicit FileStatus(FileType v) : m_Value(v) {} 535460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 5437b74a387bb3993387029859c2d9d051c41c724eStephen Hines void setType(FileType v) { m_Value = v; } 5537b74a387bb3993387029859c2d9d051c41c724eStephen Hines FileType type() const { return m_Value; } 565460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 5737b74a387bb3993387029859c2d9d051c41c724eStephen Hines private: 585460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao FileType m_Value; 595460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao}; 605460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 615460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liaoinline bool operator==(const FileStatus& rhs, const FileStatus& lhs) { 625460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao return rhs.type() == lhs.type(); 635460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao} 645460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 6537b74a387bb3993387029859c2d9d051c41c724eStephen Hinesinline bool operator!=(const FileStatus& rhs, const FileStatus& lhs) { 665460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao return !(rhs == lhs); 675460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao} 685460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 695460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liaoclass Path; 705460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liaoclass DirIterator; 715460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liaoclass Directory; 725460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 7337b74a387bb3993387029859c2d9d051c41c724eStephen Hinesbool exists(const Path& pPath); 7437b74a387bb3993387029859c2d9d051c41c724eStephen Hinesbool is_directory(const Path& pPath); 755460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 76f7ac0f19a1c8d0ad14bcf6456ce368b830fea886Stephen Hinesnamespace detail { 775460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 78f7ac0f19a1c8d0ad14bcf6456ce368b830fea886Stephen Hinesextern Path::StringType static_library_extension; 79f7ac0f19a1c8d0ad14bcf6456ce368b830fea886Stephen Hinesextern Path::StringType shared_library_extension; 80f7ac0f19a1c8d0ad14bcf6456ce368b830fea886Stephen Hinesextern Path::StringType executable_extension; 81f7ac0f19a1c8d0ad14bcf6456ce368b830fea886Stephen Hinesextern Path::StringType relocatable_extension; 82f7ac0f19a1c8d0ad14bcf6456ce368b830fea886Stephen Hinesextern Path::StringType assembly_extension; 83f7ac0f19a1c8d0ad14bcf6456ce368b830fea886Stephen Hinesextern Path::StringType bitcode_extension; 845460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 85f7ac0f19a1c8d0ad14bcf6456ce368b830fea886Stephen Hinessize_t canonicalize(Path::StringType& pPathName); 865460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liaobool not_found_error(int perrno); 875460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liaovoid status(const Path& p, FileStatus& pFileStatus); 885460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liaovoid symlink_status(const Path& p, FileStatus& pFileStatus); 895460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liaomcld::sys::fs::PathCache::entry_type* bring_one_into_cache(DirIterator& pIter); 905460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liaovoid open_dir(Directory& pDir); 915460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liaovoid close_dir(Directory& pDir); 92f7ac0f19a1c8d0ad14bcf6456ce368b830fea886Stephen Hinesvoid get_pwd(Path& pPWD); 93affc150dc44fab1911775a49636d0ce85333b634Zonr Chang 94affc150dc44fab1911775a49636d0ce85333b634Zonr Changint open(const Path& pPath, int pOFlag); 95affc150dc44fab1911775a49636d0ce85333b634Zonr Changint open(const Path& pPath, int pOFlag, int pPermission); 96f7ac0f19a1c8d0ad14bcf6456ce368b830fea886Stephen Hinesssize_t pread(int pFD, void* pBuf, size_t pCount, off_t pOffset); 97f7ac0f19a1c8d0ad14bcf6456ce368b830fea886Stephen Hinesssize_t pwrite(int pFD, const void* pBuf, size_t pCount, off_t pOffset); 98affc150dc44fab1911775a49636d0ce85333b634Zonr Changint ftruncate(int pFD, size_t pLength); 9937b74a387bb3993387029859c2d9d051c41c724eStephen Hinesvoid* mmap(void* pAddr, 10037b74a387bb3993387029859c2d9d051c41c724eStephen Hines size_t pLen, 10137b74a387bb3993387029859c2d9d051c41c724eStephen Hines int pProt, 10237b74a387bb3993387029859c2d9d051c41c724eStephen Hines int pFlags, 10337b74a387bb3993387029859c2d9d051c41c724eStephen Hines int pFD, 10437b74a387bb3993387029859c2d9d051c41c724eStephen Hines off_t pOffset); 10537b74a387bb3993387029859c2d9d051c41c724eStephen Hinesint munmap(void* pAddr, size_t pLen); 10637b74a387bb3993387029859c2d9d051c41c724eStephen Hines 10737b74a387bb3993387029859c2d9d051c41c724eStephen Hines} // namespace detail 10837b74a387bb3993387029859c2d9d051c41c724eStephen Hines} // namespace fs 10937b74a387bb3993387029859c2d9d051c41c724eStephen Hines} // namespace sys 11037b74a387bb3993387029859c2d9d051c41c724eStephen Hines} // namespace mcld 11137b74a387bb3993387029859c2d9d051c41c724eStephen Hines 11237b74a387bb3993387029859c2d9d051c41c724eStephen Hines#endif // MCLD_SUPPORT_FILESYSTEM_H_ 113