9os

Experimental kernel using plan9 ideas for embedded device
git clone git://git.simple-cc.org/9os
Log | Files | Refs | README | LICENSE

dev.h (2153B)


      1 #include <stddef.h>
      2 
      3 #define NR_FILES  20
      4 #define CHDIR     0x80
      5 #define CHFILE    0x00
      6 
      7 #define SYNCDEV   0
      8 #define SYNCALL   1
      9 
     10 typedef struct dev Dev;
     11 typedef struct dirtab Dirtab;
     12 typedef int Devgen(Chan *, Dirtab *, int, int, Dir *);
     13 typedef struct attr Attr;
     14 
     15 struct dirtab {
     16 	char name[NAMELEN];
     17 	Qid qid;
     18 	long length;
     19 	unsigned char perm;
     20 	void *data;
     21 };
     22 
     23 struct dev {
     24 	char id;
     25 	int (*stat)(Chan *c, char *file, unsigned char *buf, int n);
     26 	int (*walk)(Chan *c, char *name);
     27 	int (*read)(Chan *c, void *buf, int n);
     28 	int (*write)(Chan *c, void *buf, int n);
     29 	int (*seek)(Chan *c, long off, int whence);
     30 	int (*sync)(Chan *c, int what);
     31 	int (*close)(Chan *c);
     32 	Chan *(*clone)(Chan *c, Chan *nc);
     33 	Chan *(*attach)(int id, int dev);
     34 	Chan *(*mount)(Chan *c, char *spec);
     35 };
     36 
     37 struct attr {
     38 	char *key;
     39 	char *value;
     40 };
     41 
     42 extern int sameqid(Qid q1, Qid qid2);
     43 extern Chan *clone(Chan *c, Chan *nc);
     44 extern Chan *attach(int id, int dev);
     45 extern int buf2chan(Chan *c,
     46                     void *dst, void *src,
     47                     int nbytes, long len);
     48 extern void mkentry(Chan *c, Dir *dir,
     49                     char *name,
     50                     long length, Qid qid, unsigned mode);
     51 extern void devlink(void);
     52 
     53 extern int devclose(Chan *);
     54 extern Chan *devattach(int id, int dev);
     55 extern int devseek(Chan *c, long off, int whence);
     56 extern int devsync(Chan *c, int what);
     57 extern Chan *devclone(Chan *c, Chan *nc);
     58 extern int devgen(Chan *c,
     59                   Dirtab *tab, int ntab,
     60                   int n,
     61                   Dir *dir);
     62 extern int devwalk(Chan *c,
     63                    char *name,
     64                    Dirtab *tab, int ntab,
     65                    Devgen *gen);
     66 extern int dirread(Chan *c,
     67                    unsigned char *buf, int nbytes,
     68                    Dirtab *tab, int ntab,
     69                    Devgen *gen);
     70 int
     71 extern devstat(Chan *dirc, char *file,
     72                unsigned char *buf, int n,
     73                Dirtab *tab, int ntab,
     74                Devgen *gen);
     75 
     76 extern Chan *deverrmount(Chan *c, char *spec);
     77 extern int deverrwrite(Chan *c, void *buf, int n);
     78 extern int deverrseek(Chan *c, long off, int whence);
     79 
     80 extern Dev *devtab[];