www.pudn.com > efs.rar > fs_hotplug_ftl.c


/***********************************************************************
 * fs_hotplug_ftl.c
 *
 * Flash Translation Layer support for Hotplug
 * Copyright (C) 2006 QUALCOMM, Inc.
 *
 ***********************************************************************/

/*===========================================================================

                        EDIT HISTORY FOR MODULE

  This section contains comments describing changes made to the module.
  Notice that changes are listed in reverse chronological order.

  $Header: //depot/asic/MSMSHARED/services/efs/MSM_EFS.01.02/fs_hotplug_ftl.c#3 $ $DateTime: 2006/11/13 14:44:34 $ $Author: davidb $

when         who   what, where, why
----------   ---   ---------------------------------------------------------
2006-11-09   sch   Added extra write handler to the device table
2006-08-28   yg    Added reset handler
2006-06-02   s h   Added reset handler
2006-05-29   sh    Stub format function
2006-05-03   sh    Create

===========================================================================*/

#include "customer.h"
#include "fs_hotplug.h"
#include "fs_hotplug_i.h"
#include "fs_hotplug_ftl.h"

#ifdef FS_HOTPLUG_FTL

#include "fs_ftl_cache.h"
#include "assert.h"
#include "fs_public.h"
#include "fs_ftl.h"

static int ftl_initialized = 0;

int
hotplug_ftl_get_size (struct hotplug_device *hdev, uint32* pblk_cnt,
                      uint16* ppg_size)
{
  if (!ftl_initialized)
    return -1;

  return ftl_cache_get_size (hdev->driveno, pblk_cnt, ppg_size);
}


/*
 * We delay the call to ftl_init() until the first time the device
 * is probed by hotplug.  This allows faster boot-up, and for unit
 * testing that does not access FTL, no time is spent on the init
 * scan.
 */
int
hotplug_ftl_is_present (struct hotplug_device *hdev)
{
  (void) hdev;                  /* XXX: Multiple FTL devices?  */

  if (!ftl_initialized) {
    if (ftl_cache_init() == FTL_SUCCESS){ /* Perform init now */
      ftl_initialized = 1;
    }
  }

  return ftl_initialized;
}

/*
 * For Unit test, it's important to be able to 'reboot' the phone
 * and rescan the flash.  This function ensures that when hotplug
 * restarts, the FTL subsystem will also reinspect the flash
 * contents.
 */
int
hotplug_ftl_reset (struct hotplug_device *hdev)
{
  (void) hdev;

  ftl_initialized = 0;          /* Force a fresh ftl_init() */
  return 0;
}

int
hotplug_ftl_read (struct hotplug_device *hdev,
                  uint32 lba, unsigned char *buf, uint16 n_to_read)
{
  if (!ftl_initialized)
    return -1;

  return ftl_cache_read (hdev->driveno, lba, buf, n_to_read);
}

int
hotplug_ftl_write (struct hotplug_device *hdev,
                   uint32 lba, unsigned char *buf, uint16 n_to_write)
{
  if (!ftl_initialized)
    return -1;

  return ftl_cache_write (hdev->driveno, lba, buf, n_to_write);
}

int
hotplug_ftl_close (struct hotplug_device *hdev)
{
  (void) hdev;

  if (!ftl_initialized)
    return -1;

  ftl_cache_force_sync_all ();

  return 0;
}

struct hotplug_dev_funcs hotplug_ftl_dev = {
  hotplug_fat_mount,
  hotplug_success_stub,         /* open */
  hotplug_ftl_close,            /* close */
  hotplug_ftl_read,
  hotplug_ftl_write,            /* write */
  hotplug_ftl_write,            /* write user data */
  hotplug_no_erase,
  hotplug_ftl_get_size,
  hotplug_ftl_is_present,
  hotplug_success_stub,         /* format_prep */
  hotplug_ftl_reset,
};

#else
extern int __dont_complain_about_empty_file;
#endif /* FS_HOTPLUG_FTL */