Exemple #1
0
static ssize_t write_wifi_mac(const char *system_mnt_point, char *mac, size_t size)
{
	int ret;
	char i600_wifi_mac[1024], i200_wifi_mac[1024];

	text_path_cat(i200_wifi_mac, sizeof(i200_wifi_mac), system_mnt_point, I200_WIFI_MAC_FILE);

	ret = file_writeto(i200_wifi_mac, mac, size, 0, O_TRUNC);
	if (ret < 0)
	{
		print_error("file_writeto");
		return ret;
	}

	text_path_cat(i600_wifi_mac, sizeof(i600_wifi_mac), system_mnt_point, I600_WIFI_MAC_FILE);

	return file_hardlink(i600_wifi_mac, i200_wifi_mac);
}
Exemple #2
0
static ssize_t write_bt_mac(const char *system_mnt_point, char *mac, size_t size)
{
	char bt_mac_file[1024];

	if (get_bt_mac_file(system_mnt_point, bt_mac_file, sizeof(bt_mac_file)) == NULL)
	{
		ERROR_RETURN(ENOENT);
	}

	println("BT-MAC file is: %s", bt_mac_file);

	if (file_replace_line_simple(bt_mac_file, "&0001", 5, mac, size) < 0)
	{
		char buff[size + 1];

		buff[0] = '\n';

		memcpy(buff + 1, mac, size);

		return file_writeto(bt_mac_file, buff, sizeof(buff), 0, O_APPEND);
	}

	return 0;
}
Exemple #3
0
int bootimg_unpack(const char *input, const char *output, bool dt_support)
{
	int fd;
	int ret;
	int count;
	char *filename;
	char pathname[1024];
	struct bootimg_header hdr;
	struct bootimg_image images[4];

	fd = open(input, O_RDONLY);
	if (fd < 0)
	{
		pr_error_info("open file `%s'", input);
		return fd;
	}

	ret = bootimg_read_header(fd, &hdr);
	if (ret < 0)
	{
		pr_red_info("bootimg_read_header");
		goto out_close_fd;
	}

	bootimg_header_dump(&hdr);

	filename = text_copy(pathname, output);
	ret = mkdir_hierarchy(pathname, 0777);
	if (ret < 0)
	{
		pr_red_info("mkdir_hierarchy");
		goto out_close_fd;
	}

	*filename++ = '/';

	count = 0;

	if (hdr.kernel_size > 0)
	{
		images[count].size = hdr.kernel_size;
		images[count++].name = FILE_KERNEL_NAME;
	}

	if (hdr.ramdisk_size > 0)
	{
		images[count].size = hdr.ramdisk_size;
		images[count++].name = FILE_RAMDISK_NAME;
	}

	if (hdr.second_size > 0)
	{
		images[count].size = hdr.second_size;
		images[count++].name = FILE_SECOND_NAME;
	}
	else
	{
		strcpy(filename, FILE_SECOND_NAME);
		unlink(filename);
	}

	if (hdr.dt_size > 0 && dt_support)
	{
		images[count].size = hdr.dt_size;
		images[count++].name = FILE_DT_NAME;
	}
	else
	{
		strcpy(filename, FILE_DT_NAME);
		unlink(filename);
	}

	images[count].size = 0;
	images[count++].name = FILE_REMAIN_NAME;

	if (count > 0)
	{
		struct bootimg_image *p, *p_end;

		for (p = images, p_end = p + count; p < p_end; p++)
		{
			strcpy(filename, p->name);
			println("%s -> %s", p->name, pathname);

			if (p->size > 0)
			{
				ret = cavan_file_seek_next_page(fd, hdr.page_size);
				if (ret < 0)
				{
					pr_red_info("cavan_file_seek_next_page");
					goto out_close_fd;
				}

				ret = file_ncopy2(fd, pathname, p->size, O_WRONLY | O_TRUNC | O_CREAT, 0777);
			}
			else
			{
				ret = file_copy2(fd, pathname, O_WRONLY | O_TRUNC | O_CREAT, 0777);
			}

			if (ret < 0)
			{
				pr_red_info("file_copy2");
				goto out_close_fd;
			}
		}
	}

	if (hdr.cmdline[0])
	{
		strcpy(filename, FILE_CMDLINE_TXT);
		println("cmdline -> %s", pathname);

		if (hdr.extra_cmdline[0])
		{
			char *p;
			char buff[sizeof(hdr.cmdline) + sizeof(hdr.extra_cmdline)];

			p = text_copy(buff, (char *) hdr.cmdline);
			p = text_copy(p, (char *) hdr.extra_cmdline);

			ret = file_writeto(pathname, buff, p - buff, 0, O_TRUNC);
			if (ret < 0)
			{
				pr_red_info("file_writeto");
				goto out_close_fd;
			}
		}
		else
		{
			ret = file_writeto(pathname, hdr.cmdline, strlen((char *) hdr.cmdline), 0, O_TRUNC);
			if (ret < 0)
			{
				pr_red_info("file_writeto");
				goto out_close_fd;
			}
		}
	}

	strcpy(filename, FILE_REPACK_SH);

	ret = bootimg_gen_repack_script(&hdr, pathname, dt_support);
	if (ret < 0)
	{
		pr_red_info("bootimg_gen_pack_script");
		goto out_close_fd;
	}

	strcpy(filename, FILE_CONFIG_TXT);

	ret = bootimg_write_config_file(&hdr, pathname);
	if (ret < 0)
	{
		pr_red_info("bootimg_write_config_file");
		goto out_close_fd;
	}

	ret = 0;
out_close_fd:
	close(fd);
	return ret;
}
Exemple #4
0
int write_lines(const char *file_path, struct buffer *buff)
{
	return file_writeto(file_path, buff->space, buff->size, 0, O_TRUNC);
}