LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 05-31-2007, 09:45 AM   #16
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908

When responding to a read request that is asking for more bytes than the file contains, you can simply return all of the available bytes, and a return status that indicates EOF. Since this is your filesystem, the way in which storage for the filesystem is allocated is purely up to you. You make the rules for that, and all of it is concealed from the kernel, and other applications. That is the whole point of a filesystem. The abstraction from physical storage to files and directories makes everything look the same at some level. So, when you say 'I have to read and write blocks', that restriction may apply to your filesystem low-level driver, but should be invisible to the kernel and any applications that access your virtual files. The requirement to read blocks of data in standard chunks originates from the nature of physical storage media and the associated electronics. Filesystems were created to make application programming unconstrained by this characteristic. For reasons of efficiency (which may defined in different ways), you may elect to use the physical block nature of media access in any way that suits the purpose.

To answer your final question, files are accessed by read operations as a request for 'n' bytes, starting at the current seek position. The seek position should be automatically adjusted as appropriate after each read() or write() operation, or in response to seek() system calls. The number of bytes, 'n', is specified as a parameter in the read() or write() system call, made by the application program accessing your virtual files. A request for 'n' bytes may cause your low-level media access to span more than a single physical block, but this should be invisible at any layer above your filesystem driver.

--- rod.

Last edited by theNbomr; 05-31-2007 at 09:53 AM.
 
Old 05-31-2007, 02:33 PM   #17
Sebouh
LQ Newbie
 
Registered: Apr 2007
Posts: 15

Original Poster
Rep: Reputation: 0
Hmm, i see.
Well thanks for that clarification. I've decided to just read 512 Bytes from wherever the offset is.
 
Old 05-31-2007, 03:32 PM   #18
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
When a user application asks for less than 512 bytes, you will overrun the supplied buffer if you assume that you will always return 512 bytes. This will almost certainly cause Bad Things.
--- rod.
 
Old 05-31-2007, 05:19 PM   #19
Sebouh
LQ Newbie
 
Registered: Apr 2007
Posts: 15

Original Poster
Rep: Reputation: 0
You're right, there is a potential problem, but i'm asked to do this, to read blocks only. I'll see what happens with the other parts of the assignment. I have to reassess the whole thing. I'm not even sure if these block methods will be used by fuse anymore.
I'll keep in touch if anything comes up.
Thanks for the help.
 
Old 06-06-2007, 12:12 PM   #20
Sebouh
LQ Newbie
 
Registered: Apr 2007
Posts: 15

Original Poster
Rep: Reputation: 0
Hi guys.
I have a problem for which i cannot find a solution. The FUSE file system has a callback function:
Code:
int statvfs(const char *path, struct statvfs *buf);
As i've read, the df command uses this functions to get the file system statistics. The problem is, how do i implement this function?

I can think of two ways:

1- To do what the FUSE example does, call statvfs (...) inside this function, passing these args. But i'm thinking this wouldn't work. Aren't blocks logical partitions? The statvfs system call wouldn't know my file system's partitioning, so it would print the ext2 stats...

2- The other way is that i fill the statvfs structure's data, setting my block sizes, free blocks... But the one problem i find here is: How the heck am i gonna fill the fsblkcnt_t and fsfilcnt_t types? These are syst/types.h types that i have no clue about what they're supposed to be. The functions that i've implemented to count free blocks, bla bla... return ints and shorts!

So, any clues?

Thanks alot!
 
Old 06-06-2007, 05:16 PM   #21
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Well, since not all fields in struct statvfs are meaningful, you can probably safely put zeros or some other 'ordinary' numbers there (ie avoid 'boundary' condition numbers, like -1, 32767, 32768, etc). To be even easier on yourself, you could simply return ENOSYS, indicating that your filesystem does not implement this function.
--- rod.
 
Old 06-07-2007, 02:13 AM   #22
Sebouh
LQ Newbie
 
Registered: Apr 2007
Posts: 15

Original Poster
Rep: Reputation: 0
But i need to implement those. They have key information like the size of the file system and number of free blocks.
And chance i can make it happen?
 
Old 06-07-2007, 09:06 AM   #23
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Okay, then put meaningful numbers in all of the fields, if such numbers exist. Try it out and see if the number returned by the likes of df make sense. fsblkcnt_t and fsfilcnt_t types are integer types, probably long ints. For your small filesystem, even the smallest integer type can represent the maximum values you will require.
--- rod.
 
Old 06-07-2007, 12:11 PM   #24
Sebouh
LQ Newbie
 
Registered: Apr 2007
Posts: 15

Original Poster
Rep: Reputation: 0
ok then. I though ints won't work. It wouldn't compile or something.

Thanks.
 
Old 06-07-2007, 02:27 PM   #25
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
When I say 'integer types', I mean that in a generic sense; they are not floating point types, characters, pointers, structures, unions, enums, or whatever else I may have forgotten. As such, they should cast without loss of precision. If the compiler makes a complaint about word size conversion, you can make an explicit cast to satisfy the compiler.
--- rod.
 
Old 06-08-2007, 04:53 AM   #26
Sebouh
LQ Newbie
 
Registered: Apr 2007
Posts: 15

Original Poster
Rep: Reputation: 0
I actually assigned integers and never compiled.
I handed the assignment incomplete, so that's that.

Thanks for all who helped me understand FUSE better, especially you theNbomr. I really appreciate it.
 
  


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
notify user space application from the kernel space lordofring Linux - Software 2 06-22-2009 12:32 PM
lkl user space keylogger needs keymap file foustware Linux - Software 5 10-18-2007 09:49 AM
How to share data b/w user space and kernel space nandac Linux - Kernel 1 11-28-2006 10:15 PM
A normal user now has write permissions for the whole file system 16777216 Ubuntu 2 10-23-2006 09:32 AM
Large tar file taking huge disk space in ext3 file system pcwulf Linux - General 2 10-20-2003 07:45 AM

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

All times are GMT -5. The time now is 12:50 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