/*===========================================================================* * test_u32 * *===========================================================================*/ void test_u32(void) { int r; unsigned long value; /* Publish and retrieve. */ r = ds_publish_u32(key_u32, 1234, 0); assert(r == OK); r = ds_retrieve_u32(key_u32, &value); assert(r == OK && value == 1234); /* If dstest deletes 'test_u32' immediately after publishing it, * subs will catch the event, but it can't check it immediately. * So dstest will sleep 2 seconds to wait for subs to complete. */ sleep(2); /* Publish again without DSF_OVERWRITE. */ r = ds_publish_u32(key_u32, 4321, 0); assert(r == EEXIST); /* Publish again with DSF_OVERWRITE to overwrite it. */ r = ds_publish_u32(key_u32, 4321, DSF_OVERWRITE); assert(r == OK); r = ds_retrieve_u32(key_u32, &value); assert(r == OK && value == 4321); /* Delete. */ r = ds_delete_u32(key_u32); assert(r == OK); r = ds_retrieve_u32(key_u32, &value); assert(r == ESRCH); printf("DSTEST: U32 test successful!\n"); }
static int lu_state_restore(void) { /* Restore the state. */ u32_t value; ds_retrieve_u32("bus", &value); ds_delete_u32("bus"); bus = (int) value; ds_retrieve_u32("address", &value); ds_delete_u32("address"); address = (int) value; return OK; }
static void ds_event(void) { char key[DS_MAX_KEYLEN]; char *driver_prefix = "drv.net."; char *label; u32_t value; int type; endpoint_t owner_endpoint; int r; /* We may get one notification for multiple updates from DS. Get events * and owners from DS, until DS tells us that there are no more. */ while ((r = ds_check(key, &type, &owner_endpoint)) == OK) { r = ds_retrieve_u32(key, &value); if(r != OK) { printf("LWIP : ds_event: ds_retrieve_u32 failed\n"); return; } /* Only check for network driver up events. */ if(strncmp(key, driver_prefix, sizeof(driver_prefix)) || value != DS_DRIVER_UP) return; /* The driver label comes after the prefix. */ label = key + strlen(driver_prefix); /* A driver is (re)started. */ driver_up(label, owner_endpoint); } if(r != ENOENT) printf("LWIP : ds_event: ds_check failed: %d\n", r); }
PRIVATE int lu_state_restore() { /* Restore the state. */ u32_t value; ds_retrieve_u32("open_counter", &value); ds_delete_u32("open_counter"); open_counter = (int) value; return OK; }
static int lu_state_restore(void) { /* Restore the state. */ u32_t value; ds_retrieve_u32("cec_bus", &value); ds_delete_u32("cec_bus"); cec_bus = (int) value; ds_retrieve_u32("hdmi_bus", &value); ds_delete_u32("hdmi_bus"); hdmi_bus = (int) value; ds_retrieve_u32("cec_address", &value); ds_delete_u32("cec_address"); cec_address = (int) value; ds_retrieve_u32("hdmi_address", &value); ds_delete_u32("hdmi_address"); hdmi_address = (int) value; return OK; }
/*===========================================================================* * ds_event * *===========================================================================*/ void ds_event() { char key[DS_MAX_KEYLEN]; char *blkdriver_prefix = "drv.blk."; u32_t value; int type; endpoint_t owner_endpoint; int r; int which; /* Get the event and the owner from DS. */ r = ds_check(key, &type, &owner_endpoint); if(r != OK) { if(r != ENOENT) printf("Filter: ds_event: ds_check failed: %d\n", r); return; } r = ds_retrieve_u32(key, &value); if(r != OK) { printf("Filter: ds_event: ds_retrieve_u32 failed\n"); return; } /* Only check for VFS driver up events. */ if(strncmp(key, blkdriver_prefix, strlen(blkdriver_prefix)) || value != DS_DRIVER_UP) { return; } /* See if this is a driver we are responsible for. */ if(driver[DRIVER_MAIN].endpt == owner_endpoint) { which = DRIVER_MAIN; } else if(driver[DRIVER_BACKUP].endpt == owner_endpoint) { which = DRIVER_BACKUP; } else { return; } /* Mark the driver as (re)started. */ driver[which].up_event = driver[which].up_event == UP_EXPECTED ? UP_NONE : UP_PENDING; }
void main(void) { mq_t *mq; int r; int source, m_type, timerand, fd; u32_t tasknr; struct fssignon device; u8_t randbits[32]; struct timeval tv; #if DEBUG printk("Starting inet...\n"); printk("%s\n", version); #endif #if HZ_DYNAMIC system_hz = sys_hz(); #endif /* Read configuration. */ nw_conf(); /* Get a random number */ timerand= 1; fd= open(RANDOM_DEV_NAME, O_RDONLY | O_NONBLOCK); if (fd != -1) { r= read(fd, randbits, sizeof(randbits)); if (r == sizeof(randbits)) timerand= 0; else { printk("inet: unable to read random data from %s: %s\n", RANDOM_DEV_NAME, r == -1 ? strerror(errno) : r == 0 ? "EOF" : "not enough data"); } close(fd); } else { printk("inet: unable to open random device %s: %s\n", RANDOM_DEV_NAME, strerror(errno)); } if (timerand) { printk("inet: using current time for random-number seed\n"); r= gettimeofday(&tv, NULL); if (r == -1) { printk("sysutime failed: %s\n", strerror(errno)); exit(1); } memcpy(randbits, &tv, sizeof(tv)); } init_rand256(randbits); /* Our new identity as a server. */ r= ds_retrieve_u32("inet", &tasknr); if (r != 0) ip_panic(("inet: ds_retrieve_u32 failed for 'inet': %d", r)); this_proc= tasknr; /* Register the device group. */ device.dev= ip_dev; device.style= STYLE_CLONE; if (svrctl(FSSIGNON, (void *) &device) == -1) { printk("inet: error %d on registering ethernet devices\n", errno); pause(); } #ifdef BUF_CONSISTENCY_CHECK inet_buf_debug= (getenv("inetbufdebug") && (strcmp(getenv("inetbufdebug"), "on") == 0)); inet_buf_debug= 100; if (inet_buf_debug) { ip_warning(( "buffer consistency check enabled" )); } #endif if (getenv("killerinet")) { ip_warning(( "killer inet active" )); killer_inet= 1; } nw_init(); while (TRUE) { #ifdef BUF_CONSISTENCY_CHECK if (inet_buf_debug) { static int buf_debug_count= 0; if (++buf_debug_count >= inet_buf_debug) { buf_debug_count= 0; if (!bf_consistency_check()) break; } } #endif if (ev_head) { ev_process(); continue; } if (clck_call_expire) { clck_expire_timers(); continue; } mq= mq_get(); if (!mq) ip_panic(("out of messages")); r = kipc_module_call(KIPC_RECEIVE, 0, ENDPT_ANY, &mq->mq_mess); if (r<0) { ip_panic(("unable to receive: %d", r)); } reset_time(); source= mq->mq_mess.m_source; m_type= mq->mq_mess.m_type; if (source == VFS_PROC_NR) { sr_rec(mq); } else if (is_notify(m_type)) { if (_ENDPOINT_P(source) == CLOCK) { clck_tick(&mq->mq_mess); mq_free(mq); } else if (_ENDPOINT_P(source) == PM_PROC_NR) { /* signaled */ /* probably SIGTERM */ mq_free(mq); } else { /* A driver is (re)started. */ eth_check_drivers(&mq->mq_mess); mq_free(mq); } } else if (m_type == DL_CONF_REPLY || m_type == DL_TASK_REPLY || m_type == DL_NAME_REPLY || m_type == DL_STAT_REPLY) { eth_rec(&mq->mq_mess); mq_free(mq); } else { printk("inet: got bad message type 0x%x from %d\n", mq->mq_mess.m_type, mq->mq_mess.m_source); mq_free(mq); } } ip_panic(("task is not allowed to terminate")); }
/*===========================================================================* * fs_readsuper * *===========================================================================*/ int fs_readsuper() { /* This function reads the superblock of the partition, gets the root inode * and sends back the details of them. Note, that the FS process does not * know the index of the vmnt object which refers to it, whenever the pathname * lookup leaves a partition an -ELEAVEMOUNT error is transferred back * so that the VFS knows that it has to find the vnode on which this FS * process' partition is mounted on. */ struct ext2_inode *root_ip; cp_grant_id_t label_gid; size_t label_len; int r = 0; endpoint_t driver_e; int readonly, isroot; u32_t mask; fs_dev = fs_m_in.REQ_DEV; label_gid = fs_m_in.REQ_GRANT; label_len = fs_m_in.REQ_PATH_LEN; readonly = (fs_m_in.REQ_FLAGS & REQ_RDONLY) ? 1 : 0; isroot = (fs_m_in.REQ_FLAGS & REQ_ISROOT) ? 1 : 0; if (label_len > sizeof(fs_dev_label)) return(-EINVAL); r = sys_safecopyfrom(fs_m_in.m_source, label_gid, 0, (vir_bytes)fs_dev_label, label_len, D); if (r != 0) { printk("%s:%d fs_readsuper: safecopyfrom failed: %d\n", __FILE__, __LINE__, r); return(-EINVAL); } r= ds_retrieve_u32(fs_dev_label, &driver_e); if (r != 0) { printk("ext2:fs_readsuper: ds_retrieve_label_endpt failed for '%s': %d\n", fs_dev_label, r); return -EINVAL; } /* Map the driver endpoint for this major */ driver_endpoints[(fs_dev >> MAJOR) & BYTE].driver_e = driver_e; /* Open the device the file system lives on. */ if (dev_open(driver_e, fs_dev, driver_e, readonly ? R_BIT : (R_BIT|W_BIT)) != 0) { return(-EINVAL); } /* Fill in the super block. */ STATICINIT(superblock, sizeof(struct ext2_super_block)); if (!superblock) panic("EXT2","Can't allocate memory for superblock.",NO_NUM); superblock->s_dev = fs_dev; /* read_super() needs to know which dev */ r = read_super(superblock); /* Is it recognized as a Minix filesystem? */ if (r != 0) { superblock->s_dev = NO_DEV; dev_close(driver_e, fs_dev); return(r); } if (superblock->s_rev_level != EXT2_GOOD_OLD_REV) { struct ext2_super_block *sp = superblock; /* just shorter name */ mask = ~SUPPORTED_INCOMPAT_FEATURES; if (HAS_INCOMPAT_FEATURE(sp, mask)) { if (HAS_INCOMPAT_FEATURE(sp, INCOMPAT_COMPRESSION & mask)) printk("ext2: fs compression is not supported by server\n"); if (HAS_INCOMPAT_FEATURE(sp, INCOMPAT_FILETYPE & mask)) printk("ext2: fs in dir filetype is not supported by server\n"); if (HAS_INCOMPAT_FEATURE(sp, INCOMPAT_RECOVER & mask)) printk("ext2: fs recovery is not supported by server\n"); if (HAS_INCOMPAT_FEATURE(sp, INCOMPAT_JOURNAL_DEV & mask)) printk("ext2: fs journal dev is not supported by server\n"); if (HAS_INCOMPAT_FEATURE(sp, INCOMPAT_META_BG & mask)) printk("ext2: fs meta bg is not supported by server\n"); return(-EINVAL); } mask = ~SUPPORTED_RO_COMPAT_FEATURES; if (HAS_RO_COMPAT_FEATURE(sp, mask)) { if (HAS_RO_COMPAT_FEATURE(sp, RO_COMPAT_SPARSE_SUPER & mask)) { printk("ext2: sparse super is not supported by server, \ remount read-only\n"); } if (HAS_RO_COMPAT_FEATURE(sp, RO_COMPAT_LARGE_FILE & mask)) { printk("ext2: large files are not supported by server, \ remount read-only\n"); } if (HAS_RO_COMPAT_FEATURE(sp, RO_COMPAT_BTREE_DIR & mask)) { printk("ext2: dir's btree is not supported by server, \ remount read-only\n"); } return(-EINVAL); } } if (superblock->s_state == EXT2_ERROR_FS) { printk("ext2: filesystem wasn't cleanly unmounted previous time\n"); superblock->s_dev = NO_DEV; dev_close(driver_e, fs_dev); return(-EINVAL); } set_blocksize(superblock->s_block_size); /* Get the root inode of the mounted file system. */ if ( (root_ip = get_inode(fs_dev, ROOT_INODE)) == NULL) { printk("ext2: couldn't get root inode\n"); superblock->s_dev = NO_DEV; dev_close(driver_e, fs_dev); return(-EINVAL); } if (root_ip != NULL && root_ip->i_mode == 0) { printk("%s:%d zero mode for root inode?\n", __FILE__, __LINE__); put_inode(root_ip); superblock->s_dev = NO_DEV; dev_close(driver_e, fs_dev); return(-EINVAL); } if (root_ip != NULL && (root_ip->i_mode & I_TYPE) != I_DIRECTORY) { printk("%s:%d root inode has wrong type, it's not a DIR\n", __FILE__, __LINE__); put_inode(root_ip); superblock->s_dev = NO_DEV; dev_close(driver_e, fs_dev); return(-EINVAL); } superblock->s_rd_only = readonly; superblock->s_is_root = isroot; if (!readonly) { superblock->s_state = EXT2_ERROR_FS; superblock->s_mnt_count++; superblock->s_mtime = clock_time(); write_super(superblock); /* Commit info, we just set above */ } /* Root inode properties */ fs_m_out.RES_INODE_NR = root_ip->i_num; fs_m_out.RES_MODE = root_ip->i_mode; fs_m_out.RES_FILE_SIZE_LO = root_ip->i_size; fs_m_out.RES_UID = root_ip->i_uid; fs_m_out.RES_GID = root_ip->i_gid; return(r); }
/*===========================================================================* * main * *===========================================================================*/ int main(void) { int r; message mess; char key[DS_MAX_KEYLEN]; int type; u32_t num; char string[17]; char buf[1000]; size_t length = 1000; /* SEF local startup. */ sef_local_startup(); /* Subscribe. */ r = ds_subscribe(key_u32, DSF_INITIAL); if(r != OK && r != EEXIST) { printf("SUBSCRIBER: error in ds_subscribe: %d\n", r); return -1; } while(1) { /* Wait for a message. */ r = sef_receive(ANY, &mess); if(r != OK) { printf("SUBSCRIBER: sef_receive failed.\n"); return 1; } /* Only handle notifications from DS. */ if(mess.m_source != DS_PROC_NR) continue; /* Check which one was changed. */ r = ds_check(key, &type, NULL); if(r == ENOENT) { printf("SUBSCRIBER: the key %s was deleted.\n", key); continue; } if(r != OK) { printf("SUBSCRIBER: error in ds_check.\n"); continue; } /* Retrieve the entry. */ printf("SUBSCRIBER: key: %s, ", key); switch(type) { case DSF_TYPE_U32: r = ds_retrieve_u32(key, &num); if(r != OK) printf("error in ds_retrieve_u32.\n"); printf("U32: %d\n", num); break; case DSF_TYPE_STR: r = ds_retrieve_str(key, string, sizeof(string)-1); if(r != OK) printf("error in ds_retrieve_str.\n"); printf("STR: %s\n", string); break; case DSF_TYPE_MEM: r = ds_retrieve_mem(key, buf, &length); if(r != OK) printf("error in ds_retrieve_mem.\n"); break; case DSF_TYPE_MAP: break; default: printf("error in type! %d\n", type); } } return 0; }
/*===========================================================================* * fs_readsuper_s * *===========================================================================*/ PUBLIC int fs_readsuper_s() { /* This function reads the superblock of the partition, gets the root inode * and sends back the details of them. Note, that the FS process does not * know the index of the vmnt object which refers to it, whenever the pathname * lookup leaves a partition an ELEAVEMOUNT error is transferred back * so that the VFS knows that it has to find the vnode on which this FS * process' partition is mounted on. */ struct super_block *xp; struct inode *root_ip; cp_grant_id_t label_gid; size_t label_len; int r = OK; unsigned long tasknr; endpoint_t driver_e; fs_dev = fs_m_in.REQ_DEV; label_gid= fs_m_in.REQ_GRANT2; label_len= fs_m_in.REQ_PATH_LEN; if (label_len > sizeof(fs_dev_label)) { printf("mfs:fs_readsuper: label too long\n"); return EINVAL; } r= sys_safecopyfrom(fs_m_in.m_source, label_gid, 0, (vir_bytes)fs_dev_label, label_len, D); if (r != OK) { printf("mfs:fs_readsuper: safecopyfrom failed: %d\n", r); return EINVAL; } r= ds_retrieve_u32(fs_dev_label, &tasknr); if (r != OK) { printf("mfs:fs_readsuper: ds_retrieve_u32 failed for '%s': %d\n", fs_dev_label, r); return EINVAL; } driver_e= tasknr; /* Map the driver endpoint for this major */ driver_endpoints[(fs_dev >> MAJOR) & BYTE].driver_e = driver_e; use_getuptime2= TRUE; /* Should be removed with old * getuptime call. */ vfs_slink_storage = (char *)0xdeadbeef; /* Should be removed together * with old lookup code. */; /* Open the device the file system lives on. */ if (dev_open(driver_e, fs_dev, driver_e, fs_m_in.REQ_READONLY ? R_BIT : (R_BIT|W_BIT)) != OK) { return(EINVAL); } /* Fill in the super block. */ superblock.s_dev = fs_dev; /* read_super() needs to know which dev */ r = read_super(&superblock); /* Is it recognized as a Minix filesystem? */ if (r != OK) { superblock.s_dev = NO_DEV; dev_close(driver_e, fs_dev); return(r); } set_blocksize(superblock.s_block_size); /* Get the root inode of the mounted file system. */ if ( (root_ip = get_inode(fs_dev, ROOT_INODE)) == NIL_INODE) { printf("MFS: couldn't get root inode?!\n"); superblock.s_dev = NO_DEV; dev_close(driver_e, fs_dev); return EINVAL; } if (root_ip != NIL_INODE && root_ip->i_mode == 0) { printf("MFS: zero mode for root inode?!\n"); put_inode(root_ip); superblock.s_dev = NO_DEV; dev_close(driver_e, fs_dev); return EINVAL; } superblock.s_rd_only = fs_m_in.REQ_READONLY; superblock.s_is_root = fs_m_in.REQ_ISROOT; /* Root inode properties */ fs_m_out.RES_INODE_NR = root_ip->i_num; fs_m_out.RES_MODE = root_ip->i_mode; fs_m_out.RES_FILE_SIZE = root_ip->i_size; fs_m_out.RES_UID = root_ip->i_uid; fs_m_out.RES_GID = root_ip->i_gid; return r; }