From e221ad783cdeb532e76c8cc38a4654558bec70fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Pierre=20Andr=C3=A9?= Date: Tue, 30 Jul 2013 11:17:29 +0200 Subject: [PATCH] Improved emulation of stat(2) on Windows Made a distinction between a file and a partition when emulating stat(2) on Windows (useful for ntfsclone). --- libntfs-3g/win32_io.c | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/libntfs-3g/win32_io.c b/libntfs-3g/win32_io.c index 438e6e9f..9b7cbc3d 100644 --- a/libntfs-3g/win32_io.c +++ b/libntfs-3g/win32_io.c @@ -6,7 +6,7 @@ * Copyright (c) 2003-2004 Lode Leroy * Copyright (c) 2003-2006 Anton Altaparmakov * Copyright (c) 2004-2005 Yuval Fledel - * Copyright (c) 2012 Jean-Pierre Andre + * Copyright (c) 2012-2013 Jean-Pierre Andre * * This program/include file is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as published @@ -70,6 +70,7 @@ typedef struct { #endif #ifdef HAVE_SYS_STAT_H #include +#define stat stat64 #define st_blocks st_rdev /* emulate st_blocks, missing in Windows */ #endif @@ -1744,19 +1745,22 @@ static int ntfs_device_win32_stat(struct ntfs_device *dev, struct stat *buf) win32_fd *fd = (win32_fd *)dev->d_private; mode_t st_mode; - switch (GetFileType(fd->handle)) { - case FILE_TYPE_CHAR: - st_mode = S_IFCHR; - break; - case FILE_TYPE_DISK: + if ((dev->d_name[1] == ':') && (dev->d_name[2] == '\0')) st_mode = S_IFBLK; - break; - case FILE_TYPE_PIPE: - st_mode = S_IFIFO; - break; - default: - st_mode = 0; - } + else + switch (GetFileType(fd->handle)) { + case FILE_TYPE_CHAR: + st_mode = S_IFCHR; + break; + case FILE_TYPE_DISK: + st_mode = S_IFREG; + break; + case FILE_TYPE_PIPE: + st_mode = S_IFIFO; + break; + default: + st_mode = 0; + } memset(buf, 0, sizeof(struct stat)); buf->st_mode = st_mode; buf->st_size = fd->part_length;