Beispiel #1
0
Datei: mv.c Projekt: elbing/apex
int
mv(char *from, char *todir, char *toelem)
{
	int stat;
	Dir *dirb;

	dirb = dirstat(from);
	if(dirb == nil){
		fprint(2, "mv: can't stat %s: %r\n", from);
		return -1;
	}
	stat = mv1(from, dirb, todir, toelem);
	free(dirb);
	return stat;
}
Beispiel #2
0
int ext2(void) {
    printf("Hello World, this is the Ext2 FS\n");
    // Hardcode test fs into memory so that we can test read
    // Set up the superblock
    struct ext2_super_block *sb;
    sb = (struct ext2_super_block*) (VIRT_MEM_LOCATION +
                                     EXT2_SUPERBLOCK_LOCATION);
    sb->s_inodes_count          = 50;
    sb->s_blocks_count          = 8192;
    sb->s_r_blocks_count        = 6;
    sb->s_free_blocks_count     = 8186;
    sb->s_free_inodes_count     = 49;
    sb->s_first_data_block      = 1;
    sb->s_log_block_size        = 0;
    sb->s_log_frag_size         = 0;
    sb->s_blocks_per_group      = 8192;
    sb->s_frags_per_group       = 8192;
    sb->s_inodes_per_group      = 50;
    sb->s_magic                 = EXT2_MAGIC;
    sb->s_state                 = EXT2_VALID_FS;
    sb->s_errors                = EXT2_ERRORS_CONTINUE;
    sb->s_creator_os            = EXT2_OS_XINU;
    sb->s_first_ino             = 2;
    sb->s_inode_size            = sizeof( struct ext2_inode );
    sb->s_block_group_nr        = 0;
    char name[16]               = "FAKE RAM FS :D";
    memcpy(sb->s_volume_name,name,16);

    // Set up the group descriptors table
    struct ext2_group_desc *gpd;
    // DUMB POINTER ARITHMATIC
    gpd = (struct ext2_group_desc *) (sb + 1);
    gpd->bg_block_bitmap        = 2;
    gpd->bg_inode_bitmap        = 3;
    gpd->bg_inode_table         = 4;
    gpd->bg_free_blocks_count   = 44;
    gpd->bg_free_inodes_count   = 19;
    gpd->bg_used_dirs_count     = 1;

    // Set up the block bitmap
    uint8 *blBitmap;
    blBitmap = (uint8 *) (sb + 2);
    blBitmap[0] = 0x3F;      // super block
    int i;
    for (i = 6; i < sb->s_blocks_count; i++)
        blBitmap[i] = 0;
    // Set up the inode bitmap
    uint8 *iBitmap;
    iBitmap = (uint8 *) (sb + 3);
    iBitmap[0] = 0x1;     // .
    for (i = 1; i < sb->s_inodes_count; i++)
        iBitmap[i] = 0;

    // Set up the inode table
    struct ext2_inode *iTbl;
    iTbl = (struct ext2_inode *) (sb + 4);
    // Set up . inode
    iTbl->i_mode = EXT2_S_IFDIR;
    iTbl->i_size = sizeof(struct ext2_dir_entry_2);
    iTbl->i_links_count = 0;
    iTbl->i_blocks = 1;
    iTbl->i_flags = EXT2_NODUMP_FL;
    iTbl->i_block[0] = 5;

    // Set up . entry for the home directory
    struct ext2_dir_entry_2 *blk5;
    blk5 = (struct ext2_dir_entry_2 *) (sb + 5);
    blk5->inode = 1;
    blk5->next_dirent = 0;
    blk5->name_len = 1;
    blk5->filetype = 2;
    char homeName[255] = ".";
    memcpy(blk5->name, homeName, 255);

    _fs_ext2_init();

    touch1( xinu_fs, "./", "test" );
    char bufferL[9] = "Go long!";
    uint32 bytes_written;
    ext2_write_status stat = ext2_write_file_by_path( xinu_fs, "./test", bufferL,
                                                      &bytes_written, 0, 8 );
    touch1( xinu_fs, "./", "yo");
    stat = ext2_write_file_by_path( xinu_fs, "./yo", bufferL,
                                                      &bytes_written, 0, 8 );
    touch1( xinu_fs, "./", "whoah" );
    stat = ext2_write_file_by_path( xinu_fs, "./whoah", bufferL,
                                                    &bytes_written, 0, 8 );
    touch1( xinu_fs, "./", "iasjdf" );
    stat = ext2_write_file_by_path( xinu_fs, "./iasjdf", bufferL,
                                                    &bytes_written, 0, 8 );
    touch1( xinu_fs, "./", "f" );
    stat = ext2_write_file_by_path( xinu_fs, "./f", bufferL,
                                                    &bytes_written, 0, 8 );
    ls1( xinu_fs, "./" );
    printf("removing yo\n");
    rm1( xinu_fs, "./", "yo" );
    ls1( xinu_fs, "./" );
    printf("touching asdf\n");
    touch1( xinu_fs, "./", "asdf" );
    stat = ext2_write_file_by_path( xinu_fs, "./asdf", bufferL,
                                                    &bytes_written, 0, 8 );
    ls1( xinu_fs, "./" );
    printf("mking dir\n");
    mkdir1( xinu_fs, "./", "dir" );
    ls1( xinu_fs, "./" );
    printf("touching yo\n");
    touch1( xinu_fs, "./dir/", "yo" );
    ls1( xinu_fs, "./dir/");

    copy1( xinu_fs, "./", "whoah", "./", "hello" );
    ls1( xinu_fs, "./" );
    cat1( xinu_fs, "./", "hello" );

    copy1( xinu_fs, "./", "hello", "./dir/", "hello" );
    printf("HERE\n");
    ls1( xinu_fs, "./dir/" );
    cat1( xinu_fs, "./dir/", "hello" );

    printf("removeing\n");
    mv1( xinu_fs, "./dir/", "yo", "./", "a" );
    ls1( xinu_fs, "./" );
    cat1( xinu_fs, "./", "a" );

#if 0
    // Test the read/write functions
    printf("Testing hardcoded data\n");
    print_superblock( xinu_fs->sb );
    struct ext2_inode *i1 = ext2_get_inode(xinu_fs, 1);
    print_inode( i1, 1, xinu_fs );
    struct ext2_dir_entry_2 *home = ext2_get_first_dirent(xinu_fs, i1 );
    print_dirent( home );

    uint32 inode_num = ext2_inode_alloc( xinu_fs );
    struct ext2_inode *i2 = ext2_get_inode( xinu_fs, inode_num+1 );
    i2->i_mode = EXT2_S_IFREG;
    i2->i_size = 0;
    printf("Allocated new inode\n");
    print_inode( i2, inode_num+1, xinu_fs );

    struct ext2_dir_entry_2 *dirent = ext2_dirent_alloc( xinu_fs, i1 );
    dirent->inode = 2;
    dirent->next_dirent = 0;
    dirent->name_len = 4;
    dirent->filetype = EXT2_FT_REG_FILE;
    char testName[255] = "test";
    memcpy(dirent->name, testName, 255);
    printf("Allocated new dir_entry_2 test\n");
    print_dirent( dirent );

    char path[8] = "./test";
    char buffer[14] = "Writing! Yay!";
    char bufferL[9] = "Go long!";
    uint32 bytes_written;
    ext2_write_status stat = ext2_write_file_by_path( xinu_fs, path, buffer,
                                                      &bytes_written, 0, 13 );
    printf("bytes_written = %d stat = %d\n", bytes_written, stat);
    char buffer2[12*1024];
 //   stat = ext2_write_file_by_path( xinu_fs, path, buffer2,
  //                                                    &bytes_written, 13, (12*1024)-1 );
    printf("bytes_written = %d stat = %d\n", bytes_written, stat);
//    stat = ext2_write_file_by_path( xinu_fs, path, bufferL,
//                                                      &bytes_written, (12*1024)+12, 8 );
    printf("bytes_written = %d stat = %d\n", bytes_written, stat);
    int read = 0;
    char readBuf[30];
    read = ext2_read_dirent( xinu_fs, dirent, readBuf, 0, 29);
    printf("Read %d bytes readBuf = %s\n", read, readBuf);
//    read = ext2_read_dirent( xinu_fs, dirent, readBuf, (12*1024)+12, 10);
//    printf("Read %d bytes readBuf = %s\n", read, readBuf);
#endif
    return 0;
}
Beispiel #3
0
int Board::moveMiaiPart(Move mv, bool useMiai, int& bdset, int cpt) {
// useMiai true... continue with move( )...
  int nbr,nbrRoot; int lcn = mv.lcn; int s = mv.s;
  release_miai(mv); // your own miai, so connectivity ok
  int miReply = reply[nx(opt(s))][lcn];
  if (miReply != lcn) { // playing into opponent miai... which will be released
    // WARNING: if opp'ts next move is not to the miai response, conn'ty needs to be recomputed
    //prtLcn(lcn); printf(" released opponent miai\n"); 
    release_miai(Move(opt(s),lcn));
  }
  // avoid directional bridge bias: search in random order
  int x, perm[NumNbrs] = {0, 1, 2, 3, 4, 5}; 
  shuffle_interval(perm,0,NumNbrs-1); 
  for (int t=0; t<NumNbrs; t++) {  // look for miai nbrs
    // in this order 1) connecting to a stone  2) connecting to a side
    x = perm[t]; assert((x>=0)&&(x<NumNbrs));
    nbr = lcn + Bridge_offsets[x]; // nbr via bridge
    int c1 = lcn+Nbr_offsets[x];     // miai carrier 
    int c2 = lcn+Nbr_offsets[x+1];   // other miai carrier
    Move mv1(s,c1); 
    Move mv2(s,c2); 
         // y border realign: move the miai so stones are connected *and* adjacent to border
         //   * -         becomes  * m
         //  m m *                - m *
         // g g g g              g g g g     <-  border guards 
    // rearrange this: 4 cases: both before/after miais possible, only after, only before, none of above
    if (board[nbr] == s &&
        board[c1] == EMP &&
        board[c2] == EMP &&
        (not_in_miai(mv1)||not_in_miai(mv2))) {
          if (!not_in_miai(mv1)) {
            if (near_edge(c1) && (near_edge(lcn) || near_edge(nbr)))
              YborderRealign(Move(s,nbr),cpt,c1,reply[nx(s)][c1],c2);
          }
          else if (!not_in_miai(mv2)) {
            if (near_edge(c2) && (near_edge(lcn) || near_edge(nbr)))
              YborderRealign(Move(s,nbr),cpt,c2,reply[nx(s)][c2],c1);
         }
         else if (Find(p,nbr)!=Find(p,cpt)) {  // new miai candidate
           //nbrRoot = Find(p,nbr); //int b  = brdr[nbrRoot]  | brdr[cpt];
           //int nbr0 = lcn+Bridge_offsets[x-1]; int c0 = lcn + Nbr_offsets[x-1];
           //if ((board[nbr0]==s) && (board[c0]==EMP) && (Find(p,nbr0)!=Find(p,cpt))) {
             //// nbr0 also new miai candidate, which is better?
             //int nbrRoot0 = Find(p,nbr0);
             //int b0 = brdr[nbrRoot0] | brdr[cpt];
             //if (numSetBits(b0) > numSetBits(b)) { c2 = c0; nbrRoot = nbrRoot0; }
           //} 
           //int nbr2 = lcn+Bridge_offsets[x+1]; int c3 = lcn + Nbr_offsets[x+2];
           //if ((board[nbr2]==s) && (board[c3]==EMP) && (Find(p,nbr2)!=Find(p,cpt))) {
             //int nbrRoot2 = Find(p,nbr2);
             //int b2 = brdr[nbrRoot2] | brdr[cpt];
             //int b  = brdr[nbrRoot]  | brdr[cpt];
             //if (numSetBits(b2) > numSetBits(b)) { c1 = c3; nbrRoot = nbrRoot2; }
             nbrRoot = Find(p,nbr); //int b  = brdr[nbrRoot]  | brdr[cpt];
             brdr[nbrRoot] |= brdr[cpt];
             cpt = Union(p,cpt,nbrRoot); 
             set_miai(s,c1,c2);
             } 
         }
    else if ((board[nbr] == GRD) &&
             (board[c1]  == EMP) &&
             (board[c2]  == EMP) &&
             (not_in_miai(mv1))&&
             (not_in_miai(mv2))) { // new miai
      brdr[cpt] |= brdr[nbr];
      set_miai(s,c1,c2);
      }
  }
  bdset = brdr[cpt];
  return miReply;
}