コード例 #1
0
	void bin_index_t::file_node::remove_oldest()
	{
		for(page_wptr wp=last_page;pages.size()>=max_pages&&!wp.expired();)
		{
			page_ptr r;
			page_ptr l;

			{
				page_ptr p=wp.lock();
				r=p->right.lock();
				l=p->left.lock();
				flush_page(*p);
				pages.erase(p->page_offset);
				remove_from_list(p);
			}

			//Somebody still use this page and we can't delete it
			if(!wp.expired())
			{
				page_ptr p=wp.lock();
				pages[p->page_offset]=p;
				insert_into_list(p,r);
			}

			wp=l;
		}
	}
コード例 #2
0
	void bin_index_t::file_node::add_page(const page_ptr& p)
	{
		pages[p->page_offset]=p;
		insert_into_list(p,first_page.lock());

		remove_oldest();
	}
コード例 #3
0
ファイル: my_ls.c プロジェクト: svifflin/my_ls
int		handle_file(t_gen *gen, t_elem *elem)
{
  if (gen->opts[get_pos_strchr(OPTIONS, 'B')]
      && get_file_ending_with_tild(elem));
  else if (!gen->opts[get_pos_strchr(OPTIONS, 'd')] && !gen->opts[get_pos_strchr(OPTIONS, 'a')]
	   && !gen->opts[get_pos_strchr(OPTIONS, 'A')]
	   && elem->name[0] == '.');
  else if (!gen->opts[get_pos_strchr(OPTIONS, 'd')] && !gen->opts[get_pos_strchr(OPTIONS, 'a')]
	   && gen->opts[get_pos_strchr(OPTIONS, 'A')]
	   && (!my_strcmp(elem->name, ".") || !my_strcmp(elem->name, "..")));
  else
    {
      gen->elem = insert_into_list(elem, gen->elem, gen->opts);
      return (1);
    }
  return (0);
}
コード例 #4
0
ファイル: arplist.c プロジェクト: farhan90/ARP_Protocol
local_ent *get_local_list(){

  struct hwa_info *hwa,*hwahead;
  struct sockaddr *sa;
  local_ent *root=NULL;
  local_ent curr;

  for(hwahead=hwa=Get_hw_addrs();hwa!=NULL;hwa=hwa->hwa_next){
    if(strcmp(hwa->if_name,"eth0")==0){
      if((sa=hwa->ip_addr)!=NULL){
	char *temp=Sock_ntop_host(sa,sizeof(*sa));
	strncpy(curr.ip_info.ip,temp,INET_ADDRSTRLEN);
      }

      memcpy(curr.ip_info.hw_addr,hwa->if_haddr,HADDR_SIZE);
      root=insert_into_list(root,&curr);
    }
  }

  free_hwa_info(hwahead);
  return root;
}
コード例 #5
0
ファイル: hello_list.c プロジェクト: avasyukov/oop-2nd-term
int main()
{
	list_element* root = create_new_element(-1);

	list_element* new_elem;
	int i;
	for(i = 0; i < 10; i++) {
		new_elem = create_new_element(i);
		insert_into_list(new_elem, root);
	}

	print_list(root);

	int value = 10;

	if( search_by_value(root, value) == 0 ) {
		printf("Value %d exists in the list\n", value);
	} else {
		printf("There is no value %d in the list\n", value);
	}

	return 0;
}
コード例 #6
0
	bin_index_t::page_ptr bin_index_t::file_node::get_page(file_offset_t page_offset)
	{
		pages_t::iterator it=pages.find(page_offset);

		if(it!=pages.end())
		{
			page_ptr p=it->second;
			if(!p->left.expired())
			{
				remove_from_list(p);
				insert_into_list(p,first_page.lock());
			}
			return p;
		}

		page_ptr p(create_page());
		p->self=p;
		p->page_offset=page_offset;
		load_page(*p);

		add_page(p);

		return p;
	}
コード例 #7
0
/*Recieves the client request and addes it to the queue
 * Input:
 *      int client_fd   :       specifies the connection identifier
 * */
