mirror of
https://github.com/amadvance/snapraid.git
synced 2026-10-26 10:51:54 -04:00
Using lstat also in Windows.
This commit is contained in:
parent
3d12eaaa97
commit
0365488ce9
4 changed files with 26 additions and 12 deletions
1
HISTORY
1
HISTORY
|
|
@ -9,6 +9,7 @@ SnapRAID HISTORY
|
|||
to remove the warning.
|
||||
* In fixing, if a file cannot be written for missing permission, an error is
|
||||
reported only if a write is effectively required.
|
||||
* Ignores any symbolic links. They are not backuped.
|
||||
|
||||
1.3 2011/5
|
||||
==========
|
||||
|
|
|
|||
22
mingw.c
22
mingw.c
|
|
@ -121,10 +121,16 @@ static void windows_info2stat(const BY_HANDLE_FILE_INFORMATION* info, struct win
|
|||
*/
|
||||
static void windows_finddata2stat(const WIN32_FIND_DATAW* info, struct windows_stat* st)
|
||||
{
|
||||
/* Convert special attributes to a char device */
|
||||
/* Convert special attributes */
|
||||
if ((info->dwFileAttributes & FILE_ATTRIBUTE_DEVICE) != 0) {
|
||||
st->st_mode = S_IFBLK;
|
||||
} else if ((info->dwFileAttributes & (FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_TEMPORARY | FILE_ATTRIBUTE_OFFLINE | FILE_ATTRIBUTE_REPARSE_POINT)) != 0) {
|
||||
} else if ((info->dwFileAttributes & (
|
||||
FILE_ATTRIBUTE_SYSTEM /* System files */
|
||||
| FILE_ATTRIBUTE_HIDDEN /* Hidden files */
|
||||
| FILE_ATTRIBUTE_TEMPORARY /* Files going to be deleted on close */
|
||||
| FILE_ATTRIBUTE_OFFLINE
|
||||
| FILE_ATTRIBUTE_REPARSE_POINT /* Symbolic links */
|
||||
)) != 0) {
|
||||
st->st_mode = S_IFCHR;
|
||||
} else if ((info->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0) {
|
||||
st->st_mode = S_IFDIR;
|
||||
|
|
@ -214,7 +220,7 @@ int windows_fstat(int fd, struct windows_stat* st)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int windows_stat(const char* file, struct windows_stat* st)
|
||||
int windows_lstat(const char* file, struct windows_stat* st)
|
||||
{
|
||||
HANDLE h;
|
||||
WIN32_FIND_DATAW data;
|
||||
|
|
@ -245,12 +251,18 @@ int windows_mkdir(const char* file)
|
|||
return _wmkdir(u8tou16(file));
|
||||
}
|
||||
|
||||
int stat_inode(const char* file, struct windows_stat* st)
|
||||
int lstat_inode(const char* file, struct windows_stat* st)
|
||||
{
|
||||
BY_HANDLE_FILE_INFORMATION info;
|
||||
HANDLE h;
|
||||
|
||||
h = CreateFileW(u8tou16(file), 0, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0);
|
||||
/*
|
||||
* Open the handle of the file.
|
||||
*
|
||||
* Use FILE_FLAG_BACKUP_SEMANTICS to open directories and to override the file security checks.
|
||||
* Use FILE_FLAG_OPEN_REPARSE_POINT to open symbolic links and not the their target.
|
||||
*/
|
||||
h = CreateFileW(u8tou16(file), 0, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OPEN_REPARSE_POINT, 0);
|
||||
if (h == INVALID_HANDLE_VALUE) {
|
||||
windows_errno(GetLastError());
|
||||
return -1;
|
||||
|
|
|
|||
11
mingw.h
11
mingw.h
|
|
@ -32,6 +32,7 @@
|
|||
#define fopen windows_fopen
|
||||
#define open windows_open
|
||||
#define stat windows_stat
|
||||
#define lstat windows_lstat
|
||||
#define access windows_access
|
||||
#define off_t off64_t
|
||||
#define lseek lseek64
|
||||
|
|
@ -67,7 +68,7 @@ int windows_fstat(int fd, struct windows_stat* st);
|
|||
/**
|
||||
* Like the C stat() but without inode information.
|
||||
*/
|
||||
int windows_stat(const char* file, struct windows_stat* st);
|
||||
int windows_lstat(const char* file, struct windows_stat* st);
|
||||
|
||||
/**
|
||||
* Like the C access().
|
||||
|
|
@ -80,12 +81,12 @@ int windows_access(const char* file, int mode);
|
|||
int windows_mkdir(const char* file);
|
||||
|
||||
/**
|
||||
* Like the C stat() with inode information.
|
||||
* Like the C lstat() with inode information.
|
||||
* It doesn't work for all kind of files and directories. For example "\System Volume Information" cannot be opened.
|
||||
* Note that instead stat() works for all the files.
|
||||
* Note that instead lstat() works for all the files.
|
||||
*/
|
||||
#define HAVE_STAT_INODE 1
|
||||
int stat_inode(const char* file, struct windows_stat* st);
|
||||
#define HAVE_LSTAT_INODE 1
|
||||
int lstat_inode(const char* file, struct windows_stat* st);
|
||||
|
||||
/**
|
||||
* Like the C ftruncate().
|
||||
|
|
|
|||
4
scan.c
4
scan.c
|
|
@ -258,9 +258,9 @@ static void scan_dir(struct snapraid_scan* scan, struct snapraid_state* state, s
|
|||
continue;
|
||||
}
|
||||
|
||||
#if HAVE_STAT_INODE
|
||||
#if HAVE_LSTAT_INODE
|
||||
/* get inode info about the file, Windows needs an additional step */
|
||||
if (stat_inode(path_next, &st) != 0) {
|
||||
if (lstat_inode(path_next, &st) != 0) {
|
||||
fprintf(stderr, "Error in stat_inode file '%s'. %s.\n", path_next, strerror(errno));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue