boinc/lib/filesys.h

135 lines
3.6 KiB
C
Raw Normal View History

// This file is part of BOINC.
// http://boinc.berkeley.edu
// Copyright (C) 2008 University of California
//
// BOINC is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation,
// either version 3 of the License, or (at your option) any later version.
//
// BOINC is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
#ifndef _FILESYS_
#define _FILESYS_
#define FILE_RETRY_INTERVAL 5
// On Windows, retry for this period of time, since some other program
// (virus scan, defrag, index) may have the file open.
#if defined(_WIN32) && !defined(__CYGWIN32__)
#else
#include <dirent.h>
#include <grp.h>
2009-05-26 22:57:03 +00:00
#include <stdio.h>
#include <sys/types.h>
#ifdef __cplusplus
#include <string>
#endif
#endif /* !WIN32 */
#ifdef __cplusplus
extern "C" {
#endif
extern int boinc_delete_file(const char*);
extern int boinc_touch_file(const char *path);
extern FILE* boinc_fopen(const char* path, const char* mode);
extern int boinc_copy(const char* orig, const char* newf);
extern int boinc_rename(const char* old, const char* newf);
extern int boinc_mkdir(const char*);
#ifndef _WIN32
extern int boinc_chown(const char*, gid_t);
#endif
extern int boinc_rmdir(const char*);
extern void boinc_getcwd(char*);
extern void relative_to_absolute(const char* relname, char* path);
extern int boinc_make_dirs(char*, char*);
extern char boinc_failed_file[256];
extern int is_file(const char* path);
extern int is_dir(const char* path);
extern int is_symlink(const char* path);
extern int boinc_truncate(const char*, double);
extern int boinc_file_exists(const char* path);
extern int boinc_file_or_symlink_exists(const char* path);
#ifdef __cplusplus
}
#endif
/* C++ specific prototypes/defines follow here */
#ifdef __cplusplus
extern int file_size(const char*, double&);
extern int clean_out_dir(const char*);
extern int dir_size(const char* dirpath, double&, bool recurse=true);
- Added checks for net/*.h, arpa/*.h, netinet/*.h and code to figure out which of those files to include - Modified MAC address check to work on some non-Linux unixes. (mac_address.cpp) - Added suggested change to "already attached to project" checking. (ProjectInfoPage.cpp) - changed includes of standard c header files to their c++ equivalents (i.e. replaced <stdio.h> with <cstdio>) for namespace protection. - replaced "using namespace std;" with more explicit "using std::function" in several files. - Fixed bug in checking whether the os is OS/2 and added conditional OS_OS2 to the build environment. (boinc_platform.m4,configure.ac) - Changed build environment to not use -nostandardlibs unless we are using G++ and static linkage is specified. (configure.ac) - Added makefiles and package building files for solaris CSW package manager. - Fixed bug with attempting to find login name using logname. (configure.ac) - Added ifdef HAVE_* protection around some include files commonly found in sys. - Added support for unified binary for x86_64/i686-pc-solaris. (cs_platforms.cpp) - generate_host_cpid() now uses MAC address on non-linux unix. (hostinfo_network.cpp) - Macro BOINC_SET_COMPILE_FLAGS now doesn't check gcc only flags on non-gcc compilers. (boinc_set_compile_flags.m4) - Library compiles no longer depend upon the library extension or require the library to be prefixed with lib. - More fixes for fcgi builds. - Added declaration of "struct ether_addr" and ether_ntoa(). Have not yet implemented ether_ntoa() for machines that don't have it, or where it is buggy. (unix_util.h) - Added FCGI::perror() which calls FCGI_perror(). (boinc_fcgi.{h,cpp}) - Fixed library Makefiles so that all required headers get installed. svn path=/trunk/boinc/; revision=17388
2009-02-26 00:23:23 +00:00
extern int get_filesystem_info(double& total, double& free, char* path=const_cast<char *>("."));
// TODO TODO TODO
// remove this code - the DirScanner class does the same thing.
// But need to rewrite a couple of places that use it
//
#if defined(_WIN32) && !defined(__CYGWIN32__)
typedef struct _DIR_DESC {
char path[256];
bool first;
void* handle;
} DIR_DESC;
typedef DIR_DESC *DIRREF;
#else
typedef DIR *DIRREF;
#endif
extern DIRREF dir_open(const char*);
extern int dir_scan(char*, DIRREF, int);
int dir_scan(std::string&, DIRREF);
extern void dir_close(DIRREF);
class DirScanner {
#if defined(_WIN32) && !defined(__CYGWIN32__)
std::string dir;
bool first;
void* handle;
#else
DIR* dirp;
#endif
public:
DirScanner(std::string const& path);
~DirScanner();
bool scan(std::string& name); // return true if file returned
};
struct FILE_LOCK {
#if defined(_WIN32) && !defined(__CYGWIN32__)
HANDLE handle;
#else
int fd;
#endif
bool locked;
FILE_LOCK();
~FILE_LOCK();
int lock(const char* filename);
int unlock(const char* filename);
};
#ifndef _WIN32
// search PATH, find the directory that a program is in, if any
//
extern int get_file_dir(char* filename, char* dir);
#endif
#endif /* c++ */
#endif /* double-inclusion protection */