Click here to Skip to main content
15,881,755 members
Articles / Programming Languages / C++

Windows 2000 Junction Points

Rate me:
Please Sign up or sign in to vote.
4.93/5 (42 votes)
5 Jan 2000 444.1K   3K   83  
Explains how reparse points are used to create filesystem links
// Copyright 2000 Mikael Nordell (tamlin@algonet.se)
// Distributed without warranties. Use as you see fit, except for
// commercial purposes.
// Reparse_Dir_HANDLE.cpp
#include "Reparse_Dir_HANDLE.h"

namespace FSLinks {


Reparse_Dir_HANDLE::Reparse_Dir_HANDLE(LPCTSTR szDir, bool bWriteable)
:	m_hDir(
		CreateFile(	szDir,
					GENERIC_READ | (bWriteable ? GENERIC_WRITE : 0),
					0,
					0,
					OPEN_EXISTING,
					FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OPEN_REPARSE_POINT,
					0)
	)
{
}

Reparse_Dir_HANDLE::~Reparse_Dir_HANDLE()
{
	if (m_hDir != INVALID_HANDLE_VALUE) {
		::CloseHandle(m_hDir);
	}
}

bool Reparse_Dir_HANDLE::SetReparsePoint(const TMN_REPARSE_DATA_BUFFER& rdb)
{
	if (!IsValid()) {
		return false;
	}

	DWORD dwBytes;
	const BOOL bOK =
		DeviceIoControl(m_hDir,
						FSCTL_SET_REPARSE_POINT,
						(LPVOID)&rdb,
						rdb.BytesForIoControl(),
						NULL,
						0,
						&dwBytes,
						0);
	return bOK != 0;
}

bool Reparse_Dir_HANDLE::DeleteReparsePoint()
{
	if (!IsValid()) {
		return false;
	}

	REPARSE_GUID_DATA_BUFFER rgdb = { 0 };
	rgdb.ReparseTag = IO_REPARSE_TAG_MOUNT_POINT;
	DWORD dwBytes;
	const BOOL bOK =
		DeviceIoControl(m_hDir,
						FSCTL_DELETE_REPARSE_POINT,
						&rgdb,
						REPARSE_GUID_DATA_BUFFER_HEADER_SIZE,
						NULL,
						0,
						&dwBytes,
						0);
	return bOK != 0;
}

}	// end of namespace FSLinks

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Architect
Sweden Sweden
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions