예제 #1
0
/* Move head of userqueue to feedback queues */
void enqueue_roundrobin() {
	PcbPtr process;
	while (user_queue) { // while there are items in the user queue
		if (check_resource(io_resources,user_queue) == 1 && memChk(memory,user_queue->mbytes)){ // if resources/memory can be allocated for the given process
			process = pcb_dequeue(&user_queue);
			process->memory = memAlloc(memory,process->mbytes); // allocating memory
			if (process->memory) { // making sure it is not null
				process->memory->id = process->id;
			}
			io_resources = allocate_resource(io_resources,process);
			switch (process->priority) {
				case 0:
					break;
				case 1:
					p1_queue = pcb_enqueue(p1_queue,process);
					break;
				case 2:
					p2_queue = pcb_enqueue(p2_queue,process);
					break;
				case 3:
					p3_queue = pcb_enqueue(p3_queue,process);
					break;
				default:
					fprintf(stderr, "Error. Priority not correctly set. Process ID: %d Priority: %d\n",process->id,process->priority);
					break;
			}
		}
		else { // leave the while loop when the above condition fails
			break;
		}
	}
}
예제 #2
0
static inline int check_mem_resource(unsigned long b, unsigned long n,
				     struct pci_dev *dev)
{
	b += ISAMEM_PHYS;
	return check_resource(resource_parent(b, n, IORESOURCE_MEM, dev), b, n);
}
예제 #3
0
static inline int check_io_resource(unsigned long b, unsigned long n,
				    struct pci_dev *dev)
{
	return check_resource(resource_parent(b, n, IORESOURCE_IO, dev), b, n);
}
예제 #4
0
파일: fwup_verify.c 프로젝트: fhunleth/fwup
/**
 * @brief Verify that the firmware archive is ok
 * @param input_filename the firmware update filename
 * @param public_keys the public keys if authentication check
 * @return 0 if successful
 */
int fwup_verify(const char *input_filename, unsigned char * const *public_keys)
{
    unsigned char *meta_conf_signature = NULL;
    struct resource_list *all_resources = NULL;
    cfg_t *cfg = NULL;
    int rc = 0;

    struct archive *a = archive_read_new();
    archive_read_support_format_zip(a);

    if (!input_filename)
        ERR_CLEANUP_MSG("Specify an input firmware file");

    rc = fwup_archive_open_filename(a, input_filename);
    if (rc != ARCHIVE_OK)
        ERR_CLEANUP_MSG("%s", archive_error_string(a));

    struct archive_entry *ae;
    rc = archive_read_next_header(a, &ae);
    if (rc != ARCHIVE_OK)
        ERR_CLEANUP_MSG("%s", archive_error_string(a));

    if (strcmp(archive_entry_pathname(ae), "meta.conf.ed25519") == 0) {
        off_t total_size;
        if (archive_read_all_data(a, ae, (char **) &meta_conf_signature, crypto_sign_BYTES, &total_size) < 0)
            ERR_CLEANUP_MSG("Error reading meta.conf.ed25519 from archive.\n"
                            "Check for file corruption or libarchive built without zlib support");

        if (total_size != crypto_sign_BYTES)
            ERR_CLEANUP_MSG("Unexpected meta.conf.ed25519 size: %d", total_size);

        rc = archive_read_next_header(a, &ae);
        if (rc != ARCHIVE_OK)
            ERR_CLEANUP_MSG("Expecting more than meta.conf.ed25519 in archive");
    }
    if (strcmp(archive_entry_pathname(ae), "meta.conf") != 0)
        ERR_CLEANUP_MSG("Expecting meta.conf to be at the beginning of %s", input_filename);

    OK_OR_CLEANUP(cfgfile_parse_fw_ae(a, ae, &cfg, meta_conf_signature, public_keys));

    OK_OR_CLEANUP(rlist_get_all(cfg, &all_resources));

    while (archive_read_next_header(a, &ae) == ARCHIVE_OK) {
        const char *filename = archive_entry_pathname(ae);
        char resource_name[FWFILE_MAX_ARCHIVE_PATH];

        OK_OR_CLEANUP(archive_filename_to_resource(filename, resource_name, sizeof(resource_name)));
        OK_OR_CLEANUP(check_resource(all_resources, resource_name, a, ae));
    }

    // Check that all resources have been validated
    for (struct resource_list *r = all_resources; r != NULL; r = r->next) {
        if (!r->processed)
            ERR_CLEANUP_MSG("Resource %s not found in archive", cfg_title(r->resource));
    }

    const char *success_message;
    if (*public_keys && meta_conf_signature)
        success_message = "Valid archive with a good signature\n";
    else if (!*public_keys && meta_conf_signature)
        success_message = "Valid archive with an unverified signature. Specify a public key to authenticate.\n";
    else
        success_message = "Valid archive without a signature\n";

    fwup_output(FRAMING_TYPE_SUCCESS, 0, success_message);

cleanup:
    rlist_free(all_resources);
    archive_read_close(a);
    archive_read_free(a);

    if (meta_conf_signature)
        free(meta_conf_signature);

    if (cfg)
        cfgfile_free(cfg);

    return rc;
}