LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-24-2008, 12:24 AM   #1
simasimon
Member
 
Registered: Mar 2006
Posts: 60

Rep: Reputation: 15
Minix- Copying a file


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();
 
Old 11-27-2008, 03:40 PM   #2
simasimon
Member
 
Registered: Mar 2006
Posts: 60

Original Poster
Rep: Reputation: 15
For those interested i found one bug in that code.. One of the possibly many errors that code has is that first i 'alloced' the blocks and marked them as DIRTY.. that info goes to the cache.. afterwards y write info into that blocks, but directly into the disc. So when I call do_sync.. that function puts what is marked as DIRTY in the cache into the disc, steping over what i had directly written into the disc.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Question on File System and File Copying hey_joe Linux - Newbie 2 11-05-2003 10:30 AM
copying file ronss Linux - Software 3 08-31-2003 03:04 AM
Copying a File... Nefarious Linux - General 3 11-28-2002 12:23 AM
MINIX File System On Floppy ? Scott00TJ Linux - Newbie 1 05-31-2002 09:08 AM
Copying a file tgonetwork Linux - Newbie 3 01-16-2002 10:08 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:43 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration