Fork me on GitHub

root/include/fiwix/devices.h

/* [previous][next][first][last][top][bottom][index][help] */

INCLUDED FROM


   1 /*
   2  * fiwix/include/fiwix/devices.h
   3  *
   4  * Copyright 2018, Jordi Sanfeliu. All rights reserved.
   5  * Distributed under the terms of the Fiwix License.
   6  */
   7 
   8 #ifndef _FIWIX_DEVICES_H
   9 #define _FIWIX_DEVICES_H
  10 
  11 #include <fiwix/types.h>
  12 #include <fiwix/fs.h>
  13 
  14 #define NR_BLKDEV       128     /* maximum number of block devices */
  15 #define NR_CHRDEV       128     /* maximum number of char devices */
  16 
  17 #define BLK_DEV         1       /* block device */
  18 #define CHR_DEV         2       /* character device */
  19 
  20 #define SET_MINOR(minors, bit)   ((minors[(bit) / 32]) |= (1 << ((bit) % 32)))
  21 #define CLEAR_MINOR(minors, bit) ((minors[(bit) / 32]) &= ~(1 << ((bit) % 32)))
  22 #define TEST_MINOR(minors, bit)  ((minors[(bit) / 32]) & (1 << ((bit) % 32)))
  23 
  24 struct device {
  25         char *name;
  26         unsigned char major;
  27         unsigned int minors[8];         /* bitmap of 256 bits */
  28         int blksize;
  29         void *device_data;              /* mostly used for minor sizes, in KB */
  30         struct fs_operations *fsop;
  31         struct device *next;
  32 };
  33 
  34 extern struct device *chr_device_table[NR_CHRDEV];
  35 extern struct device *blk_device_table[NR_BLKDEV];
  36 
  37 int register_device(int, struct device *);
  38 struct device * get_device(int, __dev_t);
  39 int chr_dev_open(struct inode *, struct fd *);
  40 int blk_dev_open(struct inode *, struct fd *);
  41 int blk_dev_close(struct inode *, struct fd *);
  42 int blk_dev_read(struct inode *, struct fd *, char *, __size_t);
  43 int blk_dev_write(struct inode *, struct fd *, const char *, __size_t);
  44 int blk_dev_ioctl(struct inode *, int, unsigned long int);
  45 int blk_dev_lseek(struct inode *, __off_t);
  46 
  47 void dev_init(void);
  48 
  49 #endif /* _FIWIX_DEVICES_H */

/* [previous][next][first][last][top][bottom][index][help] */