Example #1
0
int32
TFFS_umount(
	IN	tffs_handle_t  htffs)
{
	tffs_t * ptffs;
	int32 ret;

	if (!htffs)
		return ERR_TFFS_INVALID_PARAM;
	
	ptffs = (tffs_t *)htffs;
	ret = TFFS_OK;

	if (ptffs->pbs)
		free(ptffs->pbs);

	if (ptffs->pfat)
		fat_destroy(ptffs->pfat);

	if (ptffs->root_dir)
		dir_destroy(ptffs->root_dir);
	
	if (ptffs->cur_dir)
		dir_destroy(ptffs->cur_dir);
	
	if (ptffs->pcache)
		ret = _cache_destroy(ptffs->pcache);

	if (ret > 0 && (HAI_closedevice(ptffs->hdev) != HAI_OK))
		ret = ERR_TFFS_DEVICE_FAIL;

	free(ptffs);

	return ret;
}
Example #2
0
static gboolean
cache_clean_foreach(const gchar* key,
                    Dir* dir, CleanData* cd)
{
  GTime last_access;

  last_access = dir_get_last_access(dir);

  if ((cd->now - last_access) >= cd->length)
    {
      if (!dir_sync_pending(dir))
        {
          dir_destroy(dir);
          return TRUE;
        }
      else
        {
          gconf_log(GCL_WARNING, _("Unable to remove directory `%s' from the XML backend cache, because it has not been successfully synced to disk"),
                    dir_get_name(dir));
          return FALSE;
        }
    }
  else
    return FALSE;
}
Example #3
0
File: file.c Project: ralt/tffs-lib
int32
TFFS_fclose(
	IN	tfile_handle_t hfile)
{
	int32 ret;
	tfile_t * pfile = (tfile_t *)hfile;

	if (!hfile)
		return ERR_TFFS_INVALID_PARAM;

	ret = TFFS_OK;
	if (file_write_sector(pfile) != FILE_OK) {
		ret = ERR_TFFS_DEVICE_FAIL;
	}

	dirent_set_file_size(pfile->pdir_entry, pfile->file_size);
	if (dir_update_direntry(pfile->pdir, pfile->pdir_entry) != DIR_OK) {
		ret = ERR_TFFS_DEVICE_FAIL;
	}

	dir_destroy(pfile->pdir);
	dirent_release(pfile->pdir_entry);
	Free(pfile->secbuf);
	Free(pfile);

	return ret;
}
Example #4
0
static void
cache_destroy_foreach(const gchar* key,
                      Dir* dir, gpointer data)
{
#ifdef GCONF_ENABLE_DEBUG
  if (dir_sync_pending (dir))
    gconf_log(GCL_DEBUG, "Destroying a directory (%s) with sync still pending",
              dir_get_name (dir));
#endif
  dir_destroy (dir);
}
Example #5
0
File: dir.c Project: mrvn/fstest
void dir_destroy_all(void) {
    vector_clear(active_dirs);
    List *dir = root_dir.list.next;
    while(dir != NULL) {
	List* t = dir->next;
	// FIXME: use container
	dir_destroy((Dir*)dir);
	dir = t;
    }
    //fprintf(stderr, "Destroying dir %s\n", root_path);
    int res = rmdir(root_path);
    if (res != 0 && errno != ENOENT) {
	perror(root_path);
    }    
}
Example #6
0
static void
cache_sync_foreach (Dir      *dir,
                    SyncData *sd)
{
  GError* error = NULL;
  gboolean deleted;
  
  deleted = FALSE;
  
  /* log errors but don't report the specific ones */
  if (!dir_sync (dir, &deleted, &error))
    {
      sd->failed = TRUE;
      g_return_if_fail (error != NULL);
      gconf_log (GCL_ERR, "%s", error->message);
      g_error_free (error);
      g_return_if_fail (dir_sync_pending (dir));
    }
  else
    {
      g_return_if_fail (error == NULL);
      g_return_if_fail (!dir_sync_pending (dir));

      if (deleted)
        {
          /* Get rid of this directory */
          cache_remove_from_parent (sd->dc, dir);
          g_hash_table_remove (sd->dc->cache,
                               dir_get_name (dir));
          cache_set_nonexistent (sd->dc, dir_get_name (dir),
                                 TRUE);
          dir_destroy (dir);

          sd->deleted_some = TRUE;
        }
    }
}
Example #7
0
int32
/* Start of GurumNetworks modification
TFFS_mount( IN  FileSystemDriver* driver, OUT tffs_handle_t * phtffs)
End of GurumNetworks modification*/
TFFS_mount( IN  FileSystemDriver* driver, int first_lba)
{
	int32 ret;
	tffs_t * tffs;
	boot_sector_t * pbs = NULL;
	DiskDriver* disk_driver = driver->driver;
	tdir_t * proot_dir = NULL;
	tdir_t * pcur_dir = NULL;
	tfat_t * pfat = NULL;
	uint32 rootdir_clus;
	void* read_buf = NULL;
	void* fat = NULL;

	/* Start of GurumNetworks modification
	tdev_handle_t hdev;
	tcache_t * pcache = NULL;
	End of GurumNetworks modification */

	/* Start of GurumNetworks modification	
	if (!dev || !phtffs)
		return ERR_TFFS_INVALID_PARAM;
	End of GurumNetworks modification */

	ret = TFFS_OK;
	tffs = (tffs_t *)malloc(sizeof(tffs_t));
	memset(tffs, 0, sizeof(tffs_t));
	pbs = (boot_sector_t *)gmalloc(sizeof(boot_sector_t));
	memset(pbs, 0, sizeof(boot_sector_t));

#ifdef _KERNEL_	
	ASSERT(sizeof(boot_sector_t) == 512);
#endif

	/* Start of GurumNetworks modification	
	hdev = HAI_initdevice(dev, 512);
	if (hdev == NULL) {
		ret = ERR_TFFS_DEVICE_FAIL;
		goto _release;
	}
	tffs->hdev = hdev;

	if (HAI_readsector(hdev, 0, (ubyte *)pbs) != HAI_OK) {
		ret = ERR_TFFS_DEVICE_FAIL;
		goto _release;
	}

	End of GurumNetworks modification */
	tffs->driver = driver;
	tffs->first_lba = first_lba;

	if(disk_driver->read(disk_driver, tffs->first_lba, 1, (void*)pbs) < 0)
		goto _release;

	tffs->pbs = pbs;
	
	if (!_validate_bs(pbs)) {
		ret = ERR_TFFS_BAD_BOOTSECTOR;
		goto _release;
	}

	_parse_boot_sector(pbs, tffs);
	DBG("tffs->fat_type:%d\n", tffs->fat_type);
	DBG("tffs->sec_fat:%d\n", tffs->sec_fat);
	DBG("tffs->sec_root_dir:%d\n", tffs->sec_root_dir);
	DBG("tffs->sec_first_data:%d\n", tffs->sec_first_data);

	if ((pfat = fat_init(tffs)) == NULL) {
		ret = ERR_TFFS_BAD_FAT;
		goto _release;
	}

	tffs->pfat = pfat;

	/* Start of GurumNetworks modification
	if ((pcache = cache_init(hdev, 32, tffs->pbs->byts_per_sec)) == NULL) {
		WARN("TFFS: cache is disable.\n");
		pcache = cache_init(hdev, 0, tffs->pbs->byts_per_sec);
	}
	tffs->pcache = pcache;
	End of GurumNetworks modification */

	rootdir_clus = tffs->fat_type == FT_FAT32 ? tffs->pbs->bh32.root_clus : ROOT_DIR_CLUS_FAT16;

	if (dir_init_by_clus(tffs, rootdir_clus, &proot_dir) != DIR_OK ||
		dir_init_by_clus(tffs, rootdir_clus, &pcur_dir) != DIR_OK) {
		ret = ERR_TFFS_DEVICE_FAIL;
		goto _release;
	}

	tffs->root_dir = proot_dir;
	tffs->cur_dir = pcur_dir;

	/* Start of GurumNetworks modification
	*phtffs = (tffs_handle_t)tffs;
	End of GurumNetworks modification */

	int i = 0;
	size_t read_size = 0;
	size_t fat_size = tffs->fatsz * pbs->byts_per_sec;
	read_buf = gmalloc(FS_BLOCK_SIZE);
	fat = bmalloc();

	while(read_size < fat_size) {
	#define MIN(x, y) (((x) < (y)) ? (x) : (y))
		if(disk_driver->read(disk_driver, tffs->sec_fat + i * FS_SECTOR_PER_BLOCK, FS_SECTOR_PER_BLOCK, read_buf) < 0) {
			ret = -99; // TODO: errno for fat error
			goto _release;
		}

		size_t copy_size = MIN(fat_size - read_size, FS_BLOCK_SIZE);
		memcpy((uint8_t*)fat + read_size, read_buf, copy_size);

		read_size += copy_size;
		i++;
	}

	tffs->fat = fat;
	DBG("tffs->fat:%p\n", tffs->fat);
	DBG("tffs->fat size:%d\n", tffs->fatsz);
	DBG("Tiny FAT file system mount OK.\n");
	driver->priv = tffs;

	gfree(read_buf);
	return ret;

_release:
	if (pfat)
		fat_destroy(pfat);
	if (proot_dir)
		dir_destroy(proot_dir);
	if (pcur_dir)
		dir_destroy(pcur_dir);
	if (HAI_closedevice(tffs->hdev) != HAI_OK)
		ret = ERR_TFFS_DEVICE_FAIL;

	if(read_buf)
		gfree(read_buf);
	if(fat)
		free(fat);

	free(pbs);
	free(tffs);

	return ret;
}
Example #8
0
File: file.c Project: ralt/tffs-lib
int32
TFFS_rmfile(
	IN	tffs_handle_t hfs,
	IN	byte * file_path)
{
	int32 ret;
    byte * fname, * path;
    byte * dup_file_path;
    tdir_t * pdir;
    tffs_t * ptffs;
	tdir_entry_t * pdir_entry;

	ret = TFFS_OK;

    if (!hfs || !file_path)
        return ERR_TFFS_INVALID_PARAM;
	
    ptffs = (tffs_t *)hfs;
    dup_file_path = dup_string(file_path);
    fname = (byte *)Malloc(DNAME_MAX);
	pdir_entry = dirent_malloc();

    path = dup_file_path;
    if (!divide_path(dup_file_path, fname)) {
        ret = ERR_TFFS_INVALID_PATH;
        goto _release;
    }

    if ((dir_init(ptffs, path, &pdir)) != DIR_OK) {
        ret = ERR_TFFS_INVALID_PATH;
        goto _release;
    }

	if ((ret = dirent_find(pdir, fname, pdir_entry)) == DIRENTRY_OK) {
		if (dirent_get_dir_attr(pdir_entry) & ATTR_DIRECTORY) {
			ret = ERR_TFFS_IS_NOT_A_FILE;
			goto _release;
		}

		if (dir_del_direntry(pdir, fname) != DIR_OK) {
			ret = ERR_TFFS_REMOVE_FILE_FAIL;
			goto _release;
		}

		if (fat_free_clus(pdir->ptffs->pfat, dirent_get_clus(pdir_entry)) != FAT_OK) {
			ret = ERR_TFFS_REMOVE_FILE_FAIL;
			goto _release;
		}
		
		ret = TFFS_OK;
	}
	else {
		ret = ERR_TFFS_NO_SUCH_FILE;
	    goto _release;
    }

_release:
	Free(fname);
	Free(dup_file_path);
	dirent_release(pdir_entry);
	dir_destroy(pdir);
	return ret;
}
Example #9
0
Dir*
cache_lookup     (Cache        *cache,
                  const gchar  *key,
                  gboolean create_if_missing,
                  GError  **err)
{
  Dir* dir;
  
  g_assert(key != NULL);
  g_return_val_if_fail(cache != NULL, NULL);
  
  /* Check cache */
  dir = g_hash_table_lookup(cache->cache, key);
  
  if (dir != NULL)
    {
      gconf_log(GCL_DEBUG, "Using dir %s from cache", key);
      return dir;
    }
  else
    {
      /* Not in cache, check whether we already failed
         to load it */
      if (cache_is_nonexistent(cache, key))
        {
          if (!create_if_missing)
            return NULL;
        }
      else
        {
          /* Didn't already fail to load, try to load */
          dir = dir_load (key, cache->root_dir, err);
          
          if (dir != NULL)
            {
              g_assert(err == NULL || *err == NULL);
              
              /* Cache it and add to parent */
              cache_insert (cache, dir);
              cache_add_to_parent (cache, dir);
              
              return dir;
            }
          else
            {
              /* Remember that we failed to load it */
              if (!create_if_missing)
                {
                  cache_set_nonexistent(cache, key, TRUE);
              
                  return NULL;
                }
              else
                {
                  if (err && *err)
                    {
                      g_error_free(*err);
                      *err = NULL;
                    }
                }
            }
        }
    }
  
  g_assert(dir == NULL);
  g_assert(create_if_missing);
  g_assert(err == NULL || *err == NULL);
  
  if (dir == NULL)
    {
      gconf_log(GCL_DEBUG, "Creating new dir %s", key);
      
      dir = dir_new(key, cache->root_dir, cache->dir_mode, cache->file_mode);

      if (!dir_ensure_exists(dir, err))
        {
          dir_destroy(dir);
          
          g_return_val_if_fail((err == NULL) ||
                               (*err != NULL) ,
                               NULL);
          return NULL;
        }
      else
        {
          cache_insert (cache, dir);
          cache_add_to_parent (cache, dir);
          cache_unset_nonexistent (cache, dir_get_name (dir));
        }
    }

  return dir;
}