Exemplo n.º 1
0
int checkout_commit(const char* commit_id) {
  /* COMPLETE THE REST */
  if (!strcmp(commit_id, "0000000000000000000000000000000000000000")) {
    delete_tracked_files();
    //write_string_to_file(".beargit/.index", "");
    FILE *index_new = fopen(".beargit/.index", "w");
    fclose(index_new);
    write_string_to_file(".beargit/.prev", commit_id);
    return 0;

  }

  delete_tracked_files();
  char path[BEARGIT_LENGTH + COMMIT_ID_SIZE + 7];
  sprintf(path, ".beargit/%s/.index", commit_id);
  load_files_from_commit(commit_id);
  fs_cp(path, ".beargit/.index");
  // sprintf(path, ".beargit/%s/.prev", commit_id);
  // fs_cp(commit_id, ".beargit/.prev");
  write_string_to_file(".beargit/.prev", commit_id);



  return 0;
}
Exemplo n.º 2
0
int parse_soa(unsigned char *data, unsigned short data_len, unsigned char *dns, char *output_buf, size_t output_buf_size)
{
    char write_buffer[1024] = {0};
    unsigned char name[1024] = {0};
    unsigned int p = 0;

    p = readSOA(data, dns, name, data_len);
    int offset = snprintf(write_buffer, sizeof(write_buffer), " %s ", name);

    memset(name, 0, 1024);
    p = readSOA(data + p + 1, dns, name, data_len - p - 1);
    write_string_to_file(output_buf, output_buf_size, name);

    unsigned int serial_no = parse_to_uint(data + p + 3);
    unsigned int refresh = parse_to_uint(data + p + 7);
    unsigned int retry = parse_to_uint(data + p + 11);
    unsigned int expire = parse_to_uint(data + p + 15);
    unsigned int min_ttl = parse_to_uint(data + p + 19);
    snprintf(write_buffer + offset, sizeof(write_buffer) - offset - 1, " %u %u %u %u %u", serial_no,
        refresh, retry, expire, min_ttl);

    int taken = write_string_to_file(output_buf, output_buf_size, name);
    taken += write_endl(output_buf, output_buf_size);
    return taken;
}
Exemplo n.º 3
0
void IPC::send_message(string recipient, string message_head, string message_body, bool do_log)
{
	static int lock_file_count = 0;
	string lock_file_name = "lock_" + self_name + to_string(lock_file_count);
	write_string_to_file(ipc_path + slash + lock_file_name, "");
	++lock_file_count;

	vector<string> file_name_vec = list_files_in_directory(ipc_path);

	bool found = true;
	int file_count = 0;

	while (found)
	{
		found = false;
		for (string file_name_current : file_name_vec)
			if (file_name_current == recipient + to_string(file_count))
			{
				found = true;
				++file_count;
				break;
			}
	}

	static int sent_count = 0;

	string path_new = ipc_path + slash + recipient + to_string(file_count);
	write_string_to_file(path_new, message_head + "!" + message_body);

	++sent_count;
	delete_file(ipc_path + slash + lock_file_name);
	
	// if (do_log)
		// console_log("message sent: " + recipient + " " + message_head + " " + message_body, false);
}
static void choose_default_backup_format() {
    static char* headers[] = {  "Default Backup Format",
                                "",
                                NULL
    };

    char **list;
    char* list_tar_default[] = { "tar (default)",
        "dup",
        NULL
    };
    char* list_dup_default[] = { "tar",
        "dup (default)",
        NULL
    };

    if (nandroid_get_default_backup_format() == NANDROID_BACKUP_FORMAT_DUP) {
        list = list_dup_default;
    } else {
        list = list_tar_default;
    }

    int chosen_item = get_menu_selection(headers, list, 0, 0);
    switch (chosen_item) {
        case 0:
            write_string_to_file(NANDROID_BACKUP_FORMAT_FILE, "tar");
            ui_print("Default backup format set to tar.\n");
            break;
        case 1:
            write_string_to_file(NANDROID_BACKUP_FORMAT_FILE, "dup");
            ui_print("Default backup format set to dedupe.\n");
            break;
    }
}
Exemplo n.º 5
0
int beargit_init(void) {
  fs_mkdir(".beargit");

  FILE* findex = fopen(".beargit/.index", "w");
  fclose(findex);

  FILE* fbranches = fopen(".beargit/.branches", "w");
  fprintf(fbranches, "%s\n", "master");
  fclose(fbranches);

  write_string_to_file(".beargit/.prev", "0000000000000000000000000000000000000000");
  write_string_to_file(".beargit/.current_branch", "master");

  return 0;
}
Exemplo n.º 6
0
static
int offline_blacklisted_pages(nv_blacklist_addresses_t *blacklist_addresses)
{
    int index;
    int status = 0;
    char blacklisted_addr_str[BUF_SIZE];

    for (index = 0; index < blacklist_addresses->numEntries; index++) {

        sprintf(blacklisted_addr_str, "0x%"PRIx64,
                blacklist_addresses->addresses[index]);

        SYSLOG_VERBOSE(LOG_NOTICE,
                       "NUMA: retiring memory address %s\n",
                       blacklisted_addr_str);

        status = write_string_to_file(MEMORY_HARD_OFFLINE_PATH_FMT,
                                      blacklisted_addr_str,
                                      strlen(blacklisted_addr_str));
        if (status < 0) {
            syslog(LOG_ERR,
                   "NUMA: Failed to retire memory address %s: %s\n",
                   blacklisted_addr_str, strerror(-status));
            return status;
        }
    }

    return status;
}
Exemplo n.º 7
0
int main(int argc,char** argv) {
	rsa_key *r_pu, *s_pr;
	char *id,*ds,*sender_msg,*id_ds_concat;

	if(argc != 4){
		fprintf(stderr,"Usage : ./send_message input_message sender's_private_key receiver's_public_key\n");
		exit(0);
	}

	id = read_file_to_string(argv[1]);
	s_pr = get_key_from_file(argv[2]);
	r_pu = get_key_from_file(argv[3]);

	ds = create_ds(id,s_pr);
	id_ds_concat = concatenate(id,ds);

	sender_msg = pub_enc(id_ds_concat,r_pu);
	write_string_to_file("message_to_send.txt",sender_msg);

	free(id);
	free(ds);
	free(sender_msg);
	free(id_ds_concat);
	return EXIT_SUCCESS;
}
Exemplo n.º 8
0
void IPC::send_message(const string recipient, const string message_head, const string message_body)
{
	vector<string> file_name_vec = list_files_in_directory(ipc_path);

	bool found = true;
	int file_count = 0;

	while (found)
	{
		found = false;
		for (string file_name_current : file_name_vec)
			if (file_name_current == recipient + to_string(file_count))
			{
				found = true;
				++file_count;
				break;
			}
	}

	static int sent_count = 0;

	const string path_old = ipc_path + "\\s" + self_name + to_string(sent_count);
	const string path_new = ipc_path + "\\" + recipient + to_string(file_count);

	write_string_to_file(path_old, message_head + "!" + message_body);
	rename_file(path_old, path_new);

	++sent_count;

	COUT << "message sent: " << recipient << " " << message_head << " " << message_body << endl;
}
Exemplo n.º 9
0
int parse_rrsig(unsigned char *data, unsigned char *dns, unsigned short data_len, char *output_buf, size_t output_buf_size)
{
    char write_buffer[1024] = {0};

    // TODO CONVERT TIME
    unsigned short type = ((*(data) << 8) & 0xFF00) | (*(data + 1) & 0xFF);
    unsigned char algorithm = *(data + 2) & 0xFF;
    unsigned char labels = *(data + 3) & 0xFF;
    unsigned int ttl = parse_to_uint(data + 4);
    unsigned int timestamp_exp = parse_to_uint(data + 8);
    unsigned int timestamp_inc = parse_to_uint(data + 12);
    unsigned short key_tag = type = ((*(data + 16) << 8) & 0xFF00) | (*(data + 17) & 0xFF);
    unsigned char name[1024] = {0};
    unsigned int p = 0;

    p = readSOA(data + 18, dns, name, data_len);

    int offset = snprintf(write_buffer, sizeof(write_buffer), "%u %u %u %u %u %u %u %s ", type,
        algorithm, labels, ttl, timestamp_exp, timestamp_inc, key_tag, name);
    int i = 0;
    while (i < data_len - p - 19)
    {
        offset += snprintf(
            write_buffer + offset, sizeof(write_buffer) - offset, "%02x", *(data + p + i + 19));
        ++i;
    }
    int taken = write_string_to_file(output_buf, output_buf_size, write_buffer);
    taken += write_endl(output_buf, output_buf_size);
    return taken;
}
Exemplo n.º 10
0
int getName(unsigned char *data, unsigned short data_len, unsigned char *dns_packet_resp, char *output_buf, size_t output_buf_size)
{
    unsigned char name[1024] = {0};
    unsigned int i = 0, j = 0, p = 0;

    p = readString(data, data_len, dns_packet_resp, name);
    // printf("after readString");

    // now convert 3www6google3com0 to www.google.com
    for (i = 0; i < (int)strlen((const char *)name); i++)
    {
        p = name[i];
        for (j = 0; j < (int)p; j++)
        {
            name[i] = name[i + 1];
            i = i + 1;
        }
        name[i] = '.';
    }
    if (i > 0)
    {
        name[i - 1] = '\0'; // remove the last dot
    }

    return write_string_to_file(output_buf, output_buf_size, name);
}
Exemplo n.º 11
0
static
int probe_node_memory(uint64_t probe_base_addr, uint64_t region_gpu_size,
                      uint64_t memblock_size)
{
    int status = 0;
    int memory_num;
    char start_addr_str[BUF_SIZE];
    char memory_file_str[BUF_SIZE];
    uint64_t start_addr, numa_end_addr;

    numa_end_addr = probe_base_addr + region_gpu_size;

    if ((!NV_IS_ALIGNED(probe_base_addr, memblock_size)) ||
        (!NV_IS_ALIGNED(numa_end_addr, memblock_size))) {
        syslog(LOG_ERR, "NUMA: Probe ranges not aligned to memblock size!\n");
        return -EFAULT;
    }

    for (start_addr = probe_base_addr;
         start_addr + memblock_size <= numa_end_addr;
         start_addr += memblock_size) {

        sprintf(start_addr_str, "0x%"PRIx64, start_addr);

        SYSLOG_VERBOSE(LOG_DEBUG, "NUMA: Probing memory address %s\n",
                       start_addr_str);

        status = write_string_to_file(MEMORY_PROBE_PATH_FMT, start_addr_str,
                                      strlen(start_addr_str));

        memory_num = start_addr / memblock_size;
        sprintf(memory_file_str, MEMBLK_DIR_PATH_FMT, memory_num);

        /* Check if memory node was created */
        if (access(memory_file_str, F_OK) != 0) {
            syslog(LOG_ERR,
                   "NUMA: Failed to verify memory node %d was probed: %s\n",
                   memory_num, strerror(errno));
            status = -errno;
            goto done;
        }

        if (status == -EEXIST) {
            SYSLOG_VERBOSE(LOG_INFO,
                           "NUMA: Memory address %s already probed\n",
                           start_addr_str);
            status = 0;
            continue;
        } else if (status < 0) {
            syslog(LOG_ERR,
                   "NUMA: Failed to probe memory address %s: %s\n",
                   start_addr_str, strerror(-status));
            goto done;
        }
    }

done:
    return status;
}
Exemplo n.º 12
0
int parse_nsec(unsigned char *data, unsigned char *dns, char *output_buf, size_t output_buf_size, unsigned int data_len)
{
    unsigned char name[512] = {0};
    readSOA(data, dns, name, data_len);
    int taken = write_string_to_file(output_buf, output_buf_size, name);
    taken += write_endl(output_buf, output_buf_size);
    return taken;
}
Exemplo n.º 13
0
static void
wipe_data(int confirm) {
    if (confirm && !confirm_selection( "Confirm wipe of all user data?", "Yes - Wipe all user data"))
        return;
    ui_print("\n-- Wiping data...\n");
    erase_volume("/cache");
    ensure_path_mounted("/cache");
    write_string_to_file(UBUNTU_COMMAND_FILE, "format data\n");
    reboot_main_system(ANDROID_RB_RESTART2, 0, "recovery");
}
Exemplo n.º 14
0
int parse_ip(unsigned char *data, char *output_buf, size_t output_buf_size)
{
    char write_buffer[1024] = {0};
    snprintf(write_buffer, sizeof(write_buffer), "%d.%d.%d.%d", (int)*data, (int)*(data + 1),
        (int)*(data + 2), (int)*(data + 3));

    int taken = write_string_to_file(output_buf, output_buf_size, write_buffer);
    taken += write_endl(output_buf, output_buf_size);
    return taken;
}
Exemplo n.º 15
0
int checkout_commit(const char* commit_id) {
    /* COMPLETE THE REST */
    // Going through the index of the current index file,
    // delete all those files (in the current directory;
    // i.e., the directory where we ran beargit).

    //sprintf(current_index_file, ".beargit/.index/%s", commit_id);

    // fs_rm(".beargit/.index");
    if (strcmp(commit_id, init_id) != 0) {
        FILE* findex = fopen(".beargit/.index", "r");
        FILE *findex_w = fopen(".beargit/.index", "w");
        char line[FILENAME_SIZE];
        while(fgets(line, sizeof(line), findex)) {
            strtok(line, "\n"); /* Split string to files */
            fs_rm(line);
        }
        fclose(findex);

        // Copy the index from the commit that is being
        // checked out to the .beargit directory, and use
        // it to copy all that commit's tracked files from
        // the commit's directory into the current directory.
        char newindex_dir[FILENAME_SIZE];
        strcpy(newindex_dir, ".beargit/"); // .beargit/
        strcat(newindex_dir, commit_id); // .beargit/<new_ID>
        strcat(newindex_dir, "/.index"); // .beargit/<new_ID>/.index
        FILE *fnewindex = fopen(newindex_dir, "r");
        char rec_file[FILENAME_SIZE];
        char direc[FILENAME_SIZE+15];
        fs_cp(newindex_dir, ".beargit/.index");

        while(fgets(rec_file, sizeof(rec_file), fnewindex)) {
            strtok(rec_file, "\n"); /* Split string to files */
            sprintf(direc, ".beargit/%s/%s", commit_id, rec_file);
            fs_cp(direc, rec_file);
        }
        fclose(fnewindex);
        fclose(findex_w);
    } else {
        FILE* findex = fopen(".beargit/.index", "r");
        FILE *findex_w = fopen(".beargit/.index", "w");
        char line[FILENAME_SIZE];
        while(fgets(line, sizeof(line), findex)) {
            strtok(line, "\n"); /* Split string to files */
            fs_rm(line);
        }
        fclose(findex);
        fclose(findex_w);
    }
    // Write the ID of the commit that is being checked
    // out into .prev.
    write_string_to_file(".beargit/.prev", commit_id);
    return 0;
}
Exemplo n.º 16
0
void IPC::run_js(vector<string> lines)
{
	string recipient = "menu_plus";
	string message_head = "//evaluate javascript";
	string message_body = "";
	for(string& line : lines)
		message_body += line + "\n";

	static int lock_file_count = 0;
	string lock_file_name = "lock_" + self_name + to_string(lock_file_count);
	write_string_to_file(ipc_path + slash + lock_file_name, "");
	++lock_file_count;

	vector<string> file_name_vec = list_files_in_directory(ipc_path);

	bool found = true;
	int file_count = 0;

	while (found)
	{
		found = false;
		for (string file_name_current : file_name_vec)
			if (file_name_current == recipient + to_string(file_count))
			{
				found = true;
				++file_count;
				break;
			}
	}

	static int sent_count = 0;

	string path_new = ipc_path + slash + recipient + to_string(file_count);

	message_body = "//" + path_new + "\n" + message_body;
	write_string_to_file(path_new, message_head + "!" + message_body);

	++sent_count;
	delete_file(ipc_path + slash + lock_file_name);
	
	// console_log("message sent: " + recipient + " " + message_head + " " + message_body, false);
}
Exemplo n.º 17
0
int parse_aaaa(unsigned char *data, char *output_buf, size_t output_buf_size)
{
    char ipv6_buffer[1024] = {0};
    snprintf(ipv6_buffer, sizeof(ipv6_buffer),
        "%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x", *(data),
        *(data + 1), *(data + 2), *(data + 3), *(data + 4), *(data + 5), *(data + 6), *(data + 7),
        *(data + 8), *(data + 9), *(data + 10), *(data + 11), *(data + 12), *(data + 13),
        *(data + 14), *(data + 15));
    int taken = write_string_to_file(output_buf, output_buf_size, ipv6_buffer);
    taken += write_endl(output_buf, output_buf_size);
    return taken;
}
Exemplo n.º 18
0
int parse_afsdb(unsigned char *data, unsigned char *dns, char *output_buf, size_t output_buf_size, unsigned int data_len)
{
    char write_buffer[1024] = {0};
    unsigned short subtype = parse_to_ushort(data);
    unsigned char hostname[1024] = {0};
    readSOA(data + 2, dns, hostname, data_len);
    snprintf(write_buffer, sizeof(write_buffer), "%u %s", subtype, hostname);

    int taken = write_string_to_file(output_buf, output_buf_size, write_buffer);
    taken += write_endl(output_buf, output_buf_size);
    return taken;
}
Exemplo n.º 19
0
int write_string_file(const char *fn, const char *line) {
        _cleanup_fclose_ FILE *f = NULL;

        assert(fn);
        assert(line);

        f = fopen(fn, "we");
        if (!f)
                return -errno;

        return write_string_to_file(f, line);
}
static void choose_backup_format() {
    static char* headers[] = {  "Backup Format",
                                "",
                                NULL
                             };

    char* list[] = { "dup (default)",
                     "tar"
                   };

    int chosen_item = get_menu_selection(headers, list, 0, 0);
    switch (chosen_item) {
    case 0:
        write_string_to_file(NANDROID_BACKUP_FORMAT_FILE, "dup");
        ui_print("Backup format set to dedupe.\n");
        break;
    case 1:
        write_string_to_file(NANDROID_BACKUP_FORMAT_FILE, "tar");
        ui_print("Backup format set to tar.\n");
        break;
    }
}
Exemplo n.º 21
0
/*
static int read_string_from_file(const char *fname, char *buf, int len)
{
  int fd, ret;

  if (!fname || !buf || len <= 0)
    return -1;

  fd = open(fname, O_RDONLY);
  if (fd < 0) {
    perr("Cannot open %s.\n", fname);
    return -1;
  }

  ret = read(fd, buf, len);
  close(fd);
  return ret;
}
*/
static int enable_manage_start_stop(char *devname)
{
  char fname[PATH_MAX];
  int fd;
  int ret;

  if (!devname)
    return 1;

  if (sysfs_scsi_disk_handle(devname, fname, "manage_start_stop") == NULL)
    return 1;
  return write_string_to_file(fname, "1");
}
Exemplo n.º 22
0
int parse_srv(unsigned char *data, unsigned char *dns, char *output_buf, size_t output_buf_size, unsigned int data_len)
{
    char write_buffer[1024] = {0};
    unsigned short priority = parse_to_ushort(data);
    unsigned short weight = parse_to_ushort(data + 2);
    unsigned short port = parse_to_ushort(data + 4);
    unsigned char name[512] = {0};
    readSOA(data + 6, dns, name, data_len);
    snprintf(write_buffer, sizeof(write_buffer), "%u %u %u %s", priority, weight, port, name);

    int taken = write_string_to_file(output_buf, output_buf_size, write_buffer);
    taken += write_endl(output_buf, output_buf_size);
    return taken;
}
Exemplo n.º 23
0
/*
 * Brings memory block online/offline using the sysfs memory-hotplug interface
 *   https://www.kernel.org/doc/Documentation/memory-hotplug.txt
 */
