Skip to content

Commit

Permalink
Add other filesystem entries: sock, fifo, block, char
Browse files Browse the repository at this point in the history
  • Loading branch information
teplofizik committed Sep 14, 2022
1 parent 4419f45 commit 6078819
Show file tree
Hide file tree
Showing 8 changed files with 377 additions and 3 deletions.
93 changes: 93 additions & 0 deletions NyaFs/Processor/Scripting/Commands/Fs/Block.cs
Original file line number Diff line number Diff line change
@@ -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!");
}
}
}
}
}
93 changes: 93 additions & 0 deletions NyaFs/Processor/Scripting/Commands/Fs/Char.cs
Original file line number Diff line number Diff line change
@@ -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!");
}
}
}
}
}
4 changes: 2 additions & 2 deletions NyaFs/Processor/Scripting/Commands/Fs/Dir.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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!");
Expand All @@ -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!");
}
Expand Down
82 changes: 82 additions & 0 deletions NyaFs/Processor/Scripting/Commands/Fs/Fifo.cs
Original file line number Diff line number Diff line change
@@ -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!");
}
}
}
}
}
2 changes: 1 addition & 1 deletion NyaFs/Processor/Scripting/Commands/Fs/File.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand Down
82 changes: 82 additions & 0 deletions NyaFs/Processor/Scripting/Commands/Fs/Sock.cs
Original file line number Diff line number Diff line change
@@ -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!");
}
}
}
}
}
4 changes: 4 additions & 0 deletions NyaFs/Processor/Scripting/ScriptBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Loading

0 comments on commit 6078819

Please sign in to comment.