8 typedef struct Cons Cons
;
17 closecons(Ufile
*file
)
19 Cons
*cons
= (Cons
*)file
;
21 freebufproc(cons
->bufproc
);
27 bufproccons(Cons
*cons
)
29 if(cons
->bufproc
== nil
)
30 cons
->bufproc
= newbufproc(0);
35 pollcons(Ufile
*file
, void *tab
)
37 Cons
*cons
= (Cons
*)file
;
38 return pollbufproc(bufproccons(cons
), cons
, tab
);
42 readcons(Ufile
*file
, void *buf
, int len
, vlong
)
44 Cons
*cons
= (Cons
*)file
;
47 if((cons
->mode
& O_NONBLOCK
) || (cons
->bufproc
!= nil
)){
48 ret
= readbufproc(bufproccons(cons
), buf
, len
, 0, (cons
->mode
& O_NONBLOCK
));
52 ret
= read(0, buf
, len
);
61 writecons(Ufile
*, void *buf
, int len
, vlong
)
67 ret
= write(1, buf
, len
);
75 ioctlcons(Ufile
*file
, int cmd
, void *arg
)
77 Cons
*cons
= (Cons
*)file
;
89 if((r
= nreadablebufproc(bufproccons(cons
))) < 0){
100 opencons(char *path
, int mode
, int, Ufile
**pf
)
104 if(strcmp(path
, "/dev/cons")!=0)
107 file
= mallocz(sizeof(Cons
), 1);
112 file
->path
= kstrdup(path
);
119 statcons(char *path
, int, Ustat
*s
)
121 if(strcmp(path
, "/dev/cons")!=0)
124 s
->mode
= 0666 | S_IFCHR
;
125 s
->uid
= current
->uid
;
126 s
->gid
= current
->gid
;
128 s
->ino
= hashpath(path
);
135 fstatcons(Ufile
*f
, Ustat
*s
)
137 return fsstat(f
->path
, 0, s
);
140 static Udev consdev
=
152 void consdevinit(void)
154 devtab
[CONSDEV
] = &consdev
;
156 fsmount(&consdev
, "/dev/cons");