Exemplo n.º 1
0
/**Write the V3s superblock on disk.
 *
 * @param sbi		Pointer to the superblock structure to write on disk.
 *
 * @return		EOK on success or a negative error code.
 */
static int write_superblock3(const struct mfs_sb_info *sbi)
{
	struct mfs3_superblock *sb;
	int rc;

	sb = malloc(MFS_SUPERBLOCK_SIZE);

	if (!sb)
		return ENOMEM;

	sb->s_ninodes = (uint32_t) sbi->n_inodes;
	sb->s_nzones = (uint32_t) sbi->n_zones;
	sb->s_ibmap_blocks = (uint16_t) sbi->ibmap_blocks;
	sb->s_zbmap_blocks = (uint16_t) sbi->zbmap_blocks;
	sb->s_first_data_zone = (uint16_t) sbi->first_data_zone;
	sb->s_log2_zone_size = sbi->log2_zone_size;
	sb->s_max_file_size = sbi->max_file_size;
	sb->s_magic = sbi->magic;
	sb->s_block_size = sbi->block_size;
	sb->s_disk_version = 3;

	rc = block_write_direct(service_id, MFS_SUPERBLOCK << 1, 1 << 1, sb);
	free(sb);

	return rc;
}
Exemplo n.º 2
0
/**Write a block on disk.
 *
 * @param off		64-bit block offset on disk.
 * @param size		size of the block.
 * @param data		Pointer to the block content.
 *
 * @return		EOK on success or a negative error number.
 */
static inline int write_block(aoff64_t off, size_t size, const void *data)
{
	if (shift == 3) {
		int rc;
		aoff64_t tmp_off = off << 1;
		uint8_t *data_ptr = (uint8_t *) data;

		rc = block_write_direct(service_id, tmp_off << 2,
		    size << 2, data_ptr);

		if (rc != EOK)
			return rc;

		data_ptr += 2048;
		tmp_off++;

		return block_write_direct(service_id, tmp_off << 2,
		    size << 2, data_ptr);
	}
	return block_write_direct(service_id, off << shift,
	    size << shift, data);
}
Exemplo n.º 3
0
/** Create file system with the given parameters. */
static int fat_blocks_write(struct fat_cfg const *cfg, service_id_t service_id)
{
	aoff64_t addr;
	uint8_t *buffer;
	int i;
	uint32_t j;
	int rc;
	struct fat_bs bs;

	fat_bootsec_create(cfg, &bs);

	rc = block_write_direct(service_id, BS_BLOCK, 1, &bs);
	if (rc != EOK)
		return EIO;

	addr = BS_BLOCK + 1;

	buffer = calloc(cfg->sector_size, 1);
	if (buffer == NULL)
		return ENOMEM;
	memset(buffer, 0, cfg->sector_size);

	/* Reserved sectors */
	for (i = 0; i < cfg->reserved_sectors - 1; ++i) {
		rc = block_write_direct(service_id, addr, 1, buffer);
		if (rc != EOK)
			return EIO;

		++addr;
	}

	/* File allocation tables */
	for (i = 0; i < cfg->fat_count; ++i) {
		printf("Writing allocation table %d.\n", i + 1);

		for (j = 0; j < cfg->fat_sectors; ++j) {
			memset(buffer, 0, cfg->sector_size);
			if (j == 0) {
				buffer[0] = default_media_descriptor;
				buffer[1] = 0xFF;
				buffer[2] = 0xFF;
				if (cfg->fat_type == FAT16) {
					buffer[3] = 0xFF;
				} else if (cfg->fat_type == FAT32) {
					buffer[3] = 0x0F;
					buffer[4] = 0xFF;
					buffer[5] = 0xFF;
					buffer[6] = 0xFF;
					buffer[7] = 0x0F;
					buffer[8] = 0xF8;
					buffer[9] = 0xFF;
					buffer[10] = 0xFF;
					buffer[11] = 0x0F;
				}
			}

			rc = block_write_direct(service_id, addr, 1, buffer);
			if (rc != EOK)
				return EIO;

			++addr;
		}
	}

	/* Root directory */
	printf("Writing root directory.\n");
	memset(buffer, 0, cfg->sector_size);
	if (cfg->fat_type != FAT32) {
		size_t idx;
		for (idx = 0; idx < cfg->rootdir_sectors; ++idx) {
			rc = block_write_direct(service_id, addr, 1, buffer);
			if (rc != EOK)
				return EIO;

			++addr;
		}
	} else {
		for (i = 0; i < cfg->sectors_per_cluster; i++) {
			rc = block_write_direct(service_id, addr, 1, buffer);
			if (rc != EOK)
				return EIO;

			++addr;
		}	
	}

	free(buffer);

	return EOK;
}