Esempio n. 1
0
dir_partition_t dir_partition_ntfs_init(disk_t *disk_car, const partition_t *partition, dir_data_t *dir_data, const int verbose, const int expert)
{
#if defined(HAVE_LIBNTFS) || defined(HAVE_LIBNTFS3G)
  struct ntfs_device *dev;
  my_data_t *my_data=NULL;
  ntfs_volume *vol=NULL;
#ifdef NTFS_LOG_LEVEL_VERBOSE
  ntfs_log_set_levels(NTFS_LOG_LEVEL_VERBOSE);
  ntfs_log_set_handler(ntfs_log_handler_stderr);
#endif

  dev = ntfs_device_alloc("/", 0, &ntfs_device_testdisk_io_ops, NULL);
  if (dev)
  {
    my_data=(my_data_t *)MALLOC(sizeof(*my_data));
    my_data->partition=partition;
    my_data->disk_car=disk_car;
    my_data->offset=0;
    dev->d_private=my_data;
    /* Call ntfs_device_mount() to do the actual mount. */
#ifdef MS_RDONLY
    vol = ntfs_device_mount(dev, MS_RDONLY);
#else
    vol = ntfs_device_mount(dev, NTFS_MNT_RDONLY);
#endif
#ifdef HAVE_NTFS_VOLUME_STARTUP
    if(!vol) {
#ifdef MS_RDONLY
      vol = ntfs_volume_startup(dev, MS_RDONLY);
#else
      vol = ntfs_volume_startup(dev, NTFS_MNT_RDONLY);
#endif
      if(vol)
      {
	log_warning("NTFS filesystem needs to be repaired.\n");
      }
    }
#endif
  }
  if (!vol) {
    free(my_data);
    ntfs_device_free(dev);
    return DIR_PART_EIO;
  }
  if (vol->flags & VOLUME_IS_DIRTY) {
    log_warning("NTFS Volume is dirty.\n");
  }
  {
    struct ntfs_dir_struct *ls=(struct ntfs_dir_struct *)MALLOC(sizeof(*ls));
    ls->dir_list=NULL;
    ls->vol=vol;
    ls->my_data=my_data;
    ls->dir_data=dir_data;
#ifdef HAVE_ICONV
    if ((ls->cd = iconv_open("UTF-8", "UTF-16LE")) == (iconv_t)(-1))
    {
      log_error("ntfs_ucstoutf8: iconv_open failed\n");
    }
#endif
    strncpy(dir_data->current_directory,"/",sizeof(dir_data->current_directory));
    dir_data->current_inode=FILE_root;
    dir_data->param=FLAG_LIST_ADS;
    if(expert!=0)
      dir_data->param|=FLAG_LIST_SYSTEM;
    dir_data->verbose=verbose;
    dir_data->capabilities=CAPA_LIST_ADS;
    dir_data->get_dir=&ntfs_dir;
    dir_data->copy_file=&ntfs_copy;
    dir_data->close=&dir_partition_ntfs_close;
    dir_data->local_dir=NULL;
    dir_data->private_dir_data=ls;
  }
  return DIR_PART_OK;
#else
  return DIR_PART_ENOSYS;
#endif
}
Esempio n. 2
0
bool ntfsMount (const char *name, const DISC_INTERFACE *interface, sec_t startSector, u32 cachePageCount, u32 cachePageSize, u32 flags)
{
    ntfs_vd *vd = NULL;
    gekko_fd *fd = NULL;

    // Sanity check
    if (!name || !interface) {
        errno = EINVAL;
        return -1;
    }

    // Initialise ntfs-3g
    ntfsInit();

    // Check that the requested mount name is free
    if (ntfsGetDevice(name, false)) {
        errno = EADDRINUSE;
        return false;
    }

    // Check that we can at least read from this device
    if (!(interface->features & FEATURE_MEDIUM_CANREAD)) {
        errno = EPERM;
        return false;
    }

    // Allocate the volume descriptor
    vd = (ntfs_vd*)ntfs_alloc(sizeof(ntfs_vd));
    if (!vd) {
        errno = ENOMEM;
        return false;
    }

    // Setup the volume descriptor
    vd->id = interface->ioType;
    vd->flags = 0;
    vd->uid = 0;
    vd->gid = 0;
    vd->fmask = 0;
    vd->dmask = 0;
    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);

    // Allocate the device driver descriptor
    fd = (gekko_fd*)ntfs_alloc(sizeof(gekko_fd));
    if (!fd) {
        ntfs_free(vd);
        errno = ENOMEM;
        return false;
    }

    // Setup the device driver descriptor
    fd->interface = interface;
    fd->startSector = startSector;
    fd->sectorSize = 0;
    fd->sectorCount = 0;
    fd->cachePageCount = cachePageCount;
    fd->cachePageSize = cachePageSize;

    // Allocate the device driver
    vd->dev = ntfs_device_alloc(name, 0, &ntfs_device_gekko_io_ops, fd);
    if (!vd->dev) {
        ntfs_free(fd);
        ntfs_free(vd);
        return false;
    }

    // Build the mount flags
    if (flags & NTFS_READ_ONLY)
        vd->flags |= MS_RDONLY;
    else
    {
        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;
    }
    if (flags & NTFS_RECOVER)
        vd->flags |= MS_RECOVER;
    if (flags & NTFS_IGNORE_HIBERFILE)
        vd->flags |= MS_IGNORE_HIBERFILE;

    if (vd->flags & MS_RDONLY)
        ntfs_log_debug("Mounting \"%s\" as read-only\n", name);

    // Mount the device
    vd->vol = ntfs_device_mount(vd->dev, vd->flags);
    if (!vd->vol) {
        switch(ntfs_volume_error(errno)) {
        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;
        }
        ntfs_device_free(vd->dev);
        ntfs_free(vd);
        return false;
    }

    // Initialise the volume descriptor
    if (ntfsInitVolume(vd)) {
        ntfs_umount(vd->vol, true);
        ntfs_free(vd);
        return false;
    }

    // Add the device to the devoptab table
    if (ntfsAddDevice(name, vd)) {
        ntfsDeinitVolume(vd);
        ntfs_umount(vd->vol, true);
        ntfs_free(vd);
        return false;
    }

    return true;
}
Esempio n. 3
0
ntfs_vd *ntfsMount (const char *name, struct _NTFS_VOLUME *interface, sec_t startSector, u32 cachePageCount, u32 cachePageSize, u32 flags)
{
    ntfs_vd *vd = NULL;
    struct _uefi_fd *fd = NULL;
	const devoptab_t *mnt;

	//Print(L"ntfsMount %a\n", name);

	//CpuBreakpoint();

	// Sanity check
    if (!name || !interface) {
		//Print(L"ntfsMount EINVAL\n");
        errno = EINVAL;
        return false;
    }

    // Initialise ntfs-3g
	ntfsInit();

	mnt = ntfsGetDevice(name, false);

    // Check that the requested mount name is free
    if (mnt) {
		//Print(L"ntfsMount EADDRINUSE\n");
        errno = 99; //EADDRINUSE;
	
		return (ntfs_vd*) mnt->deviceData;	// previous mnt data!
    }


    // Allocate the volume descriptor
    vd = (ntfs_vd*)ntfs_alloc(sizeof(ntfs_vd));
    if (!vd) {
		//Print(L"ntfsMount ENOMEM\n");
        errno = ENOMEM;
        return false;
    }
	else {
		//Print(L"ntfsMount ntfs_vd!\n");
	}

    // Setup the volume descriptor
	//Print(L"vd.id! [%x]\n", vd);
    vd->id = 0;//interface->ioType;
    //Print(L"vd.flags!\n");
	vd->flags = 0;
    vd->uid = 0;
    vd->gid = 0;
    vd->fmask = 0;
    vd->dmask = 0;
    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);

	//Print(L"invoking ntfs_alloc!\n");
    // Allocate the device driver descriptor
    fd = (struct _uefi_fd *)ntfs_alloc(sizeof(struct _uefi_fd));
    if (!fd) {
		//Print(L"ntfsMount ENOMEM(2)\n");
		ntfs_free(vd);
        errno = ENOMEM;
        return false;
    }
	else
	{
		//Print(L"ntfs_alloc uefi_fd\n");
	}

    // Setup the device driver descriptor
    fd->interface = interface;
    fd->startSector = startSector;
    fd->sectorSize = 0x200;
	fd->sectorCount = 0x200;
    fd->cachePageCount = cachePageCount;
    fd->cachePageSize = cachePageSize;

    // Allocate the device driver
    vd->dev = ntfs_device_alloc(name, 0, &ntfs_device_uefi_io_ops, fd);
    if (!vd->dev) {
		//Print(L"ntfsMount ntfs_device_alloc failed\n");
        ntfs_free(fd);
        ntfs_free(vd);
        return false;
    }
	//Print(L"ntfs_device_alloc success\n");

    // Build the mount flags
    if (flags & NTFS_READ_ONLY)
    	vd->flags |= NTFS_MNT_RDONLY;
    
    if (flags & NTFS_RECOVER)
        vd->flags |= NTFS_MNT_RECOVER;
    if (flags & NTFS_IGNORE_HIBERFILE)
        vd->flags |= NTFS_MNT_IGNORE_HIBERFILE;

    if (vd->flags & NTFS_MNT_RDONLY)
        ntfs_log_debug("Mounting \"%s\" as read-only\n", name);

    // Mount the device
	//Print(L"Invoking ntfs_device_mount\n");
    vd->vol = ntfs_device_mount(vd->dev, vd->flags);
    if (!vd->vol) {
        switch(ntfs_volume_error(errno)) {
            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;
        }
        ntfs_device_free(vd->dev);
        ntfs_free(vd);
		//Print(L"ntfsMount ntfs_device_mount FAILED (%x)\n", errno);
        return NULL;
    }

	if (flags & NTFS_IGNORE_CASE)
		ntfs_set_ignore_case(vd->vol);

    // Initialise the volume descriptor
    if (ntfsInitVolume(vd)) {
        ntfs_umount(vd->vol, true);
        ntfs_free(vd);
		//Print(L"ntfsMount ntfsInitVolume failed\n");
        return NULL;
    }

    // Add the device to the devoptab table
    if (ntfsAddDevice(name, vd)) {
		//Print(L"ntfsMount ntfsAddDevice failed\n");
        ntfsDeinitVolume(vd);
        ntfs_umount(vd->vol, true);
        ntfs_free(vd);
        return NULL;
    }

	//Print(L"ntfsMount done.\n");
    return vd;
}