Beispiel #1
0
int ntfs_close_r(struct _reent *r, int fd)
{
	ntfs_log_trace("fd %p\n", (void *) fd);

	ntfs_file_state* file = STATE(((intptr_t)(s64)fd));
	//ntfs_file_state* file = STATE(((s64) fd));

	// Sanity check
	if (!file || !file->vd) {
		r->_errno = EBADF;
		return -1;
	}

	// Lock
	ntfsLock(file->vd);

	// Close the file
	ntfsCloseFile(file);

	// Remove the file from the double-linked FILO list of open files
	file->vd->openFileCount--;
	if (file->nextOpenFile)
		file->nextOpenFile->prevOpenFile = file->prevOpenFile;
	if (file->prevOpenFile)
		file->prevOpenFile->nextOpenFile = file->nextOpenFile;
	else
		file->vd->firstOpenFile = file->nextOpenFile;

	// Unlock
	ntfsUnlock(file->vd);

	return 0;
}
Beispiel #2
0
void ntfsDeinitVolume (ntfs_vd *vd)
{
    // Sanity check
    if (!vd) {
        errno = ENODEV;
        return;
    }

    // Lock
    ntfsLock(vd);

    // Close any directories which are still open (lazy programmers!)
    ntfs_dir_state *nextDir = vd->firstOpenDir;
    while (nextDir) {
        ntfs_log_warning("Cleaning up orphaned directory @ %p\n", nextDir);
        ntfsCloseDir(nextDir);
        nextDir = nextDir->nextOpenDir;
    }

    // Close any files which are still open (lazy programmers!)
    ntfs_file_state *nextFile = vd->firstOpenFile;
    while (nextFile) {
        ntfs_log_warning("Cleaning up orphaned file @ %p\n", nextFile);
        ntfsCloseFile(nextFile);
        nextFile = nextFile->nextOpenFile;
    }

    // Reset open directory and file stats
    vd->openDirCount = 0;
    vd->openFileCount = 0;
    vd->firstOpenDir = NULL;
    vd->firstOpenFile = NULL;

    // Close the volumes current directory (if any)
    //if (vd->cwd_ni) {
        //ntfsCloseEntry(vd, vd->cwd_ni);
        //vd->cwd_ni = NULL;
    //}

    // Force the underlying device to sync
    ntfs_device_sync(vd->dev);

    // Unlock
    ntfsUnlock(vd);
#ifndef LIBXENON
    // Deinitialise the volume lock
    LWP_MutexDestroy(vd->lock);
#endif
    return;
}