I'm working with Minix 2.0.
I need to make a copy of a file, in a place where i only have the i-node of the file. What i want to do is, create a new node, that i can do, and then copy each block one at a time so i can have a copy of the original file but with a different inode and different disk blocks. I need to do the copy here, and i don't know what's going wrong with the code i attach. Here's where i create the node first, then create new blocks, 7 in total, and then try to copy the blocks from the node i received as a parameter in "node". I'm using the Minix Filesysten V2.
Code:
if((bck_node = new_node(mypath,I_REGULAR, NO_ZONE)) == NIL_INODE)
{
printf("Could not create inode. No backup available for this version.\n");
return;
}else printf("The node %s has been created succesfully\n", mypath);
printf("Creating Backup file...\n");
/* Creo los 7 bloques (solo backup de archivos de hasta 7K).*/
for(i=0; i < 7; i++)
{
/* Creo un nuevo bloque en el nodo backup */
myblock = new_block(bck_node, i*BLOCK_SIZE);
myblock->b_dirt = DIRTY;
put_block(myblock, BACK_DATA);
}
bck_node->i_size = BLOCK_SIZE * (7);
bck_node->i_dirt = DIRTY;
rw_inode(bck_node, WRITING);
/* Una vez creados los 7 bloques, paso a copiar */
for(i = 0; i<7; i++){
printf("Ciclo : %d\n", i);
rd = dev_io(DEV_READ, FALSE, bck_node->i_dev,
(node->i_zone[i] << scale) * BLOCK_SIZE, BLOCK_SIZE, FS_PROC_NR,
(void *)buf);
if(rd < BLOCK_SIZE)
{
printf("Svn Error: Coult not read block. Block not added to \
Backup\n");
return;
}
wr = dev_io(DEV_WRITE, FALSE, bck_node->i_dev,
(bck_node->i_zone[i] << scale)* BLOCK_SIZE, BLOCK_SIZE, FS_PROC_NR,
(void *)buf);
if(wr < BLOCK_SIZE)
{
printf("Svn Error: Coult not write in block. Block not added to \
Backup\n");
return;
}
printf("Ciclo : %d -> %s\n", i, buf);
}
do_sync();