int main() { // Criar arquivos na raiz FILE2 files[4]; files[0] = create2("/hello.txt"); printf("Testing double dot.\n"); files[1] = create2("../helloDD.txt"); files[2] = create2("/../../helloDD2.txt"); files[3] = create2("./helloD.txt"); DIRENT2 dentry; DIR2 d = opendir2("/"); while (readdir2(d, &dentry) == 0) { printf("Entry: Name => %s, Type => %s, Size => %lu.\n", dentry.name, (dentry.fileType == 0x01 ? "File" : "Directory"), dentry.fileSize); } int i; for (i = 0; i < 4; ++i) close2(files[i]); return 0; }
/** Copia arquivo dentro do T2FS Os parametros são: primeiro parametro => arquivo origem segundo parametro => arquivo destino */ void cmdCp(void) { // Pega os nomes dos arquivos origem e destion char *src = strtok(NULL," \t"); char *dst = strtok(NULL," \t"); if (src==NULL || dst==NULL) { printf ("Missing parameter\n"); return; } // Abre o arquivo origem, que deve existir FILE2 hSrc = open2 (src); if (hSrc<0) { printf ("Open source file error: %d\n", hSrc); return; } // Cria o arquivo de destino, que será resetado se existir FILE2 hDst = create2 (dst); if (hDst<0) { close2(hSrc); printf ("Create destination file error: %d\n", hDst); return; } // Copia os dados de source para destination char buffer[2]; while( read2(hSrc, buffer, 1) == 1 ) { write2(hDst, buffer, 1); } // Fecha os arquicos close2(hSrc); close2(hDst); printf ("Files successfully copied\n"); }
int main( ) /*主函数*/ { init( ); create1( ); create2( ); combine( ); getchar( ); }
int main() { create2(); printf("yey 1\n"); create2(); printf("yey 2\n"); create2(); printf("yey 3\n"); Thread* t = threadList; printf("%d\n", t->id); int result = setjmp(mainBuf); if (result == 0) { printf("%p\n", t); longjmp(*t->context, 1); } else { t = t->next; if (t == NULL) return 0; printf("a %p\n", t); longjmp(*t->context, 1); } }
int main() { int no1,no2; node *fn,*fs,*sc; printf("enter no. of elements in 1st list.. \n"); scanf("%d",&no1); fs=create1(no1); printf("enter no. of elements in 2nd list... \n"); scanf("%d",&no2); sc=create2(no2); fn=join(fs,sc); delete_duplicate(fn); return 0; }
/** Cria o arquivo informado no parametro Retorna eventual sinalização de erro Retorna o HANDLE do arquivo criado */ void cmdCreate(void) { FILE2 hFile; char *token = strtok(NULL," \t"); if (token==NULL) { printf ("Missing parameter\n"); return; } hFile = create2 (token); if (hFile<0) { printf ("Error: %d\n", hFile); return; } printf ("File created with handle %d\n", hFile); }
void run_assign_and_copy_constructor_test(const char *test_name) { REMARK("Testing assignment and copy construction for %s\n", test_name); // test initializer with exemplar T initializer0; test_helper<T>::init(initializer0); T initializer7; test_helper<T>::set(initializer7,7); tbb::enumerable_thread_specific<T> create1(initializer7); (void) create1.local(); // create an initialized value ASSERT(7 == test_helper<T>::get(create1.local()), NULL); // test copy construction with exemplar initializer create1.clear(); tbb::enumerable_thread_specific<T> copy1(create1); (void) copy1.local(); ASSERT(7 == test_helper<T>::get(copy1.local()), NULL); // test copy assignment with exemplar initializer create1.clear(); tbb::enumerable_thread_specific<T> assign1(initializer0); assign1 = create1; (void) assign1.local(); ASSERT(7 == test_helper<T>::get(assign1.local()), NULL); // test creation with finit function FunctorFinit<T,7> my_finit7(SecretTag); tbb::enumerable_thread_specific<T> create2(my_finit7); (void) create2.local(); ASSERT(7 == test_helper<T>::get(create2.local()), NULL); // test copy construction with function initializer create2.clear(); tbb::enumerable_thread_specific<T> copy2(create2); (void) copy2.local(); ASSERT(7 == test_helper<T>::get(copy2.local()), NULL); // test copy assignment with function initializer create2.clear(); FunctorFinit<T,0> my_finit(SecretTag); tbb::enumerable_thread_specific<T> assign2(my_finit); assign2 = create2; (void) assign2.local(); ASSERT(7 == test_helper<T>::get(assign2.local()), NULL); }
int main () { //printf("%d\n",g(10,20)); //printf("%f\n",h(3,2)); Parametro params [2]; params [0].amarracao = LIVRE; params [0].tipo = DOUBLE; params [1].amarracao = CONSTANTE; params [1].tipo = DOUBLE; params [1].valor.vDouble = 2; printf("satanas ta aki %x\n",params[1].valor.vInt); typedef double (*fptr) (double); fptr quadrado = (fptr) create2 (pow, DOUBLE, 2, params); printf("\n"); printf ("O valor de 5 elevado ao quadrado é %f\n", quadrado (5)); return 0; }
void RunAssignmentAndCopyConstructorTest(const char *test_name) { REMARK("Testing assignment and copy construction for %s\n", test_name); // test creation with finit function (combine returns finit return value if no threads have created locals) FunctorAddFinit7<T> my_finit7_decl; tbb::combinable<T> create2(my_finit7_decl); ASSERT(7 == create2.combine(my_combine<T>), NULL); // test copy construction with function initializer tbb::combinable<T> copy2(create2); ASSERT(7 == copy2.combine(my_combine<T>), NULL); // test copy assignment with function initializer FunctorAddFinit<T> my_finit_decl; tbb::combinable<T> assign2(my_finit_decl); assign2 = create2; ASSERT(7 == assign2.combine(my_combine<T>), NULL); }
void test_cycle_two() { create1(); create2(); triggerConversions(); TEST_ASSERT_EQUAL(1, analog1started); TEST_ASSERT_EQUAL(1, analog2started); TEST_ASSERT_EQUAL(analog1value, analogInputValue(analog1)); TEST_ASSERT_EQUAL(analog2value, analogInputValue(analog2)); // Another round analog1value = 1000; analog2value = 2000; triggerConversions(); triggerConversions(); triggerConversions(); TEST_ASSERT_EQUAL(4, analog1started); TEST_ASSERT_EQUAL(4, analog2started); TEST_ASSERT_EQUAL(analog1value, analogInputValue(analog1)); TEST_ASSERT_EQUAL(analog2value, analogInputValue(analog2)); }
void test_cycle_after_destroy() { create1(); triggerConversions(); TEST_ASSERT_EQUAL(1, analog1started); TEST_ASSERT_EQUAL(0, analog2started); create2(); triggerConversions(); TEST_ASSERT_EQUAL(2, analog1started); TEST_ASSERT_EQUAL(1, analog2started); analog1 = destroyAnalogInput(analog1); triggerConversions(); TEST_ASSERT_EQUAL(2, analog1started); TEST_ASSERT_EQUAL(2, analog2started); analog2 = destroyAnalogInput(analog2); triggerConversions(); triggerConversions(); triggerConversions(); TEST_ASSERT_EQUAL(2, analog1started); TEST_ASSERT_EQUAL(2, analog2started); }
int main(void) { dcmplx one,imu,z1,z2; int ans; one = create1(1.0); printf("One as complex number : "); writeln_dcmplx(one); imu = create2(0.0,1.0); printf("The imaginary unit : "); writeln_dcmplx(imu); srand(time(NULL)); for(;;) { printf("\nChoose one of the following :\n"); printf(" 0. exit this program; or\n"); printf(" 1. perform tests on user-given numbers; or\n"); printf(" 2. test operations on random numbers.\n"); printf("Type 0, 1, or 2 to choose : "); scanf("%d", &ans); switch(ans) { case 0: return 0; case 1: interactive_test(); break; case 2: random_test(); break; default: printf("Invalid choice. Please try again...\n"); } } return 0; }
static void stage_file_test(void) { static int name[] = { CTL_NET, NET_IPV4, NET_IPV4_LOCAL_PORT_RANGE }; int buffer[2] = { 32768, 61000 }; size_t size = sizeof(buffer); int pipe_fd[2] = { EOF, EOF }; int error = 0; int fd; char pbuffer[1024]; struct stat sbuf; struct sockaddr_un addr; struct ifreq ifreq; char *filename = ""; set_profile(3, "file::execute"); set_profile(3, "file::open"); set_profile(3, "file::create"); set_profile(3, "file::unlink"); set_profile(3, "file::mkdir"); set_profile(3, "file::rmdir"); set_profile(3, "file::mkfifo"); set_profile(3, "file::mksock"); set_profile(3, "file::truncate"); set_profile(3, "file::symlink"); set_profile(3, "file::rewrite"); set_profile(3, "file::mkblock"); set_profile(3, "file::mkchar"); set_profile(3, "file::link"); set_profile(3, "file::rename"); set_profile(3, "file::chmod"); set_profile(3, "file::chown"); set_profile(3, "file::chgrp"); set_profile(3, "file::ioctl"); set_profile(3, "file::chroot"); set_profile(3, "file::mount"); set_profile(3, "file::umount"); set_profile(3, "file::pivot_root"); policy = "allow_read /proc/sys/net/ipv4/ip_local_port_range"; write_domain_policy(policy, 0); show_result(sysctl(name, 3, buffer, &size, 0, 0), 1); write_domain_policy(policy, 1); show_result(sysctl(name, 3, buffer, &size, 0, 0), 0); policy = "allow_write /proc/sys/net/ipv4/ip_local_port_range"; write_domain_policy(policy, 0); show_result(sysctl(name, 3, 0, 0, buffer, size), 1); write_domain_policy(policy, 1); show_result(sysctl(name, 3, 0, 0, buffer, size), 0); policy = "allow_read/write /proc/sys/net/ipv4/ip_local_port_range"; write_domain_policy(policy, 0); show_result(sysctl(name, 3, buffer, &size, buffer, size), 1); write_domain_policy(policy, 1); show_result(sysctl(name, 3, buffer, &size, buffer, size), 0); policy = "allow_read /bin/true"; write_domain_policy(policy, 0); show_result(uselib("/bin/true"), 1); write_domain_policy(policy, 1); show_result(uselib("/bin/true"), 0); policy = "allow_execute /bin/true"; write_domain_policy(policy, 0); fflush(stdout); fflush(stderr); if (pipe(pipe_fd) == -1) err(1, "pipe"); if (fork() == 0) { execl("/bin/true", "/bin/true", NULL); if (write(pipe_fd[1], &errno, sizeof(errno)) == -1) err(1, "write"); exit(0); } close(pipe_fd[1]); (void)read(pipe_fd[0], &error, sizeof(error)); close(pipe_fd[0]); wait(NULL); errno = error; show_result(error ? EOF : 0, 1); write_domain_policy(policy, 1); fflush(stdout); fflush(stderr); if (pipe(pipe_fd) == -1) err(1, "pipe"); if (fork() == 0) { execl("/bin/true", "/bin/true", NULL); if (write(pipe_fd[1], &errno, sizeof(errno)) == -1) err(1, "write"); _exit(0); } close(pipe_fd[1]); (void)read(pipe_fd[0], &error, sizeof(error)); close(pipe_fd[0]); wait(NULL); errno = error; show_result(errno ? EOF : 0, 0); policy = "allow_read /dev/null"; write_domain_policy(policy, 0); fd = open("/dev/null", O_RDONLY); show_result(fd, 1); if (fd != EOF) close(fd); write_domain_policy(policy, 1); fd = open("/dev/null", O_RDONLY); show_result(fd, 0); if (fd != EOF) close(fd); policy = "allow_read /dev/null"; write_domain_policy(policy, 0); fd = open("/dev/null", O_RDONLY); show_result(fd, 1); if (fd != EOF) close(fd); write_domain_policy(policy, 1); fd = open("/dev/null", O_RDONLY); show_result(fd, 0); if (fd != EOF) close(fd); policy = "allow_read /dev/null"; write_domain_policy(policy, 0); fd = open("/dev/null", O_RDONLY); show_result(fd, 1); if (fd != EOF) close(fd); write_domain_policy(policy, 1); fd = open("/dev/null", O_RDONLY); show_result(fd, 0); if (fd != EOF) close(fd); policy = "allow_read /dev/null"; write_domain_policy(policy, 0); fd = open("/dev/null", O_RDONLY); show_result(fd, 1); if (fd != EOF) close(fd); write_domain_policy(policy, 1); fd = open("/dev/null", O_RDONLY); show_result(fd, 0); if (fd != EOF) close(fd); set_profile(3, "file::mkfifo"); policy = "allow_mkfifo /tmp/mknod_fifo_test 0644"; write_domain_policy(policy, 0); filename = "/tmp/mknod_fifo_test"; show_result(mknod(filename, S_IFIFO | 0644, 0), 1); write_domain_policy(policy, 1); unlink2(filename); show_result(mknod(filename, S_IFIFO | 0644, 0), 0); memset(pbuffer, 0, sizeof(pbuffer)); memset(&sbuf, 0, sizeof(sbuf)); filename = "/dev/null"; stat(filename, &sbuf); snprintf(pbuffer, sizeof(pbuffer) - 1, "allow_write %s", filename); policy = pbuffer; write_domain_policy(policy, 0); fd = open(filename, O_WRONLY); show_result(fd, 1); if (fd != EOF) close(fd); write_domain_policy(policy, 1); fd = open(filename, O_WRONLY); show_result(fd, 0); if (fd != EOF) close(fd); policy = "allow_read/write /tmp/fifo"; mkfifo2("/tmp/fifo"); write_domain_policy(policy, 0); fd = open("/tmp/fifo", O_RDWR); show_result(fd, 1); if (fd != EOF) close(fd); write_domain_policy(policy, 1); fd = open("/tmp/fifo", O_RDWR); show_result(fd, 0); if (fd != EOF) close(fd); policy = "allow_read /dev/null"; write_domain_policy(policy, 0); fd = open("/dev/null", O_RDONLY); show_result(fd, 1); if (fd != EOF) close(fd); write_domain_policy(policy, 1); fd = open("/dev/null", O_RDONLY); show_result(fd, 0); if (fd != EOF) close(fd); policy = "allow_write /dev/null"; write_domain_policy(policy, 0); fd = open("/dev/null", O_WRONLY); show_result(fd, 1); if (fd != EOF) close(fd); write_domain_policy(policy, 1); fd = open("/dev/null", O_WRONLY); show_result(fd, 0); if (fd != EOF) close(fd); policy = "allow_read/write /dev/null"; write_domain_policy(policy, 0); fd = open("/dev/null", O_RDWR); show_result(fd, 1); if (fd != EOF) close(fd); write_domain_policy(policy, 1); fd = open("/dev/null", O_RDWR); show_result(fd, 0); if (fd != EOF) close(fd); policy = "allow_create /tmp/open_test 0644"; write_domain_policy(policy, 0); policy = "allow_write /tmp/open_test"; write_domain_policy(policy, 0); fd = open("/tmp/open_test", O_WRONLY | O_CREAT | O_EXCL, 0644); show_result(fd, 1); if (fd != EOF) close(fd); unlink2("/tmp/open_test"); write_domain_policy(policy, 1); fd = open("/tmp/open_test", O_WRONLY | O_CREAT | O_EXCL, 0644); show_result(fd, 0); if (fd != EOF) close(fd); unlink2("/tmp/open_test"); policy = "allow_create /tmp/open_test 0644"; write_domain_policy(policy, 1); policy = "allow_write /tmp/open_test"; write_domain_policy(policy, 0); policy = "allow_create /tmp/open_test 0644"; write_domain_policy(policy, 0); fd = open("/tmp/open_test", O_WRONLY | O_CREAT | O_EXCL, 0644); show_result(fd, 1); if (fd != EOF) close(fd); unlink2("/tmp/open_test"); write_domain_policy(policy, 1); fd = open("/tmp/open_test", O_WRONLY | O_CREAT | O_EXCL, 0644); show_result(fd, 0); if (fd != EOF) close(fd); unlink2("/tmp/open_test"); policy = "allow_write /tmp/open_test"; write_domain_policy(policy, 1); filename = "/tmp/truncate_test"; create2(filename); policy = "allow_truncate /tmp/truncate_test"; write_domain_policy(policy, 0); policy = "allow_write /tmp/truncate_test"; write_domain_policy(policy, 0); fd = open(filename, O_WRONLY | O_TRUNC); show_result(fd, 1); if (fd != EOF) close(fd); write_domain_policy(policy, 1); fd = open(filename, O_WRONLY | O_TRUNC); show_result(fd, 0); if (fd != EOF) close(fd); policy = "allow_truncate /tmp/truncate_test"; write_domain_policy(policy, 1); policy = "allow_write /tmp/truncate_test"; write_domain_policy(policy, 0); policy = "allow_truncate /tmp/truncate_test"; write_domain_policy(policy, 0); fd = open(filename, O_WRONLY | O_TRUNC); show_result(fd, 1); if (fd != EOF) close(fd); write_domain_policy(policy, 1); fd = open(filename, O_WRONLY | O_TRUNC); show_result(fd, 0); if (fd != EOF) close(fd); policy = "allow_write /tmp/truncate_test"; write_domain_policy(policy, 1); policy = "allow_truncate /tmp/truncate_test"; write_domain_policy(policy, 0); show_result(truncate(filename, 0), 1); write_domain_policy(policy, 1); show_result(truncate(filename, 0), 0); policy = "allow_truncate /tmp/truncate_test"; write_domain_policy(policy, 0); set_profile(0, "file::open"); fd = open(filename, O_WRONLY); set_profile(3, "file::open"); show_result(ftruncate(fd, 0), 1); write_domain_policy(policy, 1); show_result(ftruncate(fd, 0), 0); if (fd != EOF) close(fd); unlink2(filename); policy = "allow_create /tmp/mknod_reg_test 0644"; write_domain_policy(policy, 0); filename = "/tmp/mknod_reg_test"; show_result(mknod(filename, S_IFREG | 0644, 0), 1); write_domain_policy(policy, 1); unlink2(filename); show_result(mknod(filename, S_IFREG | 0644, 0), 0); policy = "allow_mkchar /tmp/mknod_chr_test 0644 1 3"; write_domain_policy(policy, 0); filename = "/tmp/mknod_chr_test"; show_result(mknod(filename, S_IFCHR | 0644, MKDEV(1, 3)), 1); write_domain_policy(policy, 1); unlink2(filename); show_result(mknod(filename, S_IFCHR | 0644, MKDEV(1, 3)), 0); policy = "allow_mkblock /tmp/mknod_blk_test 0644 1 0"; write_domain_policy(policy, 0); filename = "/tmp/mknod_blk_test"; show_result(mknod(filename, S_IFBLK | 0644, MKDEV(1, 0)), 1); write_domain_policy(policy, 1); unlink2(filename); show_result(mknod(filename, S_IFBLK | 0644, MKDEV(1, 0)), 0); policy = "allow_mkfifo /tmp/mknod_fifo_test 0644"; write_domain_policy(policy, 0); filename = "/tmp/mknod_fifo_test"; show_result(mknod(filename, S_IFIFO | 0644, 0), 1); write_domain_policy(policy, 1); unlink2(filename); show_result(mknod(filename, S_IFIFO | 0644, 0), 0); policy = "allow_mksock /tmp/mknod_sock_test 0644"; write_domain_policy(policy, 0); filename = "/tmp/mknod_sock_test"; show_result(mknod(filename, S_IFSOCK | 0644, 0), 1); write_domain_policy(policy, 1); unlink2(filename); show_result(mknod(filename, S_IFSOCK | 0644, 0), 0); policy = "allow_mkdir /tmp/mkdir_test/ 0600"; write_domain_policy(policy, 0); filename = "/tmp/mkdir_test"; show_result(mkdir(filename, 0600), 1); write_domain_policy(policy, 1); rmdir2(filename); show_result(mkdir(filename, 0600), 0); policy = "allow_rmdir /tmp/rmdir_test/"; write_domain_policy(policy, 0); filename = "/tmp/rmdir_test"; mkdir2(filename); show_result(rmdir(filename), 1); write_domain_policy(policy, 1); mkdir2(filename); show_result(rmdir(filename), 0); rmdir2(filename); policy = "allow_unlink /tmp/unlink_test"; write_domain_policy(policy, 0); filename = "/tmp/unlink_test"; create2(filename); show_result(unlink(filename), 1); write_domain_policy(policy, 1); create2(filename); show_result(unlink(filename), 0); unlink2(filename); policy = "allow_symlink /tmp/symlink_source_test"; write_domain_policy(policy, 0); filename = "/tmp/symlink_source_test"; show_result(symlink("/tmp/symlink_dest_test", filename), 1); write_domain_policy(policy, 1); unlink2(filename); show_result(symlink("/tmp/symlink_dest_test", filename), 0); policy = "allow_symlink /tmp/symlink_source_test"; write_domain_policy(policy, 0); filename = "/tmp/symlink_source_test"; show_result(symlink("/tmp/symlink_dest_test", filename), 1); write_domain_policy(policy, 1); unlink2(filename); show_result(symlink("/tmp/symlink_dest_test", filename), 0); policy = "allow_symlink /tmp/symlink_source_test"; write_domain_policy(policy, 0); filename = "/tmp/symlink_source_test"; show_result(symlink("/tmp/symlink_dest_test", filename), 1); write_domain_policy(policy, 1); unlink2(filename); show_result(symlink("/tmp/symlink_dest_test", filename), 0); policy = "allow_symlink /tmp/symlink_source_test"; write_domain_policy(policy, 0); filename = "/tmp/symlink_source_test"; show_result(symlink("/tmp/symlink_dest_test", filename), 1); write_domain_policy(policy, 1); unlink2(filename); show_result(symlink("/tmp/symlink_dest_test", filename), 0); policy = "allow_symlink /tmp/symlink_source_test"; write_domain_policy(policy, 0); filename = "/tmp/symlink_source_test"; show_result(symlink("/tmp/symlink_dest_test", filename), 1); write_domain_policy(policy, 1); unlink2(filename); show_result(symlink("/tmp/symlink_dest_test", filename), 0); policy = "allow_link /tmp/link_source_test /tmp/link_dest_test"; write_domain_policy(policy, 0); filename = "/tmp/link_source_test"; create2(filename); show_result(link(filename, "/tmp/link_dest_test"), 1); write_domain_policy(policy, 1); unlink2("/tmp/link_dest_test"); show_result(link(filename, "/tmp/link_dest_test"), 0); unlink2(filename); policy = "allow_rename /tmp/rename_source_test /tmp/rename_dest_test"; write_domain_policy(policy, 0); filename = "/tmp/rename_source_test"; create2(filename); show_result(rename(filename, "/tmp/rename_dest_test"), 1); write_domain_policy(policy, 1); unlink2("/tmp/rename_dest_test"); create2(filename); show_result(rename(filename, "/tmp/rename_dest_test"), 0); unlink2(filename); policy = "allow_mksock /tmp/socket_test 0755"; write_domain_policy(policy, 0); filename = "/tmp/socket_test"; memset(&addr, 0, sizeof(addr)); addr.sun_family = AF_UNIX; strncpy(addr.sun_path, filename, sizeof(addr.sun_path) - 1); fd = socket(AF_UNIX, SOCK_STREAM, 0); show_result(bind(fd, (struct sockaddr *) &addr, sizeof(addr)), 1); if (fd != EOF) close(fd); write_domain_policy(policy, 1); unlink2(filename); fd = socket(AF_UNIX, SOCK_STREAM, 0); show_result(bind(fd, (struct sockaddr *) &addr, sizeof(addr)), 0); if (fd != EOF) close(fd); filename = "/tmp/rewrite_test"; create2(filename); policy = "allow_read/write /tmp/rewrite_test"; write_domain_policy(policy, 0); write_exception_policy("deny_rewrite /tmp/rewrite_test", 0); policy = "allow_truncate /tmp/rewrite_test"; write_domain_policy(policy, 0); fd = open(filename, O_RDONLY); show_result(fd, 1); if (fd != EOF) close(fd); fd = open(filename, O_WRONLY | O_APPEND); show_result(fd, 1); if (fd != EOF) close(fd); fd = open(filename, O_WRONLY); show_result(fd, 0); if (fd != EOF) close(fd); fd = open(filename, O_WRONLY | O_TRUNC); show_result(fd, 0); if (fd != EOF) close(fd); fd = open(filename, O_WRONLY | O_TRUNC | O_APPEND); show_result(fd, 0); if (fd != EOF) close(fd); show_result(truncate(filename, 0), 0); set_profile(0, "file::open"); fd = open(filename, O_WRONLY | O_APPEND); set_profile(3, "file::open"); show_result(ftruncate(fd, 0), 0); show_result(fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) & ~O_APPEND), 0); if (fd != EOF) close(fd); write_domain_policy(policy, 1); policy = "allow_read/write /tmp/rewrite_test"; write_domain_policy(policy, 1); write_exception_policy("deny_rewrite /tmp/rewrite_test", 1); unlink2(filename); policy = "allow_ioctl socket:[family=2:type=2:protocol=17] " "35122-35124"; write_domain_policy(policy, 0); fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP); memset(&ifreq, 0, sizeof(ifreq)); snprintf(ifreq.ifr_name, sizeof(ifreq.ifr_name) - 1, "lo"); show_result(ioctl(fd, 35123, &ifreq), 1); write_domain_policy(policy, 1); policy = "allow_ioctl " "socket:[family=2:type=2:protocol=17] 0-35122"; write_domain_policy(policy, 0); show_result(ioctl(fd, 35123, &ifreq), 0); write_domain_policy(policy, 1); if (fd != EOF) close(fd); }
/** Copia arquivo de um sistema de arquivos para o outro Os parametros são: primeiro parametro => direção da copia -t copiar para o T2FS -f copiar para o FS do host segundo parametro => arquivo origem terceiro parametro => arquivo destino */ void cmdFscp(void) { // Pega a direção e os nomes dos arquivos origem e destion char *direcao = strtok(NULL, " \t"); char *src = strtok(NULL," \t"); char *dst = strtok(NULL," \t"); if (direcao==NULL || src==NULL || dst==NULL) { printf ("Missing parameter\n"); return; } // Valida direção if (strncmp(direcao, "-t", 2)==0) { // src == host // dst == T2FS // Abre o arquivo origem, que deve existir FILE *hSrc = fopen(src, "r+"); if (hSrc==NULL) { printf ("Open source file error\n"); return; } // Cria o arquivo de destino, que será resetado se existir FILE2 hDst = create2 (dst); if (hDst<0) { fclose(hSrc); printf ("Create destination file error: %d\n", hDst); return; } // Copia os dados de source para destination char buffer[2]; while( fread((void *)buffer, (size_t)1, (size_t)1, hSrc) == 1 ) { write2(hDst, buffer, 1); } // Fecha os arquicos fclose(hSrc); close2(hDst); } else if (strncmp(direcao, "-f", 2)==0) { // src == T2FS // dst == host // Abre o arquivo origem, que deve existir FILE2 hSrc = open2 (src); if (hSrc<0) { printf ("Open source file error: %d\n", hSrc); return; } // Cria o arquivo de destino, que será resetado se existir FILE *hDst = fopen(dst, "w+"); if (hDst==NULL) { printf ("Open destination file error\n"); return; } // Copia os dados de source para destination char buffer[2]; while ( read2(hSrc, buffer, 1) == 1 ) { fwrite((void *)buffer, (size_t)1, (size_t)1, hDst); } // Fecha os arquicos close2(hSrc); fclose(hDst); } else { printf ("Invalid copy direction\n"); return; } printf ("Files successfully copied\n"); }
void test_create2() { create1(); create2(); }
void feedback(int n, int m, int p, int q, int nb, int output_level, int nn, int input, char *ifn, char *ofn) { dcmplx A[n][n], B[n][m], C[p][n]; dcmplx s[nn], Is[n][n], Is_A[n][n], tmp[p][n], M[p][m]; double a[nn*2], b[nn*p*m*2], *points, *planes, r; int i, j, k, start, nbsols; FILE *ifp, *ofp; timer t_phc; ofp=fopen(ofn, "w"); /*open for writing*/ fprintf(ofp, "n=%d\n", n); fprintf(ofp, "m=%d\n", m); fprintf(ofp, "p=%d\n", p); fprintf(ofp, "q=%d\n", q); if(input == 0) { ifp=fopen(ifn, "r"); /*open for reading*/ skip(ifp); read_dcmatrix0(n, n, A, ifp); printf( "The given matrix A(%d*%d) is:\n", n, n); print_dcmatrix(n, n, A); read_dcmatrix0(n, m, B, ifp); printf("The given matrix B(%d*%d) is:\n", n, m); print_dcmatrix(n, m, B); read_dcmatrix0(p, n, C, ifp); printf("The given matrix C(%d*%d) is:\n", p, n); print_dcmatrix(p, n, C); for(i=0; i<n+q; i++) read_dcmplx0(&s[i], ifp); for(i=n+q; i<nn; i++) /*generate more poles as interpolation points */ { s[i] = create1(cos(rand())); if(s[i].re>0) s[i] = min_dcmplx(s[i]); } fclose(ifp); } if(input == 1) { ifp=fopen(ifn, "r"); /*open for reading*/ skip(ifp); read_dcmatrix2(n, n, A, ifp); printf( "The given matrix A(%d*%d) is:\n", n, n); print_dcmatrix(n, n, A); read_dcmatrix2(n, m, B, ifp); printf("The given matrix B(%d*%d) is:\n", n, m); print_dcmatrix(n, m, B); read_dcmatrix2(p, n, C, ifp); printf("The given matrix C(%d*%d) is:\n", p, n); print_dcmatrix(p, n, C); for(i=0; i<n+q; i++) read_dcmplx1(&s[i], ifp); for(i=n+q; i<nn; i++) /*generate more poles as interpolation points */ { s[i] = create1(cos(rand())); if(s[i].re>0) s[i] = min_dcmplx(s[i]); } fclose(ifp); } if(input==2) { random_dcmatrix ( n, n, A); printf("\nThe random generated matrix A is:\n"); print_dcmatrix(n, n, A); random_dcmatrix ( n, m, B); printf("\nThe random generated matrix B is:\n"); print_dcmatrix(n, m, B); random_dcmatrix ( p, n, C); printf("\nThe random generated matrix C is:\n"); print_dcmatrix(p, n, C); s[0] = create2(-0.23423423423, 0); /* fix one pole for testing realization */ for(i=1; i<nn; i++) { r = rand(); s[i] = create2(cos(r), sin(r)); if(s[i].re>0) s[i] = min_dcmplx(s[i]); s[++i] = conjugate(s[i]); if(i==(nn-2)) { if((nn%2)==0) s[++i] = create1(-1.0); } } printf("\nThe random generated poles are:\n"); for(i=0; i<nn; i++) writeln_dcmplx(s[i]); } if(input==3) { random_dcmatrix0 ( n, n, A); printf("\nThe random generated matrix A is:\n"); print_dcmatrix(n, n, A); random_dcmatrix0 ( n, m, B); printf("\nThe random generated matrix B is:\n"); print_dcmatrix(n, m, B); random_dcmatrix0 ( p, n, C); printf("\nThe random generated matrix C is:\n"); print_dcmatrix(p, n, C); s[0] = create2(-0.23423423423, 0); /* fix one pole for test */ for(i=1; i<nn; i++) { r = rand(); s[i] = create2(cos(r), sin(r)); if(s[i].re>0) s[i] = min_dcmplx(s[i]); s[++i] = conjugate(s[i]); if(i==(nn-2)) { if((nn%2)==0) s[++i] = create1(-1.0); } } printf("\nThe random generated poles are:\n"); for(i=0; i<nn; i++) writeln_dcmplx(s[i]); } if(input == 4) { ifp=fopen(ifn, "r"); /*open for reading*/ skip(ifp); read_dcmatrix0(n, n, A, ifp); printf( "The given matrix A(%d*%d) is:\n", n, n); print_dcmatrix(n, n, A); read_dcmatrix0(n, m, B, ifp); printf("The given matrix B(%d*%d) is:\n", n, m); print_dcmatrix(n, m, B); read_dcmatrix0(p, n, C, ifp); printf("The given matrix C(%d*%d) is:\n", p, n); print_dcmatrix(p, n, C); for(i=0; i<n+q; i++) read_dcmplx1(&s[i], ifp); for(i=n+q; i<nn; i++) /*generate more poles as interpolation points */ { s[i] = create1(cos(rand())); if(s[i].re>0) s[i] = min_dcmplx(s[i]); } fclose(ifp); } /* print the input matrices in matlab format for further study */ fprintf(ofp,"A=[\n"); print_dcmatrix1(n, n, A, ofp); fprintf(ofp,"]\n"); fprintf(ofp,"B=[\n"); print_dcmatrix1(n, m, B, ofp); fprintf(ofp,"]\n"); fprintf(ofp,"C=[\n"); print_dcmatrix1(p, n, C, ofp); fprintf(ofp,"]\n"); fprintf(ofp, "\nPoles=["); for(i=0; i<nn; i++) { write_dcmplx1(s[i], ofp); if(i!=(nn-1)) fprintf(ofp, ","); } fprintf(ofp, "]\n"); /* end of input */ j = 0; for(i=0; i<nn; i++) { a[j++] = s[i].re; a[j++] = s[i].im; } start = 0; for(k=0; k<n+q; k++) { for(i=0; i<n; i++) for(j=0; j<n; j++) { if(i==j) Is[i][j] = s[k]; else Is[i][j] = zero; } sub_dcmatrix(n, n, Is, A, Is_A); dcinverse(n, Is_A); multiply_dcmatrix(p, n, n, C, Is_A, tmp); multiply_dcmatrix(p, n, m, tmp, B, M); c2ada_dc_matrix( p, m, M, nn*p*m*2, b, start); start = start + p*m*2; } /* generate some random planes */ for( i=start ; i<nn*p*m*2; i++ ) { b[i++] = cos(rand()); b[i] = 0.0; } fflush(stdout); fflush(ofp); printf("\nComputing the feedback law with PHC ...\n"); tstart(&t_phc); adainit(); nbsols = _ada_pieri_solver(m, p, q, nb, output_level, a, b, ofn); adafinal(); tstop(&t_phc); /* This subroutine spends almost all the time */ tprint(t_phc); printf("\nSee %s for the realization of the output feedbacks.\n", ofn); fclose(ofp); }