예제 #1
0
파일: files.c 프로젝트: jgraef/meinOS
/**
 * Gets FSID and PID by path and cuts path to relative path for FS
 *  @param path Path to file
 *  @param parent If FS of parent directory of file is needed
 *  @return FSID
 */
static struct fslist_item *fsbypath(char *path,int parent) {
  if (path==NULL || path[0]==0) return NULL;
  struct fslist_item *fs = mp_match(path,parent);
  if (fs==NULL) {
    fs = malloc(sizeof(struct fslist_item));
    char *mountpoint = strdup(path);
    fs->id = rpc_call("vfs_getfsid",RPC_FLAG_RETPARAMS,path,parent);
    if (fs->id<0) {
      free(mountpoint);
      errno = -fs->id;
      return NULL;
    }
    fs->pid = rpc_call("vfs_getpid",0,fs->id);
    if (fs->pid<0) {
      errno = -fs->pid;
      return NULL;
    }
    mountpoint[strlen(mountpoint)-strlen(path)] = 0;
    fs->mountpoint = path_parse(mountpoint);
    fs->mountpoint_str = path_output(fs->mountpoint,NULL);
    free(mountpoint);
    llist_push(fslist,fs);
  }

  return fs;
}
예제 #2
0
파일: test.c 프로젝트: albedium/liblist
END_TEST


START_TEST ( llist_07_test_stack )
{
    int retval;
    llist listToTest = NULL;
    llist_node retptr;
    listToTest = llist_create ( NULL, NULL, test_mt ? MT_SUPPORT_FALSE : MT_SUPPORT_TRUE );

    // Push 1000 nodes
    for ( unsigned long i = 0; i < 1000; i ++ )
    {
        retval = llist_push ( listToTest, ( llist_node ) i );
        ck_assert_int_eq ( retval, LLIST_SUCCESS );
    }

    // Peek at the head
    retptr = llist_peek ( listToTest );
    ck_assert_int_eq ( ( unsigned long ) retptr, 999 );
    for ( unsigned long i = 999; i > 0; i-- )
    {
        retptr = llist_pop ( listToTest );
        ck_assert_int_eq ( ( unsigned long ) retptr, i );
    }

    printf ( "Count = %d\n", llist_size ( listToTest ) );
    retptr = llist_pop ( listToTest );
    ck_assert_ptr_eq ( retptr, NULL );

    llist_destroy ( listToTest, false, NULL );
}
예제 #3
0
파일: main.c 프로젝트: jgraef/meinOS
static int cdrom_device_init(char *name) {
  struct cdrom_device *dev = cdrom_device_create(name);
  if (dev!=NULL) {
    if (cdrom_inquiry(dev)==0) {
      if (cdrom_start(dev,1,1)==0) {
        if (cdrom_read_capacity(dev)==0) {
          char *devname;
          asprintf(&devname,"cdrom%d",llist_size(cdrom_devices));
          dev->devfs = devfs_createdev(devname);
          free(devname);
          if (dev->devfs!=NULL) {
            devfs_onread(dev->devfs,cdrom_devfs_read);
            dev->devfs->user_data = dev;
            llist_push(cdrom_devices,dev);
            return 0;
          }
        }
      }
    }
    else {
      cdrom_device_destroy(dev);
      return 0;
    }
  }
  cdrom_device_destroy(dev);
  return -1;
}
예제 #4
0
status_t
connection_msg_push (connection_t * connection, msg_t * msg)
{
  pthread_mutex_lock (&connection->mutex);
  ++connection->ref_count;
  pthread_mutex_unlock (&connection->mutex);
  return (llist_push (&connection->cmd_out, msg));
}
예제 #5
0
static void test_linked_list()
{
  size_t i;
  LinkedList llist;
  llist_init(&llist);
  LinkedNode nodes[100];

  for(i = 0; i < 100; i++) {
    nodes[i].data = i;
    llist_push(&llist, &nodes[i]);
    assert(llist.last == &nodes[i]);
  }
}
예제 #6
0
파일: files.c 프로젝트: jgraef/meinOS
/**
 * Unpack filehandles
 *  @param buf Buffer
 *  @note This function should be called before any other file function (except _fs_init())
 */
void _fs_unpack_filehandles(pack_t buf) {
  struct filelist_item *file;
  struct fslist_item *fs;
  size_t i,files_num,fs_num;
  char *tmp;
  id_t id;

  // Unpack filesystems
  unpacki(buf,&fs_num);
  for (i=0;i<fs_num;i++) {
    fs = malloc(sizeof(struct fslist_item));
    unpacki(buf,&(fs->id));
    unpacki(buf,&(fs->pid));
    unpackstr(buf,&tmp);
    fs->mountpoint = path_parse(tmp);
    fs->mountpoint_str = strdup(tmp);
    llist_push(fslist,fs);
  }

  // Unpack files
  unpacki(buf,&files_num);
  for (i=0;i<files_num;i++) {
    file = malloc(sizeof(struct filelist_item));
    unpacki(buf,&(file->fh));
    unpacki(buf,&(file->fs_fh));
    unpacki(buf,&(file->shmid));
    unpacki(buf,&(file->type));
    unpacki(buf,&(file->mode));
    unpacki(buf,&(file->stfl));
    unpacki(buf,&(file->fdfl));
    unpacki(buf,&id);
    unpackstr(buf,&(file->path));
    file->shmbuf = shmat(file->shmid,NULL,0);
    file->fs = fsbyid(id);
    llist_push(filelist,file);
  }
}
예제 #7
0
파일: tbl.c 프로젝트: connorjacobsen/libtbl
void*
tbl_put(tbl_t* tt, char* key, void* value)
{
  uint32_t index = tbl_hash(key) % tt->nalloc;
  llist_t* ll = tt->buckets[index];

  bool contains = false;
  int i;
  for (i = 0; llist_size(ll); ++i) {
    if (strcmp(pair_key(llist_at(ll, i)), key) == 0) {
      contains = true;
      break;
    }
  }

  if (contains) {
    pair_t* p = ll->data[i];
    p->value = value;
  } else {
    llist_push(ll, mk_pair(key, value));
  }

  return value;
}