use of org.dcache.chimera.posix.Stat in project dcache by dCache.
the class StorageUriTest method setUp.
@Before
public void setUp() throws Exception {
fs = mock(JdbcFs.class);
root = new RootInode(fs, 0L);
file = new FsInode(fs, 1L);
locations = new ArrayList<>();
stat = new Stat();
stat.setSize(0);
stat.setMode(0);
stat.setGeneration(0);
newFsInodeSURI();
mockFileSystem();
}
use of org.dcache.chimera.posix.Stat in project dcache by dCache.
the class StorageUriTest method write.
private void write(String location, boolean append) throws Exception {
int len = location.length();
byte[] buffer = location.getBytes();
Stat stat = inode_suri.stat();
/*
* Emulate OPEN TRUNCATE for write.
*/
if (!append) {
if (ChimeraVfs.shouldRejectAttributeUpdates(inode_suri, fs)) {
throw new PermissionDeniedChimeraFsException("setStat not allowed.");
}
stat.setSize(0);
inode_suri.setStat(stat);
}
if (ChimeraVfs.shouldRejectUpdates(inode_suri, fs)) {
throw new PermissionDeniedChimeraFsException("write not allowed.");
}
inode_suri.write(stat.getSize(), buffer, 0, len);
addStorageLocation(location);
}
use of org.dcache.chimera.posix.Stat in project dcache by dCache.
the class FsSqlDriver method statTag.
Stat statTag(FsInode dir, String name) throws ChimeraFsException {
Long tagId = getTagId(dir, name);
if (tagId == null) {
throw FileNotFoundChimeraFsException.ofTag(dir, name);
}
try {
return _jdbc.queryForObject("SELECT isize,inlink,imode,iuid,igid,iatime,ictime,imtime " + "FROM t_tags_inodes WHERE itagid=?", (rs, rowNum) -> {
Stat ret = new Stat();
ret.setSize(rs.getLong("isize"));
ret.setATime(rs.getTimestamp("iatime").getTime());
ret.setCTime(rs.getTimestamp("ictime").getTime());
ret.setMTime(rs.getTimestamp("imtime").getTime());
ret.setUid(rs.getInt("iuid"));
ret.setGid(rs.getInt("igid"));
ret.setMode(rs.getInt("imode"));
ret.setNlink(rs.getInt("inlink"));
ret.setIno(tagId);
ret.setGeneration(rs.getTimestamp("imtime").getTime());
ret.setDev(17);
ret.setRdev(13);
return ret;
}, tagId);
} catch (IncorrectResultSizeDataAccessException e) {
throw FileNotFoundChimeraFsException.ofTag(dir, name);
}
}
use of org.dcache.chimera.posix.Stat in project dcache by dCache.
the class FsSqlDriver method newDirectoryStream.
/**
* Returns {@link DirectoryStreamB} of ChimeraDirectoryEntry in the directory.
*
* @param dir
* @return stream of directory entries
*/
DirectoryStreamB<ChimeraDirectoryEntry> newDirectoryStream(FsInode dir) {
return new DirectoryStreamB<ChimeraDirectoryEntry>() {
final DirectoryStreamImpl stream = new DirectoryStreamImpl(dir, _jdbc);
@Override
public Iterator<ChimeraDirectoryEntry> iterator() {
return new Iterator<ChimeraDirectoryEntry>() {
private ChimeraDirectoryEntry current = innerNext();
@Override
public boolean hasNext() {
return current != null;
}
@Override
public ChimeraDirectoryEntry next() {
if (current == null) {
throw new NoSuchElementException("No more entries");
}
ChimeraDirectoryEntry entry = current;
current = innerNext();
return entry;
}
protected ChimeraDirectoryEntry innerNext() {
try {
ResultSet rs = stream.next();
if (rs == null) {
return null;
}
Stat stat = toStat(rs);
FsInode inode = new FsInode(dir.getFs(), rs.getLong("inumber"), FsInodeType.INODE, 0, stat);
inode.setParent(dir);
return new ChimeraDirectoryEntry(rs.getString("iname"), inode, stat);
} catch (SQLException e) {
LOGGER.error("failed to fetch next entry: {}", e.getMessage());
return null;
}
}
};
}
@Override
public void close() throws IOException {
stream.close();
}
};
}
use of org.dcache.chimera.posix.Stat in project dcache by dCache.
the class FsSqlDriver method createLevel.
/**
* creates an entry in t_level_x table
*
* @param inode
* @param uid
* @param gid
* @param mode
* @param level
* @return
*/
FsInode createLevel(FsInode inode, int uid, int gid, int mode, int level) {
Timestamp now = new Timestamp(System.currentTimeMillis());
_jdbc.update("INSERT INTO t_level_" + level + "(inumber,imode,inlink,iuid,igid,isize,ictime,iatime,imtime,ifiledata) VALUES(?,?,1,?,?,0,?,?,?, NULL)", ps -> {
ps.setLong(1, inode.ino());
ps.setInt(2, mode);
ps.setInt(3, uid);
ps.setInt(4, gid);
ps.setTimestamp(5, now);
ps.setTimestamp(6, now);
ps.setTimestamp(7, now);
});
Stat stat = new Stat();
stat.setCrTime(now.getTime());
stat.setGeneration(0);
stat.setSize(0);
stat.setATime(now.getTime());
stat.setCTime(now.getTime());
stat.setMTime(now.getTime());
stat.setUid(uid);
stat.setGid(gid);
stat.setMode(mode | UnixPermission.S_IFREG);
stat.setNlink(1);
stat.setIno(inode.ino());
stat.setDev(17);
stat.setRdev(13);
return new FsInode(inode.getFs(), inode.ino(), FsInodeType.INODE, level, stat);
}
Aggregations