Page 1 of 1

File Access functions

Posted: Fri Jan 30, 2004 12:00 am
by pepito
A little silly question:

I am working into the File Manager of my OS I am looking for some examples about the OPEN-SEEK/READ/WRITE-CLOSE functions, but I don't which words I must use to look for it at the web.

Maybe somebody know about some site about this subject, or how I must structure my search at the web?

Thank you very much!

pepito

RE:File Access functions

Posted: Fri Jan 30, 2004 12:00 am
by Adek336
How about someone answering on the forum? :P

Could you be more descriptive, what can your file service do? my open() creates a file descriptor and a file handle, then calls a fs-module, for example the fat12 module. If a file is opened many times, it has one file descriptor, describing if someone can still open it, if yes r/rw, etc. It also contains a list of handles, describing the selected access to the file. All file functions take a file_handle as an argument.

int read(file_handle_t *file, char *buff, uint32 count);

Hope this helps,
Adrian

RE:File Access functions

Posted: Fri Jan 30, 2004 12:00 am
by pepito
Adrian:

Thank you for your response!

> Could you be more descriptive:

Yes, I want to know how the open(), seek(), read(), write() and close() functions works together. But when I search information about File Systems I get documents about FAT, EXT/2, etc.

I want to get information about the OPEN-SEEK/READ/WRITE-CLOSE abstraction, or other file access techniques.

pepito

RE:File Access functions

Posted: Fri Jan 30, 2004 12:00 am
by Adek336
AFAIK, it is called the "file service" or virtual file system layer.. at least that's what I call it :)

I am not a very good teacher, so I'll just describe I'll be trying to follow (me too, am implementing file services to my kernel at the moment!). The first layer are the wrappers fs_open(), fs_read() etc. around vfs.open(), vfs.read().

You surely will want to be able to mount many fs-modules, right? im my design vfs is a vfs_t class (don't know if it is a good idea to keep it in classes, but we'll see). It mount()s and umount()s fs from the service. Each mounted device tells the following:

/*procedures for devices*/
struct file_operations
{
int ( *lseek   ) ( struct file_handle_t *, int, int );
int ( *read    ) ( struct file_handle_t *, char *, int );
int ( *write   ) ( struct file_handle_t *, char *, int );
int ( *readdir ) ( struct file_handle_t *, struct dirent *, int count );
int ( *ioctl   ) ( struct file_handle_t *, uint32, uint32 );
int ( *open    ) ( struct file_handle_t * );
int ( *close   ) ( struct file_handle_t * );
};

As you see, file_operations::open returns int. vfs_t::open(), instead, returns file_handle_t, which is the handle to access a file.

A file being accessed gets it's own file_t element, counting how many handles access the file, it's name, it's handles, if the file is already open it tells if another process can open it. The handle is used for handling it, sent to the funcs.

I wonder what other designs do other people at the forum have? It would be interesting to compare the various parts.

Hope this helps,
Adrian.

RE:File Access functions

Posted: Fri Jan 30, 2004 12:00 am
by pepito
Adrian:

Thank you very much, you are a good teacher!

By now I have wrote pseudo-code for:

open(filename): This function find the file at the current directory, get memory space for the FCB and access buffer, and fill the FCB with the some fields of the directory entry and other default values. This function returns an ID (the address of the FCB).

seek(ID,P): This function set the FCB.file_pointer to some value and load the access buffer with the group where the new pointer is.

read(ID,N,B): This function read N bytes starting at FCB.file_pointer and put it in the user's buffer B.

write(ID,N,B): This function write N bytes from the user's buffers B to the file.

close(): This function update the file with the access buffer contents, update the file's directory entry and free the memory used by the FCB.

Sorry my poor english, do you belive I am in the correct way?

pepito

RE:File Access functions

Posted: Fri Jan 30, 2004 12:00 am
by Adek336
Yea, sounds good. BTW what's a FCB?

RE:File Access functions

Posted: Mon Feb 02, 2004 12:00 am
by pepito
Sorry, what is the meaning of BTW?

A FCB is the "file control block".

pepito

RE:File Access functions

Posted: Mon Feb 02, 2004 12:00 am
by Adek336
("BTW" == "By The Way")

Cheers,
Adrian.