Summary
Add a sync shell command that flushes dirty filesystem buffers to disk. With no arguments, flushes all mounted filesystems. With an optional path argument, flushes only the filesystem mounted at that path.
Motivation
With write-back caching (7baa16d), data written to disk may sit in the drive's volatile cache until unmount or power loss. There is currently no user-facing way to force a flush. A sync command fills this gap — standard on all Unix-like systems.
Implementation
Command class
package org.jnode.fs.command;
public class SyncCommand extends AbstractCommand {
private final FileArgument argPath =
new FileArgument("path", Argument.OPTIONAL,
"flush only the filesystem mounted at this path");
public SyncCommand() {
super("Flush filesystem buffers to disk");
registerArguments(argPath);
}
public static void main(String[] args) throws Exception {
new SyncCommand().execute(args);
}
@Override
public void execute() throws Exception {
FileSystemService fss = InitialNaming.lookup(FileSystemService.NAME);
PrintWriter out = getOutput().getPrintWriter();
PrintWriter err = getError().getPrintWriter();
if (argPath.isSet()) {
// Find which filesystem is mounted at or under this path
String path = argPath.getValue().getCanonicalPath();
FileSystem<?> target = null;
String mountPoint = null;
for (Map.Entry<String, FileSystem<?>> e : fss.getMountPoints().entrySet()) {
if (path.equals(e.getKey()) || path.startsWith(e.getKey() + File.separator)) {
target = e.getValue();
mountPoint = e.getKey();
}
}
if (target == null) {
err.println("No filesystem mounted at " + path);
exit(1);
}
target.flush();
out.println("synced " + mountPoint);
} else {
int errors = 0;
for (Map.Entry<String, FileSystem<?>> e : fss.getMountPoints().entrySet()) {
try {
e.getValue().flush();
out.println("synced " + e.getKey());
} catch (IOException ex) {
err.println("sync failed on " + e.getKey() + ": " + ex.getMessage());
errors++;
}
}
if (errors > 0) exit(1);
}
}
}
Plugin XML
Add to fs/descriptors/org.jnode.fs.command.xml (existing file):
<extension point="org.jnode.shell.aliases">
<alias name="sync" class="org.jnode.fs.command.SyncCommand"/>
</extension>
<extension point="org.jnode.shell.syntaxes">
<syntax alias="sync">
<empty description="Flush all mounted filesystems to disk"/>
<sequence description="Flush the filesystem at a specific path">
<argument argLabel="path"/>
</sequence>
</syntax>
</extension>
Files to create/modify
- Create:
fs/src/commands/org/jnode/fs/command/SyncCommand.java
- Modify:
fs/descriptors/org.jnode.fs.command.xml — add alias and syntax entries
Testing / Validation
Test 1: Sync all mounted filesystems
- Boot JNode, mount a FAT filesystem:
mount /dev/ide0-auto /mnt
- Write a file:
echo test > /mnt/test.txt
- Run
sync
- Expected output:
synced /mnt
- Kill VM without save, reboot — file should be intact
Test 2: Sync specific path
- Mount FAT at
/mnt
- Write a file
- Run
sync /mnt
- Expected:
synced /mnt
- Verify only that filesystem was flushed (check serial log for FLUSH CACHE)
Test 3: Sync non-mounted path
- Run
sync /nonexistent
- Expected: error message
No filesystem mounted at /nonexistent, exit code 1
Test 4: Multiple mount points
- Mount two filesystems:
mount /dev/ide0-auto /mnt1 and mount /dev/ide1-auto /mnt2
- Run
sync
- Expected:
synced /mnt1 and synced /mnt2
- Verify both FLUSH CACHE commands in serial log
Test 5: Read-only filesystem
- Mount a read-only filesystem (e.g., ISO9660)
- Run
sync
- Expected:
synced /cdrom (flush is no-op for read-only, no error)
Test 6: No filesystems mounted
- Boot with no mounts
- Run
sync
- Expected: no output, clean exit (empty loop)
Acceptance Criteria
Summary
Add a
syncshell command that flushes dirty filesystem buffers to disk. With no arguments, flushes all mounted filesystems. With an optional path argument, flushes only the filesystem mounted at that path.Motivation
With write-back caching (7baa16d), data written to disk may sit in the drive's volatile cache until unmount or power loss. There is currently no user-facing way to force a flush. A
synccommand fills this gap — standard on all Unix-like systems.Implementation
Command class
Plugin XML
Add to
fs/descriptors/org.jnode.fs.command.xml(existing file):Files to create/modify
fs/src/commands/org/jnode/fs/command/SyncCommand.javafs/descriptors/org.jnode.fs.command.xml— add alias and syntax entriesTesting / Validation
Test 1: Sync all mounted filesystems
mount /dev/ide0-auto /mntecho test > /mnt/test.txtsyncsynced /mntTest 2: Sync specific path
/mntsync /mntsynced /mntTest 3: Sync non-mounted path
sync /nonexistentNo filesystem mounted at /nonexistent, exit code 1Test 4: Multiple mount points
mount /dev/ide0-auto /mnt1andmount /dev/ide1-auto /mnt2syncsynced /mnt1andsynced /mnt2Test 5: Read-only filesystem
syncsynced /cdrom(flush is no-op for read-only, no error)Test 6: No filesystems mounted
syncAcceptance Criteria
syncwith no args flushes all mounted filesystemssync /pathflushes only the filesystem at that path