/** * 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; }
/** * 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); }
/** * Flush all changed structures to the device. * * @throws IOException */ public void flush() throws IOException { final BlockDeviceAPI api = getApi(); if (bs.isDirty()) { bs.write(api); } for (FatFile f : files.values()) { f.flush(); } if (fat.isDirty()) { for (int i = 0; i < bs.getNrFats(); i++) { fat.write(api, FatUtils.getFatOffset(bs, i)); } } if (rootDir.isDirty()) { rootDir.flush(); } }
protected AbstractDirectory(FatFileSystem fs, FatFile myFile) { this(fs, (int) myFile.getLength() / 32, myFile); }