2008年5月7日 星期三

open_by_devnum

struct block_device *open_by_devnum(dev_t dev, unsigned mode)

struct bio

struct bio {
    sector_t             bi_sector;  //  beginning sector
    struct bio          *bi_next;
    struct block_device *bi_bdev;
    unsigned short       bi_vcnt;
    unsigned short       bi_idx;  //  an offset into the bi_io_vec array
    struct bio_vec      *bi_io_vec;
    ...
};

generic_make_request

void generic_make_request (struct bio * bio);

make I/O requests of block devices. 
It is passed a &struct bio, which describes the I/O that needs to be done.

the success/failure status of the request, along with notification of completion,
is delivered asynchronously through the bio->bi_end_io function

The caller of generic_make_request must make sure that bi_io_vec are set to describe the memory buffer, and that bi_dev and bi_sector are set to describe the device address, and the bi_end_io and optionally bi_private are set to describe how completion notification should be signaled.

2008年5月6日 星期二

MKDEV

dev_t  a=  MKDEV( int major, int minor )

get major & minor
MIJOR( a )  &  MINOR( a)

struct gendisk

int major
int  first_minor
        first minor number associated with disk
int  minors
       range of minor numbers associated with disk. It control disk's max partition number 
char  disk_name[32]

struct gendisk *alloc_disk(int minors)

allocate gendisk 

system_utsname

add_disk

void add_disk(struct gendisk *disk);
add the disk to the list of active disks
the disk is active now

ioctl communication between kernel and user space

use block device as example:

user space program:
struct Test_info  test_info;
ioctl ( fd,  ADD,  &test_info);


driver:
1. define a function to deal with ioctl operation & assign this function 
    to struct block_device_operations
     ex: 
     define a function  test_ioctl
     struct block_device_operations test_ops;
     test_ops.ioctl = test_ioctl       

2.  define the function to deal with ioctl operation
     it will receive two important parameters.
     One is command, the other is argument.
     From out example,  the command received is ADD, the parameter received is &test_info

3.  copy data from user space to kernel space
     use copy_from_user

copy_from_user

copy_from_user(void *to, const void *from, long n);
to: point to kernel-space address
from :  point to user-space address

2008年5月5日 星期一

function stat

int  stat(const char *restrict pathstruct stat *restrict buf);

get file status

struct stat {
dev_t st_dev;
ino_t st_ino;
mode_t st_mode;
nlink_t st_nlink;
uid_t st_uid;
gid_t st_gid;
dev_t st_rdev;
off_t st_size;
time_t st_atime;
time_t st_mtime;
time_t st_ctime;
blksize_t st_blksize;
blkcnt_t st_blocks;
mode_t st_attr;
}; 

2008年5月4日 星期日

structure sg_io_hdr_t


getopt

getopt(int argcchar * const argv[]const char *optstring)
get option character from command line argument list

ex:getopt(argc, argv, “bf:")
     options are b & f

strdup

char *  strdup(const char *s1); 
allocates sufficient memory for a copy of the string s1, 
does the copy, and returns a pointer to it.

strstr

strstr(const char *s1, const char *s2);
locate a substring in a string

struct utsname & uname

struct utsname
hold information returned by the uname function

uname(struct utsname *name)
store information identifying the current system in the structure pointed to by name.