Lines Matching defs:channel

22  * A file descriptor is the index of a specific channel in this array.
29 /* This variable stores the channel associated to the root directory. */
32 /* This function creates a channel from a device index and registers
37 chan_t *channel = NULL;
42 channel = &fdset[i];
43 channel->index = index;
48 return channel;
52 * This function returns a pointer to an existing channel in fdset from a file
65 * This function returns a file descriptor from a channel.
66 * The caller must be sure that the channel is registered in fdset.
68 static int channel_to_fd(chan_t *channel)
70 return (channel == NULL) ? -1 : (channel - fdset);
140 * This function clears a given channel fields
142 static void channel_clear(chan_t *channel)
144 channel->offset = 0;
145 channel->qid = 0;
146 channel->index = NODEV;
147 channel->dev = 0;
148 channel->mode = 0;
152 * This function closes the channel pointed to by c.
154 void channel_close(chan_t *channel)
156 if (channel != NULL) {
157 channel_clear(channel);
163 * channel c. nbytes bytes are expected to be copied unless the data goes over
167 int buf_to_channel(chan_t *channel, void *dst, void *src, int nbytes, long len)
171 if ((channel == NULL) || (dst == NULL) || (src == NULL)) {
175 if (channel->offset >= len) {
179 if ((channel->offset + nbytes) > len) {
180 nbytes = len - channel->offset;
183 memcpy(dst, addr + channel->offset, nbytes);
185 channel->offset += nbytes;
191 * This function checks whether a channel (identified by its device index and
193 * Returns a pointer to the channel it is mounted to when found, NULL otherwise.
197 chan_t *channel;
201 channel = mp->new;
202 if (channel == NULL) {
206 if ((channel->index == index) && (channel->qid == qid)) {
231 * It creates a new channel and returns a pointer to it.
235 chan_t *channel;
243 channel = create_new_channel(index);
244 if (channel == NULL) {
248 channel->dev = dev;
249 channel->qid = CHDIR;
251 return channel;
255 * This function returns a channel given a path.
257 * device namespace ('#'), switching channel on mount points.
263 chan_t *mnt, *channel;
272 channel = clone(&slash_channel, NULL);
290 channel = attach(elem[0], n);
296 if (channel == NULL) {
302 if ((channel->qid & CHDIR) == 0) {
306 if (devtab[channel->index]->walk(channel, elem) < 0) {
307 channel_close(channel);
311 mnt = mount_point_to_channel(channel->index, channel->qid);
313 clone(mnt, channel);
322 return channel;
325 channel_close(channel);
332 * channel c.
345 * It creates a new channel and returns a pointer to it.
346 * It clones channel into new_channel.
348 chan_t *devclone(chan_t *channel, chan_t *new_channel)
350 if (channel == NULL) {
355 new_channel = create_new_channel(channel->index);
361 new_channel->qid = channel->qid;
362 new_channel->dev = channel->dev;
363 new_channel->mode = channel->mode;
364 new_channel->offset = channel->offset;
365 new_channel->index = channel->index;
376 int devwalk(chan_t *channel, const char *name, const dirtab_t *tab,
382 if ((channel == NULL) || (name == NULL) || (gen == NULL)) {
391 switch ((*gen)(channel, tab, ntab, i, &dir)) {
400 channel->qid = dir.qid;
412 int dirread(chan_t *channel, dir_t *dir, const dirtab_t *tab,
417 if ((channel == NULL) || (dir == NULL) || (gen == NULL)) {
421 i = channel->offset/sizeof(dir_t);
422 ret = (*gen)(channel, tab, ntab, i, dir);
424 channel->offset += sizeof(dir_t);
433 void make_dir_entry(chan_t *channel, dir_t *dir,
436 if ((channel == NULL) || (dir == NULL) || (name == NULL)) {
449 dir->index = channel->index;
450 dir->dev = channel->dev;
458 int devgen(chan_t *channel, const dirtab_t *tab, int ntab, int n, dir_t *dir)
462 if ((channel == NULL) || (dir == NULL) || (tab == NULL) ||
468 make_dir_entry(channel, dir, dp->name, dp->length, dp->qid, dp->perm);
473 * This function returns a file descriptor identifying the channel associated to
478 chan_t *channel;
488 channel = path_to_channel(path, mode);
490 return channel_to_fd(channel);
494 * This function closes the channel identified by the file descriptor fd.
498 chan_t *channel;
500 channel = fd_to_channel(fd);
501 if (channel == NULL) {
505 channel_close(channel);
566 chan_t *channel;
592 channel = path_to_channel(dirname, O_STAT);
593 if (channel == NULL) {
597 r = devtab[channel->index]->stat(channel, path, dir);
598 channel_close(channel);
610 chan_t *channel;
616 channel = fd_to_channel(fd);
617 if (channel == NULL) {
621 if (((channel->qid & CHDIR) != 0) && (n < sizeof(dir_t))) {
625 return devtab[channel->index]->read(channel, buf, n);
635 chan_t *channel;
641 channel = fd_to_channel(fd);
642 if (channel == NULL) {
646 if ((channel->qid & CHDIR) != 0) {
650 return devtab[channel->index]->write(channel, buf, n);
659 chan_t *channel;
661 channel = fd_to_channel(fd);
662 if (channel == NULL) {
666 if ((channel->qid & CHDIR) != 0) {
670 return devtab[channel->index]->seek(channel, off, whence);
677 chan_t *deverrmount(chan_t *channel, const char *spec)
686 int deverrwrite(chan_t *channel, void *buf, int n)
695 int deverrseek(chan_t *channel, long off, int whence)
702 * It applies the offset off according to the strategy whence to the channel c.
704 int devseek(chan_t *channel, long off, int whence)
708 channel->offset = off;
711 channel->offset += off;
722 * This function registers the channel associated to the path new as a mount
723 * point for the channel c.
725 static int add_mount_point(chan_t *channel, const char *new)
756 mp->old = channel;
771 chan_t *channel;
773 channel = path_to_channel(old, O_BIND);
774 if (channel == NULL) {
778 if (add_mount_point(channel, new) < 0) {
779 channel_close(channel);
793 chan_t *channel, *mount_point_chan;
796 channel = path_to_channel(srv, O_RDWR);
797 if (channel == NULL) {
801 mount_point_chan = devtab[channel->index]->mount(channel, spec);
811 channel_close(channel);
818 channel_close(channel);
825 * It creates the '/' channel.
830 chan_t *channel, *cloned_channel;
832 for (channel = fdset; channel < &fdset[NR_CHANS]; channel++) {
833 channel_clear(channel);
836 channel = devattach('/', 0);
837 if (channel == NULL) {
841 cloned_channel = clone(channel, &slash_channel);
846 channel_close(channel);