1 /* Copyright © 1994-1999 Lucent Technologies Inc. All rights reserved.
2 * Portions Copyright © 1997-1999 Vita Nuova Limited
3 * Portions Copyright © 2000-2007 Vita Nuova Holdings Limited
5 * Revisions Copyright © 2000-2007 Lucent Technologies Inc. and others
7 * Modified for the Akaros operating system:
8 * Copyright (c) 2013-2014 The Regents of the University of California
9 * Copyright (c) 2013-2015 Google Inc.
11 * Permission is hereby granted, free of charge, to any person obtaining a copy
12 * of this software and associated documentation files (the "Software"), to deal
13 * in the Software without restriction, including without limitation the rights
14 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 * copies of the Software, and to permit persons to whom the Software is
16 * furnished to do so, subject to the following conditions:
18 * The above copyright notice and this permission notice shall be included in
19 * all copies or substantial portions of the Software.
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
36 #include <linker_func.h>
42 * functions (possibly) linked in, complete, from libc.
45 UTFmax = 4, /* maximum bytes per rune */
46 Runesync = 0x80, /* cannot represent part of a UTF sequence (<) */
47 Runeself = 0x80, /* rune and UTF sequences are the same (<) */
48 Runeerror = 0xFFFD, /* decoding error in UTF */
49 Runemax = 0x10FFFF, /* 21-bit rune */
50 Runemask = 0x1FFFFF, /* bits used by runes (see grep) */
51 NUMSIZE32 = 10, /* max size of formatted 32 bit number (hex or decimal) */
52 NUMSIZE64 = 20, /* max size of formatted 64 bit number (hex or decimal) */
58 extern int isNaN(double);
59 extern int isInf(double, int);
60 extern double floor(double);
61 extern double frexp(double, int *);
62 extern double pow10(int);
67 extern char *cleanname(char *unused_char_p_t);
68 //extern uint32_t getcallerpc(void*);
69 static inline uint32_t getcallerpc(void *v)
74 extern int getfields(char *unused_char_p_t, char **unused_char_pp_t,
75 int unused_int, int, char *);
76 extern int tokenize(char *unused_char_p_t, char **unused_char_pp_t, int);
77 extern int dec64(uint8_t * unused_uint8_p_t, int unused_int,
78 char *unused_char_p_t, int);
79 extern void qsort(void *, long, long, int (*)(void *, void *));
81 extern int toupper(int);
82 extern int myetheraddr(uint8_t * unused_uint8_p_t, char *unused_char_p_t);
83 extern int parseether(uint8_t * unused_uint8_p_t, char *unused_char_p_t);
91 * Syscall data structures
93 #define MORDER 0x0003 /* mask for bits defining order of mounting */
94 #define MREPL 0x0000 /* mount replaces object */
95 #define MBEFORE 0x0001 /* mount goes before others in union directory */
96 #define MAFTER 0x0002 /* mount goes after others in union directory */
97 #define MCREATE 0x0004 /* permit creation in mounted directory */
98 #define MCACHE 0x0010 /* cache some data */
99 #define MMASK 0x0017 /* all bits on */
101 #define NCONT 0 /* continue after note */
102 #define NDFLT 1 /* terminate after note */
103 #define NSAVE 2 /* clear note but hold state */
104 #define NRSTR 3 /* restore saved state */
106 #define STATMAX 65535U /* max length of machine-independent stat structure */
107 #define ERRMAX 128 /* max length of error string */
108 #define KNAMELEN 28 /* max length of name held in kernel */
110 /* bits in Qid.type */
111 #define QTDIR 0x80 /* type bit for directories */
112 #define QTAPPEND 0x40 /* type bit for append only files */
113 #define QTEXCL 0x20 /* type bit for exclusive use files */
114 #define QTMOUNT 0x10 /* type bit for mounted channel */
115 #define QTAUTH 0x08 /* type bit for authentication file */
116 #define QTFILE 0x01 /* plain file */
118 /* bits in Dir.mode */
119 #define DMDIR 0x80000000 /* mode bit for directories */
120 #define DMAPPEND 0x40000000 /* mode bit for append only files */
121 #define DMEXCL 0x20000000 /* mode bit for exclusive use files */
122 #define DMMOUNT 0x10000000 /* mode bit for mounted channel */
123 #define DMWRITABLE 0x08000000 /* non-standard, for select() */
124 #define DMREADABLE 0x04000000 /* non-standard, for select() */
125 #define DMSYMLINK 0x02000000 /* symlink -- from 9p2000.u */
126 #define DMREAD 0x4 /* mode bit for read permission */
127 #define DMWRITE 0x2 /* mode bit for write permission */
128 #define DMEXEC 0x1 /* mode bit for execute permission */
137 /* system-modified data */
138 uint16_t type; /* server type */
139 unsigned int dev; /* server subtype */
141 struct qid qid; /* unique id from server */
142 int mode; /* permissions */
143 uint32_t atime; /* last read time */
144 uint32_t mtime; /* last write time */
145 int64_t length; /* file length: see <u.h> */
146 char *name; /* last element of path */
147 char *uid; /* owner name */
148 char *gid; /* group name */
149 char *muid; /* last modifier name */
153 int pid; /* of loved one */
154 uint32_t time[3]; /* of loved one and descendants */
155 char msg[ERRMAX]; /* actually variable-size in user mode */
158 #define VERSION9P "9P2000"
169 uint32_t msize; /* Tversion, Rversion */
170 char *version; /* Tversion, Rversion */
173 uint16_t oldtag; /* Tflush */
176 char *ename; /* Rerror */
179 struct qid qid; /* Rattach, Ropen, Rcreate */
180 uint32_t iounit; /* Ropen, Rcreate */
183 struct qid aqid; /* Rauth */
186 uint32_t afid; /* Tauth, Tattach */
187 char *uname; /* Tauth, Tattach */
188 char *aname; /* Tauth, Tattach */
191 uint32_t perm; /* Tcreate */
192 char *name; /* Tcreate */
193 uint8_t mode; /* Tcreate, Topen */
196 uint32_t newfid; /* Twalk */
197 uint16_t nwname; /* Twalk */
198 char *wname[MAXWELEM]; /* Twalk */
201 uint16_t nwqid; /* Rwalk */
202 struct qid wqid[MAXWELEM]; /* Rwalk */
205 int64_t offset; /* Tread, Twrite */
206 uint32_t count; /* Tread, Twrite, Rread */
207 char *data; /* Twrite, Rread */
210 uint16_t nstat; /* Twstat, Rstat */
211 uint8_t *stat; /* Twstat, Rstat */
216 #define GBIT8(p) ((p)[0])
217 #define GBIT16(p) ((p)[0]|((p)[1]<<8))
218 #define GBIT32(p) ((uint32_t)((p)[0]|((p)[1]<<8)|((p)[2]<<16)|((p)[3]<<24)))
219 #define GBIT64(p) ((uint32_t)((p)[0]|((p)[1]<<8)|((p)[2]<<16)|((p)[3]<<24)) |\
220 ((int64_t)((p)[4]|((p)[5]<<8)|((p)[6]<<16)|((p)[7]<<24)) << 32))
222 #define PBIT8(p,v) (p)[0]=(v)
223 #define PBIT16(p,v) (p)[0]=(v);(p)[1]=(v)>>8
224 #define PBIT32(p,v) (p)[0]=(v);(p)[1]=(v)>>8;(p)[2]=(v)>>16;(p)[3]=(v)>>24
225 #define PBIT64(p,v) (p)[0]=(v);(p)[1]=(v)>>8;(p)[2]=(v)>>16;(p)[3]=(v)>>24;\
226 (p)[4]=(v)>>32;(p)[5]=(v)>>40;(p)[6]=(v)>>48;(p)[7]=(v)>>56
232 #define QIDSZ (BIT8SZ+BIT32SZ+BIT64SZ)
234 /* STATFIXLEN includes leading 16-bit count */
235 /* The count, however, excludes itself; total size is BIT16SZ+count */
236 #define STATFIXLEN (BIT16SZ+QIDSZ+5*BIT16SZ+4*BIT32SZ+1*BIT64SZ) /* amount of fixed length data in a stat buffer */
238 #define NOTAG (uint16_t)~0U /* Dummy tag */
239 #define NOFID (uint32_t)~0U /* Dummy fid */
240 #define IOHDRSZ 24 /* ample room for Twrite/Rread header (iounit) */
249 Terror = 106, /* illegal */
274 void init_empty_dir(struct dir *d);
275 unsigned int convM2S(uint8_t * unused_uint8_p_t, unsigned int unused_int,
277 unsigned int convS2M(struct fcall *, uint8_t * unused_uint8_p_t, unsigned int);
278 unsigned int sizeS2M(struct fcall *);
280 unsigned int convM2kdirent(uint8_t * buf, unsigned int nbuf, struct kdirent *kd,
282 unsigned int convM2kstat(uint8_t * buf, unsigned int nbuf, struct kstat *ks);
284 int statcheck(uint8_t * abuf, unsigned int nbuf);
285 unsigned int convM2D(uint8_t * unused_uint8_p_t, unsigned int unused_int,
286 struct dir *, char *unused_char_p_t);
287 unsigned int convD2M(struct dir *, uint8_t * unused_uint8_p_t, unsigned int);
288 unsigned int sizeD2M(struct dir *);
290 int read9pmsg(int unused_int, void *, unsigned int);
302 int (*active) (void *);
303 int (*ck) (void *, int);
304 void (*f) (void *); /* called with VM acquire()'d */
322 * Access types in namec & channel flags
325 Aaccess, /* as in stat, wstat */
326 Abind, /* for left-hand-side of bind */
327 Atodir, /* as in chdir */
329 Amount, /* to be mounted or mounted upon */
330 Acreate, /* is to be created */
331 Aremove, /* will be removed by caller */
332 Acreatechan, /* return a chan for a create request. for sysrename. */
334 /* internal chan flags, used by the kernel only */
335 COPEN = 0x0001, /* for i/o */
336 CMSG = 0x0002, /* the message channel for a mount */
337 CFREE = 0x0004, /* not in use */
338 CCACHE = 0x0008, /* client cache */
339 CINTERNAL_FLAGS = (COPEN | CMSG | CFREE | CCACHE),
341 /* chan/file flags, getable via fcntl/getfl and setably via open and
342 * sometimes fcntl/setfl. those that can't be set cause an error() in
345 O_CLOEXEC | /* (prob should be on the FD, 9ns has it here) */
346 O_REMCLO | /* remove on close (also, maybe should be on FD) */
347 O_APPEND | /* append on write */
348 O_NONBLOCK | /* don't block, can't be set via setfl */
349 O_PATH | /* path open, just the name, no I/O */
353 #define NS_IPCK_SHIFT 2
354 #define NS_UDPCK_SHIFT 3
355 #define NS_TCPCK_SHIFT 4
356 #define NS_PKTCK_SHIFT 5
357 #define NS_TSO_SHIFT 6
358 #define NS_SHIFT_MAX 6
362 Bipck = (1 << NS_IPCK_SHIFT), /* ip checksum */
363 Budpck = (1 << NS_UDPCK_SHIFT), /* udp checksum */
364 Btcpck = (1 << NS_TCPCK_SHIFT), /* tcp checksum */
365 Bpktck = (1 << NS_PKTCK_SHIFT), /* packet checksum */
366 Btso = (1 << NS_TSO_SHIFT), /* TSO */
368 #define BCKSUM_FLAGS (Bipck|Budpck|Btcpck|Bpktck|Btso)
372 /* using u32s for packing reasons. this means no extras > 4GB */
380 uint8_t *rp; /* first unconsumed byte */
381 uint8_t *wp; /* first empty byte */
382 uint8_t *lim; /* 1 past the end of the buffer */
383 uint8_t *base; /* start of the buffer */
384 void (*free) (struct block *);
386 uint16_t checksum; /* IP checksum of complete packet (minus media header) */
387 uint16_t checksum_start; /* off from start of block to start csum */
388 uint16_t checksum_offset; /* off from checksum_start to store csum */
389 uint16_t mss; /* TCP MSS for TSO */
390 uint16_t network_offset; /* offset from start */
391 uint16_t transport_offset; /* offset from start */
392 /* might want something to track the next free extra_data slot */
394 unsigned int nr_extra_bufs;
395 struct extra_bdata *extra_data;
397 #define BLEN(s) ((s)->wp - (s)->rp + (s)->extra_len)
398 #define BHLEN(s) ((s)->wp - (s)->rp)
399 #define BALLOC(s) ((s)->lim - (s)->base + (s)->extra_len)
404 struct chan *next; /* allocation */
406 int64_t offset; /* in file */
409 uint16_t mode; /* read/write */
412 int fid; /* for devmnt */
413 uint32_t iounit; /* chunk size for i/o; 0==default */
414 struct mhead *umh; /* mount point that derived Chan; used in unionread */
415 struct chan *umc; /* channel in union; held for union read */
416 qlock_t umqlock; /* serialize unionreads */
417 int uri; /* union read index */
418 int dri; /* devdirread index */
420 struct mntcache *mcp; /* Mount cache pointer */
421 struct mnt *mux; /* Mnt for clients using me for messages */
424 char tag[4]; /* for iproute */
426 /* mountpoint, as discovered during walk.
427 * Used for rename at present.
429 struct chan *mountpoint;
430 struct chan *mchan; /* channel to mounted server */
431 struct qid mqid; /* qid of root of mount point */
433 /* hack for dir reads to try to get them right. */
437 /* A lot of synthetic files need something generated at open time, which the
438 * user can read from (including offsets) while the underlying file changes.
439 * Hang that buffer here. */
445 int alen; /* allocated length */
446 int len; /* strlen(s) */
453 void (*reset) (void);
455 void (*shutdown) (void);
456 struct chan *(*attach) (char *muxattach);
457 struct walkqid *(*walk) (struct chan *, struct chan *, char **name, int);
458 int (*stat) (struct chan *, uint8_t *, int);
459 struct chan *(*open) (struct chan *, int);
460 void (*create) (struct chan *, char *, int, uint32_t);
461 void (*close) (struct chan *);
462 long (*read) (struct chan *, void *, long, int64_t);
463 struct block *(*bread) (struct chan *, long, uint32_t);
464 long (*write) (struct chan *, void *, long, int64_t);
465 long (*bwrite) (struct chan *, struct block *, uint32_t);
466 void (*remove) (struct chan *);
467 int (*wstat) (struct chan *, uint8_t * unused_uint8_p_t, int);
468 void (*power) (int); /* power mgt: power(1) → on, power (0) → off */
469 // int (*config)( int unused_int, char *unused_char_p_t, DevConf*);
470 char *(*chaninfo) (struct chan *, char *, size_t);
471 int (*tapfd) (struct chan *, struct fd_tap *, int);
472 int (*chan_ctl)(struct chan *, int);
473 /* we need to be aligned to 64 bytes for the linker tables. */
474 } __attribute__ ((aligned(64)));
481 /* we need to be aligned to 64 bytes for the linker tables. */
482 } __attribute__ ((aligned(64)));
493 NSCACHE = (1 << NSLOG),
496 struct mntwalk { /* state for /proc/#/ns */
509 struct chan *to; /* channel replacing channel */
517 struct chan *from; /* channel mounted upon */
518 struct mount *mount; /* what's mounted upon it */
519 struct mhead *hash; /* Hash chain */
524 /* references are counted using c->ref; channels on this mount point incref(c->mchan) == Mnt.c */
525 struct chan *c; /* Channel to file service */
526 struct proc *rip; /* Reader in progress */
527 struct mntrpc *queue; /* Queue of pending requests on this channel */
528 uint32_t id; /* Multiplexer id for channel check */
529 struct mnt *list; /* Free list */
530 int flags; /* cache */
531 int msize; /* data + IOHDRSZ */
532 char *version; /* 9P version */
533 struct queue *q; /* input queue */
538 RENDHASH = 1 << RENDLOG, /* Hash to lookup rendezvous tags */
540 MNTHASH = 1 << MNTLOG, /* Hash to walk mount table */
541 DELTAFD = 20, /* allocation quantum for process file descriptors */
542 MAXNFD = 4000, /* max per process file descriptors */
543 MAXKEY = 8, /* keys for signed modules */
545 #define MOUNTH(p,qid) ((p)->mnthash[(qid).path&((1<<MNTLOG)-1)])
549 struct chan *authchan;
555 struct kref ref; /* also used as a lock when mounting */
557 qlock_t debug; /* single access via devproc.c */
558 struct rwlock ns; /* Namespace n read/one write lock */
560 struct mhead *mnthash[MNTHASH];
579 struct evalue *entries;
580 uint32_t path; /* qid.path of next Evalue to be allocated */
581 uint32_t vers; /* of Egrp */
591 void (*pkfree) (void *);
600 struct signerkey *keys[MAXKEY];
604 * fasttick timer interrupts
608 Trelative, /* timer programmed in ns from now */
609 Tabsolute, /* timer programmed in ns since epoch */
610 Tperiodic, /* periodic timer, period in ns */
615 NUMSIZE = 12, /* size of formatted number */
617 READSTR = 2000, /* temporary buffer size for device reads */
620 extern struct dev devtab[];
621 extern struct dev __devtabend[];
630 int index; /* used by client to switch on result */
631 char *cmd; /* command name */
632 int narg; /* expected #args; 0 ==> variadic */
635 /* queue state bits, all can be set in qopen (Qstarve is always set) */
637 Qmsg = (1 << 1), /* message stream */
638 Qclosed = (1 << 2), /* queue has been closed/hungup */
639 Qcoalesce = (1 << 3), /* coalesce empty packets on read */
640 Qkick = (1 << 4), /* always call the kick routine after qwrite */
641 Qdropoverflow = (1 << 5), /* writes that would block will be dropped */
646 typedef int Devgen(struct chan *, char *unused_char_p_t, struct dirtab *,
647 int unused_int, int, struct dir *);
649 /* inferno portfns.h. Not all these are needed. */
650 #define FPinit() fpinit() /* remove this if math lib is linked */
651 void FPrestore(void *);
653 struct cname *addelem(struct cname *, char *unused_char_p_t);
654 void addprog(struct proc *);
655 void addrootfile(char *unused_char_p_t, uint8_t * unused_uint8_p_t, uint32_t);
656 struct block *adjustblock(struct block *, int);
657 struct block *block_alloc(size_t, int);
658 int block_add_extd(struct block *b, unsigned int nr_bufs, int mem_flags);
659 int block_append_extra(struct block *b, uintptr_t base, uint32_t off,
660 uint32_t len, int mem_flags);
663 void _assert(char *unused_char_p_t);
664 struct block *bl2mem(uint8_t * unused_uint8_p_t, struct block *, int);
665 int blocklen(struct block *);
666 char *channame(struct chan *);
667 void cclose(struct chan *);
668 void chan_incref(struct chan *);
669 void chandevinit(void);
670 void chandevreset(void);
671 void chandevshutdown(void);
672 void chanfree(struct chan *);
673 void chanrec(struct mnt *);
674 void checkalarms(void);
675 void checkb(struct block *, char *unused_char_p_t);
677 struct chan *cclone(struct chan *);
678 void cclose(struct chan *);
679 void closeegrp(struct egrp *);
680 void closemount(struct mount *);
681 void closepgrp(struct pgrp *);
682 void closesigs(struct skeyset *);
683 void debugcmd(struct cmdbuf *cb);
684 struct mhead *newmhead(struct chan *from);
685 int cmount(struct chan *, struct chan *, int unused_int, char *unused_char_p_t);
686 void cnameclose(struct cname *);
687 struct block *concatblock(struct block *);
688 struct block *linearizeblock(struct block *b);
690 void cons_add_char(char c);
691 void copen(struct chan *);
692 struct block *copyblock(struct block *b, int mem_flags);
693 int cread(struct chan *, uint8_t * unused_uint8_p_t, int unused_int, int64_t);
694 struct chan *cunique(struct chan *);
695 struct chan *createdir(struct chan *, struct mhead *);
696 void cunmount(struct chan *, struct chan *);
697 void cupdate(struct chan *, uint8_t * unused_uint8_p_t, int unused_int,
699 void cursorenable(void);
700 void cursordisable(void);
703 void cwrite(struct chan *, uint8_t * unused_uint8_p_t, int unused_int, int64_t);
704 struct chan *devattach(const char *name, char *spec);
705 struct block *devbread(struct chan *, long, uint32_t);
706 long devbwrite(struct chan *, struct block *, uint32_t);
707 struct chan *devclone(struct chan *);
708 void devcreate(struct chan *, char *name, int mode, uint32_t perm);
709 void devdir(struct chan *, struct qid, char *, int64_t, char *, long,
711 long devdirread(struct chan *, char *, long, struct dirtab *, int, Devgen *);
714 int devno(const char *name, int user);
716 struct dev *devbyname(char *unused_char_p_t);
717 struct chan *devopen(struct chan *, int unused_int,
718 struct dirtab *, int unused_int2, Devgen *);
719 void devpermcheck(char *unused_char_p_t, uint32_t, int);
720 void devremove(struct chan *);
722 void devshutdown(void);
723 size_t dev_make_stat(struct chan *c, struct dir *dir, uint8_t *dp, size_t n);
724 int devstat(struct chan *, uint8_t * unused_uint8_p_t, int unused_int,
725 struct dirtab *, int unused_int2, Devgen *);
726 struct walkqid *devwalk(struct chan *,
727 struct chan *, char **unused_char_pp_t, int unused_int,
728 struct dirtab *, int unused_intw, Devgen *);
729 int devwstat(struct chan *, uint8_t * unused_uint8_p_t, int);
730 char *devchaninfo(struct chan *chan, char *ret, size_t ret_l);
731 void disinit(void *);
732 void disfault(void *, char *unused_char_p_t);
733 int domount(struct chan **, struct mhead **);
734 void drawactive(int);
736 void dumpstack(void);
737 void egrpcpy(struct egrp *, struct egrp *);
738 int emptystr(char *unused_char_p_t);
739 int eqchan(struct chan *, struct chan *, int);
740 int eqqid(struct qid, struct qid);
742 void errstr(char *unused_char_p_t, int);
747 int export(int unused_int, char *unused_char_p_t, int);
748 uint64_t fastticks(uint64_t *);
749 uint64_t fastticks2ns(uint64_t);
750 int findmount(struct chan **, struct mhead **, int unused_int, int, struct qid);
751 void free_block_extra(struct block *);
752 size_t freeb(struct block *b);
753 size_t freeblist(struct block *b);
754 void freeskey(struct signerkey *);
755 void getcolor(uint32_t, uint32_t *, uint32_t *, uint32_t *);
756 uint32_t getmalloctag(void *);
757 uint32_t getrealloctag(void *);
758 void printblock(struct block *b);
759 void ilock(spinlock_t *);
760 int iprint(char *unused_char_p_t, ...);
761 void isdir(struct chan *);
763 void iunlock(spinlock_t *);
764 void ixsummary(void);
766 int kbdcr2nl(struct queue *, int);
767 int kbdputc(struct queue *, int);
769 void kproc(char *unused_char_p_t, void (*)(void *), void *, int);
770 void kprocchild(struct proc *, void (*)(void *), void *);
771 void (*kproftick) (uint32_t);
772 void ksetenv(char *unused_char_p_t, char *, int);
773 void kstrdup(char **cp, char *name);
775 struct block *mem2bl(uint8_t * unused_uint8_p_t, int);
776 int memusehigh(void);
777 void microdelay(int);
778 uint64_t mk64fract(uint64_t, uint64_t);
779 void mkqid(struct qid *, int64_t, uint32_t, int);
781 struct chan *mntauth(struct chan *, char *unused_char_p_t);
782 long mntversion(struct chan *, char *unused_char_p_t, int unused_int, int);
783 void mountfree(struct mount *);
784 void mousetrack(int unused_int, int, int, int);
785 uint64_t ms2fastticks(uint32_t);
786 void mul64fract(uint64_t *, uint64_t, uint64_t);
787 void muxclose(struct mnt *);
788 struct chan *namec(char *unused_char_p_t, int unused_int, int, uint32_t);
789 struct chan *namec_from(struct chan *c, char *name, int amode, int omode,
791 struct chan *newchan(void);
792 struct egrp *newegrp(void);
793 struct mount *newmount(struct mhead *, struct chan *, int unused_int,
794 char *unused_char_p_t);
795 struct pgrp *newpgrp(void);
796 struct proc *newproc(void);
797 char *nextelem(char *unused_char_p_t, char *);
799 struct cname *newcname(char *unused_char_p_t);
800 void notkilled(void);
801 uint32_t random_read(void *xp, uint32_t n);
802 uint32_t urandom_read(void *xp, uint32_t n);
803 uint64_t ns2fastticks(uint64_t);
804 int okaddr(uint32_t, uint32_t, int);
805 int omode_to_rwx(int);
806 int omode_to_9p_accmode(int open_flags);
807 struct block *packblock(struct block *);
808 struct block *padblock(struct block *, int);
810 void pgrpcpy(struct pgrp *, struct pgrp *);
812 int progfdprint(struct chan *, int unused_int, int, char *unused_char_p_t,
814 int pullblock(struct block **, int);
815 struct block *pullupblock(struct block *, int);
816 struct block *pullupqueue(struct queue *, int);
817 void putmhead(struct mhead *);
818 void putstrn(char *unused_char_p_t, int);
819 void qaddlist(struct queue *, struct block *);
820 struct block *qbread(struct queue *q, size_t len);
821 struct block *qbread_nonblock(struct queue *q, size_t len);
822 ssize_t qbwrite(struct queue *, struct block *);
823 ssize_t qbwrite_nonblock(struct queue *, struct block *);
824 ssize_t qibwrite(struct queue *q, struct block *b);
825 struct queue *qbypass(void (*)(void *, struct block *), void *);
826 int qcanread(struct queue *);
827 void qclose(struct queue *);
828 struct block *qcopy(struct queue *, int unused_int, uint32_t);
829 struct block *qclone(struct queue *q, int header_len, int len,
831 struct block *blist_clone(struct block *blist, int header_len, int len,
833 size_t qdiscard(struct queue *q, size_t len);
834 void qflush(struct queue *);
835 void qfree(struct queue *);
836 int qfull(struct queue *);
837 struct block *qget(struct queue *);
838 void qhangup(struct queue *, char *unused_char_p_t);
839 int qisclosed(struct queue *);
840 ssize_t qiwrite(struct queue *, void *, int);
841 int qlen(struct queue *);
842 size_t q_bytes_read(struct queue *q);
843 void qdropoverflow(struct queue *, bool);
844 void q_toggle_qmsg(struct queue *q, bool onoff);
845 void q_toggle_qcoalesce(struct queue *q, bool onoff);
846 struct queue *qopen(int unused_int, int, void (*)(void *), void *);
847 ssize_t qpass(struct queue *, struct block *);
848 ssize_t qpassnolim(struct queue *, struct block *);
849 void qputback(struct queue *, struct block *);
850 size_t qread(struct queue *q, void *va, size_t len);
851 size_t qread_nonblock(struct queue *q, void *va, size_t len);
852 void qreopen(struct queue *);
853 void qsetlimit(struct queue *, size_t);
854 size_t qgetlimit(struct queue *);
855 int qwindow(struct queue *);
856 ssize_t qwrite(struct queue *, void *, int);
857 ssize_t qwrite_nonblock(struct queue *, void *, int);
858 typedef void (*qio_wake_cb_t)(struct queue *q, void *data, int filter);
859 void qio_set_wake_cb(struct queue *q, qio_wake_cb_t func, void *data);
860 bool qreadable(struct queue *q);
861 bool qwritable(struct queue *q);
863 void *realloc(void *, uint32_t);
864 int readmem(unsigned long offset, char *buf, unsigned long n,
865 const void *mem, size_t mem_len);
866 int readnum(unsigned long off, char *buf, unsigned long n, unsigned long val,
868 int readnum_hex(unsigned long off, char *buf, unsigned long n,
869 unsigned long val, size_t size);
870 int readstr(unsigned long offset, char *buf, unsigned long n, const char *str);
871 int readnum_int64_t(uint32_t, char *unused_char_p_t, uint32_t, int64_t, int);
872 unsigned long strtoul_from_ubuf(void *ubuf, size_t count, int base);
873 void ready(struct proc *);
874 void renameproguser(char *unused_char_p_t, char *);
875 void renameuser(char *unused_char_p_t, char *);
876 void resrcwait(char *unused_char_p_t);
877 struct proc *runproc(void);
878 void (*serwrite) (char *unused_char_p_t, int);
879 int setcolor(uint32_t, uint32_t, uint32_t, uint32_t);
881 void setmalloctag(void *, uint32_t);
883 void setrealloctag(void *, uint32_t);
884 char *skipslash(char *unused_char_p_t);
885 void *smalloc(uint32_t);
890 void swiproc(struct proc *, int);
891 uint32_t _tas(uint32_t *);
892 uint32_t tk2ms(uint32_t);
893 #define TK2MS(x) ((x)*(1000/HZ))
894 uint64_t tod2fastticks(int64_t);
895 int64_t todget(int64_t *);
897 void todsetfreq(int64_t);
899 void todset(int64_t, int64_t, int);
901 struct block *trimblock(struct block *, int unused_int, int);
904 void uartputs(char *unused_char_p_t, int);
905 void unlock(spinlock_t *);
907 uint32_t userpc(void);
908 void validname(char *, int);
909 void validwstatname(char *);
910 int walk(struct chan **, char **unused_char_pp_t, int unused_int, bool, int *);
911 void *xalloc(uint32_t);
912 void *xallocz(uint32_t, int);
914 void xhole(uint32_t, uint32_t);
916 int xmerge(void *, void *);
917 void *xspanalloc(uint32_t, int unused_int, uint32_t);
920 void validaddr(void *, uint32_t, int);
921 void *vmemchr(void *, int unused_int, int);
922 void hnputv(void *, int64_t);
923 void hnputl(void *, uint32_t);
924 void hnputs(void *, uint16_t);
925 int64_t nhgetv(void *);
926 uint32_t nhgetl(void *);
927 uint16_t nhgets(void *);
929 char *get_cur_genbuf(void);
932 #define NOW tsc2msec(read_tsc())
933 #define seconds() tsc2sec(read_tsc())
934 #define milliseconds() tsc2msec(read_tsc())
936 /* kern/drivers/dev/tab.c */
940 /* kern/src/ns/parse.c */
941 struct cmdbuf *parsecmd(char *p, int n);
942 void cmderror(struct cmdbuf *cb, char *s);
943 struct cmdtab *lookupcmd(struct cmdbuf *cb, struct cmdtab *ctab, int nctab);
945 /* kern/src/ns/sysfile.c */
946 int newfd(struct chan *c, int low_fd, int oflags, bool must_use_low);
947 struct chan *fdtochan(struct fd_table *fdt, int fd, int mode, int chkmnt,
949 long kchanio(void *vc, void *buf, int n, int mode);
950 int openmode(uint32_t o);
951 void fdclose(struct fd_table *fdt, int fd);
952 int syschdir(char *path);
953 int grpclose(struct fd_table *fdt, int fd);
954 int sysclose(int fd);
955 int syscreate(char *path, int mode, uint32_t perm);
956 int sysdup(int old, int low_fd, bool must_use_low);
957 int sys_dup_to(struct proc *from_proc, unsigned int from_fd,
958 struct proc *to_proc, unsigned int to_fd);
959 int sysfstat(int fd, uint8_t*, int n);
960 int sysfstatakaros(int fd, struct kstat *);
961 char *sysfd2path(int fd);
962 int sysfauth(int fd, char *aname);
963 int sysfversion(int fd, unsigned int msize, char *vers, unsigned int arglen);
964 int sysfwstat(int fd, uint8_t * buf, int n);
965 long bindmount(struct chan *c, char *old, int flag, char *spec);
966 int sysbind(char *new, char *old, int flags);
967 int sysmount(int fd, int afd, char *old, int flags, char *spec);
968 int sysunmount(char *old, char *new);
969 int sysopenat(int dirfd, char *path, int vfs_flags);
970 int sysopen(char *path, int vfs_flags);
971 long unionread(struct chan *c, void *va, long n);
972 void read_exactly_n(struct chan *c, void *vp, long n);
973 long sysread(int fd, void *va, long n);
974 long syspread(int fd, void *va, long n, int64_t off);
975 int sysremove(char *path);
976 int64_t sysseek(int fd, int64_t off, int whence);
977 void validstat(uint8_t * s, int n, int slashok);
978 int sysstat(char *path, uint8_t*, int n);
979 int sysstatakaros(char *path, struct kstat *);
980 long syswrite(int fd, void *va, long n);
981 long syspwrite(int fd, void *va, long n, int64_t off);
982 int syswstat(char *path, uint8_t * buf, int n);
983 struct dir *chandirstat(struct chan *c);
984 struct dir *sysdirstat(char *name);
985 struct dir *sysdirfstat(int fd);
986 int sysdirwstat(char *name, struct dir *dir);
987 int sysdirfwstat(int fd, struct dir *dir);
988 long sysdirread(int fd, struct kdirent **d);
989 int sysiounit(int fd);
990 void print_chaninfo(struct chan *ch);
991 int plan9setup(struct proc *new_proc, struct proc *parent, int flags);
993 int fd_getfl(int fd);
994 int fd_setfl(int fd, int flags);
996 /* kern/drivers/dev/srv.c */
997 char *srvname(struct chan *c);
999 /* kern/src/eipconv.c. Put them here or face real include hell. */
1000 void printqid(void (*putch) (int, void **), void **putdat, struct qid *q);
1001 void printcname(void (*putch) (int, void **), void **putdat, struct cname *c);
1002 void printchan(void (*putch) (int, void **), void **putdat, struct chan *c);
1004 static inline int abs(int a)
1011 extern struct username eve;
1012 extern unsigned int qiomaxatomic;
1014 /* special sections */
1015 #define __devtab __attribute__((__section__(".devtab")))
1017 #define DEVVARS_ENTRY(name, fmt) \
1018 struct dirtab __attribute__((__section__("devvars"))) __devvars_##name = \
1020 {(uint64_t)&(name), 0, QTFILE}, \