void test01 ( ) /******************************************************************************/ /* Purpose: TEST01 tests PERM_IS_UNICYCLE. Licensing: This code is distributed under the GNU LGPL license. Modified: 17 June 2012 Author: John Burkardt */ { int n = 5; int *p; int seed; int test; int test_num = 10; int *u; int value; seed = 123456789; printf ( "\n" ); printf ( "TEST01\n" ); printf ( " PERM_IS_UNICYCLE determines whether a permutation\n" ); printf ( " is a unicyle\n" ); for ( test = 1; test <= test_num; test++ ) { p = perm_random ( n, &seed ); value = perm_is_unicycle ( n, p ); if ( value ) { perm_print ( n, p, " This permutation is a unicycle" ); u = unicycle_index_to_sequence ( n, p ); unicycle_print ( n, u, " The permutation in sequence form" ); free ( u ); } else { perm_print ( n, p, " This permutation is NOT a unicycle" ); } } return; }
/* * namer_stat() * Do stat */ void namer_stat(struct msg *m, struct file *f) { char buf[MAXSTAT]; char buf2[8]; struct node *n = f->f_node; int len; struct llist *l; /* * Verify access */ if (!(f->f_mode & ACC_READ)) { msg_err(m->m_sender, EPERM); return; } /* * Calculate length */ if (n->n_internal) { len = 0; l = n->n_elems.l_forw; while (l != &n->n_elems) { len += 1; l = l->l_forw; } } else { sprintf(buf2, "%d", n->n_port); len = strlen(buf2); } sprintf(buf, "size=%d\ntype=%c\nowner=%d\ninode=%lu\n", len, n->n_internal ? 'd' : 'f', n->n_owner, (ulong)n); strcat(buf, perm_print(&n->n_prot)); m->m_buf = buf; m->m_arg = m->m_buflen = strlen(buf); m->m_nseg = 1; m->m_arg1 = 0; msg_reply(m->m_sender, m); }
/* * nvram_stat() * Do stat */ void nvram_stat(struct msg *m, struct file *f) { char buf[MAXSTAT]; if (!(f->f_flags & ACC_READ)) { msg_err(m->m_sender, EPERM); return; } sprintf(buf, "size=%d\ntype=%c\nowner=0\ninode=%d\ngen=%d\n", (f->f_node == ALL_INO) ? nvram_bytes : fe[f->f_node].fe_size, (f->f_node == ROOT_INO) ? 'd' : 's', f->f_node, nvram_accgen); strcat(buf, perm_print(&nvram_prot)); if (f->f_node == RTC_INO) { /* * Is this the rtc node? If it is we * add extra stat fields to identify * whether or not we're using BCD counting, * whether or not we're * using 12 or 24 hour clocks and whether * or not we're using daylight * saving mode. */ sprintf(&buf[strlen(buf)], "count_mode=%s\n", nvram_get_count_mode() ? "binary" : "bcd"); sprintf(&buf[strlen(buf)], "clock_mode=%s\n", nvram_get_clock_mode() ? "24hr" : "12hr" ); sprintf(&buf[strlen(buf)], "daysave_mode=%s\n", nvram_get_daysave_mode() ? "enabled" : "disabled"); } m->m_buf = buf; m->m_arg = m->m_buflen = strlen(buf); m->m_nseg = 1; m->m_arg1 = 0; msg_reply(m->m_sender, m); }
/* * fd_stat() * Do stat */ void fd_stat(struct msg *m, struct file *f) { char buf[MAXSTAT]; int size, ino; char type; struct floppy *fl = NULL; if (!(f->f_flags & ACC_READ)) { msg_err(m->m_sender, EPERM); return; } if (f->f_slot == ROOTDIR) { int x; size = 0; ino = 0; type = 'd'; /* * Work out the dir size */ for (x = 0; x < NFD; x++) { if (floppies[x].f_state != F_NXIO) { int y; struct floppy *fl = &floppies[x]; size++; for (y = 0; fl->f_posdens[y] != -1; y++) { size++; } } } } else { fl = unit(f->f_unit); size = fl->f_parms.f_size; ino = MKNODE(f->f_unit, f->f_slot) + UNITSTEP; type = 's'; } sprintf(buf, "size=%d\ntype=%c\nowner=0\ninode=%d\n" \ "fdc=%s\nirq=%d\ndma=%d\nbaseio=0x%0x\nretries=%d\n" \ "messages=%s\n", size, type, ino, fdc_names[fdc_type], fd_irq, fd_dma, fd_baseio, (f->f_slot == ROOTDIR ? fd_retries : fl->f_retries), fdm_opts[(f->f_slot == ROOTDIR ? fd_messages : fl->f_messages)]); strcat(buf, perm_print(&fd_prot)); if (f->f_slot != ROOTDIR) { /* * If we're a device we report on media changes and * the size of blocks we'll handle */ sprintf(&buf[strlen(buf)], "blksize=%d\nmediachg=%d\n", (size != FD_PUNDEF ? SECSZ(fl->f_parms.f_secsize) : 512), fl->f_mediachg); } if (f->f_slot == SPECIALNODE) { /* * If we're the special node we can deal with drive/media * parameters */ struct fdparms *fp; fp = (fl->f_specialdens == DISK_USERDEF) ? &fl->f_userp : &fl->f_parms; sprintf(&buf[strlen(buf)], "findparms=%s\n", fl->f_specialdens == DISK_USERDEF ? "userdef" : "auto"); if (fp->f_size == FD_PUNDEF) { sprintf(&buf[strlen(buf)], "parms=undefined\n"); } else { sprintf(&buf[strlen(buf)], "parms=%d:%d:%d:%d:%d:0x%02x:0x%02x:" \ "0x%02x:0x%02x:0x%02x:0x%02x\n", fp->f_size, fp->f_tracks, fp->f_heads, fp->f_sectors, fp->f_stretch, fp->f_gap, fp->f_fmtgap, fp->f_rate, fp->f_spec1, fp->f_spec2, fp->f_secsize); } } m->m_buf = buf; m->m_buflen = strlen(buf); m->m_nseg = 1; m->m_arg = m->m_arg1 = 0; msg_reply(m->m_sender, m); }