static
int change_memblock_state(uint32_t mem_block_id, mem_state_t new_state)
{
    int status = 0;
    const char *cmd;
    mem_state_t cur_state;
    char buf[BUF_SIZE];
    char numa_file_path[BUF_SIZE];

    sprintf(numa_file_path, MEMBLK_STATE_PATH_FMT, mem_block_id);

    status = read_string_from_file(numa_file_path, buf, sizeof(buf));
    if (status < 0)
        goto done;

    cur_state = !!strstr(buf, STATE_ONLINE) ?
                NV_IOCTL_NUMA_STATUS_ONLINE : NV_IOCTL_NUMA_STATUS_OFFLINE;

    if (cur_state == new_state)
        goto done;

    switch (new_state)
    {
        case NV_IOCTL_NUMA_STATUS_ONLINE:
            cmd = BRING_ONLINE_CMD;
            break;
        case NV_IOCTL_NUMA_STATUS_OFFLINE:
            cmd = BRING_OFFLINE_CMD;
            break;
        default:
            return -EINVAL;
    }

    status = write_string_to_file(numa_file_path, cmd, strlen(cmd));

done:
    if (status == 0) {
        SYSLOG_VERBOSE(LOG_DEBUG,
                       "NUMA: Successfully changed memblock state of %s to %s\n",
                       numa_file_path, mem_state_to_string(new_state));
    }
    else {
        SYSLOG_VERBOSE(LOG_DEBUG,
                       "NUMA: Failed to change state of %s to %s: %s\n",
                       numa_file_path, mem_state_to_string(new_state),
                       strerror(-status));
    }

    return status;
}
Exemplo n.º 24
0
int beargit_commit(const char* msg) {
  if (!is_commit_msg_ok(msg)) {
    fprintf(stderr, "ERROR:  Message must contain \"%s\"\n", go_bears);
    return 1;
  }

  char commit_id[COMMIT_ID_SIZE];
  read_string_from_file(".beargit/.prev", commit_id, COMMIT_ID_SIZE);
  next_commit_id(commit_id);
  //fprintf(stdout, "Before Kostya's mistake");

  /* COMPLETE THE REST */
  if(*commit_id == '\0'){
    fprintf(stderr, "ERROR:  Need to be on HEAD of a branch to commit.\n");
    return 1;
  }
  char bear_directory[BEARGIT_LENGTH + COMMIT_ID_SIZE];
  char fileNames[FILENAME_SIZE];
  sprintf(bear_directory, ".beargit/%s", commit_id);
  fs_mkdir(bear_directory);
  copy_files(".beargit/.index", bear_directory, 1);
  copy_files(".beargit/.prev", bear_directory, 1);

  FILE *tracked_files = fopen(".beargit/.index", "r");

  while(fgets(fileNames,sizeof(fileNames), tracked_files)) {
      strtok(fileNames, "\n");
      copy_files(fileNames, bear_directory, 0);
  }
  sprintf(fileNames,"%s/.msg", bear_directory);
  write_string_to_file(fileNames,msg);

  write_string_to_file(".beargit/.prev", commit_id);
  fclose(tracked_files);
  return 0;
}
Exemplo n.º 25
0
int parse_loc(unsigned char *data, char *output_buf, size_t output_buf_size)
{
    char write_buffer[1024] = {0};
    uint8_t size = (uint8_t)*data + 1;
    uint8_t version = (uint8_t)*data;
    uint8_t hor_precision = (uint8_t)*data + 2;
    uint8_t ver_precision = (uint8_t)*data + 3;
    unsigned int latitude = parse_to_uint(data + 4);
    unsigned int longitude = parse_to_uint(data + 8);
    unsigned int altitude = parse_to_uint(data + 12);
    snprintf(write_buffer, sizeof(write_buffer), "%u %u %u %u %u %u %u", version, size,
        hor_precision, ver_precision, latitude, longitude, altitude);

    int taken = write_string_to_file(output_buf, output_buf_size, write_buffer);
    taken += write_endl(output_buf, output_buf_size);
    return taken;
}
Exemplo n.º 26
0
int main() {
	string file_data;
	if (!read_file_to_string(&file_data, "blah.txt"))
	{
		printf("Could not read file.\n");
	}

	printf("file_data:\n\n%s\n\n", file_data.data);

	if (!write_string_to_file(file_data, "C:\\Users\\Lucas\\Desktop\\"))
	{
		printf("Failed to write to file.\n");
	}

	getchar();

	return 0;
}
Exemplo n.º 27
0
int checkout_commit(const char* commit_id) {
  if (strcmp(commit_id, d) == 0) { 
    FILE* findex = fopen(".beargit/.index", "r");
    char line[FILENAME_SIZE];
    while(fgets(line, sizeof(line), findex)){
      strtok(line, "\n");
      char gg[FILENAME_SIZE];
      sprintf(gg, "%s", line);  
      fs_rm(gg);
    }
    fclose(findex);
    FILE* troll = fopen(".beargit/.index", "w");
    fclose(troll);
  } else {
        
    FILE* findex = fopen(".beargit/.index", "r");
    char line[FILENAME_SIZE];
    while(fgets(line, sizeof(line), findex)){
        strtok(line, "\n");
        char gg[FILENAME_SIZE];
        sprintf(gg, "%s", line);  
        fs_rm(gg);
    }
    fclose(findex);
      char dir[FILENAME_SIZE];
      sprintf(dir, ".beargit/%s/.index", commit_id);

    fs_cp(dir, ".beargit/.index"); // commit id change
    FILE* cIndex = fopen(dir , "r");
    char cline[FILENAME_SIZE];
    while (fgets(cline,sizeof(cline),cIndex)) {
    strtok(cline, "\n");
    char fName[FILENAME_SIZE];
    sprintf(fName, ".beargit/%s/%s", commit_id, cline);
    fs_cp(fName, cline); // needs to be fixed, it's not copying
    }
    fclose(cIndex);
  }
  write_string_to_file(".beargit/.prev", commit_id);
  return 0;



}
Exemplo n.º 28
0
int gen_nandroid_md5sum(const char* backup_path) {
    char md5file[PATH_MAX];
    char** files;
    int ret = -1;
    int numFiles = 0;

    ui_print("\n>> Generating md5 sum...\n");
    ensure_path_mounted(backup_path);

    // this will exclude subfolders!
    set_gather_hidden_files(1);
    files = gather_files(backup_path, "", &numFiles);
    set_gather_hidden_files(0);
    if (numFiles == 0) {
        LOGE("No files found in backup path %s\n", backup_path);
        goto out;
    }

    // create empty md5file, overwrite existing one if we're regenerating the md5 for the backup
    sprintf(md5file, "%s/nandroid.md5", backup_path);
    write_string_to_file(md5file, "");

    int i = 0;
    for (i = 0; i < numFiles; i++) {
        // exclude md5 and log files
        if (strcmp(BaseName(files[i]), "nandroid.md5") == 0 || strcmp(BaseName(files[i]), "recovery.log") == 0)
            continue;

        ui_quick_reset_and_show_progress(1, 0);
        ui_print("  > %s\n", BaseName(files[i]));
        if (write_md5digest(files[i], md5file, 1) < 0)
            goto out;
    }

    ret = 0;

out:
    ui_reset_progress();
    free_string_array(files);
    if (ret != 0)
        LOGE("Error while generating md5 sum!\n");

    return ret;
}
Exemplo n.º 29
0
int remove_hdd(char *devname, const char *sas_addr_attr)
{
  char sysfs_handle[PATH_MAX];
  char sys_disk_device_path[PATH_MAX];  /* /sys/block/sdX/device */
  char sys_device_path[PATH_MAX];  /* /sys/devices/X, for wait_device_delete */
  char *shortname = dev_short_name(devname);
  char file_read_buf[256] = {0};
  int read_len;

  if (!devname || !shortname || !sas_addr_attr)
    return 1;

  if (enable_manage_start_stop(devname)) {
    perr("Failed to enable manage_start_stop for device %s.\n", devname);
  }

  snprintf(sys_disk_device_path, PATH_MAX, "/sys/block/%s/device/", shortname);
  if (!realpath(sys_disk_device_path, sys_device_path)) {
    perr("Device %s is not available.\n", sys_disk_device_path);
    return 1;
  }

/*
  snprintf(sysfs_handle, PATH_MAX, "/sys/block/%s/device/state", shortname);

  if (write_string_to_file(sysfs_handle, "offline\n") != 0) {
    perr("Failed to offline device %s.\n", shortname);
    return 1;
  }

  if (wait_device_busy_zero(shortname, 30) != 0) {
    perr("Failed to drain IO for %s.\n", shortname);
    return 1;
  }
*/
  snprintf(sysfs_handle, PATH_MAX, "/sys/block/%s/device/delete", shortname);
  if (write_string_to_file(sysfs_handle, "1") != 0)
    perr("Failed to write 1 to %s.\n", sysfs_handle);

  return wait_device_delete(sys_device_path, 30);
}
Exemplo n.º 30
0
int parse_hinfo(unsigned char *data, unsigned short data_len, char *output_buf, size_t output_buf_size)
{
    char write_buffer[1024] = {0};
    int len_cpu = (int)*data;
    int len_os = (int)*(data + len_cpu + 1);

    int offset =
        snprintf(write_buffer, sizeof(write_buffer), "cpu len: %d os len: %d ", len_cpu, len_os);
    unsigned char algorithm = *(data + 3);
    int i = 0;
    while (i < data_len)
    {
        offset +=
            snprintf(write_buffer + offset, sizeof(write_buffer) - offset - 1, "%02x", *(data + i));
        ++i;
    }

    int taken = write_string_to_file(output_buf, output_buf_size, write_buffer);
    taken += write_endl(output_buf, output_buf_size);
    return taken;
}