/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* Windows implementation of DosFileAttributes/BasicFileAttributes
*/
class WindowsFileAttributes
implements DosFileAttributes
{
/*
* typedef struct _BY_HANDLE_FILE_INFORMATION {
* DWORD dwFileAttributes;
* FILETIME ftCreationTime;
* FILETIME ftLastAccessTime;
* FILETIME ftLastWriteTime;
* DWORD dwVolumeSerialNumber;
* DWORD nFileSizeHigh;
* DWORD nFileSizeLow;
* DWORD nNumberOfLinks;
* DWORD nFileIndexHigh;
* DWORD nFileIndexLow;
* } BY_HANDLE_FILE_INFORMATION;
*/
/*
* typedef struct _WIN32_FILE_ATTRIBUTE_DATA {
* DWORD dwFileAttributes;
* FILETIME ftCreationTime;
* FILETIME ftLastAccessTime;
* FILETIME ftLastWriteTime;
* DWORD nFileSizeHigh;
* DWORD nFileSizeLow;
* } WIN32_FILE_ATTRIBUTE_DATA;
*/
/**
* typedef struct _WIN32_FIND_DATA {
* DWORD dwFileAttributes;
* FILETIME ftCreationTime;
* FILETIME ftLastAccessTime;
* FILETIME ftLastWriteTime;
* DWORD nFileSizeHigh;
* DWORD nFileSizeLow;
* DWORD dwReserved0;
* DWORD dwReserved1;
* TCHAR cFileName[MAX_PATH];
* TCHAR cAlternateFileName[14];
* } WIN32_FIND_DATA;
*/
// used to adjust values between Windows and java epoch
// indicates if accurate metadata is required (interesting on NTFS only)
private static final boolean ensureAccurateMetadata;
static {
}
// attributes
private final int fileAttrs;
private final long creationTime;
private final long lastAccessTime;
private final long lastWriteTime;
private final long size;
private final int reparseTag;
// additional attributes when using GetFileInformationByHandle
private final int volSerialNumber;
private final int fileIndexHigh;
private final int fileIndexLow;
/**
* Convert 64-bit value representing the number of 100-nanosecond intervals
* since January 1, 1601 to a FileTime.
*/
// 100ns -> us
time /= 10L;
// adjust to java epoch
}
/**
* Convert FileTime to 64-bit value representing the number of 100-nanosecond
* intervals since January 1, 1601.
*/
// adjust to Windows epoch+= 11644473600000000L;
// us -> 100ns
value *= 10L;
return value;
}
/**
* Initialize a new instance of this class
*/
long creationTime,
long lastAccessTime,
long lastWriteTime,
long size,
int reparseTag,
int volSerialNumber,
int fileIndexHigh,
int fileIndexLow)
{
this.creationTime = creationTime;
this.lastAccessTime = lastAccessTime;
this.lastWriteTime = lastWriteTime;
this.reparseTag = reparseTag;
this.volSerialNumber = volSerialNumber;
this.fileIndexHigh = fileIndexHigh;
this.fileIndexLow = fileIndexLow;
}
/**
* Create a WindowsFileAttributes from a BY_HANDLE_FILE_INFORMATION structure
*/
return new WindowsFileAttributes(fileAttrs,
size,
}
/**
* Create a WindowsFileAttributes from a WIN32_FILE_ATTRIBUTE_DATA structure
*/
return new WindowsFileAttributes(fileAttrs,
size,
0, // volSerialNumber
0, // fileIndexHigh
0); // fileIndexLow
}
/**
* Allocates a native buffer for a WIN32_FIND_DATA structure
*/
}
/**
* Create a WindowsFileAttributes from a WIN32_FIND_DATA structure
*/
return new WindowsFileAttributes(fileAttrs,
size,
0, // volSerialNumber
0, // fileIndexHigh
0); // fileIndexLow
}
/**
* Reads the attributes of an open file
*/
throws WindowsException
{
try {
// if file is a reparse point then read the tag
int reparseTag = 0;
if (isReparsePoint(fileAttrs)) {
try {
} finally {
}
}
} finally {
}
}
/**
* Returns attributes of given file.
*/
throws WindowsException
{
if (!ensureAccurateMetadata) {
// GetFileAttributesEx is the fastest way to read the attributes
try {
// if reparse point then file may be a sym link; otherwise
// just return the attributes
if (!isReparsePoint(fileAttrs))
} catch (WindowsException x) {
if (x.lastError() != ERROR_SHARING_VIOLATION)
throw x;
firstException = x;
} finally {
}
// For sharing violations, fallback to FindFirstFile if the file
// is not a root directory.
if (firstException != null) {
throw firstException;
try {
// FindFirstFile does not follow sym links. Even if
// followLinks is false, there isn't sufficient information
// in the WIN32_FIND_DATA structure to know if the reparse
// point is a sym link.
if (attrs.isReparsePoint())
throw firstException;
return attrs;
} catch (WindowsException ignore) {
throw firstException;
} finally {
}
}
}
// file is reparse point so need to open file to get attributes
try {
return readAttributes(handle);
} finally {
}
}
/**
* Returns true if the attributes are of the same file - both files must
* be open.
*/
{
// volume serial number and file index must be the same
}
/**
* Returns true if the attributes are of a file with a reparse point.
*/
}
// package-private
int attributes() {
return fileAttrs;
}
int volSerialNumber() {
if (volSerialNumber == 0)
throw new AssertionError("Should not get here");
return volSerialNumber;
}
int fileIndexHigh() {
if (volSerialNumber == 0)
throw new AssertionError("Should not get here");
return fileIndexHigh;
}
int fileIndexLow() {
if (volSerialNumber == 0)
throw new AssertionError("Should not get here");
return fileIndexLow;
}
public long size() {
return size;
}
return toFileTime(lastWriteTime);
}
return toFileTime(lastAccessTime);
}
return toFileTime(creationTime);
}
return null;
}
// package private
boolean isReparsePoint() {
return isReparsePoint(fileAttrs);
}
boolean isDirectoryLink() {
}
public boolean isSymbolicLink() {
return reparseTag == IO_REPARSE_TAG_SYMLINK;
}
public boolean isDirectory() {
// ignore FILE_ATTRIBUTE_DIRECTORY attribute if file is a sym link
if (isSymbolicLink())
return false;
}
public boolean isOther() {
if (isSymbolicLink())
return false;
// return true if device or reparse point
}
public boolean isRegularFile() {
}
public boolean isReadOnly() {
}
public boolean isHidden() {
}
public boolean isArchive() {
}
public boolean isSystem() {
}
}