/** * ReadLink event triggered by FUSE. * * @param pid PID of the triggering process. * @param iotime IO time of the operation. * @param path Path indicating target file. */ public void readlink(int pid, int iotime, String path) { checkProgramTree(Integer.toString(pid)); path = sanitizePath(path); // Create the file artifact and populate the annotations with file information. long now = System.currentTimeMillis(); File linkFile = createLinkVertex(path); putVertex(linkFile); Used edge = new Used((Program) localCache.get(Integer.toString(pid)), linkFile); edge.addAnnotation("endtime", Long.toString(now)); edge.addAnnotation("operation", "readlink"); putEdge(edge); // If the given path represents a link, then perform the same operation on the // artifact to which the link points. if (links.containsKey(path)) { read(pid, iotime, links.get(path), 0); } }
/** * Read event triggered by FUSE. * * @param pid PID of the triggering process. * @param iotime IO time of the operation. * @param path Path indicating target file. * @param link An integer used to indicate whether the target was a link or not. */ public void read(int pid, int iotime, String path, int link) { checkProgramTree(Integer.toString(pid)); path = sanitizePath(path); long now = System.currentTimeMillis(); // Create file artifact depending on whether this is a link or not. // Link artifacts are created differently to avoid recursion that may // cause FUSE to crash. File fileVertex = (link == 1) ? createLinkVertex(path) : createFileVertex(path); putVertex(fileVertex); Used edge = new Used((Program) localCache.get(Integer.toString(pid)), fileVertex); edge.addAnnotation("iotime", Integer.toString(iotime)); edge.addAnnotation("endtime", Long.toString(now)); putEdge(edge); // If the given path represents a link, then perform the same operation on the // artifact to which the link points. if (link == 1 && links.containsKey(path)) { read(pid, iotime, links.get(path), 0); } }
/** * Rename event triggered by FUSE. * * @param pid PID of the triggering process. * @param iotime IO time of the operation. * @param pathfrom The source path. * @param pathto The destination path. * @param link An integer used to indicate whether the target was a link or not. * @param done An intiger used to indicate whether this event was triggered before or after the * rename operation. */ public void rename(int pid, int iotime, String pathfrom, String pathto, int link, int done) { checkProgramTree(Integer.toString(pid)); pathfrom = sanitizePath(pathfrom); pathto = sanitizePath(pathto); long now = System.currentTimeMillis(); // 'done' is used to indicate whether this is a pre-rename or a post-rename // call. In pre-rename, a Used edge is created from the process to the old // file. In post-rename, a WasGeneratedBy edge is created from the process // to the new file and a WasDerivedEdge created between the two file // artifacts. if (done == 0) { // Create file artifact depending on whether this is a link or not. // Link artifacts are created differently to avoid recursion that may // cause FUSE to crash. File fileVertex = (link == 1) ? createLinkVertex(pathfrom) : createFileVertex(pathfrom); putVertex(fileVertex); // Put the file artifact in the localCache to be removed on post-rename. localCache.put(pathfrom, fileVertex); Used edge = new Used((Program) localCache.get(Integer.toString(pid)), fileVertex); edge.addAnnotation("endtime", Long.toString(now)); putEdge(edge); } else { // Create file artifact depending on whether this is a link or not. // Link artifacts are created differently to avoid recursion that may // cause FUSE to crash. File fileVertex = (link == 1 ? createLinkVertex(pathto) : createFileVertex(pathto)); putVertex(fileVertex); WasGeneratedBy writeEdge = new WasGeneratedBy(fileVertex, (Program) localCache.get(Integer.toString(pid))); writeEdge.addAnnotation("endtime", Long.toString(now)); putEdge(writeEdge); WasDerivedFrom renameEdge = new WasDerivedFrom(fileVertex, (File) localCache.remove(pathfrom)); renameEdge.addAnnotation("iotime", Integer.toString(iotime)); renameEdge.addAnnotation("endtime", Long.toString(now)); renameEdge.addAnnotation("operation", "rename"); putEdge(renameEdge); if (links.containsKey(pathfrom)) { // If the rename is on a link then update the link name. String linkedLocation = links.get(pathfrom); links.remove(pathfrom); links.put(pathto, linkedLocation); } } }