From 60788196aaec85d42b033dc6d5d56a0c68592de8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=BE=D0=BD=D1=8C=D0=BA=D0=B8=D0=BD=20=D0=90=D0=BB?= =?UTF-8?q?=D0=B5=D0=BA=D1=81=D0=B5=D0=B9?= Date: Wed, 14 Sep 2022 12:52:09 +0300 Subject: [PATCH] Add other filesystem entries: sock, fifo, block, char --- .../Processor/Scripting/Commands/Fs/Block.cs | 93 +++++++++++++++++++ NyaFs/Processor/Scripting/Commands/Fs/Char.cs | 93 +++++++++++++++++++ NyaFs/Processor/Scripting/Commands/Fs/Dir.cs | 4 +- NyaFs/Processor/Scripting/Commands/Fs/Fifo.cs | 82 ++++++++++++++++ NyaFs/Processor/Scripting/Commands/Fs/File.cs | 2 +- NyaFs/Processor/Scripting/Commands/Fs/Sock.cs | 82 ++++++++++++++++ NyaFs/Processor/Scripting/ScriptBase.cs | 4 + readme.md | 20 ++++ 8 files changed, 377 insertions(+), 3 deletions(-) create mode 100644 NyaFs/Processor/Scripting/Commands/Fs/Block.cs create mode 100644 NyaFs/Processor/Scripting/Commands/Fs/Char.cs create mode 100644 NyaFs/Processor/Scripting/Commands/Fs/Fifo.cs create mode 100644 NyaFs/Processor/Scripting/Commands/Fs/Sock.cs diff --git a/NyaFs/Processor/Scripting/Commands/Fs/Block.cs b/NyaFs/Processor/Scripting/Commands/Fs/Block.cs new file mode 100644 index 0000000..c5a8212 --- /dev/null +++ b/NyaFs/Processor/Scripting/Commands/Fs/Block.cs @@ -0,0 +1,93 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace NyaFs.Processor.Scripting.Commands.Fs +{ + public class Block : ScriptStepGenerator + { + public Block() : base("block") + { + AddConfig(new ScriptArgsConfig(1, new ScriptArgsParam[] { + new Params.FsPathScriptArgsParam(), + new Params.NumberScriptArgsParam("major"), + new Params.NumberScriptArgsParam("minor"), + new Params.ModeScriptArgsParam(), + new Params.NumberScriptArgsParam("user"), + new Params.NumberScriptArgsParam("group") + })); + } + + public override ScriptStep Get(ScriptArgs Args) + { + var A = Args.RawArgs; + + return new BlockScriptStep(A[0], Convert.ToUInt32(A[1]), Convert.ToUInt32(A[2]), Utils.ConvertMode(A[3]), Convert.ToUInt32(A[4]), Convert.ToUInt32(A[5])); + } + + public class BlockScriptStep : ScriptStep + { + string Path; + uint User; + uint Group; + uint Mode; + uint Major; + uint Minor; + + public BlockScriptStep(string Path, uint Major, uint Minor, uint Mode, uint User, uint Group) : base("block") + { + this.Path = Path; + this.User = User; + this.Group = Group; + this.Mode = Mode; + this.Major = Major; + this.Minor = Minor; + } + + public override ScriptStepResult Exec(ImageProcessor Processor) + { + var Fs = Processor.GetFs(); + // Проверим наличие загруженной файловой системы + if (Fs == null) + return new ScriptStepResult(ScriptStepStatus.Error, "Filesystem is not loaded"); + + if (Fs.Exists(Path)) + { + var Item = Fs.GetElement(Path); + if (Item.ItemType == Filesystem.Universal.Types.FilesystemItemType.Block) + { + var File = Item as Filesystem.Universal.Items.Block; + + File.Mode = Mode; + File.User = User; + File.Group = Group; + + File.Major = Major; + File.Minor = Minor; + + File.Modified = DateTime.Now; + + return new ScriptStepResult(ScriptStepStatus.Ok, $"Block device {Path} updated!"); + } + else + return new ScriptStepResult(ScriptStepStatus.Error, $"{Path} is not Block device!"); + } + else + { + var Parent = Fs.GetParentDirectory(Path); + if (Parent != null) + { + var File = new Filesystem.Universal.Items.Block(Path, User, Group, Mode); + + File.Major = Major; + File.Minor = Minor; + + Parent.Items.Add(File); + return new ScriptStepResult(ScriptStepStatus.Ok, $"Block device {Path} added!"); } + else + return new ScriptStepResult(ScriptStepStatus.Error, $"Parent dir for {Path} is not found!"); + } + } + } + } +} diff --git a/NyaFs/Processor/Scripting/Commands/Fs/Char.cs b/NyaFs/Processor/Scripting/Commands/Fs/Char.cs new file mode 100644 index 0000000..6fb37a0 --- /dev/null +++ b/NyaFs/Processor/Scripting/Commands/Fs/Char.cs @@ -0,0 +1,93 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace NyaFs.Processor.Scripting.Commands.Fs +{ + public class Char : ScriptStepGenerator + { + public Char() : base("char") + { + AddConfig(new ScriptArgsConfig(1, new ScriptArgsParam[] { + new Params.FsPathScriptArgsParam(), + new Params.NumberScriptArgsParam("major"), + new Params.NumberScriptArgsParam("minor"), + new Params.ModeScriptArgsParam(), + new Params.NumberScriptArgsParam("user"), + new Params.NumberScriptArgsParam("group") + })); + } + + public override ScriptStep Get(ScriptArgs Args) + { + var A = Args.RawArgs; + + return new CharScriptStep(A[0], Convert.ToUInt32(A[1]), Convert.ToUInt32(A[2]), Utils.ConvertMode(A[3]), Convert.ToUInt32(A[4]), Convert.ToUInt32(A[5])); + } + + public class CharScriptStep : ScriptStep + { + string Path; + uint User; + uint Group; + uint Mode; + uint Major; + uint Minor; + + public CharScriptStep(string Path, uint Major, uint Minor, uint Mode, uint User, uint Group) : base("char") + { + this.Path = Path; + this.User = User; + this.Group = Group; + this.Mode = Mode; + this.Major = Major; + this.Minor = Minor; + } + + public override ScriptStepResult Exec(ImageProcessor Processor) + { + var Fs = Processor.GetFs(); + // Проверим наличие загруженной файловой системы + if (Fs == null) + return new ScriptStepResult(ScriptStepStatus.Error, "Filesystem is not loaded"); + + if (Fs.Exists(Path)) + { + var Item = Fs.GetElement(Path); + if (Item.ItemType == Filesystem.Universal.Types.FilesystemItemType.Character) + { + var File = Item as Filesystem.Universal.Items.Char; + + File.Mode = Mode; + File.User = User; + File.Group = Group; + + File.Major = Major; + File.Minor = Minor; + + File.Modified = DateTime.Now; + + return new ScriptStepResult(ScriptStepStatus.Ok, $"Char device {Path} updated!"); + } + else + return new ScriptStepResult(ScriptStepStatus.Error, $"{Path} is not Char device!"); + } + else + { + var Parent = Fs.GetParentDirectory(Path); + if (Parent != null) + { + var File = new Filesystem.Universal.Items.Char(Path, User, Group, Mode); + + File.Major = Major; + File.Minor = Minor; + + Parent.Items.Add(File); + return new ScriptStepResult(ScriptStepStatus.Ok, $"Char device {Path} added!"); } + else + return new ScriptStepResult(ScriptStepStatus.Error, $"Parent dir for {Path} is not found!"); + } + } + } + } +} diff --git a/NyaFs/Processor/Scripting/Commands/Fs/Dir.cs b/NyaFs/Processor/Scripting/Commands/Fs/Dir.cs index cf790ee..9ce4c85 100644 --- a/NyaFs/Processor/Scripting/Commands/Fs/Dir.cs +++ b/NyaFs/Processor/Scripting/Commands/Fs/Dir.cs @@ -59,7 +59,7 @@ public override ScriptStepResult Exec(ImageProcessor Processor) File.Modified = DateTime.Now; - return new ScriptStepResult(ScriptStepStatus.Ok, $"{Path} updated!"); + return new ScriptStepResult(ScriptStepStatus.Ok, $"Dir {Path} updated!"); } else return new ScriptStepResult(ScriptStepStatus.Error, $"{Path} is not dir!"); @@ -72,7 +72,7 @@ public override ScriptStepResult Exec(ImageProcessor Processor) var File = new Filesystem.Universal.Items.Dir(Path, User, Group, Mode); Parent.Items.Add(File); - return new ScriptStepResult(ScriptStepStatus.Ok, $"{Path} added!"); } + return new ScriptStepResult(ScriptStepStatus.Ok, $"Dir {Path} added!"); } else return new ScriptStepResult(ScriptStepStatus.Error, $"Parent dir for {Path} is not found!"); } diff --git a/NyaFs/Processor/Scripting/Commands/Fs/Fifo.cs b/NyaFs/Processor/Scripting/Commands/Fs/Fifo.cs new file mode 100644 index 0000000..df0f9ba --- /dev/null +++ b/NyaFs/Processor/Scripting/Commands/Fs/Fifo.cs @@ -0,0 +1,82 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace NyaFs.Processor.Scripting.Commands.Fs +{ + public class Fifo : ScriptStepGenerator + { + public Fifo() : base("fifo") + { + AddConfig(new ScriptArgsConfig(1, new ScriptArgsParam[] { + new Params.FsPathScriptArgsParam(), + new Params.ModeScriptArgsParam(), + new Params.NumberScriptArgsParam("user"), + new Params.NumberScriptArgsParam("group") + })); + } + + public override ScriptStep Get(ScriptArgs Args) + { + var A = Args.RawArgs; + + return new FifoScriptStep(A[0], Utils.ConvertMode(A[1]), Convert.ToUInt32(A[2]), Convert.ToUInt32(A[3])); + + } + + public class FifoScriptStep : ScriptStep + { + string Path = null; + uint User = uint.MaxValue; + uint Group = uint.MaxValue; + uint Mode = uint.MaxValue; + + public FifoScriptStep(string Path, uint Mode, uint User, uint Group) : base("fifo") + { + this.Path = Path; + this.User = User; + this.Group = Group; + this.Mode = Mode; + } + + public override ScriptStepResult Exec(ImageProcessor Processor) + { + var Fs = Processor.GetFs(); + // Проверим наличие загруженной файловой системы + if (Fs == null) + return new ScriptStepResult(ScriptStepStatus.Error, "Filesystem is not loaded"); + + if (Fs.Exists(Path)) + { + var Item = Fs.GetElement(Path); + if (Item.ItemType == Filesystem.Universal.Types.FilesystemItemType.Fifo) + { + var File = Item as Filesystem.Universal.Items.Fifo; + + File.Mode = Mode; + File.User = User; + File.Group = Group; + + File.Modified = DateTime.Now; + + return new ScriptStepResult(ScriptStepStatus.Ok, $"Fifo {Path} updated!"); + } + else + return new ScriptStepResult(ScriptStepStatus.Error, $"{Path} is not Fifo!"); + } + else + { + var Parent = Fs.GetParentDirectory(Path); + if (Parent != null) + { + var File = new Filesystem.Universal.Items.Fifo(Path, User, Group, Mode); + + Parent.Items.Add(File); + return new ScriptStepResult(ScriptStepStatus.Ok, $"Fifo {Path} added!"); } + else + return new ScriptStepResult(ScriptStepStatus.Error, $"Parent dir for {Path} is not found!"); + } + } + } + } +} diff --git a/NyaFs/Processor/Scripting/Commands/Fs/File.cs b/NyaFs/Processor/Scripting/Commands/Fs/File.cs index 4415486..96ab962 100644 --- a/NyaFs/Processor/Scripting/Commands/Fs/File.cs +++ b/NyaFs/Processor/Scripting/Commands/Fs/File.cs @@ -108,7 +108,7 @@ public override ScriptStepResult Exec(ImageProcessor Processor) var File = new Filesystem.Universal.Items.File(Path, User, Group, Mode, Content); Parent.Items.Add(File); - return new ScriptStepResult(ScriptStepStatus.Ok, $"{Path} added!"); + return new ScriptStepResult(ScriptStepStatus.Ok, $"File {Path} added!"); } else return new ScriptStepResult(ScriptStepStatus.Error, $"File {Path} not exists! Cannot update. Specify user, group and mode to add file."); diff --git a/NyaFs/Processor/Scripting/Commands/Fs/Sock.cs b/NyaFs/Processor/Scripting/Commands/Fs/Sock.cs new file mode 100644 index 0000000..4dad7bd --- /dev/null +++ b/NyaFs/Processor/Scripting/Commands/Fs/Sock.cs @@ -0,0 +1,82 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace NyaFs.Processor.Scripting.Commands.Fs +{ + public class Sock : ScriptStepGenerator + { + public Sock() : base("sock") + { + AddConfig(new ScriptArgsConfig(1, new ScriptArgsParam[] { + new Params.FsPathScriptArgsParam(), + new Params.ModeScriptArgsParam(), + new Params.NumberScriptArgsParam("user"), + new Params.NumberScriptArgsParam("group") + })); + } + + public override ScriptStep Get(ScriptArgs Args) + { + var A = Args.RawArgs; + + return new SockScriptStep(A[0], Utils.ConvertMode(A[1]), Convert.ToUInt32(A[2]), Convert.ToUInt32(A[3])); + + } + + public class SockScriptStep : ScriptStep + { + string Path = null; + uint User = uint.MaxValue; + uint Group = uint.MaxValue; + uint Mode = uint.MaxValue; + + public SockScriptStep(string Path, uint Mode, uint User, uint Group) : base("sock") + { + this.Path = Path; + this.User = User; + this.Group = Group; + this.Mode = Mode; + } + + public override ScriptStepResult Exec(ImageProcessor Processor) + { + var Fs = Processor.GetFs(); + // Проверим наличие загруженной файловой системы + if (Fs == null) + return new ScriptStepResult(ScriptStepStatus.Error, "Filesystem is not loaded"); + + if (Fs.Exists(Path)) + { + var Item = Fs.GetElement(Path); + if (Item.ItemType == Filesystem.Universal.Types.FilesystemItemType.Socket) + { + var File = Item as Filesystem.Universal.Items.Socket; + + File.Mode = Mode; + File.User = User; + File.Group = Group; + + File.Modified = DateTime.Now; + + return new ScriptStepResult(ScriptStepStatus.Ok, $"Socket {Path} updated!"); + } + else + return new ScriptStepResult(ScriptStepStatus.Error, $"{Path} is not Socket!"); + } + else + { + var Parent = Fs.GetParentDirectory(Path); + if (Parent != null) + { + var File = new Filesystem.Universal.Items.Socket(Path, User, Group, Mode); + + Parent.Items.Add(File); + return new ScriptStepResult(ScriptStepStatus.Ok, $"Socket {Path} added!"); } + else + return new ScriptStepResult(ScriptStepStatus.Error, $"Parent dir for {Path} is not found!"); + } + } + } + } +} diff --git a/NyaFs/Processor/Scripting/ScriptBase.cs b/NyaFs/Processor/Scripting/ScriptBase.cs index eceea40..dcb9374 100644 --- a/NyaFs/Processor/Scripting/ScriptBase.cs +++ b/NyaFs/Processor/Scripting/ScriptBase.cs @@ -38,6 +38,10 @@ public ScriptBaseAll() Add(new Commands.Fs.Dir()); Add(new Commands.Fs.File()); Add(new Commands.Fs.SLink()); + Add(new Commands.Fs.Block()); + Add(new Commands.Fs.Char()); + Add(new Commands.Fs.Fifo()); + Add(new Commands.Fs.Sock()); Add(new Commands.Fs.Rm()); Add(new Commands.Fs.Chmod()); Add(new Commands.Fs.Chown()); diff --git a/readme.md b/readme.md index 6912812..4cbf31a 100644 --- a/readme.md +++ b/readme.md @@ -277,6 +277,26 @@ Add symlink to : slink ``` +Add char device: +``` +char +``` + +Add block device: +``` +block +``` + +Add socket: +``` +sock +``` + +Add fifo: +``` +fifo +``` + Remove file or dir or etc: ``` rm