Beispiel #1
0
FS_FILE* FS_FOpen(const TCHAR *pFileName, const FS_i32 Mode) 
{
  _FS_PTR * fp;

  FS_X_OS_LockFileHandle();	  

  fp = (_FS_PTR*)FS_malloc();
  if (fp == 0) {
	  FS_X_OS_UnlockFileHandle();   
	  DEBUG_PRINT("FSW_ERROR:Open %s ,but fs malloc fail \r\n",pFileName);
    return 0;  /* Device not found */
  }

  fp->error = f_open(&fp->fs.file,pFileName , Mode);

  if (fp->error!=FR_OK) 
  {
  	FS_free((void *)fp );
  	fp = 0;
  }

  FS_X_OS_UnlockFileHandle();	

  return (FS_FILE*)fp;
}
Beispiel #2
0
void FS_FClose(FS_FILE *pFile) {
  if (!pFile) {
    return;  /* No pointer to a FS_FILE structure */
  }
  FS_X_OS_LockFileHandle();
  if (!pFile->inuse) {
    FS_X_OS_UnlockFileHandle(); /* The FS_FILE structure is not in use */
    return;
  }
  if (pFile->dev_index >= 0) {
    if (FS__pDevInfo[pFile->dev_index].fs_ptr->fsl_fclose) {
      /* Execute the FSL function */
      (FS__pDevInfo[pFile->dev_index].fs_ptr->fsl_fclose)(pFile);
    }
  }
  FS_X_OS_UnlockFileHandle();
}
Beispiel #3
0
int FS_Remove(const char *pFileName) {
  FS_FARCHARPTR s;
  unsigned int i;
  int idx;
  int x;

  /* Find correct FSL  (device:unit:name) */
  idx = FS__find_fsl(pFileName, &s);
  if (idx < 0) {
    return -1;  /* Device not found */
  }
  if (FS__pDevInfo[idx].fs_ptr->fsl_fopen) {
    /*  Find next free entry in _FS_filehandle */
    FS_X_OS_LockFileHandle();
    i = 0;
    while (1) {
      if (i >= _FS_maxopen) {
        break;  /* No free file handle found */
      }
      if (!_FS_filehandle[i].inuse) {
        break;  /* Free file handle found */
      }
      i++;
    }
    if (i < _FS_maxopen) {
      /* Set file open mode to write & truncate */
      _FS_filehandle[i].mode_r = 0;
      _FS_filehandle[i].mode_w = 1;
      _FS_filehandle[i].mode_a = 0;
      _FS_filehandle[i].mode_c = 0;
      _FS_filehandle[i].mode_b = 0;
      _FS_filehandle[i].dev_index = idx;
      /* 
         Call the FSL function 'open' with the parameter 'del' to indicate,
         that we want to delete the file.
      */
      (FS__pDevInfo[idx].fs_ptr->fsl_fopen)(s, "del", &_FS_filehandle[i]);
      x = _FS_filehandle[i].error;
      FS_X_OS_UnlockFileHandle();
      return x;
    }
    FS_X_OS_UnlockFileHandle();
  }
  return -1;
}
Beispiel #4
0
FS_i32 FS_FClose(FS_FILE* pFile) 
{
  _FS_PTR * fp = (_FS_PTR *)pFile;

  if (!pFile) {
    return -1;  /* No pointer to a FS_FILE structure */
  }

  FS_X_OS_LockFileHandle();

  fp->error = f_close(&fp->fs.file);

  if(fp->error!=FR_OK)
  {
  	FS_X_OS_UnlockFileHandle();
  	return -1;
  }

  FS_free((void *)pFile);

  FS_X_OS_UnlockFileHandle();
  return 0;
}
Beispiel #5
0
FS_FILE *FS_FOpen(const char *pFileName, const char *pMode) {
  FS_FARCHARPTR s;
  FS_FILE *handle;
  unsigned int i;
  int idx;
  int j;
  int c;

  /* Find correct FSL  (device:unit:name) */
  idx = FS__find_fsl(pFileName, &s);
  if (idx < 0) {
    return 0;  /* Device not found */
  }
  if (FS__pDevInfo[idx].fs_ptr->fsl_fopen) {
    /*  Find next free entry in _FS_filehandle */
    FS_X_OS_LockFileHandle();
    i = 0;
    while (1) {
      if (i >= _FS_maxopen) {
        break;  /* No free entry found. */
      }
      if (!_FS_filehandle[i].inuse) {
        break;  /* Unused entry found */
      }
      i++;
    }
    if (i < _FS_maxopen) {
      /*
         Check for valid mode string and set flags in file
         handle
      */
      j = 0;
      while (1) {
        if (j >= FS_VALID_MODE_NUM) {
          break;  /* Not in list of valid modes */
        }
        c = FS__CLIB_strcmp(pMode, _FS_valid_modes[j].mode);
        if (c == 0) {
          break;  /* Mode found in list */
        }
        j++;
      }
      if (j < FS_VALID_MODE_NUM) {
        /* Set mode flags according to the mode string */
        _FS_filehandle[i].mode_r = _FS_valid_modes[j].mode_r;
        _FS_filehandle[i].mode_w = _FS_valid_modes[j].mode_w;
        _FS_filehandle[i].mode_a = _FS_valid_modes[j].mode_a;
        _FS_filehandle[i].mode_c = _FS_valid_modes[j].mode_c;
        _FS_filehandle[i].mode_b = _FS_valid_modes[j].mode_b;
      }
      else {
        FS_X_OS_UnlockFileHandle();
        return 0;
      }
      _FS_filehandle[i].dev_index = idx;
      /* Execute the FSL function */
      handle = (FS__pDevInfo[idx].fs_ptr->fsl_fopen)(s, pMode, &_FS_filehandle[i]);
      FS_X_OS_UnlockFileHandle();
      return handle;
    }
    FS_X_OS_UnlockFileHandle();
  }
  return 0;
}