int doclri(File *f) { Iobuf *p, *p1; Dentry *d, *d1; int err; err = 0; p = 0; p1 = 0; if(f->fs->dev->type == Devro) { err = Eronly; goto out; } /* * check on parent directory of file to be deleted */ if(f->wpath == 0 || f->wpath->addr == f->addr) { err = Ephase; goto out; } p1 = getbuf(f->fs->dev, f->wpath->addr, Brd); d1 = getdir(p1, f->wpath->slot); if(!d1 || checktag(p1, Tdir, QPNONE) || !(d1->mode & DALLOC)) { err = Ephase; goto out; } accessdir(p1, d1, FWRITE, 0); putbuf(p1); p1 = 0; /* * check on file to be deleted */ p = getbuf(f->fs->dev, f->addr, Brd); d = getdir(p, f->slot); /* * do it */ memset(d, 0, sizeof(Dentry)); settag(p, Tdir, QPNONE); freewp(f->wpath); freefp(f); out: if(p1) putbuf(p1); if(p) putbuf(p); return err; }
void f_clunk(Chan *cp, Oldfcall *in, Oldfcall *ou) { File *f; Tlock *t; int32_t tim; if(CHAT(cp)) { print("c_clunk %d\n", cp->chan); print(" fid = %d\n", in->fid); } f = filep(cp, in->fid, 0); if(!f) { print("%p\n", f); ou->err = Efid; goto out; } if(t = f->tlock) { tim = time(0); if(t->time < tim || t->file != f) ou->err = Ebroken; t->time = 0; /* free the lock */ f->tlock = 0; } if(f->open & FREMOV) ou->err = doremove(f, 0); f->open = 0; freewp(f->wpath); freefp(f); out: if(f) qunlock(f); ou->fid = in->fid; }
void f_attach(Chan *cp, Oldfcall *in, Oldfcall *ou) { Iobuf *p; Dentry *d; File *f; int u; Filsys *fs; int32_t raddr; if(CHAT(cp)) { print("c_attach %d\n", cp->chan); print(" fid = %d\n", in->fid); print(" uid = %s\n", in->uname); print(" arg = %s\n", in->aname); } ou->qid = QID9P1(0,0); ou->fid = in->fid; if(!in->aname[0]) /* default */ strncpy(in->aname, filesys[0].name, sizeof(in->aname)); p = 0; f = filep(cp, in->fid, 1); if(!f) { ou->err = Efid; goto out; } u = -1; if(cp != cons.chan){ if(authorize(cp, in, ou) == 0 || strcmp(in->uname, "adm") == 0){ ou->err = Eauth; goto out; } u = strtouid(in->uname); if(u < 0){ ou->err = Ebadu; goto out; } } fs = fsstr(in->aname); if(fs == 0) { ou->err = Ebadspc; goto out; } raddr = getraddr(fs->dev); p = getbuf(fs->dev, raddr, Bread); d = getdir(p, 0); if(!d || checktag(p, Tdir, QPROOT) || !(d->mode & DALLOC)) { ou->err = Ealloc; goto out; } f->uid = u; if(iaccess(f, d, DREAD)) { ou->err = Eaccess; goto out; } accessdir(p, d, FREAD); mkqid(&f->qid, d, 1); f->fs = fs; f->addr = raddr; f->slot = 0; f->open = 0; freewp(f->wpath); f->wpath = 0; mkqid9p1(&ou->qid, &f->qid); out: if(p) putbuf(p); if(f) { qunlock(f); if(ou->err) freefp(f); } }
void convolve_frequency(struct convolveparams *p) { double *tmp; size_t dsize[2]; struct timeval t1; gal_data_t *data=NULL; struct fftonthreadparams *fp; /* Make the padded arrays. */ if(!p->cp.quiet) gettimeofday(&t1, NULL); frequency_make_padded_complex(p); if(!p->cp.quiet) gal_timing_report(&t1, "Input and Kernel images padded.", 1); if(p->checkfreqsteps) { /* Prepare the data structure for viewing the steps, note that we don't need the array that is initially made. */ dsize[0]=p->ps0; dsize[1]=p->ps1; data=gal_data_alloc(NULL, GAL_TYPE_FLOAT64, 2, dsize, NULL, 0, p->cp.minmapsize, NULL, NULL, NULL); free(data->array); /* Save the padded input image. */ complextoreal(p->pimg, p->ps0*p->ps1, COMPLEX_TO_REAL_REAL, &tmp); data->array=tmp; data->name="input padded"; gal_fits_img_write(data, p->freqstepsname, NULL, PROGRAM_NAME); free(tmp); data->name=NULL; /* Save the padded kernel image. */ complextoreal(p->pker, p->ps0*p->ps1, COMPLEX_TO_REAL_REAL, &tmp); data->array=tmp; data->name="kernel padded"; gal_fits_img_write(data, p->freqstepsname, NULL, PROGRAM_NAME); free(tmp); data->name=NULL; } /* Initialize the structures: */ fftinitializer(p, &fp); /* Forward 2D FFT on each image. */ if(!p->cp.quiet) gettimeofday(&t1, NULL); twodimensionfft(p, fp, 1); if(!p->cp.quiet) gal_timing_report(&t1, "Images converted to frequency domain.", 1); if(p->checkfreqsteps) { complextoreal(p->pimg, p->ps0*p->ps1, COMPLEX_TO_REAL_SPEC, &tmp); data->array=tmp; data->name="input transformed"; gal_fits_img_write(data, p->freqstepsname, NULL, PROGRAM_NAME); free(tmp); data->name=NULL; complextoreal(p->pker, p->ps0*p->ps1, COMPLEX_TO_REAL_SPEC, &tmp); data->array=tmp; data->name="kernel transformed"; gal_fits_img_write(data, p->freqstepsname, NULL, PROGRAM_NAME); free(tmp); data->name=NULL; } /* Multiply or divide the two arrays and save them in the output.*/ if(!p->cp.quiet) gettimeofday(&t1, NULL); if(p->makekernel) { complexarraydivide(p->pimg, p->pker, p->ps0*p->ps1, p->minsharpspec); if(!p->cp.quiet) gal_timing_report(&t1, "Divided in the frequency domain.", 1); } else { complexarraymultiply(p->pimg, p->pker, p->ps0*p->ps1); if(!p->cp.quiet) gal_timing_report(&t1, "Multiplied in the frequency domain.", 1); } if(p->checkfreqsteps) { complextoreal(p->pimg, p->ps0*p->ps1, COMPLEX_TO_REAL_SPEC, &tmp); data->array=tmp; data->name=p->makekernel ? "Divided" : "Multiplied"; gal_fits_img_write(data, p->freqstepsname, NULL, PROGRAM_NAME); free(tmp); data->name=NULL; } /* Forward (in practice inverse) 2D FFT on each image. */ if(!p->cp.quiet) gettimeofday(&t1, NULL); twodimensionfft(p, fp, -1); if(p->makekernel) correctdeconvolve(p, &p->rpad); else complextoreal(p->pimg, p->ps0*p->ps1, COMPLEX_TO_REAL_REAL, &p->rpad); if(!p->cp.quiet) gal_timing_report(&t1, "Converted back to the spatial domain.", 1); if(p->checkfreqsteps) { data->array=p->rpad; data->name="padded output"; gal_fits_img_write(data, p->freqstepsname, NULL, PROGRAM_NAME); data->name=NULL; data->array=NULL; } /* Free the padded arrays (they are no longer needed) and put the converted array (that is real, not complex) in p->pimg. */ gal_data_free(data); free(p->pimg); free(p->pker); /* Crop out the center, numbers smaller than 10^{-17} are errors, remove them. */ if(!p->cp.quiet) gettimeofday(&t1, NULL); removepaddingcorrectroundoff(p); if(!p->cp.quiet) gal_timing_report(&t1, "Padded parts removed.", 1); /* Free all the allocated space. */ freefp(fp); }