2009-12-19 15:06:57 +01:00
|
|
|
/**
|
|
|
|
* ntfs.c - Simple functionality for startup, mounting and unmounting of NTFS-based devices.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2009 Rhys "Shareese" Koedijk
|
|
|
|
* Copyright (c) 2006 Michael "Chishm" Chisholm
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* by the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program/include file 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 for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_STDLIB_H
|
|
|
|
#include <stdlib.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_ERRNO_H
|
|
|
|
#include <errno.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
#include <string.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "ntfs.h"
|
|
|
|
#include "ntfsinternal.h"
|
|
|
|
#include "ntfsfile.h"
|
|
|
|
#include "ntfsdir.h"
|
|
|
|
#include "gekko_io.h"
|
|
|
|
#include "cache.h"
|
|
|
|
|
|
|
|
// NTFS device driver devoptab
|
2010-09-19 01:16:05 +02:00
|
|
|
static const devoptab_t devops_ntfs =
|
|
|
|
{
|
2009-12-19 15:06:57 +01:00
|
|
|
NULL, /* Device name */
|
2010-09-19 01:16:05 +02:00
|
|
|
sizeof ( ntfs_file_state ),
|
2009-12-19 15:06:57 +01:00
|
|
|
ntfs_open_r,
|
|
|
|
ntfs_close_r,
|
|
|
|
ntfs_write_r,
|
|
|
|
ntfs_read_r,
|
|
|
|
ntfs_seek_r,
|
|
|
|
ntfs_fstat_r,
|
|
|
|
ntfs_stat_r,
|
|
|
|
ntfs_link_r,
|
|
|
|
ntfs_unlink_r,
|
|
|
|
ntfs_chdir_r,
|
|
|
|
ntfs_rename_r,
|
|
|
|
ntfs_mkdir_r,
|
2010-09-19 01:16:05 +02:00
|
|
|
sizeof ( ntfs_dir_state ),
|
2009-12-19 15:06:57 +01:00
|
|
|
ntfs_diropen_r,
|
|
|
|
ntfs_dirreset_r,
|
|
|
|
ntfs_dirnext_r,
|
|
|
|
ntfs_dirclose_r,
|
|
|
|
ntfs_statvfs_r,
|
|
|
|
ntfs_ftruncate_r,
|
|
|
|
ntfs_fsync_r,
|
|
|
|
NULL /* Device data */
|
|
|
|
};
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
void ntfsInit ( void )
|
2010-02-09 11:59:55 +01:00
|
|
|
{
|
2009-12-19 15:06:57 +01:00
|
|
|
static bool isInit = false;
|
2010-09-16 21:59:41 +02:00
|
|
|
|
2009-12-19 15:06:57 +01:00
|
|
|
// Initialise ntfs-3g (if not already done so)
|
2010-09-19 01:16:05 +02:00
|
|
|
if ( !isInit )
|
|
|
|
{
|
2009-12-19 15:06:57 +01:00
|
|
|
isInit = true;
|
|
|
|
|
|
|
|
// Set the log handler
|
2010-09-19 01:16:05 +02:00
|
|
|
#ifdef NTFS_ENABLE_LOG
|
|
|
|
ntfs_log_set_handler( ntfs_log_handler_stderr );
|
|
|
|
#else
|
|
|
|
ntfs_log_set_handler( ntfs_log_handler_null );
|
|
|
|
#endif
|
2009-12-19 15:06:57 +01:00
|
|
|
// Set our current local
|
|
|
|
ntfs_set_locale();
|
2010-09-16 21:59:41 +02:00
|
|
|
|
2009-12-19 15:06:57 +01:00
|
|
|
}
|
2010-09-16 21:59:41 +02:00
|
|
|
|
2009-12-19 15:06:57 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
int ntfsFindPartitions ( const DISC_INTERFACE *interface, sec_t **partitions )
|
2010-02-09 11:59:55 +01:00
|
|
|
{
|
2009-12-19 15:06:57 +01:00
|
|
|
MASTER_BOOT_RECORD mbr;
|
|
|
|
PARTITION_RECORD *partition = NULL;
|
|
|
|
sec_t partition_starts[NTFS_MAX_PARTITIONS] = {0};
|
|
|
|
int partition_count = 0;
|
|
|
|
sec_t part_lba = 0;
|
|
|
|
int i;
|
2010-09-16 21:59:41 +02:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
union
|
|
|
|
{
|
2010-09-16 21:59:41 +02:00
|
|
|
u8 buffer[512];
|
2009-12-19 15:06:57 +01:00
|
|
|
MASTER_BOOT_RECORD mbr;
|
|
|
|
EXTENDED_BOOT_RECORD ebr;
|
|
|
|
NTFS_BOOT_SECTOR boot;
|
|
|
|
} sector;
|
2010-09-16 21:59:41 +02:00
|
|
|
|
2009-12-19 15:06:57 +01:00
|
|
|
// Sanity check
|
2010-09-19 01:16:05 +02:00
|
|
|
if ( !interface )
|
|
|
|
{
|
2009-12-19 15:06:57 +01:00
|
|
|
errno = EINVAL;
|
|
|
|
return -1;
|
|
|
|
}
|
2010-09-19 01:16:05 +02:00
|
|
|
if ( !partitions )
|
2009-12-19 15:06:57 +01:00
|
|
|
return 0;
|
2010-09-16 21:59:41 +02:00
|
|
|
|
2009-12-19 15:06:57 +01:00
|
|
|
// Initialise ntfs-3g
|
|
|
|
ntfsInit();
|
2010-09-16 21:59:41 +02:00
|
|
|
|
2009-12-19 15:06:57 +01:00
|
|
|
// Start the device and check that it is inserted
|
2010-09-19 01:16:05 +02:00
|
|
|
if ( !interface->startup() )
|
|
|
|
{
|
2009-12-19 15:06:57 +01:00
|
|
|
errno = EIO;
|
|
|
|
return -1;
|
|
|
|
}
|
2010-09-19 01:16:05 +02:00
|
|
|
if ( !interface->isInserted() )
|
|
|
|
{
|
2009-12-19 15:06:57 +01:00
|
|
|
return 0;
|
|
|
|
}
|
2010-09-16 21:59:41 +02:00
|
|
|
|
2009-12-19 15:06:57 +01:00
|
|
|
// Read the first sector on the device
|
2010-09-19 01:16:05 +02:00
|
|
|
if ( !interface->readSectors( 0, 1, §or.buffer ) )
|
|
|
|
{
|
2009-12-19 15:06:57 +01:00
|
|
|
errno = EIO;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If this is the devices master boot record
|
2010-09-19 01:16:05 +02:00
|
|
|
if ( sector.mbr.signature == MBR_SIGNATURE )
|
|
|
|
{
|
|
|
|
memcpy( &mbr, §or, sizeof( MASTER_BOOT_RECORD ) );
|
|
|
|
ntfs_log_debug( "Valid Master Boot Record found\n" );
|
2010-09-16 21:59:41 +02:00
|
|
|
|
2009-12-19 15:06:57 +01:00
|
|
|
// Search the partition table for all NTFS partitions (max. 4 primary partitions)
|
2010-09-19 01:16:05 +02:00
|
|
|
for ( i = 0; i < 4; i++ )
|
|
|
|
{
|
2009-12-19 15:06:57 +01:00
|
|
|
partition = &mbr.partitions[i];
|
2010-09-19 01:16:05 +02:00
|
|
|
part_lba = le32_to_cpu( mbr.partitions[i].lba_start );
|
2010-09-16 21:59:41 +02:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
ntfs_log_debug( "Partition %i: %s, sector %d, type 0x%x\n", i + 1,
|
|
|
|
partition->status == PARTITION_STATUS_BOOTABLE ? "bootable (active)" : "non-bootable",
|
|
|
|
part_lba, partition->type );
|
2009-12-19 15:06:57 +01:00
|
|
|
|
|
|
|
// Figure out what type of partition this is
|
2010-09-19 01:16:05 +02:00
|
|
|
switch ( partition->type )
|
|
|
|
{
|
2009-12-19 15:06:57 +01:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
// Ignore empty partitions
|
2010-02-09 11:59:55 +01:00
|
|
|
case PARTITION_TYPE_EMPTY:
|
|
|
|
continue;
|
2010-09-16 21:59:41 +02:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
// NTFS partition
|
|
|
|
case PARTITION_TYPE_NTFS:
|
|
|
|
{
|
|
|
|
ntfs_log_debug( "Partition %i: Claims to be NTFS\n", i + 1 );
|
|
|
|
|
|
|
|
// Read and validate the NTFS partition
|
|
|
|
if ( interface->readSectors( part_lba, 1, §or ) )
|
|
|
|
{
|
|
|
|
if ( sector.boot.oem_id == NTFS_OEM_ID )
|
|
|
|
{
|
|
|
|
ntfs_log_debug( "Partition %i: Valid NTFS boot sector found\n", i + 1 );
|
|
|
|
if ( partition_count < NTFS_MAX_PARTITIONS )
|
|
|
|
{
|
|
|
|
partition_starts[partition_count] = part_lba;
|
|
|
|
partition_count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ntfs_log_debug( "Partition %i: Invalid NTFS boot sector, not actually NTFS\n", i + 1 );
|
2009-12-19 15:06:57 +01:00
|
|
|
}
|
|
|
|
}
|
2010-09-16 21:59:41 +02:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
break;
|
2010-09-16 21:59:41 +02:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
2010-09-16 21:59:41 +02:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
// DOS 3.3+ or Windows 95 extended partition
|
2010-02-09 11:59:55 +01:00
|
|
|
case PARTITION_TYPE_DOS33_EXTENDED:
|
2010-09-19 01:16:05 +02:00
|
|
|
case PARTITION_TYPE_WIN95_EXTENDED:
|
|
|
|
{
|
|
|
|
ntfs_log_debug( "Partition %i: Claims to be Extended\n", i + 1 );
|
|
|
|
|
|
|
|
// Walk the extended partition chain, finding all NTFS partitions within it
|
|
|
|
sec_t ebr_lba = part_lba;
|
|
|
|
sec_t next_erb_lba = 0;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
|
|
|
|
// Read and validate the extended boot record
|
|
|
|
if ( interface->readSectors( ebr_lba + next_erb_lba, 1, §or ) )
|
|
|
|
{
|
|
|
|
if ( sector.ebr.signature == EBR_SIGNATURE )
|
|
|
|
{
|
|
|
|
ntfs_log_debug( "Logical Partition @ %d: type 0x%x\n", ebr_lba + next_erb_lba,
|
|
|
|
sector.ebr.partition.status == PARTITION_STATUS_BOOTABLE ? "bootable (active)" : "non-bootable",
|
|
|
|
sector.ebr.partition.type );
|
|
|
|
|
|
|
|
// Get the start sector of the current partition
|
|
|
|
// and the next extended boot record in the chain
|
|
|
|
part_lba = ebr_lba + next_erb_lba + le32_to_cpu( sector.ebr.partition.lba_start );
|
|
|
|
next_erb_lba = le32_to_cpu( sector.ebr.next_ebr.lba_start );
|
|
|
|
|
|
|
|
// Check if this partition has a valid NTFS boot record
|
|
|
|
if ( interface->readSectors( part_lba, 1, §or ) )
|
|
|
|
{
|
|
|
|
if ( sector.boot.oem_id == NTFS_OEM_ID )
|
|
|
|
{
|
|
|
|
ntfs_log_debug( "Logical Partition @ %d: Valid NTFS boot sector found\n", part_lba );
|
|
|
|
if ( sector.ebr.partition.type != PARTITION_TYPE_NTFS )
|
|
|
|
{
|
|
|
|
ntfs_log_warning( "Logical Partition @ %d: Is NTFS but type is 0x%x; 0x%x was expected\n", part_lba, sector.ebr.partition.type, PARTITION_TYPE_NTFS );
|
|
|
|
}
|
|
|
|
if ( partition_count < NTFS_MAX_PARTITIONS )
|
|
|
|
{
|
|
|
|
partition_starts[partition_count] = part_lba;
|
|
|
|
partition_count++;
|
|
|
|
}
|
2009-12-19 15:06:57 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
next_erb_lba = 0;
|
|
|
|
}
|
2009-12-19 15:06:57 +01:00
|
|
|
}
|
2010-09-16 21:59:41 +02:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
|
|
|
while ( next_erb_lba );
|
2010-09-16 21:59:41 +02:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
break;
|
2010-09-16 21:59:41 +02:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
2010-09-16 21:59:41 +02:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
// Unknown or unsupported partition type
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
|
|
|
|
// Check if this partition has a valid NTFS boot record anyway,
|
|
|
|
// it might be misrepresented due to a lazy partition editor
|
|
|
|
if ( interface->readSectors( part_lba, 1, §or ) )
|
|
|
|
{
|
|
|
|
if ( sector.boot.oem_id == NTFS_OEM_ID )
|
|
|
|
{
|
|
|
|
ntfs_log_debug( "Partition %i: Valid NTFS boot sector found\n", i + 1 );
|
|
|
|
if ( partition->type != PARTITION_TYPE_NTFS )
|
|
|
|
{
|
|
|
|
ntfs_log_warning( "Partition %i: Is NTFS but type is 0x%x; 0x%x was expected\n", i + 1, partition->type, PARTITION_TYPE_NTFS );
|
|
|
|
}
|
|
|
|
if ( partition_count < NTFS_MAX_PARTITIONS )
|
|
|
|
{
|
|
|
|
partition_starts[partition_count] = part_lba;
|
|
|
|
partition_count++;
|
|
|
|
}
|
2009-12-19 15:06:57 +01:00
|
|
|
}
|
|
|
|
}
|
2010-09-16 21:59:41 +02:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
break;
|
2010-09-16 21:59:41 +02:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
2010-09-16 21:59:41 +02:00
|
|
|
|
2009-12-19 15:06:57 +01:00
|
|
|
}
|
2010-09-16 21:59:41 +02:00
|
|
|
|
2009-12-19 15:06:57 +01:00
|
|
|
}
|
2010-09-16 21:59:41 +02:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
// Else it is assumed this device has no master boot record
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ntfs_log_debug( "No Master Boot Record was found!\n" );
|
2009-12-19 15:06:57 +01:00
|
|
|
|
|
|
|
// As a last-ditched effort, search the first 64 sectors of the device for stray NTFS partitions
|
2010-09-19 01:16:05 +02:00
|
|
|
for ( i = 0; i < 64; i++ )
|
|
|
|
{
|
|
|
|
if ( interface->readSectors( i, 1, §or ) )
|
|
|
|
{
|
|
|
|
if ( sector.boot.oem_id == NTFS_OEM_ID )
|
|
|
|
{
|
|
|
|
ntfs_log_debug( "Valid NTFS boot sector found at sector %d!\n", i );
|
|
|
|
if ( partition_count < NTFS_MAX_PARTITIONS )
|
|
|
|
{
|
2009-12-19 15:06:57 +01:00
|
|
|
partition_starts[partition_count] = i;
|
|
|
|
partition_count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-09-16 21:59:41 +02:00
|
|
|
|
2009-12-19 15:06:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Shutdown the device
|
|
|
|
/*interface->shutdown();*/
|
2010-09-16 21:59:41 +02:00
|
|
|
|
2009-12-19 15:06:57 +01:00
|
|
|
// Return the found partitions (if any)
|
2010-09-19 01:16:05 +02:00
|
|
|
if ( partition_count > 0 )
|
|
|
|
{
|
|
|
|
*partitions = ( sec_t* )ntfs_alloc( sizeof( sec_t ) * partition_count );
|
|
|
|
if ( *partitions )
|
|
|
|
{
|
|
|
|
memcpy( *partitions, &partition_starts, sizeof( sec_t ) * partition_count );
|
2009-12-19 15:06:57 +01:00
|
|
|
return partition_count;
|
|
|
|
}
|
|
|
|
}
|
2010-09-16 21:59:41 +02:00
|
|
|
|
2009-12-19 15:06:57 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
int ntfsMountAll ( ntfs_md **mounts, u32 flags )
|
2010-02-09 11:59:55 +01:00
|
|
|
{
|
2009-12-19 15:06:57 +01:00
|
|
|
const INTERFACE_ID *discs = ntfsGetDiscInterfaces();
|
|
|
|
const INTERFACE_ID *disc = NULL;
|
|
|
|
ntfs_md mount_points[NTFS_MAX_MOUNTS];
|
|
|
|
sec_t *partitions = NULL;
|
|
|
|
int mount_count = 0;
|
|
|
|
int partition_count = 0;
|
|
|
|
char name[128];
|
|
|
|
int i, j, k;
|
|
|
|
|
|
|
|
// Initialise ntfs-3g
|
|
|
|
ntfsInit();
|
2010-09-16 21:59:41 +02:00
|
|
|
|
2009-12-19 15:06:57 +01:00
|
|
|
// Find and mount all NTFS partitions on all known devices
|
2010-09-19 01:16:05 +02:00
|
|
|
for ( i = 0; discs[i].name != NULL && discs[i].interface != NULL; i++ )
|
|
|
|
{
|
2009-12-19 15:06:57 +01:00
|
|
|
disc = &discs[i];
|
2010-09-19 01:16:05 +02:00
|
|
|
partition_count = ntfsFindPartitions( disc->interface, &partitions );
|
|
|
|
if ( partition_count > 0 && partitions )
|
|
|
|
{
|
|
|
|
for ( j = 0, k = 0; j < partition_count; j++ )
|
|
|
|
{
|
2009-12-19 15:06:57 +01:00
|
|
|
|
|
|
|
// Find the next unused mount name
|
2010-09-19 01:16:05 +02:00
|
|
|
do
|
|
|
|
{
|
|
|
|
sprintf( name, "%s%i", NTFS_MOUNT_PREFIX, k++ );
|
|
|
|
if ( k >= NTFS_MAX_MOUNTS )
|
|
|
|
{
|
|
|
|
ntfs_free( partitions );
|
2009-12-19 15:06:57 +01:00
|
|
|
errno = EADDRNOTAVAIL;
|
|
|
|
return -1;
|
|
|
|
}
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
|
|
|
while ( ntfsGetDevice( name, false ) );
|
2009-12-19 15:06:57 +01:00
|
|
|
|
|
|
|
// Mount the partition
|
2010-09-19 01:16:05 +02:00
|
|
|
if ( mount_count < NTFS_MAX_MOUNTS )
|
|
|
|
{
|
|
|
|
if ( ntfsMount( name, disc->interface, partitions[j], CACHE_DEFAULT_PAGE_SIZE, CACHE_DEFAULT_PAGE_COUNT, flags ) )
|
|
|
|
{
|
|
|
|
strcpy( mount_points[mount_count].name, name );
|
2009-12-19 15:06:57 +01:00
|
|
|
mount_points[mount_count].interface = disc->interface;
|
|
|
|
mount_points[mount_count].startSector = partitions[j];
|
|
|
|
mount_count++;
|
|
|
|
}
|
|
|
|
}
|
2010-09-16 21:59:41 +02:00
|
|
|
|
2009-12-19 15:06:57 +01:00
|
|
|
}
|
2010-09-19 01:16:05 +02:00
|
|
|
ntfs_free( partitions );
|
2009-12-19 15:06:57 +01:00
|
|
|
}
|
|
|
|
}
|
2010-09-16 21:59:41 +02:00
|
|
|
|
2009-12-19 15:06:57 +01:00
|
|
|
// Return the mounts (if any)
|
2010-09-19 01:16:05 +02:00
|
|
|
if ( mount_count > 0 && mounts )
|
|
|
|
{
|
|
|
|
*mounts = ( ntfs_md* )ntfs_alloc( sizeof( ntfs_md ) * mount_count );
|
|
|
|
if ( *mounts )
|
|
|
|
{
|
|
|
|
memcpy( *mounts, &mount_points, sizeof( ntfs_md ) * mount_count );
|
2009-12-19 15:06:57 +01:00
|
|
|
return mount_count;
|
|
|
|
}
|
|
|
|
}
|
2010-09-16 21:59:41 +02:00
|
|
|
|
2009-12-19 15:06:57 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
int ntfsMountDevice ( const DISC_INTERFACE *interface, ntfs_md **mounts, u32 flags )
|
2010-02-09 11:59:55 +01:00
|
|
|
{
|
2009-12-19 15:06:57 +01:00
|
|
|
const INTERFACE_ID *discs = ntfsGetDiscInterfaces();
|
|
|
|
const INTERFACE_ID *disc = NULL;
|
|
|
|
ntfs_md mount_points[NTFS_MAX_MOUNTS];
|
|
|
|
sec_t *partitions = NULL;
|
|
|
|
int mount_count = 0;
|
|
|
|
int partition_count = 0;
|
|
|
|
char name[128];
|
|
|
|
int i, j, k;
|
2010-09-16 21:59:41 +02:00
|
|
|
|
2009-12-19 15:06:57 +01:00
|
|
|
// Sanity check
|
2010-09-19 01:16:05 +02:00
|
|
|
if ( !interface )
|
|
|
|
{
|
2009-12-19 15:06:57 +01:00
|
|
|
errno = EINVAL;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Initialise ntfs-3g
|
|
|
|
ntfsInit();
|
2010-09-16 21:59:41 +02:00
|
|
|
|
2009-12-19 15:06:57 +01:00
|
|
|
// Find the specified device then find and mount all NTFS partitions on it
|
2010-09-19 01:16:05 +02:00
|
|
|
for ( i = 0; discs[i].name != NULL && discs[i].interface != NULL; i++ )
|
|
|
|
{
|
|
|
|
if ( discs[i].interface == interface )
|
|
|
|
{
|
2009-12-19 15:06:57 +01:00
|
|
|
disc = &discs[i];
|
2010-09-19 01:16:05 +02:00
|
|
|
partition_count = ntfsFindPartitions( disc->interface, &partitions );
|
|
|
|
if ( partition_count > 0 && partitions )
|
|
|
|
{
|
|
|
|
for ( j = 0, k = 0; j < partition_count; j++ )
|
|
|
|
{
|
2010-09-16 21:59:41 +02:00
|
|
|
|
2009-12-19 15:06:57 +01:00
|
|
|
// Find the next unused mount name
|
2010-09-19 01:16:05 +02:00
|
|
|
do
|
|
|
|
{
|
|
|
|
sprintf( name, "%s%i", NTFS_MOUNT_PREFIX, k++ );
|
|
|
|
if ( k >= NTFS_MAX_MOUNTS )
|
|
|
|
{
|
|
|
|
ntfs_free( partitions );
|
2009-12-19 15:06:57 +01:00
|
|
|
errno = EADDRNOTAVAIL;
|
|
|
|
return -1;
|
|
|
|
}
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
|
|
|
while ( ntfsGetDevice( name, false ) );
|
2010-09-16 21:59:41 +02:00
|
|
|
|
2009-12-19 15:06:57 +01:00
|
|
|
// Mount the partition
|
2010-09-19 01:16:05 +02:00
|
|
|
if ( mount_count < NTFS_MAX_MOUNTS )
|
|
|
|
{
|
|
|
|
if ( ntfsMount( name, disc->interface, partitions[j], CACHE_DEFAULT_PAGE_SIZE, CACHE_DEFAULT_PAGE_COUNT, flags ) )
|
|
|
|
{
|
|
|
|
strcpy( mount_points[mount_count].name, name );
|
2009-12-19 15:06:57 +01:00
|
|
|
mount_points[mount_count].interface = disc->interface;
|
|
|
|
mount_points[mount_count].startSector = partitions[j];
|
|
|
|
mount_count++;
|
|
|
|
}
|
|
|
|
}
|
2010-09-16 21:59:41 +02:00
|
|
|
|
2009-12-19 15:06:57 +01:00
|
|
|
}
|
2010-09-19 01:16:05 +02:00
|
|
|
ntfs_free( partitions );
|
2009-12-19 15:06:57 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we couldn't find the device then return with error status
|
2010-09-19 01:16:05 +02:00
|
|
|
if ( !disc )
|
|
|
|
{
|
2009-12-19 15:06:57 +01:00
|
|
|
errno = ENODEV;
|
|
|
|
return -1;
|
|
|
|
}
|
2010-09-16 21:59:41 +02:00
|
|
|
|
2009-12-19 15:06:57 +01:00
|
|
|
// Return the mounts (if any)
|
2010-09-19 01:16:05 +02:00
|
|
|
if ( mount_count > 0 && mounts )
|
|
|
|
{
|
|
|
|
*mounts = ( ntfs_md* )ntfs_alloc( sizeof( ntfs_md ) * mount_count );
|
|
|
|
if ( *mounts )
|
|
|
|
{
|
|
|
|
memcpy( *mounts, &mount_points, sizeof( ntfs_md ) * mount_count );
|
2009-12-19 15:06:57 +01:00
|
|
|
return mount_count;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
bool ntfsMount ( const char *name, const DISC_INTERFACE *interface, sec_t startSector, u32 cachePageCount, u32 cachePageSize, u32 flags )
|
2010-02-09 11:59:55 +01:00
|
|
|
{
|
2009-12-19 15:06:57 +01:00
|
|
|
ntfs_vd *vd = NULL;
|
|
|
|
gekko_fd *fd = NULL;
|
2010-09-16 21:59:41 +02:00
|
|
|
|
2009-12-19 15:06:57 +01:00
|
|
|
// Sanity check
|
2010-09-19 01:16:05 +02:00
|
|
|
if ( !name || !interface )
|
|
|
|
{
|
2009-12-19 15:06:57 +01:00
|
|
|
errno = EINVAL;
|
2010-09-16 21:59:41 +02:00
|
|
|
return false;
|
2009-12-19 15:06:57 +01:00
|
|
|
}
|
2010-09-16 21:59:41 +02:00
|
|
|
|
2009-12-19 15:06:57 +01:00
|
|
|
// Initialise ntfs-3g
|
|
|
|
ntfsInit();
|
|
|
|
|
|
|
|
// Check that the requested mount name is free
|
2010-09-19 01:16:05 +02:00
|
|
|
if ( ntfsGetDevice( name, false ) )
|
|
|
|
{
|
2009-12-19 15:06:57 +01:00
|
|
|
errno = EADDRINUSE;
|
|
|
|
return false;
|
|
|
|
}
|
2010-09-16 21:59:41 +02:00
|
|
|
|
2009-12-19 15:06:57 +01:00
|
|
|
// Check that we can at least read from this device
|
2010-09-19 01:16:05 +02:00
|
|
|
if ( !( interface->features & FEATURE_MEDIUM_CANREAD ) )
|
|
|
|
{
|
2009-12-19 15:06:57 +01:00
|
|
|
errno = EPERM;
|
|
|
|
return false;
|
|
|
|
}
|
2010-09-16 21:59:41 +02:00
|
|
|
|
2009-12-19 15:06:57 +01:00
|
|
|
// Allocate the volume descriptor
|
2010-09-19 01:16:05 +02:00
|
|
|
vd = ( ntfs_vd* )ntfs_alloc( sizeof( ntfs_vd ) );
|
|
|
|
if ( !vd )
|
|
|
|
{
|
2009-12-19 15:06:57 +01:00
|
|
|
errno = ENOMEM;
|
|
|
|
return false;
|
|
|
|
}
|
2010-09-16 21:59:41 +02:00
|
|
|
|
2009-12-19 15:06:57 +01:00
|
|
|
// Setup the volume descriptor
|
|
|
|
vd->id = interface->ioType;
|
|
|
|
vd->flags = 0;
|
|
|
|
vd->uid = 0;
|
|
|
|
vd->gid = 0;
|
|
|
|
vd->fmask = 0;
|
|
|
|
vd->dmask = 0;
|
2010-09-19 01:16:05 +02:00
|
|
|
vd->atime = ( ( flags & NTFS_UPDATE_ACCESS_TIMES ) ? ATIME_ENABLED : ATIME_DISABLED );
|
|
|
|
vd->showHiddenFiles = ( flags & NTFS_SHOW_HIDDEN_FILES );
|
|
|
|
vd->showSystemFiles = ( flags & NTFS_SHOW_SYSTEM_FILES );
|
2010-09-16 21:59:41 +02:00
|
|
|
|
2009-12-19 15:06:57 +01:00
|
|
|
// Allocate the device driver descriptor
|
2010-09-19 01:16:05 +02:00
|
|
|
fd = ( gekko_fd* )ntfs_alloc( sizeof( gekko_fd ) );
|
|
|
|
if ( !fd )
|
|
|
|
{
|
|
|
|
ntfs_free( vd );
|
2009-12-19 15:06:57 +01:00
|
|
|
errno = ENOMEM;
|
|
|
|
return false;
|
|
|
|
}
|
2010-09-16 21:59:41 +02:00
|
|
|
|
2009-12-19 15:06:57 +01:00
|
|
|
// Setup the device driver descriptor
|
|
|
|
fd->interface = interface;
|
|
|
|
fd->startSector = startSector;
|
|
|
|
fd->sectorSize = 0;
|
|
|
|
fd->sectorCount = 0;
|
|
|
|
fd->cachePageCount = cachePageCount;
|
|
|
|
fd->cachePageSize = cachePageSize;
|
2010-09-16 21:59:41 +02:00
|
|
|
|
2009-12-19 15:06:57 +01:00
|
|
|
// Allocate the device driver
|
2010-09-19 01:16:05 +02:00
|
|
|
vd->dev = ntfs_device_alloc( name, 0, &ntfs_device_gekko_io_ops, fd );
|
|
|
|
if ( !vd->dev )
|
|
|
|
{
|
|
|
|
ntfs_free( fd );
|
|
|
|
ntfs_free( vd );
|
2009-12-19 15:06:57 +01:00
|
|
|
return false;
|
|
|
|
}
|
2010-09-16 21:59:41 +02:00
|
|
|
|
2009-12-19 15:06:57 +01:00
|
|
|
// Build the mount flags
|
2010-09-19 01:16:05 +02:00
|
|
|
if ( flags & NTFS_READ_ONLY )
|
|
|
|
vd->flags |= MS_RDONLY;
|
2010-02-09 11:59:55 +01:00
|
|
|
else
|
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
if ( !( interface->features & FEATURE_MEDIUM_CANWRITE ) )
|
|
|
|
vd->flags |= MS_RDONLY;
|
|
|
|
if ( ( interface->features & FEATURE_MEDIUM_CANREAD ) && ( interface->features & FEATURE_MEDIUM_CANWRITE ) )
|
|
|
|
vd->flags |= MS_EXCLUSIVE;
|
2010-02-01 00:14:14 +01:00
|
|
|
}
|
2010-09-19 01:16:05 +02:00
|
|
|
if ( flags & NTFS_RECOVER )
|
2009-12-19 15:06:57 +01:00
|
|
|
vd->flags |= MS_RECOVER;
|
2010-09-19 01:16:05 +02:00
|
|
|
if ( flags & NTFS_IGNORE_HIBERFILE )
|
2009-12-19 15:06:57 +01:00
|
|
|
vd->flags |= MS_IGNORE_HIBERFILE;
|
2010-09-16 21:59:41 +02:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
if ( vd->flags & MS_RDONLY )
|
|
|
|
ntfs_log_debug( "Mounting \"%s\" as read-only\n", name );
|
2010-09-16 21:59:41 +02:00
|
|
|
|
2009-12-19 15:06:57 +01:00
|
|
|
// Mount the device
|
2010-09-19 01:16:05 +02:00
|
|
|
vd->vol = ntfs_device_mount( vd->dev, vd->flags );
|
|
|
|
if ( !vd->vol )
|
|
|
|
{
|
|
|
|
switch ( ntfs_volume_error( errno ) )
|
|
|
|
{
|
2010-02-09 11:59:55 +01:00
|
|
|
case NTFS_VOLUME_NOT_NTFS: errno = EINVALPART; break;
|
|
|
|
case NTFS_VOLUME_CORRUPT: errno = EINVALPART; break;
|
|
|
|
case NTFS_VOLUME_HIBERNATED: errno = EHIBERNATED; break;
|
|
|
|
case NTFS_VOLUME_UNCLEAN_UNMOUNT: errno = EDIRTY; break;
|
|
|
|
default: errno = EINVAL; break;
|
2009-12-19 15:06:57 +01:00
|
|
|
}
|
2010-09-19 01:16:05 +02:00
|
|
|
ntfs_device_free( vd->dev );
|
|
|
|
ntfs_free( vd );
|
2009-12-19 15:06:57 +01:00
|
|
|
return false;
|
|
|
|
}
|
2010-09-16 21:59:41 +02:00
|
|
|
|
2009-12-19 15:06:57 +01:00
|
|
|
// Initialise the volume descriptor
|
2010-09-19 01:16:05 +02:00
|
|
|
if ( ntfsInitVolume( vd ) )
|
|
|
|
{
|
|
|
|
ntfs_umount( vd->vol, true );
|
|
|
|
ntfs_free( vd );
|
2009-12-19 15:06:57 +01:00
|
|
|
return false;
|
|
|
|
}
|
2010-09-16 21:59:41 +02:00
|
|
|
|
2009-12-19 15:06:57 +01:00
|
|
|
// Add the device to the devoptab table
|
2010-09-19 01:16:05 +02:00
|
|
|
if ( ntfsAddDevice( name, vd ) )
|
|
|
|
{
|
|
|
|
ntfsDeinitVolume( vd );
|
|
|
|
ntfs_umount( vd->vol, true );
|
|
|
|
ntfs_free( vd );
|
2009-12-19 15:06:57 +01:00
|
|
|
return false;
|
|
|
|
}
|
2010-09-16 21:59:41 +02:00
|
|
|
|
2009-12-19 15:06:57 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
void ntfsUnmount ( const char *name, bool force )
|
2010-02-09 11:59:55 +01:00
|
|
|
{
|
2009-12-19 15:06:57 +01:00
|
|
|
ntfs_vd *vd = NULL;
|
|
|
|
|
|
|
|
// Get the devices volume descriptor
|
2010-09-19 01:16:05 +02:00
|
|
|
vd = ntfsGetVolume( name );
|
|
|
|
if ( !vd )
|
2009-12-19 15:06:57 +01:00
|
|
|
return;
|
2010-09-16 21:59:41 +02:00
|
|
|
|
2009-12-19 15:06:57 +01:00
|
|
|
// Remove the device from the devoptab table
|
2010-09-19 01:16:05 +02:00
|
|
|
ntfsRemoveDevice( name );
|
2010-09-16 21:59:41 +02:00
|
|
|
|
2009-12-19 15:06:57 +01:00
|
|
|
// Deinitialise the volume descriptor
|
2010-09-19 01:16:05 +02:00
|
|
|
ntfsDeinitVolume( vd );
|
2010-09-16 21:59:41 +02:00
|
|
|
|
2009-12-19 15:06:57 +01:00
|
|
|
// Unmount the volume
|
2010-09-19 01:16:05 +02:00
|
|
|
ntfs_umount( vd->vol, force );
|
2010-09-16 21:59:41 +02:00
|
|
|
|
2009-12-19 15:06:57 +01:00
|
|
|
// Free the volume descriptor
|
2010-09-19 01:16:05 +02:00
|
|
|
ntfs_free( vd );
|
2010-09-16 21:59:41 +02:00
|
|
|
|
2009-12-19 15:06:57 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
const char *ntfsGetVolumeName ( const char *name )
|
2010-02-09 11:59:55 +01:00
|
|
|
{
|
2009-12-19 15:06:57 +01:00
|
|
|
ntfs_vd *vd = NULL;
|
2010-02-01 00:14:14 +01:00
|
|
|
//ntfs_attr *na = NULL;
|
|
|
|
//ntfschar *ulabel = NULL;
|
|
|
|
//char *volumeName = NULL;
|
2010-09-16 21:59:41 +02:00
|
|
|
|
2009-12-19 15:06:57 +01:00
|
|
|
// Sanity check
|
2010-09-19 01:16:05 +02:00
|
|
|
if ( !name )
|
|
|
|
{
|
2009-12-19 15:06:57 +01:00
|
|
|
errno = EINVAL;
|
|
|
|
return NULL;
|
|
|
|
}
|
2010-09-16 21:59:41 +02:00
|
|
|
|
2009-12-19 15:06:57 +01:00
|
|
|
// Get the devices volume descriptor
|
2010-09-19 01:16:05 +02:00
|
|
|
vd = ntfsGetVolume( name );
|
|
|
|
if ( !vd )
|
|
|
|
{
|
2009-12-19 15:06:57 +01:00
|
|
|
errno = ENODEV;
|
2010-02-01 00:14:14 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return vd->vol->vol_name;
|
2010-09-19 01:16:05 +02:00
|
|
|
/*
|
2010-09-16 21:59:41 +02:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
// If the volume name has already been cached then just use that
|
|
|
|
if (vd->name[0])
|
|
|
|
return vd->name;
|
2010-09-16 21:59:41 +02:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
// Lock
|
|
|
|
ntfsLock(vd);
|
2010-09-16 21:59:41 +02:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
// Check if the volume name attribute exists
|
|
|
|
na = ntfs_attr_open(vd->vol->vol_ni, AT_VOLUME_NAME, NULL, 0);
|
|
|
|
if (!na) {
|
|
|
|
ntfsUnlock(vd);
|
|
|
|
errno = ENOENT;
|
|
|
|
return false;
|
|
|
|
}
|
2010-02-09 07:33:18 +01:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
// Allocate a buffer to store the raw volume name
|
|
|
|
ulabel = ntfs_alloc(na->data_size * sizeof(ntfschar));
|
|
|
|
if (!ulabel) {
|
|
|
|
ntfsUnlock(vd);
|
|
|
|
errno = ENOMEM;
|
|
|
|
return false;
|
|
|
|
}
|
2010-09-16 21:59:41 +02:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
// Read the volume name
|
|
|
|
if (ntfs_attr_pread(na, 0, na->data_size, ulabel) != na->data_size) {
|
|
|
|
ntfs_free(ulabel);
|
|
|
|
ntfsUnlock(vd);
|
|
|
|
errno = EIO;
|
|
|
|
return false;
|
|
|
|
}
|
2010-02-01 00:14:14 +01:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
// Convert the volume name to the current local
|
|
|
|
if (ntfsUnicodeToLocal(ulabel, na->data_size, &volumeName, 0) < 0) {
|
|
|
|
errno = EINVAL;
|
|
|
|
ntfs_free(ulabel);
|
|
|
|
ntfsUnlock(vd);
|
|
|
|
return false;
|
|
|
|
}
|
2010-02-01 00:14:14 +01:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
// If the volume name was read then cache it (for future fetches)
|
|
|
|
if (volumeName)
|
|
|
|
strcpy(vd->name, volumeName);
|
2010-09-16 21:59:41 +02:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
// Close the volume name attribute
|
|
|
|
if (na)
|
|
|
|
ntfs_attr_close(na);
|
2010-02-09 11:59:55 +01:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
// Clean up
|
|
|
|
ntfs_free(volumeName);
|
|
|
|
ntfs_free(ulabel);
|
2010-09-16 21:59:41 +02:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
// Unlock
|
|
|
|
ntfsUnlock(vd);
|
2010-09-16 21:59:41 +02:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
return vd->name;
|
|
|
|
*/
|
2009-12-19 15:06:57 +01:00
|
|
|
}
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
bool ntfsSetVolumeName ( const char *name, const char *volumeName )
|
2010-02-09 11:59:55 +01:00
|
|
|
{
|
2009-12-19 15:06:57 +01:00
|
|
|
ntfs_vd *vd = NULL;
|
|
|
|
ntfs_attr *na = NULL;
|
|
|
|
ntfschar *ulabel = NULL;
|
|
|
|
int ulabel_len;
|
2010-09-16 21:59:41 +02:00
|
|
|
|
2009-12-19 15:06:57 +01:00
|
|
|
// Sanity check
|
2010-09-19 01:16:05 +02:00
|
|
|
if ( !name )
|
|
|
|
{
|
2009-12-19 15:06:57 +01:00
|
|
|
errno = EINVAL;
|
|
|
|
return false;
|
|
|
|
}
|
2010-09-16 21:59:41 +02:00
|
|
|
|
2009-12-19 15:06:57 +01:00
|
|
|
// Get the devices volume descriptor
|
2010-09-19 01:16:05 +02:00
|
|
|
vd = ntfsGetVolume( name );
|
|
|
|
if ( !vd )
|
|
|
|
{
|
2009-12-19 15:06:57 +01:00
|
|
|
errno = ENODEV;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Lock
|
2010-09-19 01:16:05 +02:00
|
|
|
ntfsLock( vd );
|
2010-09-16 21:59:41 +02:00
|
|
|
|
2009-12-19 15:06:57 +01:00
|
|
|
// Convert the new volume name to unicode
|
2010-09-19 01:16:05 +02:00
|
|
|
ulabel_len = ntfsLocalToUnicode( volumeName, &ulabel ) * sizeof( ntfschar );
|
|
|
|
if ( ulabel_len < 0 )
|
|
|
|
{
|
|
|
|
ntfsUnlock( vd );
|
2009-12-19 15:06:57 +01:00
|
|
|
errno = EINVAL;
|
|
|
|
return false;
|
|
|
|
}
|
2010-09-16 21:59:41 +02:00
|
|
|
|
2009-12-19 15:06:57 +01:00
|
|
|
// Check if the volume name attribute exists
|
2010-09-19 01:16:05 +02:00
|
|
|
na = ntfs_attr_open( vd->vol->vol_ni, AT_VOLUME_NAME, NULL, 0 );
|
|
|
|
if ( na )
|
|
|
|
{
|
2010-09-16 21:59:41 +02:00
|
|
|
|
2009-12-19 15:06:57 +01:00
|
|
|
// It does, resize it to match the length of the new volume name
|
2010-09-19 01:16:05 +02:00
|
|
|
if ( ntfs_attr_truncate( na, ulabel_len ) )
|
|
|
|
{
|
|
|
|
ntfs_free( ulabel );
|
|
|
|
ntfsUnlock( vd );
|
2009-12-19 15:06:57 +01:00
|
|
|
return false;
|
|
|
|
}
|
2010-09-16 21:59:41 +02:00
|
|
|
|
2009-12-19 15:06:57 +01:00
|
|
|
// Write the new volume name
|
2010-09-19 01:16:05 +02:00
|
|
|
if ( ntfs_attr_pwrite( na, 0, ulabel_len, ulabel ) != ulabel_len )
|
|
|
|
{
|
|
|
|
ntfs_free( ulabel );
|
|
|
|
ntfsUnlock( vd );
|
2009-12-19 15:06:57 +01:00
|
|
|
return false;
|
|
|
|
}
|
2010-09-16 21:59:41 +02:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-09-16 21:59:41 +02:00
|
|
|
|
2009-12-19 15:06:57 +01:00
|
|
|
// It doesn't, create it now
|
2010-09-19 01:16:05 +02:00
|
|
|
if ( ntfs_attr_add( vd->vol->vol_ni, AT_VOLUME_NAME, NULL, 0, ( u8* )ulabel, ulabel_len ) )
|
|
|
|
{
|
|
|
|
ntfs_free( ulabel );
|
|
|
|
ntfsUnlock( vd );
|
2009-12-19 15:06:57 +01:00
|
|
|
return false;
|
|
|
|
}
|
2010-09-16 21:59:41 +02:00
|
|
|
|
2009-12-19 15:06:57 +01:00
|
|
|
}
|
|
|
|
|
2010-02-01 00:14:14 +01:00
|
|
|
// Reset the volumes name cache (as it has now been changed)
|
|
|
|
vd->name[0] = '\0';
|
2010-09-16 21:59:41 +02:00
|
|
|
|
2009-12-19 15:06:57 +01:00
|
|
|
// Close the volume name attribute
|
2010-09-19 01:16:05 +02:00
|
|
|
if ( na )
|
|
|
|
ntfs_attr_close( na );
|
2010-09-16 21:59:41 +02:00
|
|
|
|
2009-12-19 15:06:57 +01:00
|
|
|
// Sync the volume node
|
2010-09-19 01:16:05 +02:00
|
|
|
if ( ntfs_inode_sync( vd->vol->vol_ni ) )
|
|
|
|
{
|
|
|
|
ntfs_free( ulabel );
|
|
|
|
ntfsUnlock( vd );
|
2009-12-19 15:06:57 +01:00
|
|
|
return false;
|
|
|
|
}
|
2010-09-16 21:59:41 +02:00
|
|
|
|
2009-12-19 15:06:57 +01:00
|
|
|
// Clean up
|
2010-09-19 01:16:05 +02:00
|
|
|
ntfs_free( ulabel );
|
2010-09-16 21:59:41 +02:00
|
|
|
|
2009-12-19 15:06:57 +01:00
|
|
|
// Unlock
|
2010-09-19 01:16:05 +02:00
|
|
|
ntfsUnlock( vd );
|
2010-09-16 21:59:41 +02:00
|
|
|
|
2009-12-19 15:06:57 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
const devoptab_t *ntfsGetDevOpTab ( void )
|
2010-02-09 11:59:55 +01:00
|
|
|
{
|
2009-12-19 15:06:57 +01:00
|
|
|
return &devops_ntfs;
|
|
|
|
}
|