void server_response (int client_fd, thread_pool_t *pool_obj, C_Request* c_request)
{
        char* buffer;
        char* data;
        int len         =       0;
        int ret         =       0;
        long res        =       0;
        int buf_ptr     =       0;
        buffer = (char*) calloc (1,1024);

        ret = read (client_fd, buffer, 1024);
        printf ("Recieved bytes %d\n", ret);
        if(ret > 0)
        {
                /* Read the footer. */
                memcpy (&res, (buffer + (ret - sizeof (int)) ), sizeof (int));

                /* Checking the message is valid or not .*/
                if (res != 0xbaadf00d) {
                        goto out;
                }
                
                /* Read the length of the message */
                memcpy (&len, buffer, sizeof (int));
                buf_ptr += sizeof (int);

                /* If valid message  read the type of the request. */
                memcpy (&res, buffer + buf_ptr, sizeof (int));
                buf_ptr += sizeof (int);

                switch (res)
                {
                        case file_request:
                                        /* Process the file request */
                                        c_request -> type = file_request;
                                        c_request -> buf = (char*) calloc (1, ret - buf_ptr);
                                        memcpy (c_request -> buf, buffer + buf_ptr, 
                                                                ret - buf_ptr) ;
                                        c_request -> client_fd = client_fd;
                                        c_request -> operation = (void*) file_handler;
                                        break;
                        case write_request:
                                        /* Process the write request */
                                        c_request -> type = write_request;
                                        c_request -> buf = buffer;
                                        c_request -> client_fd = client_fd;
                                        c_request -> operation = (void*) write_handler;
                                        break;
                        case open_file_request:
                                        /* Process the open_file_request */
                                        c_request -> type = open_file_request;
                                        c_request -> buf = (char*) calloc (1, ret - buf_ptr);
                                        memcpy (c_request -> buf, buffer + buf_ptr, 
                                                                ret - buf_ptr) ;
                                        c_request -> client_fd = client_fd;
                                        c_request -> operation = (void*) open_file_handler;
                                        break;
                        case close_file_request:
                                        /* Process the close file request */
                                        c_request -> type = close_file_request;
                                        c_request -> buf = (char*) calloc (1, ret - buf_ptr);
                                        memcpy (c_request -> buf, buffer + buf_ptr,
                                                                ret - buf_ptr);
                                        c_request -> client_fd = client_fd;
                                        c_request -> operation = (void*) close_file_handler;
                                        break;
                        case read_in_chunks:
                                        /* Process the read in chunks from the file 
                                         * and send it  back to the client */
                                        c_request -> type = read_in_chunks;
                                        c_request -> buf = (char*) calloc (1, ret - buf_ptr);
                                        memcpy (c_request -> buf, buffer + buf_ptr,
                                                                ret - buf_ptr);
                                        c_request -> client_fd = client_fd;
                                        c_request -> operation = (void*) read_chunks_handler;
                                        break;
                }
                /* Check whether the list is full or not 
                * if list is full then send feedback to client that
                * client is full otherwise the request is added to the
                * queue
                * */
        data_read:
                if (list_full (pool -> list) == 1)
                {
                        /* Clears the buffer */
                        memset (buffer, 0, 1024);
                        res = 0;
                        /* Gives the length of the response. */
                        len = calc_response_queue_full ();
                        
                        /* Allocate the memory */
                        buffer = (char*) calloc (1, len + 4);
                        
                        /* Copy the length of the request. */
                        memcpy (buffer, &len, sizeof (int));
                        res += sizeof (int);
                        
                        /*Copy the type of the response */
                        len = fail_response;
                        memcpy (buffer + res, &len, sizeof (int));
                        res += sizeof (int);
                        
                        /* Copy the response */
                        len = queue_ful;
                        memcpy (buffer + res, &len, sizeof (int));
                        res +=sizeof (int);
                        
                        /* Send the response to the client */
                        ret = write (client_fd, data, res);
                        if (ret < 0)
                        {
                                printf ("\tSome error ocurred\n");
                                goto data_read;
                        }
                        goto out;
                }

                /*Calls the function to add the client_request to the 
                * list */
                pool_obj -> list -> first_node = insert_into_list 
                                                (pool_obj -> list, c_request);
                printf ("\tClient : %d's request is inserted\n", client_fd);
                pthread_mutex_lock (& (pool_obj -> q_lock));
                pthread_cond_broadcast (& pool_obj -> cond_t);
                pthread_mutex_unlock (& (pool_obj -> q_lock));
                
        }
        out:
                return ;
}
コード例 #8
0
/*
 * Enable memory and I/O on pci devices. Care about already enabled devices
 * (probabaly by the console driver).
 *
 * The idea behind the following code is:
 * We build a by sizes sorted list of the requirements of the different
 * pci devices. After that we choose the start addresses of that areas
 * in such a way that they are placed as closed as possible together.
 */
