Пример #1
0
/*
 * struct fs32_flushbuf_parms {
 *     unsigned short flag;
 *     unsigned short hVPB;
 * };
 */
int FS32ENTRY fs32_flushbuf(struct fs32_flushbuf_parms *parms)
{
    int rc;
    struct super_block *sb;


    if (trace_FS_FLUSHBUF)
    {
        kernel_printf("FS_FLUSHBUF - flag = %d, hVPB = 0x%0X", (int)(parms->flag), (int)(parms->hVPB));
    }

    if (Read_Write)
    {
        sb = getvolume(parms->hVPB);

        if ((sb) && (sb->s_magic_internal == SUPER_MAGIC))
        {
            if (sb->s_status == VOL_STATUS_MOUNTED)
            {
                kernel_printf("\tmedia is present");
                switch (parms->flag)
                {
                    case FLUSH_RETAIN:
                    case FLUSH_DISCARD:
                        sync_buffers(sb->s_dev, 1);
                        if ((sb->s_op) && (sb->s_op->write_super))
                            sb->s_op->write_super(sb);
                        sync_inodes(sb->s_dev);
                        sync_buffers(sb->s_dev, 1);
                        rc = NO_ERROR;
                        break;


                    default:
                        rc = ERROR_INVALID_PARAMETER;
                        break;
                }
            }
            else
            {
                rc = NO_ERROR;
            }
        }
        else
        {
            rc = ERROR_INVALID_PARAMETER;
        }
    }
    else
    {
        rc = NO_ERROR;
    }

    if (trace_FS_FLUSHBUF)
    {
        kernel_printf("FS_FLUSHBUF - flag = %d, hVPB = 0x%0X, rc = %d", (int)(parms->flag), (int)(parms->hVPB), rc);
    }

    return rc;
}
Пример #2
0
int main(int argc, char* argv[]) {
	char *status;
    char volume[20];
	char *datetime;
	char bat[20] = "";
    int laptop = 0;
    char hostname[30];
    gethostname(hostname, 30); 
    printf("%s\n", hostname);
    
    if (strcmp(hostname, "johan-laptop") == 0){
        laptop = 1;
        printf("This is a laptop\n");
    }
    else {
        printf("This is not a laptop\n");
    }

    snd_mixer_t *handle;
	snd_mixer_open(&handle, 0);
	snd_mixer_attach(handle, "default");
	const char* vol_ch = "Master";
	snd_mixer_selem_register(handle, NULL, NULL);
	snd_mixer_load(handle);

	if (!(dpy = XOpenDisplay(NULL))) {
		fprintf(stderr, "Cannot open display.\n");
		return 1;
	}

	if((status = malloc(200)) == NULL)
		exit(1);
	

	for (;;usleep(1000000)) {
	    datetime = getdatetime();
        //volume = getcmd("$HOME/Scripts/volume\\ get.sh");
        sprintf(volume, "%.0f%", getvolume(handle, vol_ch));
		if (laptop){
            sprintf(bat, " Bat: %.0f% |", getbattery());
        }

        snprintf(status, 200, "Vol: %s% |%s %s ", volume, bat, datetime );

		free(datetime);
		setstatus(status);
	}

	free(status);
	XCloseDisplay(dpy);

	return 0;
}
Пример #3
0
int main(void) {
    char *status;
    float mem;
    int bat0;
    char *datetime;
    char *address;
    char battext[6];
    char *volume;

    if (!(dpy = XOpenDisplay(NULL))) {
        fprintf(stderr, "Cannot open display.\n");
        return 1;
    }

    status = xmalloc(200);

    for (;;sleep(1)) {
        datetime = getdatetime();
        mem = getmeminfo();
        bat0 = getbattery();
        address = getaddress();
        volume = getvolume();

        if (ischarging())
            strcpy(battext, "ac:");
        else {
            if (bat0 > 50)
                strcpy(battext, "bat:");
            else if (bat0 < 20)
                strcpy(battext, "bat:");
            else
                strcpy(battext, "bat:");
        }

        snprintf(status, 200,
                "|%s|mem:%0.0f%%|%s%d%%|vol:%s|%s|",
                address, mem, battext, bat0, volume, datetime);

        free(datetime);
        free(address);
        free(volume);
        setstatus(status);
    }

    free(status);
    XCloseDisplay(dpy);

    return 0;
}
Пример #4
0
int main(void) {
    Display *dpy;
    char *temp;
    char *status;
    char *tmny;
    char *batt;
    char *wifi;
    char *volume;

    if (!(dpy = XOpenDisplay(NULL))) {
        fprintf(stderr, "dwmstatus: cannot open display.\n");
        return 1;
    }

    for (;;sleep(1)) {
        wifi = getsignalstrength();
        batt = getbattery();
        volume = getvolume();
        temp = gettemperature("/sys/class/hwmon/hwmon0/temp1_input");
        tmny = mktimes("%a %d %b %H:%M:%S", tzny);

        /* status = smprintf("\x8D   | \x8F | \x90 | \x9D | \x81 | %s", tmny); */
        /*                    charge | batt | vol  | mute | wifi | time        */
        status = smprintf("%s | %s%s%s %s", temp, volume, batt, wifi, tmny);

        XStoreName(dpy, DefaultRootWindow(dpy), status);
        XSync(dpy, False);

        free(tmny);
        free(batt);
        free(wifi);
        free(volume);
        free(status);
    }

    XCloseDisplay(dpy);

    return 0;
}
Пример #5
0
void MTInstrumentInstance::sendevents(int nevents,MTIEvent **events)
{
	int x,y;
	double next,tmp_vol,b,b1,b2;
	float tmp_panx,tmp_pany,tmp_panz;
	MTInstrument &cparent = *(MTInstrument*)parent;
	bool first = true;
	
	for (x=0;x<nevents;x++){
		MTIEvent *cevent = events[x];
		MTINoteEvent *nevent = (MTINoteEvent*)cevent;
		MTIParamEvent *pevent = (MTIParamEvent*)cevent;
		if (cevent){
			switch (cevent->type){
			case MTIE_NOTE:
				nextevent = cpos;
				if (nevent->note==0){
					flags |= MTIIF_NOTEOFF;
					if ((cparent.env[0].flags & EF_ENABLED)==0){
						flags |= MTIIF_NOTECUT;
						tvol = mvol = 0.0;
						if (osc[0]) osc[0]->setvolume(0.0,FAST_RAMP,0);
					}
					else{
						for (y=0;y<8;y++){
							if (envs[y].wait){
								envs[y].wait = false;
								envs[y].count = 0.0;
							};
						};
					};
					continue;
				};
				flags &= (~(MTIIF_NOTEOFF|MTIIF_NOTECUT|MTIIF_FADEOUT));
				// Global parameters
				if (nevent->flags & MTIEF_ISINS){ // Is there an instrument?
					gvol = cparent.gvol*nevent->gvolume;
					gpanx = pan_mul(nevent->gpanx,cparent.gpanx);
					gpany = pan_mul(nevent->gpany,cparent.gpany);
					gpanz = pan_mul(nevent->gpanz,cparent.gpanz);
					mtmemzero(envs,sizeof(envs));
					for (x=0;x<8;x++) envs[x].lenvp = 65535;
					cvol = getvolume();
					getpanning(&cpanx,&cpany,&cpanz);
					lastpos = cpos;
					fadepos = 0.0;
					MTInstrument &ins = *((MTInstrument*)parent);
					fadeout = ins.fadeout;
					nna = ins.nna;
					iflags = ins.flags;
				};
				note = nevent->note;
				if (osc[0]) first = false;
				if (nevent->flags & MTIEF_ISNOTE){ // Is there a note?
					if (osc[0]){
						first = true;
						delete osc[0];
						osc[0] = 0;
					};
					if ((note<12) || (note>106)) continue;
					grp[0] = cparent.range[0][(int)note-12];
				}
				else{
					if ((note<12) || (note>106)) continue;
					grp[0] = cparent.range[0][(int)note-12];
				};
				if (!osc[0]){
					if (cparent.grp[grp[0]].spl){
						if (filter){
							osc[0] = cparent.grp[grp[0]].spl->createinstance(track->noutputs,buffer,this);
						}
						else{
							osc[0] = cparent.grp[grp[0]].spl->createinstance(track->noutputs,track->buffer,this);
						};
					};
				};
				// Set the oscillator parameters
				if (osc[0]){
					if (first){
						osc[0]->setnote(note+(double)cparent.grp[grp[0]].pitch/128);
					};
					y = (int)note-12;
					gvol *= cparent.grp[grp[0]].vol;
					if (nevent->flags & MTIEF_ISINS){
						if (nevent->volume>-1.0) mvol = nevent->volume;
						else mvol = (float)cparent.range[1][y]/128;
						if (nevent->panx>-2.0) mpanx = pan_mul(cparent.grp[grp[0]].panx,nevent->panx);
						else mpanx = pan_mul(cparent.grp[grp[0]].panx,(float)((signed char)cparent.range[2][y])/127);
						if (nevent->pany>-2.0) mpany = pan_mul(cparent.grp[grp[0]].pany,nevent->pany);
						else mpany = pan_mul(cparent.grp[grp[0]].pany,(float)((signed char)cparent.range[3][y])/127);
						if (nevent->panz>-2.0) mpanz = pan_mul(cparent.grp[grp[0]].panz,nevent->panz);
						else mpanz = pan_mul(cparent.grp[grp[0]].panz,(float)((signed char)cparent.range[4][y])/127);
					};
					tvol = cvol*mvol;
					tpanx = pan_mul(mpanx,cpanx);
					tpany = pan_mul(mpany,cpany);
					tpanz = pan_mul(mpanz,cpanz);
					osc[0]->setvolume(gvol*tvol);
					osc[0]->setpanning(pan_mul(gpanx,tpanx),pan_mul(gpany,tpany),pan_mul(gpanz,tpanz));
				};
				break;
			case MTIE_KILL:
				if (!osc[0]) return;
				flags |= IIF_BACKGROUND;
				switch (nna & 0xFF){
				case NNA_NOTECUT:
					flags |= MTIIF_NOTECUT;
					tvol = mvol = 0.0;
					osc[0]->setvolume(0.0,FAST_RAMP,0);
					break;
				case NNA_NOTEOFF:
					flags |= MTIIF_NOTEOFF;
					if ((cparent.env[0].flags & EF_ENABLED)==0){
						flags |= MTIIF_NOTECUT;
						tvol = mvol = 0.0;
						osc[0]->setvolume(0.0,FAST_RAMP,0);
					}
					else{
						for (y=0;y<8;y++){
							if (envs[y].wait){
								envs[y].wait = false;
								envs[y].count = 0.0;
							};
						};
						nextevent = cpos;
					};
					break;
				case NNA_FADEOUT:
					flags |= MTIIF_FADEOUT;
					fadepos = cpos;
					nextevent = cpos;
/*
					tvol = mvol = 0.0;
					osc[0]->setvolume(0.0,FAST_RAMP,0);
*/
					break;
				};
				break;
			case MTIE_RESET:
				break;
			case MTIE_PARAM:
				if ((!osc[0]) || (flags & MTIIF_NOTECUT)) return;
				y = 0;
				if ((pevent->param==MTIP_VOLUME) || (pevent->param==MTIP_PANNING)){
					b1 = module->samplestobeats(MIN_RAMP);
					b2 = module->samplestobeats(MAX_RAMP);
					b = nextevent-cpos;
					if (b<b1){
						y = 0;
						b = 0.0;
					}
					else if (b>b2){
						y = FAST_RAMP;
						b = module->samplestobeats(FAST_RAMP);
					}
					else{
						y = (int)module->beatstosamples(b);
					};
					next = cpos+b;
					if (next<nextevent) nextevent = next;
				};
				switch (pevent->param){
				case MTIP_VOLUME:
					tmp_vol = getvolume(b);
					if (pevent->flags & MTIEF_MUL) mvol *= pevent->dvalue1;
					else if (pevent->flags & MTIEF_ADD) mvol += pevent->dvalue1;
					else mvol = pevent->dvalue1;
					if (mvol<0.0) mvol = 0.0;
					else if ((mvol>1.0) && ((pevent->flags & MTIEF_DONTSATURATE)==0)) mvol = 1.0;
					tvol = tmp_vol*mvol;
					osc[0]->setvolume(gvol*tvol,y);
					break;
				case MTIP_PANNING:
					getpanning(&tmp_panx,&tmp_pany,&tmp_panz,b);
					if (pevent->flags & MTIEF_MUL){
						pan_self_mul(mpanx,pevent->fvalue1);
						pan_self_mul(mpany,pevent->fvalue2);
						pan_self_mul(mpanz,pevent->fvalue3);
					}
					else if (pevent->flags & MTIEF_ADD){
						mpanx += pevent->fvalue1;
						mpany += pevent->fvalue2;
						mpanz += pevent->fvalue3;
						if (mpanx<-1.0) mpanx = -1.0;
						else if (mpanx>1.0) mpanx = 1.0;
						if (mpany<-1.0) mpany = -1.0;
						else if (mpany>1.0) mpany = 1.0;
						if (mpanz<-1.0) mpanz = -1.0;
						else if (mpanz>1.0) mpanz = 1.0;
					}
					else{
						mpanx = pevent->fvalue1;
						mpany = pevent->fvalue2;
						mpanz = pevent->fvalue3;
					};
					pan_self_mul(mpanx,cparent.grp[grp[0]].panx);
					pan_self_mul(mpany,cparent.grp[grp[0]].pany);
					pan_self_mul(mpanz,cparent.grp[grp[0]].panz);
					tpanx = pan_mul(mpanx,tmp_panx);
					tpany = pan_mul(mpany,tmp_pany);
					tpanz = pan_mul(mpanz,tmp_panz);
					osc[0]->setpanning(pan_mul(gpanx,tpanx),pan_mul(gpany,tpany),pan_mul(gpanz,tpanz),y);
					break;
				case MTIP_NOTE:
					if (pevent->flags & MTIEF_MUL) note *= pevent->dvalue1;
					else if (pevent->flags & MTIEF_ADD) note += pevent->dvalue1;
					else note = pevent->dvalue1;
					osc[0]->setnote(note);
					break;
				};
				break;
			};
		};
	};
}
Пример #6
0
void MTInstrumentInstance::processevents()
{
	int x,l,lp,e;
	double inc;
	MTInstrument &cins = *(MTInstrument*)parent;

	if (!osc[0]){
		nextevent = -1.0;
		return;
	};
	inc = cpos-lastpos;
	if (inc>0.0){
		for (x=0;x<8;x++){
			IEnvelope &cenv = ((MTInstrument*)parent)->env[x];
			EnvStatus &cs = envs[x];
			if ((cenv.flags & EF_ENABLED) && (cenv.npoints)){
				// If the envelope was active then increment the position
				if (!cs.process) cs.pos += inc;
				// If the envelope was not idle then decrement the counter until next point
				if (!cs.wait) cs.count -= inc;
			};
			// Mark the envelope as not active (it'll be active later if there is something to do with it)
			cs.process = false;
		};
	};
	lastpos = cpos;
	inc = 1000.0;
	if ((flags & MTIIF_NOTECUT)==0){
		for (x=0;x<8;x++){
			IEnvelope &cenv = cins.env[x];
			if ((cenv.flags & EF_ENABLED) && (cenv.npoints)){
				EnvStatus &cs = envs[x];
/*				if (x==0){
					FLOG4("%f\t%f\t%d\t%d\t%f",cs.pos,cs.count,cs.envp,cs.lenvp);
					FLOG1("%f"NL,cvol);
				};*/
				l = 0;
				if (cs.count<=0.0){ // We reached a new point
					lp = cs.lenvp;
					cs.lenvp = cs.envp;
					// Calculate the last point we can reach
					e = cenv.npoints-1; // ...either the last point
					if (cenv.flags & EF_LOOP) e = cenv.loope; // ...or the loop end
					if ((cenv.flags & EF_SUSTAIN) && ((flags & MTIIF_NOTEOFF)==0) && (cenv.suste<e)) e = cenv.suste; // ...or the sustain loop end
					if (e==0){ // First and only point
						switch (x){
						case 0:
							if ((e==cenv.npoints-1) && (iflags & MTIF_FAE) && ((flags & MTIIF_FADEOUT)==0)){
								if (((cenv.flags & EF_SUSTAIN)==0) || ((flags & MTIIF_NOTEOFF)!=0)){
									flags |= MTIIF_FADEOUT;
									fadepos = cpos;
								};
							};
							cvol = cenv.points[cs.envp].y;
							break;
						case 1:
							cpanx = cenv.points[cs.envp].y;
							break;
						case 3:
							ccutoff = cenv.points[cs.envp].y;
							break;
						};
						cs.wait = true;
						cs.count = 1000.0;
						l = -1;
					}
					else if (cs.envp<e){ // Not at the end
//						cs.process = true;
						if (lp==65535){ // First point
							switch (x){
							case 0:
								cvol = cenv.points[0].y;
								tvol = cvol*mvol;
								osc[0]->setvolume(gvol*tvol);
								break;
							case 1:
								cpanx = cenv.points[0].y;
								tpanx = pan_mul(mpanx,cpanx);
								osc[0]->setpanning(pan_mul(gpanx,tpanx));
								break;
							case 3:
								ccutoff = cenv.points[0].y;
								if (filter) filter->setparam(0,0,ccutoff*cins.cutoff);
								break;
							};
						};
						cs.count = cenv.points[cs.envp+1].x-cs.pos;
						if (cs.count<inc){
							inc = cs.count;
						};
						l = (int)module->beatstosamples(cs.count);
						switch (x){
						case 0:
							cvol = cenv.points[cs.envp+1].y;
							break;
						case 1:
							cpanx = cenv.points[cs.envp+1].y;
							break;
						case 3:
							ccutoff = cenv.points[cs.envp+1].y;
							break;
						};
						cs.envp++;
					}
					else{ // At the end -> check for loop / sustain
//						cs.process = true;
						if (((cenv.flags & EF_LOOP)==0) && (((cenv.flags & EF_SUSTAIN)==0) || (flags & MTIIF_NOTEOFF))){
							if (x==0){
								if (osc[0]->volume<VOLUME_THRESOLD) inc = -1.0;
								else{
									if ((iflags & MTIF_FAE) && ((flags & MTIIF_FADEOUT)==0)){
										if (ai->recording) ai->debugpoint(module->beatstosamples(module->playstatus.pos),"FO");
										flags |= MTIIF_FADEOUT;
										fadepos = cpos;
									};
								};
							};
							cs.wait = true;
							cs.count = 1000.0;
							l = -1;
						}
						else{
							lp = cs.envp;
							if ((cenv.flags & EF_SUSTAIN) && ((flags & MTIIF_NOTEOFF)==0) && (cenv.suste<cenv.loope)){
								cs.envp = cenv.susts;
								cs.pos = cs.pos-cenv.points[cenv.suste].x+cenv.points[cenv.susts].x;
							}
							else if (cenv.flags & EF_LOOP){
								cs.envp = cenv.loops;
								cs.pos = cs.pos-cenv.points[cenv.loope].x+cenv.points[cenv.loops].x;
							};
							if (lp!=cs.envp){
								l = FAST_RAMP;
								cs.count = module->samplestobeats(l);
								if (cs.count<inc) inc = cs.count;
								switch (x){
								case 0:
									cvol = cenv.points[cs.envp].y;
									break;
								case 1:
									cpanx = cenv.points[cs.envp].y;
									break;
								case 3:
									ccutoff = cenv.points[cs.envp].y;
									break;
								};
								cs.wait = false;
							}
							else{
								cs.wait = true;
								cs.count = 1000.0;
								l = -1;
							};
						};
					};
				}
				else{
					l = (int)module->beatstosamples(cs.count);
					if (cs.count<inc) inc = cs.count;
				};
				if (l>=0){
					switch (x){
					case 0:
						tvol = cvol*mvol;
						osc[0]->setvolume(gvol*tvol,l,0);
						break;
					case 1:
						tpanx = pan_mul(mpanx,cpanx);
						osc[0]->setpanning(pan_mul(gpanx,tpanx),pan_mul(gpany,tpany),pan_mul(gpanz,tpanz),l,0);
						break;
					case 3:
						if (filter) filter->setparam(0,0,(int)(ccutoff*cins.cutoff),l);
						break;
					};
				};
			};
			if ((x==0) && (flags & MTIIF_FADEOUT)){
				if (inc<=0.0) continue;
/*
				if (cfadeout==0.0){
					inc = -1.0;
					continue;
				};
				cvol = getvolume(0.0,false)*(1.0+fadeout*(cpos-fadepos+inc));
				cfadeout = cvol;
				if (cvol<0.0){
					cvol = 0.0;
					inc = -(cpos-fadepos+1.0/fadeout);
				};
				l = (int)module->beatstosamples(inc);
				tvol = cvol*mvol;
				osc[0]->setvolume(gvol*tvol,l,0);
*/
				if (fadepos==0.0){
					fadepos = cpos;
				};
				cvol = getvolume(inc);
				if (cvol<0.0){
					cvol = 0.0;
					inc = -(cpos-fadepos+1.0/fadeout);
				};
				l = (int)module->beatstosamples(inc);
				tvol = cvol*mvol;
				osc[0]->setvolume(gvol*tvol,l,0);
			};
		};
	};
// Filter
	if ((filter) && (((cins.env[3].flags & EF_ENABLED)==0) || (cins.env[3].npoints==0))){
		double bpt = 1/(double)cins.tpb;
		if ((cins.attack==0) && (cpos>=(double)cins.attack*bpt)){
			if ((inc==0) || (inc>bpt)) inc = bpt;
//			if ((inc==0) || (inc>bpt*0.5)) inc = bpt*0.5;
			l = (int)module->beatstosamples(inc);
			double c = sqrt(1.0f/((1.0f+(float)cins.decay*0.5f)*(1+(cpos+inc)*cins.tpb-cins.attack)));
			c = acos(1-c)/f2pi;
			filter->setparam(0,0,(float)cins.cutoff*c,l);
		};
	};
	if (inc>0.0){
		nextevent += inc;
		for (x=0;x<8;x++){
			IEnvelope &cenv = ((MTInstrument*)parent)->env[x];
			EnvStatus &cs = envs[x];
			cs.process = cs.wait;
		};
/*
		for (x=0;x<8;x++){
			IEnvelope &cenv = ((MTInstrument*)parent)->env[x];
			EnvStatus &cs = envs[x];
			if ((cenv.npoints) && (!cs.wait) && (cs.process)){
				cs.pos += inc;
			};
		};
*/
	}
	else{
		flags |= IIF_SLEEPING;
//		nextevent = -1.0;
	};
}
Пример #7
0
/*
 * struct fs32_chdir_parms {
 *     unsigned short      iCurDirEnd;
 *     PTR16               pDir;
 *     PTR16               pcdfsd;
 *     PTR16               pcdfsi;
 *     unsigned short      flag;
 * };
 */
int FS32ENTRY fs32_chdir(struct fs32_chdir_parms *parms)
{
    char *pDir;
    struct cdfsi32 *pcdfsi;
    union cdfsd32 *pcdfsd;
    int rc;
    struct file *p_file;
    struct super_block *sb;
    int valid;
    char *tmp;
    struct inode *base;

    switch (parms->flag)
    {
        case CD_EXPLICIT:
            pcdfsi = VDHQueryLin(parms->pcdfsi);
            pcdfsd = VDHQueryLin(parms->pcdfsd);
            pDir = VDHQueryLin(parms->pDir);

            if (trace_FS_CHDIR)
            {
                kernel_printf("FS_CHDIR( CD_EXPLICIT, %s )", pDir);
            }

            rc = ERROR_INVALID_PARAMETER;
            if (parms->iCurDirEnd != CURDIREND_INVALID)
            {
                tmp = pDir + parms->iCurDirEnd;
                if ((pcdfsd->u.p_file) && (pcdfsd->u.p_file->f_magic == FILE_MAGIC))
                {
                    base = pcdfsd->u.p_file->f_inode;
                    if (base)
                    {
                        rc = NO_ERROR;
                    }
                }
            }
            else
            {
                sb = getvolume(pcdfsi->cdi_hVPB);
                if ((sb) && (sb->s_magic_internal == SUPER_MAGIC))
                {
                    tmp = skip_drive(pDir);
                    base = sb->s_mounted;
                    if (base)
                    {
                        rc = NO_ERROR;
                    }
                }
            }

            if (rc == NO_ERROR)
            {
                if ((p_file = open_by_name(base, tmp, OPENMODE_READONLY)) == 0)
                {
                    rc = ERROR_PATH_NOT_FOUND;
                }
                else
                {
                    if (!S_ISDIR(p_file->f_inode->i_mode))
                    {
                        kernel_printf("FS_CHDIR( %s ) Not a directory", pDir);
                        vfs_close(p_file);
                        rc = ERROR_ACCESS_DENIED;
                    }
                    else
                    {
                        pcdfsd->u.is_valid = 1;
                        pcdfsd->u.p_file = p_file;
                        rc = NO_ERROR;
                    }
                }
            }
            break;

        case CD_VERIFY:
            pcdfsi = VDHQueryLin(parms->pcdfsi);
            pcdfsd = VDHQueryLin(parms->pcdfsd);

            if (trace_FS_CHDIR)
            {
                kernel_printf("FS_CHDIR : flag = CD_VERIFY hVPB=0x%04X", pcdfsi->cdi_hVPB);
            }

            //
            // Gets the superblock from pcdfsi
            //
            sb = getvolume(pcdfsi->cdi_hVPB);
            valid = 1;
            if ((p_file = open_by_name(sb->s_mounted, skip_drive(pcdfsi->cdi_curdir), OPENMODE_READONLY)) == 0)
            {
                valid = 0;
            }
            else
            {
                if (!S_ISDIR(p_file->f_inode->i_mode))
                {
                    vfs_close(p_file);
                    valid = 0;
                }

                if (pcdfsi->cdi_flags & CDI_ISVALID)
                {
                    vfs_close(pcdfsd->u.p_file);
                }
                if (valid)
                {
                    pcdfsd->u.is_valid = 1;
                    pcdfsd->u.p_file = p_file;
                    return NO_ERROR;
                }
                else
                {
                    vfs_close(p_file);
                    return ERROR_PATH_NOT_FOUND;
                }
            }
            break;

        case CD_FREE:
            pcdfsd = VDHQueryLin(parms->pcdfsd);

            if (trace_FS_CHDIR)
            {
                kernel_printf("FS_CHDIR( CD_FREE )");
            }


            if (pcdfsd->u.is_valid == 1)
            {
                pcdfsd->u.is_valid = 0;
                if ((rc = vfs_close(pcdfsd->u.p_file)) != NO_ERROR)
                {
                    fs_err(FUNC_FS_CHDIR, FUNC_CLOSE, rc, THISFILE, __LINE__);
                }
//                return rc;
            }
            else
            {
                rc = NO_ERROR;
            }
            break;

        default:
            fs_log("FS_CHDIR : invalid flag");
            rc = ERROR_INVALID_PARAMETER;

    }

    return rc;
}
Пример #8
0
int main(void) {
	char *status;
	if((status = malloc(STATUS_LENGTH*sizeof(char))) == NULL){
		printf("Cannot allocate memory for status");
		return 0;
	}

	char *datetime = NULL;
	char state_bat[12];
	int bat1, energy_full; // bat2;

	int rem_hours = 0, rem_min = 0, rem_sec = 0;
	long rem_usec = 0;

	char *net_intf, *ip = NULL;

	if((net_intf = malloc(5*sizeof(char))) == NULL){
		printf("Cannot allocate memory for net_intf");
		return 0;
	}

	if((ip = malloc(100*sizeof(char))) == NULL){
		printf("Cannot allocate memory for ip");
		return 0;
	}

	char net_displ[50];

	long left_volume;
	long right_volume;

	int mem_used;
	int mem_available;

	float cpu_avg_freq;

	long usec1, usec2 = 0;
	struct timeval time1, time2;

	int connected = 0;

	int energy1, energy2, dummy = 0;

	int count = 0;

	char *mpc_vol, *mpc_state, *mpc_song = NULL;

	if((mpc_vol = malloc(3*sizeof(char))) == NULL){
		printf("Cannot allocate memory for mpc_vol");
		return 0;
	}

	if((mpc_state = malloc(5*sizeof(char))) == NULL){
		printf("Cannot allocate memory for mpc_state");
		return 0;
	}

	if((mpc_song = malloc(100*sizeof(char))) == NULL){
		printf("Cannot allocate memory for mpc_song");
		return 0;
	}

	if (!(dpy = XOpenDisplay(NULL))) {
		fprintf(stderr, "Cannot open display.\n");
		return 0;
	}

	strcpy(state_bat, "unknown");

	for (;;sleep(1)) {

		bat1 = getbattery(&dummy, &energy_full);

		connected = net(&net_intf, &ip);

		datetime = getdatetime();
		getvolume(&left_volume, &right_volume);

		getmemoryusage(&mem_available, &mem_used);
		getcpuusage(&cpu_avg_freq);

		if (connected == 1) sprintf(net_displ, "%s: %s", net_intf, ip);
		else sprintf(net_displ, "not connected");

		//mpc_stat(&mpc_vol, &mpc_state, &mpc_song);

		if (count == 0) {
			usec1 = time_usec(&time1);
			getbattery(&energy1, &energy_full);
			count++;
		} else if (count >= 5) {

			count = 0;

			usec2 = time_usec(&time2);
			getbattery(&energy2, &energy_full);

			if ((energy2 - energy1) < 0){
				rem_usec = ((float)(usec2-usec1))*(((float)(energy1+energy2))/((float)(2*(energy1-energy2))));
				strcpy(state_bat, "discharging");
			} else if ((energy2 - energy1) > 0) {
				rem_usec = (((float)(usec2-usec1))*((float)energy_full)/((float)(energy2-energy1)))*(1-(((float)(energy2+energy1))/((float)(2*energy_full))));
				strcpy(state_bat, "charging");
			} else if ( (energy2 == energy1) && bat1 >= 100) {
				rem_usec = 0;
				strcpy(state_bat, "charged");
			} else {
				rem_usec = 0;
				strcpy(state_bat, "unknown");
			}

			rem_hours = (int)(rem_usec/(1e6*60*60));
			rem_min = (int)((rem_usec/(1e6*60)) - rem_hours*60);
			rem_sec = (int)((rem_usec/(1e6)) - rem_hours*60*60 - rem_min*60);


			if ((bat1 < 15) && (strcmp(state_bat, "discharging") == 0)) {
				system("mplayer /home/andrea/.local/statusbar/sound/siren.mp3");
			}

		} else {
			count++;
		}

//		snprintf(status, STATUS_LENGTH,  "MPC: status: %s - song: %s | %s | volume left %i - right %i | Battery %d%% (%s %d h %d min %d s) | %s", mpc_state, mpc_song, net_displ, (int)left_volume, (int)right_volume, bat1, state_bat, rem_hours, rem_min, rem_sec, datetime);
		snprintf(status, STATUS_LENGTH,  "CPU (avg) %4.3f MHz | RAM used %d%% available %d%% | %s | volume left %i - right %i | Battery %d%% (%s %d h %d min %d s) | %s", cpu_avg_freq, mem_used, mem_available, net_displ, (int)left_volume, (int)right_volume, bat1, state_bat, rem_hours, rem_min, rem_sec, datetime);

		setstatus(status);
	}

	free(mpc_song);
	free(mpc_state);
	free(mpc_vol);
	free(net_intf);
	free(ip);
	free(datetime);
	free(status);
	XCloseDisplay(dpy);

	return 0;
}
Пример #9
0
/*
 * struct fs32_opencreate_parms {
 *     PTR16          pfgenflag;
 *     PTR16          pEABuf;
 *     unsigned short attr;
 *     PTR16          pAction;
 *     unsigned short openflag;
 *     unsigned long  openmode;
 *     PTR16          psffsd;
 *     PTR16          psffsi;
 *     unsigned short iCurDirEnd;
 *     PTR16          pName;
 *     PTR16          pcdfsd;
 *     PTR16          pcdfsi;
 * };
 */
int FS32ENTRY fs32_opencreate(struct fs32_opencreate_parms *parms)
{
    char *pName;
    struct cdfsi32 *pcdfsi;
    union cdfsd32 *pcdfsd;
    struct sffsi32 *psffsi;
    union sffsd32 *psffsd;
    unsigned short *pAction;
    int rc;
    struct super_block *sb;
    struct file *p_file, *dir;
    UINT32 openmode, DOSmode;
    UINT32 accessmode;
    UINT16 newflag, existflag;
    char component[CCHMAXPATH];
    char parent[CCHMAXPATH];
    struct inode *inode;
    struct inode *inode_parent;
    struct inode *base;
    char *tmp;
    ino_t ino_no;

    psffsi = VDHQueryLin(parms->psffsi);
    psffsd = VDHQueryLin(parms->psffsd);
    if (parms->pcdfsi.seg)
        pcdfsi = VDHQueryLin(parms->pcdfsi);
    else
        pcdfsi = 0;
    if (parms->pcdfsd.seg)
        pcdfsd = VDHQueryLin(parms->pcdfsd);
    else
        pcdfsd = 0;
    pName = VDHQueryLin(parms->pName);
    pAction = VDHQueryLin(parms->pAction);

    if (trace_FS_OPENCREATE)
    {
        kernel_printf("FS_OPENCREATE(%s)", pName);
    }


#ifdef FS_TRACE
    if (parms->ulOpenMode & OPEN_FLAGS_DASD)
    {
        fs_log("OPEN_FLAGS_DASD");
    }


    if (parms->ulOpenMode & OPEN_FLAGS_WRITE_THROUGH)
    {
        fs_log("OPEN_FLAGS_WRITE_THROUGH");
    }
    if (parms->ulOpenMode & OPEN_FLAGS_FAIL_ON_ERROR)
    {
        fs_log("OPEN_FLAGS_FAIL_ON_ERROR");
    }
    if (parms->ulOpenMode & OPEN_FLAGS_NO_CACHE)
    {
        fs_log("OPEN_FLAGS_NO_CACHE");
    }
    if (parms->ulOpenMode & OPEN_FLAGS_NOINHERIT)
    {
        fs_log("OPEN_FLAGS_NO_INHERIT");
    }
#endif
    accessmode = parms->ulOpenMode & OPEN_ACCESS_MASK;

    if (accessmode == OPEN_ACCESS_READONLY)
    {
#ifdef FS_TRACE
        fs_log("OPEN_ACCESS_READONLY");
#endif
        openmode = OPENMODE_READONLY;
    }

    if (accessmode == OPEN_ACCESS_WRITEONLY)
    {
#ifdef FS_TRACE
        fs_log("OPEN_ACCESS_WRITEONLY");
#endif
        openmode = OPENMODE_WRITEONLY;
    }

    if (accessmode == OPEN_ACCESS_READWRITE)
    {
#ifdef FS_TRACE
        fs_log("OPEN_ACCESS_READWRITE");
#endif
        openmode = OPENMODE_READWRITE;
    }

#ifdef FS_TRACE
    if (accessmode == OPEN_ACCESS_EXECUTE)
    {
        fs_log("OPEN_ACCESS_EXECUTE");
    }
#endif

    newflag = parms->openflag & OPEN_ACTION_NEW_MASK;

#ifdef FS_TRACE
    if (newflag == OPEN_ACTION_FAIL_IF_NEW)
    {
        fs_log("OPEN_ACTION_FAIL_IF_NEW");
    }
    if (newflag == OPEN_ACTION_CREATE_IF_NEW)
    {
        fs_log("OPEN_ACTION_CREATE_IF_NEW");
    }
#endif

    existflag = parms->openflag & OPEN_ACTION_EXIST_MASK;

#ifdef FS_TRACE
    if (existflag == OPEN_ACTION_OPEN_IF_EXISTS)
    {
        fs_log("OPEN_ACTION_OPEN_IF_EXISTS");
    }
    if (existflag == OPEN_ACTION_FAIL_IF_EXISTS)
    {
        fs_log("OPEN_ACTION_FAIL_IF_EXISTS");
    }
    if (existflag == OPEN_ACTION_REPLACE_IF_EXISTS)
    {
        fs_log("OPEN_ACTION_REPLACE_IF_EXISTS");
    }
#endif

    if ((!Read_Write) &&
        ((accessmode == OPEN_ACCESS_READWRITE) ||
         (accessmode == OPEN_ACCESS_WRITEONLY)))
    {
        fs_log("FS_OPENCREATE() - Write access not enabled");
        return ERROR_WRITE_PROTECT;
    }

    //
    // Direct access open of the whole device
    //
    if (parms->ulOpenMode & OPEN_FLAGS_DASD)
    {
        sb = getvolume(psffsi->sfi_hVPB);
        kernel_printf("OPEN_FLAGS_DASD");
        if ((p_file = _open_by_inode(sb, INODE_DASD, openmode)) == 0)
        {
            kernel_printf("FS_OPENCREATE() - couldn't DASD open %s", pName);
            return ERROR_OPEN_FAILED;
        }
        psffsd->f = p_file;
        psffsi->sfi_tstamp = ST_SCREAT | ST_PCREAT;
        psffsi->sfi_size = p_file->f_inode->i_size;
        psffsi->sfi_position = p_file->f_pos;
        date_unix2dos(p_file->f_inode->i_ctime, &(psffsi->sfi_ctime), &(psffsi->sfi_cdate));
        date_unix2dos(p_file->f_inode->i_atime, &(psffsi->sfi_atime), &(psffsi->sfi_adate));
        date_unix2dos(p_file->f_inode->i_mtime, &(psffsi->sfi_mtime), &(psffsi->sfi_mdate));
        return NO_ERROR;

    }

    //
    // Now that we treated the OPEN_FLAGS_DASD special case, lets treat the general case :
    // Try to open the file readonly
    // Success : the file exists
    //     if !S_ISDIR && !S_ISREG => error
    //     if OPEN_ACTION_FAIL_IF_EXISTS set => error
    //     if OPEN_ACTION_OPEN_IF_EXISTS set
    //         <test file attrs>
    //         change the open mode and return OK
    //     if OPEN_ACTION_REPLACE_IF_EXISTS set
    //         OPEN_ACCESS_READONLY or OPEN_ACCESS_EXECUTE set => error
    //         OPEN_ACCESS_READWRITE or OPEN_ACCESS_WRITEONLY set
    //             truncate
    //             change openmode and return
    // Failure : the file does not exist
    //     OPEN_ACCESS_READONLY or OPEN_ACCESS_EXECUTE set => error
    //     OPEN_ACCESS_READWRITE or OPEN_ACCESS_WRITEONLY set
    //         if OPEN_ACTION_CREATE_IF_NEW set
    //             try to create the file
    //             open the file and return
    //         if OPEN_ACTION_FAIL_IF_NEW   set => error
    rc = ERROR_INVALID_PARAMETER;
    if (parms->iCurDirEnd != CURDIREND_INVALID)
    {
        tmp = pName + parms->iCurDirEnd;
        if ((pcdfsd->u.p_file) && (pcdfsd->u.p_file->f_magic == FILE_MAGIC))
        {
            base = pcdfsd->u.p_file->f_inode;
            if (base)
            {
                sb = base->i_sb;
                rc = NO_ERROR;
            }
        }
    }
    else
    {
        sb = getvolume(psffsi->sfi_hVPB);
        if ((sb) && (sb->s_magic_internal == SUPER_MAGIC))
        {
            tmp = skip_drive(pName);
            base = sb->s_mounted;
            if (base)
            {
                rc = NO_ERROR;
            }
        }
    }

    if (rc != NO_ERROR)
    {
        return rc;
    }

    p_file = open_by_name(base, tmp, openmode);
    if (p_file)
    {                           // The file exists
        //
        // If it's not a regular file or a directory we cannot open
        //

        if (!S_ISREG(p_file->f_inode->i_mode))
        {
//            kernel_printf("Can't FS_OPENCREATE - %s is not a regular file", pName);
            if ((rc = vfs_close(p_file)) != NO_ERROR)
            {
                fs_err(FUNC_FS_OPENCREATE, FUNC_CLOSE, rc, FILE_TEST_C, __LINE__);
                return rc;
            }
            return ERROR_ACCESS_DENIED;
        }
        //
        // if OPEN_ACTION_FAIL_IF_EXISTS set => error
        //
        if (existflag == OPEN_ACTION_FAIL_IF_EXISTS)
        {
#ifdef FS_TRACE
            fs_log("Can't FS_OPENCREATE() - File exists & OPEN_ACTION_FAIL_IF_EXISTS");
#endif
            if ((rc = vfs_close(p_file)) != NO_ERROR)
            {
                fs_err(FUNC_FS_OPENCREATE, FUNC_CLOSE, rc, FILE_TEST_C, __LINE__);
                return rc;
            }
            return ERROR_FILE_EXISTS;
        }

        //
        // if OPEN_ACTION_OPEN_IF_EXISTS : OK
        //
        if (existflag == OPEN_ACTION_OPEN_IF_EXISTS)
        {
            *pAction = FILE_EXISTED;
        }

        //
        // if OPEN_ACTION_REPLACE_IF_EXISTS : truncate
        //
        if (existflag == OPEN_ACTION_REPLACE_IF_EXISTS)
        {
            p_file->f_inode->i_size = psffsi->sfi_size;
            p_file->f_inode->i_op->truncate(p_file->f_inode);
            p_file->f_inode->i_dirt = 1;
            p_file->f_flags = O_TRUNC;
            *pAction = FILE_TRUNCATED;
#if 0
            psffsi->sfi_tstamp = ST_PWRITE | ST_SWRITE;
#else
            /*
             * Time stamping is done by inode routines - Only propagate value.
             */
            psffsi->sfi_tstamp = ST_PWRITE;
#endif

        }
    }
    else
    {                           // The file doesn't exist

        ExtractPath(pName, __StackToFlat(parent));
        ExtractName(pName, __StackToFlat(component));
        //
        // We try to open the parent dir
        //
        if ((dir = open_by_name(sb->s_mounted, Skip_drive(__StackToFlat(parent)), OPENMODE_READONLY)) == 0)
        {
//            kernel_printf("FS_OPENCREATE() - The parent directory %s doesn't seem to exist", parent);
            return ERROR_PATH_NOT_FOUND;
        }

        //
        // The parent dir exists
        //

        //
        // If the file is open for execution : error (it doesn't even exist)
        //
        if (accessmode == OPEN_ACCESS_EXECUTE)
        {
#ifdef FS_TRACE
            fs_log("Can't FS_OPENCREATE() - File doesn't exist & OPEN_ACCESS_EXECUTE");
#endif
            if ((rc = vfs_close(dir)) != NO_ERROR)
            {
                fs_err(FUNC_FS_OPENCREATE, FUNC_CLOSE, rc, FILE_TEST_C, __LINE__);
                return rc;
            }
            return ERROR_FILE_NOT_FOUND;
        }

        //
        // If the file is open for writing or readwrite ...
        //
        if ((accessmode == OPEN_ACCESS_READONLY) ||
            (accessmode == OPEN_ACCESS_READWRITE) ||
            (accessmode == OPEN_ACCESS_WRITEONLY))
        {
            if (newflag == OPEN_ACTION_FAIL_IF_NEW)
            {
#ifdef FS_TRACE
                fs_log("Can't FS_OPENCREATE() - File doesn't exist &  OPEN_ACTION_FAIL_IF_NEW");
#endif
                if ((rc = vfs_close(dir)) != NO_ERROR)
                {
                    fs_err(FUNC_FS_OPENCREATE, FUNC_CLOSE, rc, FILE_TEST_C, __LINE__);
                    return rc;
                }
                return ERROR_OPEN_FAILED;
            }

            if (newflag == OPEN_ACTION_CREATE_IF_NEW)
            {
//                ino_no = dir->f_inode->i_ino;
                inode_parent = dir->f_inode;
                inode_parent->i_count++;
                if ((rc = vfs_close(dir)) != NO_ERROR)
                {
                    fs_err(FUNC_FS_OPENCREATE, FUNC_CLOSE, rc, THISFILE, __LINE__);
                    return rc;
                }
//                inode_parent = iget(sb, ino_no);
                inode_parent->i_count++;
                down(&inode_parent->i_sem);
                rc = inode_parent->i_op->create(inode_parent, __StackToFlat(component), strlen(component), S_IRWXU | S_IFREG, __StackToFlat(&inode));
                up(&inode_parent->i_sem);
                if (rc)
                {
                    kernel_printf("Couldn't create %s", pName);
                    iput(inode_parent);
                    return rc;
                }
                ino_no = inode->i_ino;
                iput(inode_parent);
                iput(inode);
                if ((p_file = _open_by_inode(sb, ino_no, openmode)) == 0)
                {
                    kernel_printf("open_by_inode(%lu) failed in FS_OPENCREATE", ino_no);
                    return ERROR_OPEN_FAILED;
                }
                p_file->f_inode->i_size = psffsi->sfi_size;
                p_file->f_inode->i_dirt = 1;
                p_file->f_flags = O_CREAT;
                *pAction = FILE_CREATED;
#if 0
                psffsi->sfi_tstamp = ST_SCREAT | ST_PCREAT | ST_PWRITE | ST_SWRITE;
#else
                /*
                 * Time stamping is done by inode routines - Only propagate value.
                 */
                psffsi->sfi_tstamp = ST_PCREAT | ST_PWRITE;
#endif

            }

        }

    }





    psffsd->f = p_file;
    /*
     * Time stamping is done by inode routines - Only propagate value.
     */
#if 0
    psffsi->sfi_tstamp |= ST_PREAD | ST_SREAD;
#else
    /*
     * Time stamping is done by inode routines - Only propagate value.
     */
    psffsi->sfi_tstamp |= ST_PREAD;
#endif
    psffsi->sfi_size = p_file->f_inode->i_size;
    psffsi->sfi_position = p_file->f_pos;

//    kernel_printf("date = %u/%u/%u", (pCommon->dateCreate) & 31, (pCommon->dateCreate >> 5) & 15 , (pCommon->dateCreate) >> 9);

    date_unix2dos(p_file->f_inode->i_ctime, &(psffsi->sfi_ctime), &(psffsi->sfi_cdate));
    date_unix2dos(p_file->f_inode->i_atime, &(psffsi->sfi_atime), &(psffsi->sfi_adate));
    date_unix2dos(p_file->f_inode->i_mtime, &(psffsi->sfi_mtime), &(psffsi->sfi_mdate));

    psffsi->sfi_DOSattr = (unsigned char)Linux_To_DOS_Attrs(p_file->f_inode, __StackToFlat(component));
    if (write_through_support)
    {
        if ((parms->ulOpenMode & OPEN_FLAGS_WRITE_THROUGH) ||
            (parms->ulOpenMode & OPEN_FLAGS_NO_CACHE))
        {
            p_file->f_flags |= O_SYNC;
            p_file->f_inode->i_flags |= MS_SYNCHRONOUS;
        }
    }
    return NO_ERROR;

}