예제 #1
0
파일: kksh.c 프로젝트: ampotos/kcatos
void start_kksh() {
  char  command[BLOC_SIZE];

  const programs_t prog[] = {
    {"tictactoe", &tictactoe}, 
    {"connectFour", &connectFour}, 
//    {"sw", &swascii}, 
    {"clear", &cleanWrap},
    {"", NULL}
  };

  cleanWrap(NULL);
  
  for(;;){
    put_prompt();
    if (get_input_line(command, BLOC_SIZE) == -1)
    {
      syscall_puts_screen("READ ERROR");
      continue;
    }
    if (!kstrcmp(command, "exit"))
      return ;
    //syscall_puts_screen("Prout !2");
    execsh(command, prog);
  }
}
예제 #2
0
파일: dictionary.c 프로젝트: joshwyant/myos
int dict_index(dict *d, const char* name)
{
    int i;
    for (i = 0; i < d->count; i++)
        if (!kstrcmp(name, d->items[i].name)) return i;
    return -1;
}
예제 #3
0
파일: fat32.c 프로젝트: narhen/OS
int fat_init(struct ptable_entry *part, struct fat_part_desc *desc)
{
    char tmpb[512];

    block_read_lba(part->start_lba, tmpb);
    kmemcpy(&desc->bootrecord, tmpb, sizeof(struct bpb));

    if (kstrcmp(desc->bootrecord.OEM_ID, "mkdosfs"))
        return 0; /* error */

    desc->root_cyl_start_lba = part->start_lba + desc->bootrecord.reserved_sectors +
        fat_sectors(&desc->bootrecord);
    desc->type = fat_version(&desc->bootrecord);
    desc->fat_start_lba = part->start_lba + desc->bootrecord.reserved_sectors;
    if (desc->type == 32) {
        struct fat32_ebpb *eb = (struct fat32_ebpb *)&desc->bootrecord.ebpb[0];
        desc->root_cluster = eb->root_cluster;
    } else {
        desc->root_cluster = 2;
    }

    desc->fat = kmalloc(desc->bootrecord.sectors_pr_FAT * sizeof(long *));
    if (desc->fat == NULL)
        return 1;

    return 1;
}
예제 #4
0
파일: list.c 프로젝트: jangsoopark/firewall
int DeleteList(list *head, klp_flow *data)
{
    listNode *del = head->head;
    listNode *pre = 0;
    
    while(del && kstrcmp((char*)&del->data.key, (char*)&data->key))
    {
        pre = del;
        del = del->next;
    }
    
    if(del == 0)
        return -1;
    
    if(del == head->head)
        head->head = head->head->next;
    else if(del->next)
        pre->next = 0;
    else
        pre->next = del->next;
    
    kfree(del);
    
    return 0;
}
예제 #5
0
console *get_console( char *name )
{
  console *p = contab;

  for( ; p->name != NULL; p++ ) {
    if( kstrcmp( name, p->name ) == 0 ) { return p; }
  } 

  return NULL;
}
예제 #6
0
파일: symtab.c 프로젝트: virtuoso/koowaldah
int symtab_lookup_name(char *name)
{
	int i;

	for (i = 0; i < total_symbols; i++)
		if (!kstrcmp(symbol_table[i].name, name))
			return i;

	return 0;
}
예제 #7
0
파일: list.c 프로젝트: jangsoopark/firewall
listNode *SearchList(list *head, klp_flow *data)
{
    listNode *cur = head->head;
    
    while(cur && kstrcmp((char*)&cur->data.key, (char*)&data->key))
    {
        cur = cur->next;
    }
    return cur;
}
예제 #8
0
파일: fat32.c 프로젝트: narhen/OS
static struct dirent *search_cluster(char *name, void *cluster, int dircount)
{
    int i;
    char filename[255];
    struct dirent *dir = cluster;

