Results 1 to 15 of 15

Thread: own file_system

  1. #1
    kate88 is offline Member
    Join Date
    Nov 2010
    Posts
    10
    Rep Power
    0

    Default own file_system

    Hi everyone! I've just seen the topic of my semester's project from Operating Systems and I need your help:P What I have to do is write an disturbed file system in java (use some server like Glassfish )
    So I'm asking anyone who have some kind of experience in operating systems for some advices how to start with this (maybe give me some links to interesting examples etc.). Any help would be useful.
    Last edited by kate88; 12-28-2010 at 12:11 PM.

  2. #2
    kate88 is offline Member
    Join Date
    Nov 2010
    Posts
    10
    Rep Power
    0

    Default

    please help me!

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,767
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by kate88 View Post
    please help me!
    You can follow some unix 'philosophy', i.e. you should be able to open( ... ) and close( ... ) a file and you should be able to read( ... ) and write( ... ) it; before you have a file you should be able to create( ... ) it and you should be able to remove( ... ) it. Optionally you could implement some ioctl( ... ) (IO control) functionality. Your functionality can 'lean' on any existing functionality offered by a 'real' file systyem.,

    kind regards,

    Jos
    Last edited by JosAH; 12-27-2010 at 05:54 PM.
    cenosillicaphobia: the fear for an empty beer glass

  4. #4
    kate88 is offline Member
    Join Date
    Nov 2010
    Posts
    10
    Rep Power
    0

    Default

    thanks for reply!
    Now I have problem how to do it on glassfish server. As far as I know Java EE does not allow using java.io .. Do you have any idea how to store data on such server?

  5. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,767
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by kate88 View Post
    thanks for reply!
    Now I have problem how to do it on glassfish server. As far as I know Java EE does not allow using java.io .. Do you have any idea how to store data on such server?
    It would surprise me if a server wouldn't allow any file I/O; it would be an ESS(tm) (Extemely Silly Server ;-) Remember that your code runs on a server side so it is part of a server. A client can't do any file I/O on a server without a sever wanting to do file I/O.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  6. #6
    kate88 is offline Member
    Join Date
    Nov 2010
    Posts
    10
    Rep Power
    0

    Default

    and what do you think about using JNDI?
    Like:
    ByteArrayOutputStream b= new ByteArrayOutputStream();
    ObjectOutputStream o = new ObjectOutputStream(b);
    o.writeObject(myObj);
    new InitialContext().bind("path/to/myobject", baos.toByteArray());


    Would it be effective?

  7. #7
    toadaly is offline Senior Member
    Join Date
    Jan 2009
    Posts
    671
    Rep Power
    6

    Default

    If your server will expose a distributed file system, then necessarily there are multiple servers involved. Before you start thinking about writing code, you need to plan out how one portal is going to display links to files on other servers, and allow files on those servers to be copied, deleted, moved, and renamed, while presenting a consistent view to the user.

    (you might also allow changing of permissions, restrictions based on user and group, a secure log in, etc.)

  8. #8
    kate88 is offline Member
    Join Date
    Nov 2010
    Posts
    10
    Rep Power
    0

    Default

    my teacher told that i can assume that there will be only one server but many users can read one file in the same time (and only one can write).He want me to nicely solve the problem of synchronization. FIles will be big (for example 2gb) and they will be divided into small parts. In addition every user will who read the file, will use another instance of file.

  9. #9
    toadaly is offline Senior Member
    Join Date
    Jan 2009
    Posts
    671
    Rep Power
    6

    Default

    Ok, well, you might want to take a look at the java.nio.channels.FileChannel API, which is designed for this purpose. It allows you to lock an entire file, or just portions of a file, and also works with RandomAccessFile's, which is what you're going to want if you're dealling with very large files accessed by multiple users.

  10. #10
    kate88 is offline Member
    Join Date
    Nov 2010
    Posts
    10
    Rep Power
    0

    Default

    Is it possible with java.nio to create new instance of file for every reader? In my system I want every reader to have another instance of file (file is divided into blocks).. And I want to have only one writer who also get another instance. After writer finishes editing file the file is updated on server (while all readers are still reading their own instances). Can you tell me how to do this with java nio?

  11. #11
    toadaly is offline Senior Member
    Join Date
    Jan 2009
    Posts
    671
    Rep Power
    6

    Default

    You keep saying that the file is divided into blocks. I'm not sure what the significance of that statement is. Does it imply something about how the file is permitted to be accessed?

  12. #12
    kate88 is offline Member
    Join Date
    Nov 2010
    Posts
    10
    Rep Power
    0

    Default

    I have to do something like this:
    http://img822.imageshack.us/img822/2539/schemes.png

    And I am looking for the best way to synchronize processes of readers and writer.

  13. #13
    toadaly is offline Senior Member
    Join Date
    Jan 2009
    Posts
    671
    Rep Power
    6

    Default

    In the picture, it shows different users accessing different parts of the file, is that the conop, or is it expected they could access the same part of the file simultaneously?

  14. #14
    kate88 is offline Member
    Join Date
    Nov 2010
    Posts
    10
    Rep Power
    0

    Default

    yes, users can access the file simultaneously.
    we can leave the idea of dividing file into parts (it's just one of the concepts of this filesystem.. files can be big like 3gb and that's why users read/write files in chunks)
    What I don't know is how to synchronize everything in a nice way (create new instance of file for every reader and ensure that there will be only one writer per file).

  15. #15
    toadaly is offline Senior Member
    Join Date
    Jan 2009
    Posts
    671
    Rep Power
    6

    Default

    Ok, so take a look at the java.nio.channels.FileChannel API. I think it already handles the details of locking portions of a file that someone is writing to.

    Here's a pseudocode example of using it to lock a portion of a file for write:

    Java Code:
    File file = new File(...);
    
    FileOutputStream out = new FileOutputStream(file);
    
    FileChannel fc = out.getChannel();
    FileLock lock = fc.lock(position, size, false);
    
    ...write to the file...
    
    lock.release();
    ...
    If under the hood, you use FileChannels to handle the read and write access, the rest of your project involves developing the user API.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •