void oserrstr(void) { if (errno == EINTR) kstrcpy(up->errstr, Eintr, ERRMAX); else kstrcpy(up->errstr, strerror(errno), ERRMAX); }
/* Get kernel error string */ void kgerrstr(char *err, uint size) { char tmp[ERRMAX]; kstrcpy(tmp, up->env->errstr, sizeof(tmp)); kstrcpy(up->env->errstr, err, ERRMAX); kstrcpy(err, tmp, size); }
/* supported formats: %%, %d, %u, %x, %p, %s, %c * TODO: * - return number of bytes copied into 'str' */ int kvsprintf(char *str, const char *fmt, va_list ap) { char *ptr, *stmp; unsigned utmp; int itmp; char ctmp; for (; *fmt; fmt = ptr + 2) { ptr = kstrchr(fmt, '%'); if (ptr == NULL) { kstrcpy(str, fmt); return 1; } str += kstrncpy(str, fmt, (int)ptr - (int)fmt); switch (*(ptr + 1)) { case 'd': /* signed int */ itmp = va_arg(ap, int); str = sitoa(str, itmp); break; case 'u': /* unsigned int */ utmp = va_arg(ap, unsigned); str = uitoa(str, utmp); break; case 'p': /* pointer */ *str++ = '0'; *str++ = 'x'; case 'x': /* hex */ utmp = va_arg(ap, unsigned); str = htoa(str, utmp); break; case 's': /* string */ stmp = va_arg(ap, char *); str += kstrcpy(str, stmp); break; case '%': *str++ = '%'; break; case 'c': ctmp = va_arg(ap, int); *str++ = ctmp; break; default: /* unsupported format */ break; } } return 1; }
static void telldbg(Progctl *ctl, char *msg) { kstrcpy(ctl->msg, msg, ERRMAX); ctl->debugger = nil; Wakeup(&ctl->r); }
static int envgen(Chan *c, char *name, Dirtab* dir, int i, int s, Dir *dp) { Proc *up = externup(); Egrp *eg; Evalue *e; if(s == DEVDOTDOT){ devdir(c, c->qid, "#e", 0, eve, DMDIR|0775, dp); return 1; } eg = envgrp(c); rlock(&eg->rwl); e = 0; if(name) e = envlookup(eg, name, -1); else if(s < eg->nent) e = eg->ent[s]; if(e == 0) { runlock(&eg->rwl); return -1; } /* make sure name string continues to exist after we release lock */ kstrcpy(up->genbuf, e->name, sizeof up->genbuf); devdir(c, e->qid, up->genbuf, e->len, eve, 0666, dp); runlock(&eg->rwl); return 1; }
/* * Mark a queue as closed. No further IO is permitted. * All blocks are released. */ void qclose(Queue *q) { Block *bfirst; if(q == nil) return; /* mark it */ ilock(q); q->state |= Qclosed; q->state &= ~(Qflow|Qstarve); kstrcpy(q->err, Ehungup, ERRMAX); bfirst = q->bfirst; q->bfirst = nil; q->len = 0; q->dlen = 0; q->noblock = 0; iunlock(q); /* free queued blocks */ freeblist(bfirst); /* wake up readers/writers */ wakeup(&q->rr); wakeup(&q->wr); }
static char *get_filename(struct dirent *d, char buffer[255]) { int i, ret = 0; char *ptr; struct dirent_long *dl = (struct dirent_long *)d; /* make sure we actually have long entries */ if ((dl - 1)->attr != DENT_LONG) { kstrcpy(buffer, d->filename); if ((ptr = kstrchr(buffer, 0x20)) < &buffer[10]) *ptr = 0; return buffer; } do { --dl; for (i = 0; i < 5 && dl->filename_1[i] != 0; ++i) buffer[ret++] = (char)dl->filename_1[i]; if (i < 5 && dl->filename_1[i] == 0) break; for (i = 0; i < 6 && dl->filename_2[i] != 0; ++i) buffer[ret++] = (char)dl->filename_2[i]; if (i < 6 && dl->filename_2[i] == 0) break; for (i = 0; i < 2 && dl->filename_3[i] != 0; ++i) buffer[ret++] = (char)dl->filename_3[i]; if (i < 2 && dl->filename_2[i] == 0) break; } while (!(dl->order & 0x40)); buffer[ret] = 0; return buffer; }
static int envgen(Chan *c, char *name, Dirtab *d, int nd, int s, Dir *dp) { Egrp *eg; Evalue *e; USED(name); USED(d); USED(nd); if(s == DEVDOTDOT){ devdir(c, c->qid, "#e", 0, eve, DMDIR|0775, dp); return 1; } eg = up->env->egrp; qlock(&eg->l); for(e = eg->entries; e != nil && s != 0; e = e->next) s--; if(e == nil) { qunlock(&eg->l); return -1; } /* make sure name string continues to exist after we release lock */ kstrcpy(up->genbuf, e->var, sizeof up->genbuf); devdir(c, e->qid, up->genbuf, e->len, eve, 0666, dp); qunlock(&eg->l); return 1; }
static Ctlr* newctlr(char *path) { Ctlr *c; if(ctlrlookup(path)) error(Eexist); if((c = malloc(sizeof *c)) == nil) error(Enomem); if(waserror()){ free(c); nexterror(); } c->c = namec(path, Aopen, ORDWR, 0); poperror(); kstrcpy(c->path, path, sizeof c->path); lock(&ctlrlock); if(head != nil) tail->next = c; else head = c; tail = c; unlock(&ctlrlock); return c; }
int MediaSrvGetName(HANDLE hmedia, char *name, int max) #endif { PMEDIA_OBJECT obj; int ret; kMutexWait(hMediaMutex); obj = (PMEDIA_OBJECT)HandleGet(hmedia, MEDIA_MAGIC); if(obj == NULL) { kMutexRelease(hMediaMutex); return -1; } ret = kstrlen(obj->MediaInfo); if(ret <= max) { kstrcpy(name, obj->MediaInfo); } else { kmemcpy(name, obj->MediaInfo, max); ret = max; } kMutexRelease(hMediaMutex); return ret; }
// changes the current directory. // returns whether succesful. int chdir(const char* dir) { if (!read_dir_info(dir)) return 0; kstrcpy(current_dir, dir); cdir_info = dir_info; return 1; }
static int envgen(Chan *c, char *name, Dirtab*, int, int s, Dir *dp) { Egrp *eg; Evalue *e; if(s == DEVDOTDOT){ devdir(c, c->qid, "#e", 0, eve, DMDIR|0775, dp); return 1; } eg = envgrp(c); rlock(eg); if(name != nil) e = envlookup(eg, name, -1); else if(s < eg->nent) e = &eg->ent[s]; else e = nil; if(e == nil || name != nil && (strlen(e->name) >= sizeof(up->genbuf))) { runlock(eg); return -1; } /* make sure name string continues to exist after we release lock */ kstrcpy(up->genbuf, e->name, sizeof up->genbuf); devdir(c, e->qid, up->genbuf, e->len, eve, 0666, dp); runlock(eg); return 1; }
static int srvgen(Chan *c, char*, Dirtab*, int, int s, Dir *dp) { Srv *sp; Qid q; if(s == DEVDOTDOT){ devdir(c, c->qid, "#s", 0, eve, 0555, dp); return 1; } qlock(&srvlk); for(sp = srv; sp && s; sp = sp->link) s--; if(sp == 0) { qunlock(&srvlk); return -1; } mkqid(&q, sp->path, 0, QTFILE); /* make sure name string continues to exist after we release lock */ kstrcpy(up->genbuf, sp->name, sizeof up->genbuf); devdir(c, q, up->genbuf, 0, sp->owner, sp->perm, dp); qunlock(&srvlk); return 1; }
static int pipewstat(Chan *c, uchar *dp, int n) { Dir *d; Pipe *p; int d1; if (c->qid.type&QTDIR) error(Eperm); p = c->aux; if(strcmp(up->env->user, p->user) != 0) error(Eperm); d = smalloc(sizeof(*d)+n); if(waserror()){ free(d); nexterror(); } n = convM2D(dp, n, d, (char*)&d[1]); if(n == 0) error(Eshortstat); d1 = NETTYPE(c->qid.path) == Qdata1; if(!emptystr(d->name)){ validwstatname(d->name); if(strlen(d->name) >= KNAMELEN) error(Efilename); if(strcmp(p->pipedir[1+!d1].name, d->name) == 0) error(Eexist); kstrcpy(p->pipedir[1+d1].name, d->name, KNAMELEN); } if(d->mode != ~0U) p->pipedir[d1 + 1].perm = d->mode & 0777; poperror(); free(d); return n; }
void error(char *err) { if(err != up->env->errstr && up->env->errstr != nil) kstrcpy(up->env->errstr, err, ERRMAX); // ossetjmp(up->estack[NERR-1]); nexterror(); }
void kcadvalor(char far *s, int n) { char cadena[80], far * p = cadena; kstrcpy(p, s); kitoa(p + kstrlen(s), n); kstrcat(p, "\n\r"); kputs(p); }
void dict_add(dict *d, const char* name, void* value, int size) { dict_ensure_size(d, d->count+1); d->items[d->count].name = kmalloc(kstrlen(name)+1); d->items[d->count].value = kmalloc(size); kstrcpy(d->items[d->count].name, name); kmemcpy(d->items[d->count].value, value, size); d->count++; }
void error(char *err) { spllo(); assert(up->nerrlab < NERR); kstrcpy(up->errstr, err, ERRMAX); setlabel(&up->errlab[NERR-1]); nexterror(); }
void werrstr(char *fmt, ...) { va_list arg; char buf[ERRMAX]; va_start(arg, fmt); vseprint(buf, buf+sizeof(buf), fmt, arg); va_end(arg); kstrcpy(up->env->errstr, buf, ERRMAX); }
void error(char *err) { Mach *m = machp(); spllo(); assert(m->externup->nerrlab < NERR); kstrcpy(m->externup->errstr, err, ERRMAX); setlabel(&m->externup->errlab[NERR-1]); nexterror(); }
//////////////////////////////////////////////////// // 功能: 为音频任务申请并初始化节点 // 输入: // 输出: // 返回: // 说明: //////////////////////////////////////////////////// static PMEDIA_OBJECT MediaSrvObjCreate(void *media, char *name, int type) { PMEDIA_OBJECT obj; // 输入参数检查 if(!media) return NULL; // 申请节点,并初始化 obj = kmalloc(sizeof(MEDIA_OBJECT)); if(obj == NULL) return NULL; kmemset(obj, 0x00, sizeof(MEDIA_OBJECT)); ListInit(&obj->Link); if(MediaSrvGetCallback(type, &obj->Cb) < 0) { kdebug(mod_media, PRINT_ERROR, "MediaSrvGetCallback error\n"); kfree(obj); return NULL; } if(((PMEDIA_TASK)media)->ExterdType == 1 && JzSrvUseMplayer() < 0) { kdebug(mod_media, PRINT_ERROR, "MediaSrvGetCallback error: mplayer already exist\n"); kfree(obj); return NULL; } // 创建媒体任务 obj->Media = obj->Cb.MediaCreate(media); if(obj->Media == NULL) { kfree(obj); return NULL; } // 保存媒体名称 if(name) { obj->MediaInfo = kmalloc(kstrlen(name)+1); if(obj->MediaInfo) kstrcpy(obj->MediaInfo, name); } // 设置媒体任务 #if defined(STC_EXP) obj->hTask = sTaskSelf(); #else obj->hTask = TaskSelf(); #endif // 返回媒体对象 return obj; }
void error(char *err) { if(up == nil) panic("error(%s) not in a process", err); spllo(); if(up->nerrlab > NERR) panic("error stack too deep"); if(err != up->env->errstr) kstrcpy(up->env->errstr, err, ERRMAX); setlabel(&up->errlab[NERR-1]); nexterror(); }
void make_node(struct file *node, struct file *parent, char *name, uint64_t start, uint64_t end, int type, uint64_t inode_no) { kstrcpy(node->f_name, name); node->start = start; node->end = end; node->curr = start; node->f_type = type; node->f_inode_no = inode_no; node->f_child[0] = node; node->f_child[1] = parent; //return (void *)node; }
/* * Mark a queue as closed. Wakeup any readers. Don't remove queued * blocks. */ void qhangup(Queue *q, char *msg) { /* mark it */ ilock(q); q->state |= Qclosed; if(msg == nil || *msg == '\0') msg = Ehungup; kstrcpy(q->err, msg, ERRMAX); iunlock(q); /* wake up readers/writers */ wakeup(&q->rr); wakeup(&q->wr); }
/* * Mark a queue as closed. Wakeup any readers. Don't remove queued * blocks. */ void qhangup(Queue *q, char *msg) { /* mark it */ lock(&q->l); q->state |= Qclosed; if(msg == 0 || *msg == 0) strcpy(q->err, Ehungup); else kstrcpy(q->err, msg, sizeof q->err); unlock(&q->l); /* wake up readers/writers */ Wakeup(&q->rr); Wakeup(&q->wr); }
static void genPointerUpdate( struct KgenContext *ctx, const char *ptrName, const char *ldName, size_t bwidth, size_t bheight, unsigned int vecLen, DataType dtype, BlasGenFlags gflags, bool rowMaj, bool isLocal) { const char *uptr; Kstring tmp; const char *p; if (gflags & BGF_UPTRS) { getVectorTypeName(dtype, vecLen, NULL, &uptr); ksprintf(&tmp, "%s.%s", ptrName, uptr); p = tmp.buf; } else { p = ptrName; } if (rowMaj) { kgenPrintf(ctx, "%s += %lu;\n", p, bwidth / vecLen); } else if (isLocal) { kgenPrintf(ctx, "%s += %lu;\n", p, bwidth * (bheight / vecLen)); } else { Kstring ld; Kstring bwStr, madExpr; unsigned int scale; kstrcpy(&ld, ldName); ksprintf(&bwStr, "%lu", bwidth); scale = (gflags & BGF_LD_IN_VECTORS) ? 0 : vecLen; sprintfFastScalarMad(&madExpr, &bwStr, &ld, scale, NULL); kgenPrintf(ctx, "%s += %s;\n", p, madExpr.buf); } }
static Ctlr* newctlr(char *path) { Ctlr *c; if(ctlrlookup(path)) error(Eexist); if((c = malloc(sizeof *c)) == nil) return 0; kstrcpy(c->path, path, sizeof c->path); lock(&ctlrlock); if(head != nil) tail->next = c; else head = c; tail = c; unlock(&ctlrlock); return c; }
void parse(char *dir_path, int type, uint64_t start, uint64_t end) { fnode_t *temp_node, *aux_node, *currnode = root_node->f_child[2]; char *temp; int i = 0; char *path = (char *)kmalloc(sizeof(char) * kstrlen(dir_path)); kstrcpy(path, dir_path); temp = kstrtok(path, "/"); while (temp != NULL) { aux_node = currnode; //kprintf("%s \n", temp); //iterate through all childrens of currnode for(i = 2; i < currnode->end; ++i){ if(kstrcmp(temp, currnode->f_child[i]->f_name) == 0) { currnode = (fnode_t *)currnode->f_child[i]; break; } } //kprintf("\n....%s...%s...", currnode->f_name, temp); //if no child has been found //add this as child of current if (i == aux_node->end) { temp_node = (fnode_t *)kmalloc(sizeof(struct file)); make_node(temp_node, currnode, temp, start, end, type, 0); currnode->f_child[currnode->end] = temp_node; currnode->end += 1; } //kprintf("....%d...%s...", currnode->end, temp); //while(1); temp = kstrtok(NULL, "/"); } }
void* file_lookup(char *dir_path) { char* file_path = (char *)dir_path; fnode_t *aux_node, *currnode = root_node; char *temp = NULL; int i; char *path = (char *)kmalloc(sizeof(char) * kstrlen(file_path)); kstrcpy(path, file_path); temp = kstrtok(path, "/"); if (temp == NULL) return NULL; //kprintf("\n step1 %s", temp); while (temp != NULL) { aux_node = currnode; for (i = 2; i < currnode->end; ++i) { if (kstrcmp(temp, currnode->f_child[i]->f_name) == 0) { currnode = (fnode_t *)currnode->f_child[i]; break; } } if (i == aux_node->end) { return NULL; } temp = kstrtok(NULL, "/"); } if (currnode->f_type == FILE) return (void *)currnode->start; else return NULL; }
// Call before using any FAT functions. void fat_init() { // Copy BIOS parameter block from where the boot sector was loaded void* bootsect = (void*)0x7C00; bpb = *(BPBMain*)bootsect; bpb16 = *(BPB16*)(bootsect+36); bpb32 = *(BPB32*)(bootsect+36); // make current directory the root directory kstrcpy(current_dir, "/"); dir_info.cluster_low = 0; // cluster 0 directory is root // sector-based calculations root_start = bpb.RsvdSecCnt+(bpb.FATSz16 ? bpb.FATSz16 : bpb32.FATSz32)*bpb.NumFATs; root_sectors = bpb.RootEntCnt*32+(bpb.BytsPerSec-1)/bpb.BytsPerSec; data_start = root_start+root_sectors; cluster_size = bpb.SecPerClus*bpb.BytsPerSec; count_of_clusters = ((bpb.TotSec16 ? bpb.TotSec16 : bpb.TotSec32)-data_start)/bpb.SecPerClus; // Determine FAT type fat_type = count_of_clusters < 4085 ? TFAT12: count_of_clusters < 65525 ? TFAT16 : TFAT32; // invalidate current FAT sector number cur_fat_sec = 0; }