    for (i = 0; i < dircount; ++i, ++dir) {
        if (dir->attr == DENT_LONG || dir->attr == 0)
            continue;
        if (!kstrcmp(name, get_filename(dir, filename)))
            return dir;
    }
    return NULL;
}
예제 #9
0
void parse(char *dir_path, int type, uint64_t start, uint64_t end)
{
    fnode_t *temp_node, *aux_node, *currnode = root_node->f_child[2];
    char *temp; 
    int i = 0;

    char *path = (char *)kmalloc(sizeof(char) * kstrlen(dir_path));
    kstrcpy(path, dir_path); 

    temp = kstrtok(path, "/");  

    while (temp != NULL) {
        aux_node = currnode; 
        //kprintf("%s \n", temp);
        //iterate through all childrens of currnode        
        for(i = 2; i < currnode->end; ++i){
            if(kstrcmp(temp, currnode->f_child[i]->f_name) == 0) {
                currnode = (fnode_t *)currnode->f_child[i];
                break;       
            }        
        }

        //kprintf("\n....%s...%s...", currnode->f_name, temp);
        //if no child has been found
        //add this as child of current
        if (i == aux_node->end) {

            temp_node = (fnode_t *)kmalloc(sizeof(struct file));
            make_node(temp_node, currnode, temp, start, end, type, 0);  

            currnode->f_child[currnode->end] = temp_node;
            currnode->end += 1; 
        } 

        //kprintf("....%d...%s...", currnode->end, temp);
        //while(1); 

        temp = kstrtok(NULL, "/");          

    }
}
예제 #10
0
void* file_lookup(char *dir_path)
{

    char* file_path = (char *)dir_path;

    fnode_t *aux_node, *currnode = root_node;

    char *temp = NULL; 
    int i;
    char *path = (char *)kmalloc(sizeof(char) * kstrlen(file_path));
    kstrcpy(path, file_path); 

    temp = kstrtok(path, "/");  
    
    if (temp == NULL)
        return NULL;
    
    //kprintf("\n step1 %s", temp);

    while (temp != NULL) {
        
        aux_node = currnode;
        for (i = 2; i < currnode->end; ++i) {
            if (kstrcmp(temp, currnode->f_child[i]->f_name) == 0) {
                currnode = (fnode_t *)currnode->f_child[i];
                break;       
            }        
        }

        if (i == aux_node->end) {
            return NULL;
        }

        temp = kstrtok(NULL, "/");          
    }

    if (currnode->f_type == FILE)
        return (void *)currnode->start; 
    else
        return NULL;
}
예제 #11
0
void* init_tarfs()
{
    HEADER *header = (HEADER*) &_binary_tarfs_start;
    int size_of_file = 0;
    fnode_t *temp_node;

    root_node = (fnode_t *)kmalloc(sizeof(struct file));
    make_node(root_node, root_node, "/", 0, 2, DIRECTORY, 0);  

    temp_node = (fnode_t *)kmalloc(sizeof(struct file)); 
    make_node(temp_node, root_node, "rootfs", 0, 2, DIRECTORY, 0);
    root_node->f_child[2] = temp_node; 
    root_node->end += 1;
    
    temp_node = (fnode_t *)kmalloc(sizeof(struct file)); 
    make_node(temp_node, root_node, "Disk", 0, 2, DIRECTORY, 0);
    root_node->f_child[3] = temp_node; 
    root_node->end += 1;

    do {
        size_of_file = oct_to_dec(atoi(header->size));

        if (kstrcmp(header->typeflag, "5") == 0) {
            parse(header->name, DIRECTORY, 0, 2);
        } else {
            parse(header->name, FILE, (uint64_t)(header + 1), (uint64_t)((void *)header + 512 + size_of_file));
        }

        if (size_of_file > 0) {
            header = header + size_of_file / (sizeof(HEADER) + 1) + 2;
        } else {
            header = header + 1;
        }
    } while(header < (HEADER*)&_binary_tarfs_end);

    return (void *)&root_node; 
}
예제 #12
0
파일: kksh.c 프로젝트: ampotos/kcatos
void execsh(char *command, const programs_t *prog) {
  char buff[BLOC_SIZE];
  int i;
  
  if ((get_arg(buff, BLOC_SIZE, command, 0)) == -1)
    return ;

  for (i = 0; prog[i].function != NULL; ++i) {
    if (kstrcmp(prog[i].name, buff) == 0)
    {
        (*(prog[i].function))(command);
        break;
    }
  }

  if (prog[i].function == NULL)
  {
    syscall_puts_screen("Unvalible command. List of avalible command :");
    for (i = 0; prog[i].function != NULL; ++i) {
      printf("  -  %s\n", prog[i].name);
    }
    printf("  -  exit\n");
  }
}
예제 #13
0
파일: mgmt.c 프로젝트: scyphus/aos
/*
 * Management process
 * start mgmt <cpuid> <nic> <ip address/mask> <default-gw>
 */
