Disk image tools
Posted: Fri, 22.11.2013 00:03:56
Утилита для создания RAW образов дисков
Для работы утилиты нужен .NET Framework 2.0 (входит в состав дотнетов 3.0 3.5)
Для скриптинга используется язык сценариев Lua, расширенный через LuaInterface до возможности работы с дотнетом
В глобальную область видимости добавленные несколько функций для работы с дотнетом
командная строка
scriptFile - имя файла с скриптом lua
imgFile - имя файла образа
Для создания образа необходимо написать скрипт на Lua, в глобальную область видимости добавлены следующие функции
Функции предоставляемые контекстом ImageFile
глобальная функция get_extfs и ImageFile:Open возвращают контекст файловой системы DiskFileSystem, предоставляют одинаковые функции
Описание функций контекста файловой системы
Для работы утилиты нужен .NET Framework 2.0 (входит в состав дотнетов 3.0 3.5)
Для скриптинга используется язык сценариев Lua, расширенный через LuaInterface до возможности работы с дотнетом
В глобальную область видимости добавленные несколько функций для работы с дотнетом
import "Namespace" - импорт дотнетовского пространства имен, по умолчанию всегда импортируются System, System.IO, System.Collection
each(IEnumerable) - посредник между дотнетовскими коллекциями и Lua, нужен для обхода циклом массивов и коллекций возвращаемых расширением Lua
командная строка
ImgTool scriptFile imgFile
scriptFile - имя файла с скриптом lua
imgFile - имя файла образа
Для создания образа необходимо написать скрипт на Lua, в глобальную область видимости добавлены следующие функции
img_exists() - возвращает true если образ существует
img_drop() - удаляет файл образа
img_create(int size) - создает пустой не форматированный файл образа, size - размер образа в mb, размер должен быть не менее 5мб
img_open() - открывает образ
get_extfs() - возвращает контекст нативной файловой системы
copy(inStream, outStream) - копирует полностью входящий поток в исходящий
img_create, img_open возвращают контекст образа ImageFile
Функции предоставляемые контекстом ImageFile
:Open() - открывает файл образа и возвращает контекст файловой системы первого раздела, открыть можно только форматированный раздел
:Format(string label) - форматирует диск образа, если размер образа больше 512мб, файловая система будет FAT32, label - метка тома, создается MBR и один раздел на весь диск
глобальная функция get_extfs и ImageFile:Open возвращают контекст файловой системы DiskFileSystem, предоставляют одинаковые функции
Описание функций контекста файловой системы
- Code: Select all
// Скопировать файл в пределах файловой системы, параметр overwrite не обязательный, по умолчанию false
:CopyFile(string sourceFile, string destinationFile[, bool overwrite]);
// Создать каталог
:CreateDirectory(string path);
// Удалить каталог, параметр recursive не обязательный, по умолчанию false
:DeleteDirectory(string path[, bool recursive]);
// Удалить файл
:DeleteFile(string path);
// Проверить существование каталога, возвращает true если существует
bool DirectoryExists(string path);
// Проверить существование файла, возвращает true если существует
bool FileExists(string path);
// Проверить существование файла или каталога, true если существует
bool Exists(string path);
// Вернуть список каталогов по заданному пути, возвращает массив строк с именами каталогов
// необязательный параметр searchPattern задает маску для списка каталогов
// необязательный параметр searchOption задает параметры поиска каталогов
string[] GetDirectories(string path [[, string searchPattern], SearchOption searchOption] );
// Вернуть список файлов по заданному пути, возвращает массив строк с именами файлов
// необязательный параметр searchPattern задает маску для списка файлов
// необязательный параметр searchOption задает параметры поиска файлов
string[] GetFiles(string path [[, string searchPattern],SearchOption searchOption] );
// Вернуть список файлов и подкаталогов для заданного пути, возвращает массив строк с именами каталогов и файлов
// Необязательный параметр searchPattern задает маску для списка
string[] GetFileSystemEntries(string path [, string searchPattern] );
// Переместить каталог
:MoveDirectory(string sourceDirectoryName, string destinationDirectoryName);
// Переместить файл
// необязательный параметр overwrite указывает необходимость перезаписи файла, по умолчанию false
:MoveFile(string sourceName, string destinationName [, bool overwrite] );
// Открыть файл
// параметр FileMode задает режим открытия (FileMode.Open, FileMode.Create, FileMode.CreateNew, FileMode.Append)
// необязательный параметр access задает режим доступа к файлу
SparseStream OpenFile(string path, FileMode mode [, FileAccess access] )
/// <summary>
/// Gets the attributes of a file or directory.
/// </summary>
/// <param name="path">The file or directory to inspect</param>
/// <returns>The attributes of the file or directory</returns>
FileAttributes GetAttributes(string path);
/// <summary>
/// Sets the attributes of a file or directory.
/// </summary>
/// <param name="path">The file or directory to change</param>
/// <param name="newValue">The new attributes of the file or directory</param>
void SetAttributes(string path, FileAttributes newValue);
/// <summary>
/// Gets the creation time (in local time) of a file or directory.
/// </summary>
/// <param name="path">The path of the file or directory</param>
/// <returns>The creation time.</returns>
DateTime GetCreationTime(string path);
/// <summary>
/// Sets the creation time (in local time) of a file or directory.
/// </summary>
/// <param name="path">The path of the file or directory.</param>
/// <param name="newTime">The new time to set.</param>
void SetCreationTime(string path, DateTime newTime);
/// <summary>
/// Gets the creation time (in UTC) of a file or directory.
/// </summary>
/// <param name="path">The path of the file or directory.</param>
/// <returns>The creation time.</returns>
DateTime GetCreationTimeUtc(string path);
/// <summary>
/// Sets the creation time (in UTC) of a file or directory.
/// </summary>
/// <param name="path">The path of the file or directory.</param>
/// <param name="newTime">The new time to set.</param>
void SetCreationTimeUtc(string path, DateTime newTime);
/// <summary>
/// Gets the last access time (in local time) of a file or directory.
/// </summary>
/// <param name="path">The path of the file or directory</param>
/// <returns>The last access time</returns>
DateTime GetLastAccessTime(string path);
/// <summary>
/// Sets the last access time (in local time) of a file or directory.
/// </summary>
/// <param name="path">The path of the file or directory.</param>
/// <param name="newTime">The new time to set.</param>
void SetLastAccessTime(string path, DateTime newTime);
/// <summary>
/// Gets the last access time (in UTC) of a file or directory.
/// </summary>
/// <param name="path">The path of the file or directory</param>
/// <returns>The last access time</returns>
DateTime GetLastAccessTimeUtc(string path);
/// <summary>
/// Sets the last access time (in UTC) of a file or directory.
/// </summary>
/// <param name="path">The path of the file or directory.</param>
/// <param name="newTime">The new time to set.</param>
void SetLastAccessTimeUtc(string path, DateTime newTime);
/// <summary>
/// Gets the last modification time (in local time) of a file or directory.
/// </summary>
/// <param name="path">The path of the file or directory</param>
/// <returns>The last write time</returns>
DateTime GetLastWriteTime(string path);
/// <summary>
/// Sets the last modification time (in local time) of a file or directory.
/// </summary>
/// <param name="path">The path of the file or directory.</param>
/// <param name="newTime">The new time to set.</param>
void SetLastWriteTime(string path, DateTime newTime);
/// <summary>
/// Gets the last modification time (in UTC) of a file or directory.
/// </summary>
/// <param name="path">The path of the file or directory</param>
/// <returns>The last write time</returns>
DateTime GetLastWriteTimeUtc(string path);
/// <summary>
/// Sets the last modification time (in UTC) of a file or directory.
/// </summary>
/// <param name="path">The path of the file or directory.</param>
/// <param name="newTime">The new time to set.</param>
void SetLastWriteTimeUtc(string path, DateTime newTime);
/// <summary>
/// Gets the length of a file.
/// </summary>
/// <param name="path">The path to the file</param>
/// <returns>The length in bytes</returns>
long GetFileLength(string path);
/// <summary>
/// Gets an object representing a possible file.
/// </summary>
/// <param name="path">The file path</param>
/// <returns>The representing object</returns>
/// <remarks>The file does not need to exist</remarks>
DiscFileInfo GetFileInfo(string path);
/// <summary>
/// Gets an object representing a possible directory.
/// </summary>
/// <param name="path">The directory path</param>
/// <returns>The representing object</returns>
/// <remarks>The directory does not need to exist</remarks>
DiscDirectoryInfo GetDirectoryInfo(string path);
/// <summary>
/// Gets an object representing a possible file system object (file or directory).
/// </summary>
/// <param name="path">The file system path</param>
/// <returns>The representing object</returns>
/// <remarks>The file system object does not need to exist</remarks>
DiscFileSystemInfo GetFileSystemInfo(string path);