2008-08-06 18:36:30 +00:00
|
|
|
// This file is part of BOINC.
|
2005-01-20 23:22:22 +00:00
|
|
|
// http://boinc.berkeley.edu
|
2008-08-06 18:36:30 +00:00
|
|
|
// Copyright (C) 2008 University of California
|
2004-11-14 08:29:32 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// 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.
|
2004-07-13 13:54:09 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// BOINC is distributed in the hope that it will be useful,
|
2005-01-20 23:22:22 +00:00
|
|
|
// 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.
|
2002-04-30 22:22:54 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
|
2003-07-01 20:37:09 +00:00
|
|
|
|
2003-12-24 21:50:41 +00:00
|
|
|
#ifndef _FILESYS_
|
|
|
|
#define _FILESYS_
|
|
|
|
|
2005-12-16 03:35:15 +00:00
|
|
|
#if defined(_WIN32) && !defined(__CYGWIN32__)
|
2012-09-16 20:22:15 +00:00
|
|
|
#include "boinc_win.h"
|
2004-12-04 00:56:22 +00:00
|
|
|
#else
|
|
|
|
#include <dirent.h>
|
2006-07-13 16:48:44 +00:00
|
|
|
#include <grp.h>
|
2009-05-26 22:57:03 +00:00
|
|
|
#include <stdio.h>
|
2010-03-05 12:43:52 +00:00
|
|
|
#include <sys/types.h>
|
2011-03-24 09:32:02 +00:00
|
|
|
#include <sys/param.h>
|
2009-05-27 17:23:08 +00:00
|
|
|
#ifdef __cplusplus
|
2003-06-24 00:17:36 +00:00
|
|
|
#include <string>
|
2009-05-27 17:23:08 +00:00
|
|
|
#endif
|
2004-01-08 00:27:59 +00:00
|
|
|
|
2004-12-04 00:56:22 +00:00
|
|
|
#endif /* !WIN32 */
|
|
|
|
|
2012-11-01 17:05:05 +00:00
|
|
|
#ifndef MAXPATHLEN
|
|
|
|
#define MAXPATHLEN 4096
|
|
|
|
#endif
|
|
|
|
|
2012-08-01 21:02:54 +00:00
|
|
|
#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.
|
|
|
|
|
2004-12-04 00:56:22 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
2002-07-30 23:44:22 +00:00
|
|
|
#endif
|
2004-12-04 00:56:22 +00:00
|
|
|
extern int boinc_delete_file(const char*);
|
2005-06-27 16:31:49 +00:00
|
|
|
extern int boinc_touch_file(const char *path);
|
2004-12-04 00:56:22 +00:00
|
|
|
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*);
|
2012-11-30 04:45:00 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
extern int boinc_allocate_file(const char*, double size);
|
|
|
|
#else
|
2006-06-12 04:05:10 +00:00
|
|
|
extern int boinc_chown(const char*, gid_t);
|
|
|
|
#endif
|
2004-12-04 00:56:22 +00:00
|
|
|
extern int boinc_rmdir(const char*);
|
2006-12-14 20:44:39 +00:00
|
|
|
extern void boinc_getcwd(char*);
|
2005-02-16 23:17:43 +00:00
|
|
|
extern void relative_to_absolute(const char* relname, char* path);
|
2011-05-25 21:16:45 +00:00
|
|
|
extern int boinc_make_dirs(const char*, const char*);
|
2012-09-02 20:05:20 +00:00
|
|
|
extern char boinc_failed_file[MAXPATHLEN];
|
2006-01-18 23:04:05 +00:00
|
|
|
extern int is_file(const char* path);
|
|
|
|
extern int is_dir(const char* path);
|
2012-11-27 18:50:32 +00:00
|
|
|
extern int is_file_follow_symlinks(const char* path);
|
2012-03-23 17:45:04 +00:00
|
|
|
extern int is_dir_follow_symlinks(const char* path);
|
2008-04-03 21:59:05 +00:00
|
|
|
extern int is_symlink(const char* path);
|
2006-01-18 22:12:55 +00:00
|
|
|
extern int boinc_truncate(const char*, double);
|
2006-01-18 23:04:05 +00:00
|
|
|
extern int boinc_file_exists(const char* path);
|
2008-03-27 20:30:19 +00:00
|
|
|
extern int boinc_file_or_symlink_exists(const char* path);
|
2004-12-04 00:56:22 +00:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* C++ specific prototypes/defines follow here */
|
|
|
|
#ifdef __cplusplus
|
2006-06-12 21:53:18 +00:00
|
|
|
|
2004-12-04 00:56:22 +00:00
|
|
|
extern int file_size(const char*, double&);
|
2008-01-14 18:32:20 +00:00
|
|
|
extern int clean_out_dir(const char*);
|
2007-05-08 23:12:40 +00:00
|
|
|
extern int dir_size(const char* dirpath, double&, bool recurse=true);
|
2009-02-26 00:23:23 +00:00
|
|
|
extern int get_filesystem_info(double& total, double& free, char* path=const_cast<char *>("."));
|
2004-12-04 00:56:22 +00:00
|
|
|
|
2004-01-08 00:27:59 +00:00
|
|
|
// TODO TODO TODO
|
|
|
|
// remove this code - the DirScanner class does the same thing.
|
|
|
|
// But need to rewrite a couple of places that use it
|
|
|
|
//
|
2006-06-12 21:53:18 +00:00
|
|
|
#if defined(_WIN32) && !defined(__CYGWIN32__)
|
|
|
|
typedef struct _DIR_DESC {
|
2012-09-02 20:05:20 +00:00
|
|
|
char path[MAXPATHLEN];
|
2006-06-12 21:53:18 +00:00
|
|
|
bool first;
|
|
|
|
void* handle;
|
|
|
|
} DIR_DESC;
|
|
|
|
typedef DIR_DESC *DIRREF;
|
|
|
|
#else
|
|
|
|
typedef DIR *DIRREF;
|
|
|
|
#endif
|
|
|
|
|
2003-11-08 00:56:55 +00:00
|
|
|
extern DIRREF dir_open(const char*);
|
2003-03-11 00:49:07 +00:00
|
|
|
extern int dir_scan(char*, DIRREF, int);
|
2010-08-11 23:03:09 +00:00
|
|
|
extern int dir_scan(std::string&, DIRREF);
|
2002-08-09 21:43:19 +00:00
|
|
|
extern void dir_close(DIRREF);
|
2004-01-08 00:27:59 +00:00
|
|
|
|
2010-08-11 23:03:09 +00:00
|
|
|
extern bool is_dir_empty(const char*);
|
2003-06-24 00:17:36 +00:00
|
|
|
|
|
|
|
class DirScanner {
|
2005-12-16 03:35:15 +00:00
|
|
|
#if defined(_WIN32) && !defined(__CYGWIN32__)
|
2004-10-19 06:29:26 +00:00
|
|
|
std::string dir;
|
2003-06-24 00:17:36 +00:00
|
|
|
bool first;
|
|
|
|
void* handle;
|
2004-10-19 06:29:26 +00:00
|
|
|
#else
|
2003-06-24 00:17:36 +00:00
|
|
|
DIR* dirp;
|
|
|
|
#endif
|
|
|
|
public:
|
2004-06-30 18:17:21 +00:00
|
|
|
DirScanner(std::string const& path);
|
2003-06-24 00:17:36 +00:00
|
|
|
~DirScanner();
|
2004-06-30 18:17:21 +00:00
|
|
|
bool scan(std::string& name); // return true if file returned
|
2003-06-24 00:17:36 +00:00
|
|
|
};
|
2003-12-24 21:50:41 +00:00
|
|
|
|
2005-03-05 23:12:31 +00:00
|
|
|
struct FILE_LOCK {
|
2005-12-16 03:35:15 +00:00
|
|
|
#if defined(_WIN32) && !defined(__CYGWIN32__)
|
2005-03-05 23:12:31 +00:00
|
|
|
HANDLE handle;
|
|
|
|
#else
|
|
|
|
int fd;
|
|
|
|
#endif
|
2009-03-23 17:00:34 +00:00
|
|
|
bool locked;
|
2006-12-14 20:44:39 +00:00
|
|
|
FILE_LOCK();
|
|
|
|
~FILE_LOCK();
|
2005-03-05 23:12:31 +00:00
|
|
|
int lock(const char* filename);
|
|
|
|
int unlock(const char* filename);
|
|
|
|
};
|
|
|
|
|
2004-12-04 00:56:22 +00:00
|
|
|
#endif /* c++ */
|
|
|
|
|
|
|
|
#endif /* double-inclusion protection */
|
2004-01-04 06:48:40 +00:00
|
|
|
|