int bullet_start() { long free; /* # units of resource still free */ /* Now that we can start ... */ message("BULLET SERVER STARTUP"); if (a_begin(A_DISKBLOCKS, (Res_addr) Superblock.s_inodetop + 1, (Res_addr) Superblock.s_numblocks) < 0) { bpanic("Cannot begin resource allocator for disk blocks.\n"); } /* Convert file get-port to put-port */ priv2pub(&Superblock.s_fileport,&FilePutPort) ; /* Get the inode table and start inode allocator */ /* Could have been done by setinodes() as a result of a welcome */ if ( !Inode_table) inode_init(); /* Work out which inodes and disk blocks are in use. */ build_free_list(); message("%ld inodes free, %ld inodes used", bs_local_inodes_free, - 1); if ((free = a_notused(A_DISKBLOCKS)) < 0) { bpanic("Defective diskblock free list\n"); } message("%ld disk blocks free, %ld disk blocks used", free, Superblock.s_numblocks - free); return 1 ; }
void test_int_range () { int inputs [] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 19, 99, 999, -1, -3, -99, 234234 }; int outputs [] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, -1, -1, -1, 10 }; std::vector<int> results; std::vector<int> in_v; std::copy ( a_begin(inputs), a_end(inputs), std::back_inserter ( in_v )); ba::clamp_range ( a_begin(inputs), a_end(inputs), std::back_inserter ( results ), -1, 10 ); BOOST_CHECK ( std::equal ( results.begin(), results.end (), outputs )); results.clear (); ba::clamp_range ( in_v.begin (), in_v.end (), std::back_inserter ( results ), -1, 10 ); BOOST_CHECK ( std::equal ( results.begin(), results.end (), outputs )); results.clear (); ba::clamp_range ( a_begin(inputs), a_end(inputs), std::back_inserter ( results ), 10, -1, intGreater ); BOOST_CHECK ( std::equal ( results.begin(), results.end (), outputs )); results.clear (); ba::clamp_range ( in_v.begin (), in_v.end (), std::back_inserter ( results ), 10, -1, intGreater ); BOOST_CHECK ( std::equal ( results.begin(), results.end (), outputs )); results.clear (); ba::clamp_range ( a_range(inputs), std::back_inserter ( results ), -1, 10 ); BOOST_CHECK ( std::equal ( results.begin(), results.end (), outputs )); results.clear (); ba::clamp_range ( in_v, std::back_inserter ( results ), -1, 10 ); BOOST_CHECK ( std::equal ( results.begin(), results.end (), outputs )); results.clear (); ba::clamp_range ( a_range(inputs), std::back_inserter ( results ), 10, -1, intGreater ); BOOST_CHECK ( std::equal ( results.begin(), results.end (), outputs )); results.clear (); ba::clamp_range ( in_v, std::back_inserter ( results ), 10, -1, intGreater ); BOOST_CHECK ( std::equal ( results.begin(), results.end (), outputs )); results.clear (); int junk[elementsof(inputs)]; ba::clamp_range ( inputs, junk, 10, -1, intGreater ); BOOST_CHECK ( std::equal ( b_e(junk), outputs )); }
int compare_filenames(const std::string& a, const std::string& b) { utf8_const_iterator a_begin(a.begin()), a_end(a.end()); utf8_const_iterator b_begin(b.begin()), b_end(b.end()); utf8_const_iterator a_it(a_begin); utf8_const_iterator b_it(b_begin); for (; a_it != a_end && b_it != b_end; ) { int a_chr = *a_it; int b_chr = *b_it; if ((a_chr >= '0') && (a_chr <= '9') && (b_chr >= '0') && (b_chr <= '9')) { utf8_const_iterator a_it2 = a_it; utf8_const_iterator b_it2 = b_it; while (a_it2 != a_end && (*a_it2 >= '0') && (*a_it2 <= '9')) ++a_it2; while (b_it2 != b_end && (*b_it2 >= '0') && (*b_it2 <= '9')) ++b_it2; int a_num = std::strtol(std::string(a_it, a_it2).c_str(), NULL, 10); int b_num = std::strtol(std::string(b_it, b_it2).c_str(), NULL, 10); if (a_num != b_num) return a_num - b_num < 0 ? -1: 1; a_it = a_it2; b_it = b_it2; } else if (is_path_separator(a_chr) && is_path_separator(b_chr)) { ++a_it; ++b_it; } else { a_chr = std::tolower(a_chr); b_chr = std::tolower(b_chr); if (a_chr != b_chr) return a_chr - b_chr < 0 ? -1: 1; ++a_it; ++b_it; } } if (a_it == a_end && b_it == b_end) return 0; else if (a_it == a_end) return -1; else return 1; }
int bullet_init() { vir_bytes size; peer_bits test_var ; /* Initialize to logging */ bs_log_msgs=1 ; #ifndef USER_LEVEL bs_print_msgs = 0; #endif bs_debug_level = DEBUG_LEVEL ; /* Check that inode size is sensible - otherwise the compiler is odd */ if (sizeof (Inode) != INODE_SIZE) { bwarn("Inode size is %d, should be %d\nServer is inactive!", sizeof(Inode), INODE_SIZE); return 0; } /* Check that the peer bitmap can contain all members */ test_var=1 ; test_var <<= (S_MAXMEMBER-1) ; if ( test_var == 0 || test_var!= (1<<(S_MAXMEMBER-1)) ) { bwarn("type \"peer_bits\" is too small\nServer is inactive!"); return 0; } /* Figure out which vdisk to use and read the superblock */ if (get_disk_server_cap() == 0) return 0; /* Now that we know there is a disk we can announce ourselves */ message("BULLET SERVER INITIALIZATION"); /* * Set up pointers to beginning and end of buffer cache. * Make sure that our buffer cache is block aligned! The inode table * goes at the start of the cache memory and relies on blocksize * alignment. * NB: We must leave some memory free for other kernel threads and * possible user processes (such as soap). It leaves * BS_MEM_RESERVE bytes if no fixed cache size is defined. */ #ifdef BULLET_MEMSIZE size = BULLET_MEMSIZE; #else size = seg_maxfree(); if (size < BS_MEM_RESERVE) { bpanic( "bullet_init: memory reserve (0x%x) exceeds free memory (0x%x)\n", BS_MEM_RESERVE, size); } size -= BS_MEM_RESERVE; #endif /* BULLET_MEMSIZE */ /* * The following allocate may take a long time, especially when lots * of memory (32Mb :-) is involved. However, since kernel threads are * not preempted the enqueued interrupt routines never get a chance to * run, and eventually the interrupt queue will overflow causing a * panic. */ #ifndef USER_LEVEL disable(); #endif /* USER_LEVEL */ Bc_begin = (bufptr) aalloc(size, (int) Blksizemin1 + 1); #ifndef USER_LEVEL enable(); #endif /* USER_LEVEL */ Bc_end = Bc_begin + size; if (Bc_begin >= Bc_end) bpanic("bullet_init: no buffer cache"); /* Initialise resource allocation. NB: cache_mem is initially free! */ a_init(BYTES_TO_MEG(Bc_end - Bc_begin) + BLOCKS_TO_MEG(Superblock.s_numblocks, Blksizemin1 + 1)); if (a_begin(A_CACHE_MEM, (Res_addr) Bc_begin, (Res_addr) Bc_end) < 0) bpanic("Cannot begin resource allocator for buffer cache.\n"); /* Initialise buffer cache management */ cache_init(); Largest_file_size = (b_fsize) a_notused(A_CACHE_MEM); /* Print some cheery statistics about the current state of the server */ message("Buffer cache size = 0x%lx bytes", Bc_end - Bc_begin); message("Largest possible file size = 0x%lx bytes",Largest_file_size); /* Calculate the size of the super struct in local blocks */ /* It is the of disk blocks into a D_PHYSBLK */ if ( D_PHYS_SHIFT<=Superblock.s_blksize ) { /* Super info takes one block or less */ bs_super_size= 1 ; } else { /* To be honest, bs_supersize will always be one, because * D_PHYS_SHIFT seems to be the minimum. */ bwarn("Super block takes more then one block") ; bs_super_size= 1 << (D_PHYS_SHIFT-Superblock.s_blksize) ; } /* Super Block Lock */ mu_init(&SuperLock) ; /* Init group structures */ bs_grp_init() ; return 1 ; }