int
mgmt_main(int argc, char *argv[])
{
    /* Search network device for management */
    struct netdev_list *list;
    struct netdev *netdev;
    char *nic;
    char *ipaddr;
    char *gw;
    int m;
    int ret;
    u32 ipa;
    int ipm;
    u32 gwa;

    /* Check the argument first */
    if ( argc < 4 ) {
        kprintf("Invalid argument: %s <nic> <ip address/mask> <default-gw>\r\n",
                argv[0]);
        return -1;
    }

    nic = argv[1];
    ipaddr = argv[2];
    gw = argv[3];

    /* Obtain the specified netdev */
    netdev = NULL;
    list = netdev_head;
    while ( NULL != list ) {
        if ( 0 == kstrcmp(nic, list->netdev->name) ) {
            netdev = list->netdev;
            break;
        }
        list = list->next;
    }
    if ( NULL == netdev ) {
        kprintf("netdev %s cannot be found\r\n", nic);
        return -1;
    }

    ret = str2v4addr(ipaddr, &ipa, &ipm);
    if ( ret < 0 || ipm < 0 ) {
        /* Wrint IP address */
        kprintf("%s is wrong IP address format\r\n", ipaddr);
        return -1;
    }
    ret = str2v4addr(gw, &gwa, &m);
    if ( ret < 0 || m >= 0 ) {
        /* Wrint gateway address */
        kprintf("%s is wrong gateway address format\r\n", gw);
        return -1;
    }


    /* Network */
    int i;
    int n;
    u8 *pkt;
    struct net_port port;
    struct net_port_host hport;

    arch_busy_usleep(1000);

    pkt = alloca(gnet.sys_mtu);

    /* Port */
    kmemcpy(hport.macaddr, netdev->macaddr, 6);
    hport.ip4addr.nr = 1;
    hport.ip4addr.addrs = kmalloc(sizeof(u32) * 1);
    if ( NULL == hport.ip4addr.addrs ){
        return -1;
    }
    hport.ip4addr.addrs[0] = bswap32(ipa);
    hport.arp.sz = 4096;
    hport.arp.entries = kmalloc(sizeof(struct net_arp_entry) * hport.arp.sz);
    for ( i = 0; i < hport.arp.sz; i++ ) {
        hport.arp.entries[i].state = -1;
    }
    hport.ip6addr.nr = 0;
    hport.port = &port;
    port.netdev = netdev;
    port.next.data = (void *)&hport;
    port.next.func = net_sc_rx_port_host;
    hport.tx.func = NULL;
    hport.tx.data = (void *)&port;

    /* Routing table */
    hport.rib4.nr = 0;
    hport.rib4.entries = NULL;
    net_rib4_add(&hport.rib4, bswap32(ipa & (0xffffffffULL<<(32-ipm))), ipm, 0);
    net_rib4_add(&hport.rib4, 0, 0, bswap32(gwa));

    u64 tsc0 = rdtsc();
    u64 tsc1;
    for ( ;; ) {
        n = port.netdev->recvpkt(pkt, gnet.sys_mtu, port.netdev);
        if ( n <= 0 ) {
            continue;
        }
        port.next.func(&gnet, pkt, n, port.next.data);

        /* Trigger for TCP transmission */
        tsc1 = rdtsc();
        if ( tsc1 - tsc0 > 3000 * 1000 * 100 /* ~100ms FIXME */ ) {
            net_tcp_trigger(&gnet);
            tsc0 = tsc1;
        }
    }

    return 0;
}
예제 #14
0
BOOL Cleaner::UnloadObject(__in const char* szFilePath)
{
	bool unloaded = true;
	WinProcesses sysprss;
	System::GetProcesses(sysprss);

	WinProcesses::iterator end = sysprss.end();

	// Enumerate all system processes
	for(WinProcesses::iterator p_iter = sysprss.begin(); p_iter != end; ++p_iter)
	{
		// Compare object name with name of process.
		// If it's a process - just have to terminate it

		if (kstrcmp((*p_iter)->szExeFile, szFilePath) == 0)
		{
			HANDLE hproc = OpenProcess(PROCESS_TERMINATE, false, (*p_iter)->th32ProcessID);
			if(!hproc){
				unloaded = false;
				break;
			}

			unloaded = TerminateProcess(hproc, 0);
			CloseHandle(hproc);
			if (!unloaded) break;

		} else
		{
			// If it isn't the process - enumerate all its modules and
			// try to find lib with the same name

			WinModules m;
			System::GetModules((*p_iter)->th32ProcessID, m);
			for(WinModules::const_iterator m_i = m.constBegin(); m_i != m.constEnd(); ++m_i)
			{
				// Unloading mechanism
				if(kstrcmp((*m_i)->szExePath, szFilePath) == 0)
				{
					DWORD loadCount = m_sys.Get_LoadCount((*m_i)->th32ProcessID, (PVOID)(*m_i)->modBaseAddr);
					
					// If call has failed, may be it's a hidden object
					// I have to send the message to worklog
					if(!loadCount)
					{
						WorkLog::GetLog().printmain(QString("Couldn't get loadCount value of the %1 in pid %2")
							.arg(szFilePath)
							.arg((*m_i)->th32ProcessID));
					}

					// Remote call FreeLibrary
					for(int i=0; i<loadCount; ++i)
					{
						unloaded = System::UnloadDll((HMODULE)(*m_i)->modBaseAddr, (*p_iter)->th32ProcessID);
						
						// If even only one call will fail - I have to return 
						if(!unloaded) 
							break;
					}

					// Another way to do the same things.
					// Change .LoadCount value in LDR_MODULE structure of the remote process

					// ....
					// ....
				}
			}

			System::Close(m);
		}
	}

	System::Close(sysprss);
	return unloaded;
}