Re: Getting a block from a block device?
Hallo, On Tue, Nov 8, 2011 at 12:27 PM, Stephen Gream <poisonthemon@gmail.com> wrote:
Once you have the device registered (on /sys or /dev), register a read callback on the file and use copy_to_user to output the data
I read that article you referred to, but I don't think it addresses my problem, as I may have been more clear on what I want to achieve before. Sorry for that! I want to eventually implement a file system, and therefore I am studying the kernel sources to get an idea about all that. Here is my general understanding on how thinks may work :) virtual file system (VFS) <-[1]-> my file system implementation <-[2]-> a block device As I understood, all these subsystems are running in kernel mode. For [1] I read vfs.txt and learned about the VFS-API For [2] I have no idea where I can find the API documentation, however there were some hints on the book "Linux Driver Development" from O'Reilly in chapter "block devices". Nothing really helpful, as they were talking about registering new block devices. I want to use already present devices where I expect my filesystem to be present on. To check that, I have to read the first 512 bytes. The userspace implementation I was talking about previously is something like a mkfs.myfilesystem, that's why i referred to fopen() there. Thank you! Greetings, Dan -- Dan Luedtke http://www.danrl.de
On Tue, Nov 8, 2011 at 5:26 PM, Dan Luedtke <maildanrl@googlemail.com>wrote:
Hallo,
On Tue, Nov 8, 2011 at 12:27 PM, Stephen Gream <poisonthemon@gmail.com> wrote:
Once you have the device registered (on /sys or /dev), register a read callback on the file and use copy_to_user to output the data
I read that article you referred to, but I don't think it addresses my problem, as I may have been more clear on what I want to achieve before. Sorry for that! I want to eventually implement a file system, and therefore I am studying the kernel sources to get an idea about all that.
Here is my general understanding on how thinks may work :)
virtual file system (VFS) <-[1]-> my file system implementation <-[2]-> a block device
As I understood, all these subsystems are running in kernel mode.
For [1] I read vfs.txt and learned about the VFS-API For [2] I have no idea where I can find the API documentation, however there were some hints on the book "Linux Driver Development" from O'Reilly in chapter "block devices". Nothing really helpful, as they were talking about registering new block devices. I want to use already present devices where I expect my filesystem to be present on. To check that, I have to read the first 512 bytes.
The userspace implementation I was talking about previously is something like a mkfs.myfilesystem, that's why i referred to fopen() there.
Thank you!
Greetings,
Dan -- Dan Luedtke http://www.danrl.de
_______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Dan, You need to look at other block-based file systems in the kernel sources in fs dir for examples and understand how they do it. Regards, Rohan Puri
if you wanna open a block device specificallyy you can look into fs/block_dev.c struct block_device *open_bdev_exclusive(const char *path, fmode_t mode, void *holder) Also i think if you are interested in reading the first sector then you can probably check the block/genhd.c file get the disk (i.e struct genhd) then the partition (struct hdpart) you will be able to get the first sector. Thanks On Tue, Nov 8, 2011 at 5:29 PM, rohan puri <rohan.puri15@gmail.com> wrote:
On Tue, Nov 8, 2011 at 5:26 PM, Dan Luedtke <maildanrl@googlemail.com>wrote:
Hallo,
On Tue, Nov 8, 2011 at 12:27 PM, Stephen Gream <poisonthemon@gmail.com> wrote:
Once you have the device registered (on /sys or /dev), register a read callback on the file and use copy_to_user to output the data
I read that article you referred to, but I don't think it addresses my problem, as I may have been more clear on what I want to achieve before. Sorry for that! I want to eventually implement a file system, and therefore I am studying the kernel sources to get an idea about all that.
Here is my general understanding on how thinks may work :)
virtual file system (VFS) <-[1]-> my file system implementation <-[2]-> a block device
As I understood, all these subsystems are running in kernel mode.
For [1] I read vfs.txt and learned about the VFS-API For [2] I have no idea where I can find the API documentation, however there were some hints on the book "Linux Driver Development" from O'Reilly in chapter "block devices". Nothing really helpful, as they were talking about registering new block devices. I want to use already present devices where I expect my filesystem to be present on. To check that, I have to read the first 512 bytes.
The userspace implementation I was talking about previously is something like a mkfs.myfilesystem, that's why i referred to fopen() there.
Thank you!
Greetings,
Dan -- Dan Luedtke http://www.danrl.de
_______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Dan,
You need to look at other block-based file systems in the kernel sources in fs dir for examples and understand how they do it.
Regards, Rohan Puri
_______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Thanks for all the answers!
You need to look at other block-based file systems in the kernel sources in fs dir for examples and understand how they do it. I looked at fs/minix/* fs/fat/* and peeked into fs/ext2/, but got more confused so I decided to ask for a starting point.
Also i think if you are interested in reading the first sector then you can probably check the block/genhd.c file get the disk (i.e struct genhd) then the partition (struct hdpart) you will be able to get the first sector. Thanks, a well documented source file. However, shouldn't I get the right partition (I called it block device in previously sent mails, thought of e.g. /dev/sda2 as a device not a partition) from VFS when a user requestes mounting it?
That's an old assignment from my uni. Wow, exactly what I needed! Thanks for this starting point.
I would redirect you to learn about struct gendisk and struct bio. Noted, I will take a look after studying the vvfs-files from Stephens link.
Can you tell what are you trying to achieve? I'd like to implement a filesystem as kernel modul (like fat, ext2, ...). The filesystem is a very simple one, based on chained blocks (similar to linked lists in c). I "invented" it when I tried to write a bootloader that does not require a second stage to read an kernel image. (This is all more or less a "because we can"-project, no commercial background, just learning).
Once again, thank you guys! Greetings, Dan -- Dan Luedtke http://www.danrl.de
On Tue, Nov 8, 2011 at 6:02 AM, Dan Luedtke <maildanrl@googlemail.com> wrote:
Thanks for all the answers!
You need to look at other block-based file systems in the kernel sources in fs dir for examples and understand how they do it. I looked at fs/minix/* fs/fat/* and peeked into fs/ext2/, but got more confused so I decided to ask for a starting point.
Hi Dan, You may find https://github.com/mkatiyar/testfs helpful.
Also i think if you are interested in reading the first sector then you can probably check the block/genhd.c file get the disk (i.e struct genhd) then the partition (struct hdpart) you will be able to get the first sector. Thanks, a well documented source file. However, shouldn't I get the right partition (I called it block device in previously sent mails, thought of e.g. /dev/sda2 as a device not a partition) from VFS when a user requestes mounting it?
That's an old assignment from my uni. Wow, exactly what I needed! Thanks for this starting point.
I would redirect you to learn about struct gendisk and struct bio. Noted, I will take a look after studying the vvfs-files from Stephens link.
Can you tell what are you trying to achieve? I'd like to implement a filesystem as kernel modul (like fat, ext2, ...). The filesystem is a very simple one, based on chained blocks (similar to linked lists in c). I "invented" it when I tried to write a bootloader that does not require a second stage to read an kernel image. (This is all more or less a "because we can"-project, no commercial background, just learning).
Once again, thank you guys!
Greetings,
Dan -- Dan Luedtke http://www.danrl.de
_______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
-- Thanks - Manish
On Tue, Nov 8, 2011 at 8:48 PM, Manish Katiyar <mkatiyar@gmail.com> wrote:
On Tue, Nov 8, 2011 at 6:02 AM, Dan Luedtke <maildanrl@googlemail.com> wrote:
Thanks for all the answers!
You need to look at other block-based file systems in the kernel sources in fs dir for examples and understand how they do it. I looked at fs/minix/* fs/fat/* and peeked into fs/ext2/, but got more confused so I decided to ask for a starting point.
Hi Dan,
You may find https://github.com/mkatiyar/testfs helpful.
Also i think if you are interested in reading the first sector then you can probably check the block/genhd.c file get the disk (i.e struct genhd) then the partition (struct hdpart) you will be able to get the first sector. Thanks, a well documented source file. However, shouldn't I get the right partition (I called it block device in previously sent mails, thought of e.g. /dev/sda2 as a device not a partition) from VFS when a user requestes mounting it?
That's an old assignment from my uni. Wow, exactly what I needed! Thanks for this starting point.
I would redirect you to learn about struct gendisk and struct bio. Noted, I will take a look after studying the vvfs-files from Stephens
link.
Can you tell what are you trying to achieve? I'd like to implement a filesystem as kernel modul (like fat, ext2, ...). The filesystem is a very simple one, based on chained blocks (similar to linked lists in c). I "invented" it when I tried to write a bootloader that does not require a second stage to read an kernel image. (This is all more or less a "because we can"-project, no commercial background, just learning).
Once again, thank you guys!
Greetings,
Dan -- Dan Luedtke http://www.danrl.de
_______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
-- Thanks - Manish
Nice reference manish :) Regards, Rohan Puri
You may find https://github.com/mkatiyar/testfs helpful. Thanks! That helped me to get an idea of what actually happens.
-- Dan Luedtke http://www.danrl.de
On Tue, Nov 8, 2011 at 1:56 PM, Dan Luedtke <maildanrl@googlemail.com> wrote:
Hallo,
On Tue, Nov 8, 2011 at 12:27 PM, Stephen Gream <poisonthemon@gmail.com> wrote:
Once you have the device registered (on /sys or /dev), register a read callback on the file and use copy_to_user to output the data
I read that article you referred to, but I don't think it addresses my problem, as I may have been more clear on what I want to achieve before. Sorry for that! I want to eventually implement a file system, and therefore I am studying the kernel sources to get an idea about all that.
Here is my general understanding on how thinks may work :)
virtual file system (VFS) <-[1]-> my file system implementation <-[2]-> a block device
As I understood, all these subsystems are running in kernel mode.
For [1] I read vfs.txt and learned about the VFS-API For [2] I have no idea where I can find the API documentation, however there were some hints on the book "Linux Driver Development" from O'Reilly in chapter "block devices". Nothing really helpful, as they were talking about registering new block devices. I want to use already present devices where I expect my filesystem to be present on. To check that, I have to read the first 512 bytes.
The userspace implementation I was talking about previously is something like a mkfs.myfilesystem, that's why i referred to fopen() there.
Thank you!
Greetings,
While in the kernel you would be able to read the blocks from a device without using a file path (you don't need to open a file and read from it). You will need to interact with the IO System. I would redirect you to learn about struct gendisk and struct bio.
http://web.archive.org/web/20100711055535/http://cs.anu.edu.au/students/comp... That's an old assignment from my uni. It should get you across the basics of filesystem implementation if you work through it ;) On Tue, Nov 8, 2011 at 11:12 PM, Alexandru Juncu <alex.juncu@rosedu.org> wrote:
On Tue, Nov 8, 2011 at 1:56 PM, Dan Luedtke <maildanrl@googlemail.com> wrote:
Hallo,
On Tue, Nov 8, 2011 at 12:27 PM, Stephen Gream <poisonthemon@gmail.com> wrote:
Once you have the device registered (on /sys or /dev), register a read callback on the file and use copy_to_user to output the data
I read that article you referred to, but I don't think it addresses my problem, as I may have been more clear on what I want to achieve before. Sorry for that! I want to eventually implement a file system, and therefore I am studying the kernel sources to get an idea about all that.
Here is my general understanding on how thinks may work :)
virtual file system (VFS) <-[1]-> my file system implementation <-[2]-> a block device
As I understood, all these subsystems are running in kernel mode.
For [1] I read vfs.txt and learned about the VFS-API For [2] I have no idea where I can find the API documentation, however there were some hints on the book "Linux Driver Development" from O'Reilly in chapter "block devices". Nothing really helpful, as they were talking about registering new block devices. I want to use already present devices where I expect my filesystem to be present on. To check that, I have to read the first 512 bytes.
The userspace implementation I was talking about previously is something like a mkfs.myfilesystem, that's why i referred to fopen() there.
Thank you!
Greetings,
While in the kernel you would be able to read the blocks from a device without using a file path (you don't need to open a file and read from it). You will need to interact with the IO System.
I would redirect you to learn about struct gendisk and struct bio.
participants (6)
-
Alexandru Juncu -
Dan Luedtke -
mani -
Manish Katiyar -
rohan puri -
Stephen Gream