00001 #ifndef __fs_h__
00002 #define __fs_h__
00003
00004 #include <iostream>
00005 #include <string>
00006 #include <vector>
00007
00008 #ifdef HAVE_SYS_TYPES_H
00009 #include <sys/types.h>
00010 #endif
00011 #ifdef HAVE_SYS_STAT_H
00012 #include <sys/stat.h>
00013 #endif
00014 #ifdef HAVE_UNISTD_H
00015 #include <unistd.h>
00016 #endif
00017 #include <pwd.h>
00018 #include <grp.h>
00019 #ifdef HAVE_SYS_PARAM_H
00020 #include <sys/param.h>
00021 #endif
00022 #ifdef HAVE_SYS_MOUNT_H
00023 #include <sys/mount.h>
00024 #endif
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #ifdef HAVE_SYS_STATVFS_H
00035 # ifdef sun
00036 # ifdef _FILE_OFFSET_BITS
00037 # if _FILE_OFFSET_BITS == 64
00038 # define __HOLD_FILE_OFFSET_BITS_64
00039 # undef _FILE_OFFSET_BITS
00040 # endif
00041 # endif
00042 # endif
00043 #include <sys/statvfs.h>
00044 # ifdef __HOLD_FILE_OFFSET_BITS_64
00045 # define _FILE_OFFSET_BITS 64
00046 # undef __HOLD_FILE_OFFSET_BITS_64
00047 # endif
00048 #endif
00049
00050 #ifdef HAVE_SYS_VFS_H
00051 #include <sys/vfs.h>
00052 #endif
00053
00054 #include "types.h"
00055
00056 #ifdef HAVE_SYS_STATVFS_H
00057 #define STATFS statvfs
00058 #else
00059 #define STATFS statfs
00060 #endif
00061
00062 const std::string cwd(void);
00063 const pid_t pid(void);
00064 const pid_t parent_pid(void);
00065
00066 bool absolute_path(const std::string& a_path);
00067 bool relative_path(const std::string& a_path);
00068 std::string reform_path(const std::string& a_path);
00069 std::string permute_path(const std::string& a_path);
00070 std::string path_basename(const std::string& a_path);
00071 std::string path_dirname(const std::string& a_path);
00072 std::string mk_absolute_path(
00073 const std::string a_path,
00074 const std::string a_rel_path
00075 );
00076 std::string mk_relative_path(
00077 const std::string a_path_to,
00078 const std::string a_path_from
00079 );
00080 bool exists(const std::string& a_path);
00081 bool readable(const std::string& a_path);
00082 bool writable(const std::string& a_path);
00083 bool executable(const std::string& a_path);
00084 #ifdef S_ISFIFO
00085 bool is_fifo_special(const std::string& a_path);
00086 #endif
00087 #ifdef S_ISCHR
00088 bool is_char_special(const std::string& a_path);
00089 #endif
00090 #ifdef S_ISDIR
00091 bool is_dir(const std::string& a_path);
00092 #endif
00093 #ifdef S_ISREG
00094 bool is_file(const std::string& a_path);
00095 #endif
00096 #ifdef S_ISBLK
00097 bool is_block_special(const std::string& a_path);
00098 #endif
00099 #ifdef S_ISLNK
00100 bool is_link(const std::string& a_path);
00101 #endif
00102 #ifdef S_ISSOCK
00103 bool is_socket(const std::string& a_path);
00104 #endif
00105 #ifdef S_ISDOOR
00106 bool is_door(const std::string& a_path);
00107 #endif
00108 void mk_dir(const std::string& a_path);
00109 void rm_dir(const std::string a_path);
00110 void rm_file(const std::string a_path);
00111 void mk_dirhier(const std::string a_path);
00112 void rename_file(const std::string a_from, const std::string a_to);
00113 void mk_symlink(const std::string a_from, const std::string a_to);
00114 void mk_relative_symlink(const std::string a_from, const std::string a_to);
00115
00116
00117 class filestatus
00118 {
00119 public:
00120 enum filetype {
00121 #ifdef S_ISFIFO
00122 type_fifo_special,
00123 #endif
00124 #ifdef S_ISCHR
00125 type_character_special,
00126 #endif
00127 #ifdef S_ISDIR
00128 type_directory,
00129 #endif
00130 #ifdef S_ISREG
00131 type_regular_file,
00132 #endif
00133 #ifdef S_ISBLK
00134 type_block_special,
00135 #endif
00136 #ifdef S_ISLNK
00137 type_link,
00138 #endif
00139 #ifdef S_ISSOCK
00140 type_socket,
00141 #endif
00142 #ifdef S_ISDOOR
00143 type_door,
00144 #endif
00145 type_unknown
00146 };
00147 typedef mode_t mode_type;
00148 typedef ino_t inode_type;
00149 typedef dev_t device_type;
00150 typedef uint32 major_type;
00151 typedef uint32 minor_type;
00152 typedef nlink_t num_links_type;
00153 typedef uid_t uid_type;
00154 typedef gid_t gid_type;
00155 typedef uint64 size_type;
00156 typedef time_t time_type;
00157
00158 filestatus();
00159 filestatus(const std::string a_path);
00160 ~filestatus();
00161
00162 void path(const std::string a_path);
00163 const std::string path(void) const;
00164 const filetype type(void) const;
00165 const std::string link(void) const;
00166
00167 const mode_type mode(void) const;
00168 const inode_type inode(void) const;
00169 const device_type dev(void) const;
00170 const device_type rdev(void) const;
00171 const major_type get_major(void) const;
00172 const minor_type get_minor(void) const;
00173 const num_links_type num_links(void) const;
00174 const uid_type uid(void) const;
00175 const gid_type gid(void) const;
00176 const size_type size(void) const;
00177 const time_type last_access_time(void) const;
00178 const time_type last_modification_time(void) const;
00179 const time_type last_status_change_time(void) const;
00180 const size_type blocksize(void) const;
00181 const size_type blocks(void) const;
00182 const bool uid_is_found(void) const;
00183 const bool gid_is_found(void) const;
00184 const std::string uid_name(void) const;
00185 const std::string gid_name(void) const;
00186
00187 void clear(void);
00188
00189 #ifdef S_ISFIFO
00190 const bool is_fifo_special(void) const;
00191 #endif
00192 #ifdef S_ISCHR
00193 const bool is_character_special(void) const;
00194 #endif
00195 #ifdef S_ISBLK
00196 const bool is_block_special(void) const;
00197 #endif
00198 #ifdef S_ISLNK
00199 const bool is_link(void) const;
00200 #endif
00201 #ifdef S_ISSOCK
00202 const bool is_socket(void) const;
00203 #endif
00204 #ifdef S_ISDOOR
00205 const bool is_door(void) const;
00206 #endif
00207 #ifdef S_ISDIR
00208 const bool is_directory(void) const;
00209 #endif
00210 #ifdef S_ISREG
00211 const bool is_regular_file(void) const;
00212 #endif
00213
00214 #ifdef S_IRUSR
00215 const bool user_can_read(void) const;
00216 #endif
00217 #ifdef S_IWUSR
00218 const bool user_can_write(void) const;
00219 #endif
00220 #ifdef S_IXUSR
00221 const bool user_can_execute(void) const;
00222 #endif
00223 #ifdef S_IRGRP
00224 const bool group_can_read(void) const;
00225 #endif
00226 #ifdef S_IWGRP
00227 const bool group_can_write(void) const;
00228 #endif
00229 #ifdef S_IXGRP
00230 const bool group_can_execute(void) const;
00231 #endif
00232 #ifdef S_IROTH
00233 const bool other_can_read(void) const;
00234 #endif
00235 #ifdef S_IWOTH
00236 const bool other_can_write(void) const;
00237 #endif
00238 #ifdef S_IXOTH
00239 const bool other_can_execute(void) const;
00240 #endif
00241 #ifdef S_ISUID
00242 const bool is_set_uid(void) const;
00243 #endif
00244 #ifdef S_ISGID
00245 const bool is_set_gid(void) const;
00246 #endif
00247 #ifdef S_ISVTX
00248 const bool is_set_sticky(void) const;
00249 #endif
00250
00251 private:
00252 std::string m_path;
00253 struct stat m_stat;
00254 std::string m_link;
00255 major_type m_major;
00256 minor_type m_minor;
00257 bool m_uidfound;
00258 bool m_gidfound;
00259 std::string m_uname;
00260 std::string m_gname;
00261 };
00262
00263
00264
00265
00266
00267
00268 class subdirectory : public std::vector<std::string>
00269 {
00270 public:
00271 typedef std::vector<std::string> type;
00272
00273 subdirectory();
00274 subdirectory(const subdirectory& a_class);
00275 subdirectory(const std::string a_path, const std::string a_filter = "*");
00276 ~subdirectory();
00277
00278 void assign(const subdirectory& a_class);
00279
00280 const type&
00281 path(const std::string a_path, const std::string a_filter = "*");
00282
00283 subdirectory& operator=(const subdirectory& a_class);
00284
00285 private:
00286 };
00287
00288 void rm_recursive(const std::string a_path);
00289
00290
00291
00292
00293
00294
00295 class directory : public std::vector<std::string>
00296 {
00297 public:
00298 typedef std::vector<std::string> type;
00299
00300 directory();
00301 directory(const directory& a_class);
00302 directory(const std::string& a_str);
00303 ~directory();
00304
00305 const type& path(const std::string& a_path);
00306
00307 private:
00308 };
00309
00310
00311 class filesystem {
00312 public:
00313 typedef uint64 size_type;
00314
00315 filesystem();
00316 filesystem(const std::string& a_path);
00317
00318 void clear(void);
00319
00320 void path(const std::string& a_path);
00321 const std::string path(void) const;
00322 const size_type blocksize(void) const;
00323 const size_type total_blocks(void) const;
00324 const size_type free_blocks(void) const;
00325 const size_type used_blocks(void) const;
00326 const size_type total_inodes(void) const;
00327 const size_type free_inodes(void) const;
00328 const size_type used_inodes(void) const;
00329
00330 filesystem& operator=(const filesystem& a_class);
00331
00332 private:
00333 std::string m_path;
00334 struct STATFS m_statfs;
00335 };
00336
00337 #endif