static int mtnfs_rename(const char *old_path, const char *new_path) { int r; char d0[PATH_MAX]; char d1[PATH_MAX]; MTN *mtn = MTN_CONTEXT; dirbase(old_path, d0, NULL); dirbase(new_path, d1, NULL); mtnlogger(mtn, 8, "[debug] %s: old_path=%s new_path=%s\n", __func__, old_path, new_path); r = mtn_rename(mtn, old_path, new_path); setstat_dircache(d0, NULL); setstat_dircache(d1, NULL); return(r); }
static int mtnfs_getattr(const char *path, struct stat *stbuf) { MTN *mtn = MTN_CONTEXT; MTNSTAT *krt = NULL; MTNSTAT *kst = NULL; struct timeval tv; char d[PATH_MAX]; char f[PATH_MAX]; mtnlogger(mtn, 8, "[debug] %s: path=%s\n", __func__, path); memset(stbuf, 0, sizeof(struct stat)); if(strcmp(path, "/") == 0) { stbuf->st_mode = S_IFDIR | 0755; stbuf->st_nlink = 2; return(0); } if(is_mtnstatus(path, f)){ if(f[0] == 0){ stbuf->st_mode = S_IFDIR | 0555; stbuf->st_nlink = 2; return(0); } gettimeofday(&tv, NULL); stbuf->st_mode = S_IFREG | 0444; stbuf->st_atime = tv.tv_sec; stbuf->st_mtime = tv.tv_sec; stbuf->st_ctime = tv.tv_sec; if(strcmp(f, "members") == 0) { stbuf->st_size = set_mtnstatus_members(mtn); return(0); } if(strcmp(f, "debuginfo") == 0) { stbuf->st_size = set_mtnstatus_debuginfo(mtn); return(0); } if(strcmp(f, "loglevel") == 0) { stbuf->st_mode = S_IFREG | 0644; stbuf->st_size = set_mtnstatus_loglevel(mtn); return(0); } return(-ENOENT); } dirbase(path, d, f); krt = get_dircache(d, 0); for(kst=krt;kst;kst=kst->next){ if(strcmp(kst->name, f) == 0){ memcpy(stbuf, &(kst->stat), sizeof(struct stat)); break; } } if(!kst){ if((kst = mtn_stat(mtn, path))){ addstat_dircache(d, kst); memcpy(stbuf, &(kst->stat), sizeof(struct stat)); } } clrstat(krt); return(kst ? 0 : -ENOENT); }
static int mtnfs_utimens(const char *path, const struct timespec tv[2]) { int r; char d[PATH_MAX]; MTN *mtn = MTN_CONTEXT; dirbase(path, d, NULL); mtnlogger(mtn, 8, "[debug] %s: path=%s\n", __func__, path); r = mtn_utime(mtn, path, tv[0].tv_sec, tv[1].tv_sec); setstat_dircache(d, NULL); return(r); }
static int mtnfs_chown(const char *path, uid_t uid, gid_t gid) { int r; char d[PATH_MAX]; MTN *mtn = MTN_CONTEXT; dirbase(path, d, NULL); mtnlogger(mtn, 8, "[debug] %s: path=%s uid=%d gid=%d\n", __func__, path, uid, gid); r = mtn_chown(mtn, path, uid, gid); setstat_dircache(d, NULL); return(r); }
static int mtnfs_chmod(const char *path, mode_t mode) { int r; char d[PATH_MAX]; MTN *mtn = MTN_CONTEXT; dirbase(path, d, NULL); mtnlogger(mtn, 8, "[debug] %s: path=%s\n", __func__, path); r = mtn_chmod(mtn, path, mode); setstat_dircache(d, NULL); return(r); }
static int mtnfs_symlink(const char *oldpath, const char *newpath) { int r = 0; char d[PATH_MAX]; MTN *mtn = MTN_CONTEXT; dirbase(newpath, d, NULL); mtnlogger(mtn, 8, "[debug] %s: oldpath=%s newpath=%s\n", __func__, oldpath, newpath); r = mtn_symlink(mtn, oldpath, newpath); setstat_dircache(d, NULL); return(r); }
int mkdir_ex(const char *path) { struct stat st; char d[PATH_MAX]; char f[PATH_MAX]; dirbase(path,d,f); if(stat(path, &st) == 0) { return(0); } if(stat(d, &st) == -1) { if(mkdir_ex(d) == -1) { return(-1); } } return(mkdir(path, 0755)); }
int write_trace (Dbptr db, char *sta, char *chan, char *dir, char *dfile, Trace *trace, double tstart, double tend, int overwrite) { int fd; char outdir[1024]; char outbase[1024]; char fname[1024]; int sz, size, ret; int is, ie, ns; Dbvalue dbv; is = (tstart-trace->tstart)/trace->dt + 0.0001; ie = (tend-trace->tstart)/trace->dt - 0.0001; if (is > trace->nsamps-1) return (1); if (ie < 0) return (1); if (is < 0) is = 0; if (ie > trace->nsamps-1) ie = trace->nsamps-1; ns = ie - is + 1; if (ns < 1) return (1); db = dblookup (db, 0, "wfdisc", 0, 0); if (dir[0] == '/') { sprintf (fname, "%s/%s", dir, dfile); } else { dbquery (db, dbTABLE_DIRNAME, &dbv); strcpy (outbase, dbv.t); sprintf (fname, "%s/%s/%s", outbase, dir, dfile); } if (!overwrite) { if (zaccess(fname, F_OK) != -1) { fprintf (stderr, "write_trace: wf file conflict for '%s'.\n", fname); return (0); } } dirbase (fname, outdir, outbase); if (makedir(outdir) == -1) { fprintf (stderr, "write_trace: Unable to create %s\n", outdir); return (0); } fd = open (fname, (O_RDWR|O_CREAT|O_TRUNC), 0666); if (fd < 0) { fprintf (stderr, "write_trace: Open error on '%s'.\n", fname); return (0); } sz = atoi(&trace->rawdata_format[strlen(trace->rawdata_format)-1]); size = sz*ns; ret = write (fd, &(((char *)trace->raw_data)[is*sz]), size); close (fd); if (ret < size) { fprintf (stderr, "write_trace: Write error on '%s'.\n", fname); return (0); } db.record = dbNULL; db.field = dbALL; dbget(db, 0); db.record = dbSCRATCH; dbputv (db, 0, "sta", sta, "chan", chan, "time", trace->tstart+is*trace->dt, "wfid", dbnextid(db, "wfid"), /* "chanid", chanid,*/ "jdate", yearday(trace->tstart), "endtime", trace->tstart+trace->dt*(trace->nsamps-1), "nsamp", (long)ns, "samprate", 1.0/trace->dt, "calib", trace->calib, "calper", trace->calper, "instype", "BEAM", "segtype", trace->rawdata_type, "datatype", trace->rawdata_format, /* "clip", clip,*/ "dir", dir, "dfile", dfile, "foff", (long)0, NULL); dbadd (db, 0); return (1); }