/** * Add a new (sub-)directory with a given name to this directory. * * @param name * @throws IOException */ public FSEntry addDirectory(String name) throws IOException { if (getFileSystem().isReadOnly()) { throw new ReadOnlyFileSystemException("addDirectory in readonly filesystem"); } final long parentCluster; if (file == null) { parentCluster = 0; } else { parentCluster = file.getStartCluster(); } return addFatDirectory(name, parentCluster); }
/** * Add a directory entry of the type directory. * * @param nameExt * @param parentCluster * @throws IOException */ protected synchronized FatDirEntry addFatDirectory(String nameExt, long parentCluster) throws IOException { final FatDirEntry entry = addFatFile(nameExt); final int clusterSize = getFatFileSystem().getClusterSize(); entry.setFlags(FatConstants.F_DIRECTORY); final FatFile file = entry.getFatFile(); file.setLength(clusterSize); // TODO optimize it also to use ByteBuffer at lower level // final byte[] buf = new byte[clusterSize]; final ByteBuffer buf = ByteBuffer.allocate(clusterSize); // Clean the contents of this cluster to avoid reading strange data // in the directory. // file.write(0, buf, 0, buf.length); file.write(0, buf); file.getDirectory().initialize(file.getStartCluster(), parentCluster); flush(); return entry; }