static void
enable_pci_devices(void)
{
    PCI_MEMREG memlist;
    PCI_MEMREG iolist;
    struct pci_memreg *p, *q;
    int dev, reg, id, class;
    pcitag_t tag;
    pcireg_t csr, address, mask;
    pci_chipset_tag_t pc;
    int sizecnt, membase_1m;

    pc = 0;
    csr = 0;
    tag = 0;

    LIST_INIT(&memlist);
    LIST_INIT(&iolist);

    /*
     * first step: go through all devices and gather memory and I/O
     * sizes
     */
    for (dev = 0; dev < pci_bus_maxdevs(pc,0); dev++) {

	tag = pci_make_tag(pc, 0, dev, 0);
	id  = pci_conf_read(pc, tag, PCI_ID_REG);
	if (id == 0 || id == 0xffffffff)
	    continue;

	csr = pci_conf_read(pc, tag, PCI_COMMAND_STATUS_REG);

	/*
	 * special case: if a display card is found and memory is enabled
	 * preserve 128k at 0xa0000 as vga memory.
	 * XXX: if a display card is found without being enabled, leave
	 *      it alone! You will usually only create conflicts by enabeling
	 *      it.
	 */
	class = pci_conf_read(pc, tag, PCI_CLASS_REG);
	switch (PCI_CLASS(class)) {
	    case PCI_CLASS_PREHISTORIC:
	    case PCI_CLASS_DISPLAY:
	      if (csr & (PCI_COMMAND_MEM_ENABLE | PCI_COMMAND_MASTER_ENABLE)) {
		    p = (struct pci_memreg *)malloc(sizeof(struct pci_memreg),
				M_TEMP, M_WAITOK);
		    memset(p, '\0', sizeof(struct pci_memreg));
		    p->dev = dev;
		    p->csr = csr;
		    p->tag = tag;
		    p->reg = 0;     /* there is no register about this */
		    p->size = 0x20000;  /* 128kByte */
		    p->mask = 0xfffe0000;
		    p->address = 0xa0000;

		    insert_into_list(&memlist, p);
	      }
	      else continue;
	}

	for (reg = PCI_MAPREG_START; reg < PCI_MAPREG_END; reg += 4) {

	    address = pci_conf_read(pc, tag, reg);
	    pci_conf_write(pc, tag, reg, 0xffffffff);
	    mask    = pci_conf_read(pc, tag, reg);
	    pci_conf_write(pc, tag, reg, address);
	    if (mask == 0)
		continue; /* Register unused */

	    p = (struct pci_memreg *)malloc(sizeof(struct pci_memreg),
			M_TEMP, M_WAITOK);
	    memset(p, '\0', sizeof(struct pci_memreg));
	    p->dev = dev;
	    p->csr = csr;
	    p->tag = tag;
	    p->reg = reg;
	    p->mask = mask;
	    p->address = 0;

	    if (mask & PCI_MAPREG_TYPE_IO) {
		p->size = PCI_MAPREG_IO_SIZE(mask);

		/*
		 * Align IO if necessary
		 */
		if (p->size < PCI_MAPREG_IO_SIZE(PCI_MACHDEP_IO_ALIGN_MASK)) {
		    p->mask = PCI_MACHDEP_IO_ALIGN_MASK;
		    p->size = PCI_MAPREG_IO_SIZE(p->mask);
		}

		/*
		 * if I/O is already enabled (probably by the console driver)
		 * save the address in order to take care about it later.
		 */
		if (csr & PCI_COMMAND_IO_ENABLE)
		    p->address = address;

		insert_into_list(&iolist, p);
	    } else {
		p->size = PCI_MAPREG_MEM_SIZE(mask);

		/*
		 * Align memory if necessary
		 */
		if (p->size < PCI_MAPREG_IO_SIZE(PCI_MACHDEP_MEM_ALIGN_MASK)) {
		    p->mask = PCI_MACHDEP_MEM_ALIGN_MASK;
		    p->size = PCI_MAPREG_MEM_SIZE(p->mask);
		}

		/*
		 * if memory is already enabled (probably by the console driver)
		 * save the address in order to take care about it later.
		 */
		if (csr & PCI_COMMAND_MEM_ENABLE)
		    p->address = address;

		insert_into_list(&memlist, p);

		if (PCI_MAPREG_MEM_TYPE(mask) == PCI_MAPREG_MEM_TYPE_64BIT)
		    reg++;
	    }
	}


#if defined(_ATARIHW_)
	/*
	 * Both interrupt pin & line are set to the device (== slot)
	 * number. This makes sense on the atari Hades because the
	 * individual slots are hard-wired to a specific MFP-pin.
	 */
	csr  = (DEV2SLOT(dev) << PCI_INTERRUPT_PIN_SHIFT);
	csr |= (DEV2SLOT(dev) << PCI_INTERRUPT_LINE_SHIFT);
	pci_conf_write(pc, tag, PCI_INTERRUPT_REG, csr);
#else
	/*
	 * On the Milan, we accept the BIOS's choice.
	 */
#endif
    }

    /*
     * second step: calculate the memory and I/O addresses beginning from
     * PCI_MEM_START and PCI_IO_START. Care about already mapped areas.
     *
     * begin with memory list
     */

    address = PCI_MEM_START;
    sizecnt = 0;
    membase_1m = 0;
    p = LIST_FIRST(&memlist);
    while (p != NULL) {
	if (!(p->csr & PCI_COMMAND_MEM_ENABLE)) {
	    if (PCI_MAPREG_MEM_TYPE(p->mask) == PCI_MAPREG_MEM_TYPE_32BIT_1M) {
		if (p->size > membase_1m)
		    membase_1m = p->size;
		do {
		    p->address = membase_1m;
		    membase_1m += p->size;
		} while (overlap_pci_areas(LIST_FIRST(&memlist), p, p->address,
					   p->size, PCI_COMMAND_MEM_ENABLE));
		if (membase_1m > 0x00100000) {
		    /*
		     * Should we panic here?
		     */
		    printf("\npcibus0: dev %d reg %d: memory not configured",
			    p->dev, p->reg);
		    p->reg = 0;
		}
	    } else {

		if (sizecnt && (p->size > sizecnt))
		    sizecnt = ((p->size + sizecnt) & p->mask) &
			      PCI_MAPREG_MEM_ADDR_MASK;
		if (sizecnt > address) {
		    address = sizecnt;
		    sizecnt = 0;
		}

		do {
		    p->address = address + sizecnt;
		    sizecnt += p->size;
		} while (overlap_pci_areas(LIST_FIRST(&memlist), p, p->address,
					   p->size, PCI_COMMAND_MEM_ENABLE));

		if ((address + sizecnt) > PCI_MEM_END) {
		    /*
		     * Should we panic here?
		     */
		    printf("\npcibus0: dev %d reg %d: memory not configured",
			    p->dev, p->reg);
		    p->reg = 0;
		}
	    }
	    if (p->reg > 0) {
		pci_conf_write(pc, p->tag, p->reg, p->address);
		csr = pci_conf_read(pc, p->tag, PCI_COMMAND_STATUS_REG);
		csr |= PCI_COMMAND_MEM_ENABLE | PCI_COMMAND_MASTER_ENABLE;
		pci_conf_write(pc, p->tag, PCI_COMMAND_STATUS_REG, csr);
		p->csr = csr;
	    }
	}
	p = LIST_NEXT(p, link);
    }

    /*
     * now the I/O list
     */

    address = PCI_IO_START;
    sizecnt = 0;
    p = LIST_FIRST(&iolist);
    while (p != NULL) {
	if (!(p->csr & PCI_COMMAND_IO_ENABLE)) {

	    if (sizecnt && (p->size > sizecnt))
		sizecnt = ((p->size + sizecnt) & p->mask) &
			  PCI_MAPREG_IO_ADDR_MASK;
	    if (sizecnt > address) {
		address = sizecnt;
		sizecnt = 0;
	    }

	    do {
		p->address = address + sizecnt;
		sizecnt += p->size;
	    } while (overlap_pci_areas(LIST_FIRST(&iolist), p, p->address,
				       p->size, PCI_COMMAND_IO_ENABLE));

	    if ((address + sizecnt) > PCI_IO_END) {
		/*
		 * Should we panic here?
		 */
		printf("\npcibus0: dev %d reg %d: io not configured",
			p->dev, p->reg);
	    } else {
		pci_conf_write(pc, p->tag, p->reg, p->address);
		csr = pci_conf_read(pc, p->tag, PCI_COMMAND_STATUS_REG);
		csr |= PCI_COMMAND_IO_ENABLE | PCI_COMMAND_MASTER_ENABLE;
		pci_conf_write(pc, p->tag, PCI_COMMAND_STATUS_REG, csr);
		p->csr = csr;
	    }
	}
	p = LIST_NEXT(p, link);
    }

#ifdef DEBUG_PCI_MACHDEP
    printf("\nI/O List:\n");
    p = LIST_FIRST(&iolist);

    while (p != NULL) {
	printf("\ndev: %d, reg: 0x%02x, size: 0x%08x, addr: 0x%08x", p->dev,
			p->reg, p->size, p->address);
	p = LIST_NEXT(p, link);
    }
    printf("\nMemlist:");
    p = LIST_FIRST(&memlist);

    while (p != NULL) {
	printf("\ndev: %d, reg: 0x%02x, size: 0x%08x, addr: 0x%08x", p->dev,
			p->reg, p->size, p->address);
	p = LIST_NEXT(p, link);
    }
#endif

    /*
     * Free the lists
     */
    p = LIST_FIRST(&iolist);
    while (p != NULL) {
	q = p;
	LIST_REMOVE(q, link);
	free(p, M_WAITOK);
	p = LIST_FIRST(&iolist);
    }
    p = LIST_FIRST(&memlist);
    while (p != NULL) {
	q = p;
	LIST_REMOVE(q, link);
	free(p, M_WAITOK);
	p = LIST_FIRST(&memlist);
    }
}