123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253 |
- /*++
- Copyright (c) 2014 Minoca Corp. All Rights Reserved
- Module Name:
- setup.h
- Abstract:
- This header contains definitions for the setup application.
- Author:
- Evan Green 10-Apr-2014
- --*/
- //
- // ------------------------------------------------------------------- Includes
- //
- #define RTL_API __DLLEXPORT
- #include <minoca/lib/minocaos.h>
- #include <minoca/lib/partlib.h>
- #include "chalk.h"
- //
- // ---------------------------------------------------------------- Definitions
- //
- //
- // Define the assumed block size of the install media.
- //
- #define SETUP_BLOCK_SIZE 512
- //
- // Set this flag to enable more printing.
- //
- #define SETUP_FLAG_VERBOSE 0x00000001
- //
- // Set this flag to reboot at the end of the installation.
- //
- #define SETUP_FLAG_REBOOT 0x00000002
- //
- // Set this flag to enable debugging in the new boot configuration.
- //
- #define SETUP_FLAG_INSTALL_DEBUG 0x00000004
- //
- // Set this flag to enable boot debugging in the target.
- //
- #define SETUP_FLAG_INSTALL_BOOT_DEBUG 0x00000008
- //
- // Set this flag to run in automated mode, where setup will try to install to
- // any free partition that is not the current system partition. This flag
- // shouldn't be used by real users, only test automation.
- //
- #define SETUP_FLAG_AUTO_DEPLOY 0x00000010
- //
- // Set this flag to print nothing but errors.
- //
- #define SETUP_FLAG_QUIET 0x00000020
- //
- // Define the name of the source install image.
- //
- #define SETUP_DEFAULT_IMAGE_NAME "./install.img"
- //
- // Define the path of the page file.
- //
- #define SETUP_PAGE_FILE_PATH "pagefile.sys"
- //
- // This flag is set if this is the system disk or partition.
- //
- #define SETUP_DEVICE_FLAG_SYSTEM 0x00000001
- //
- // Define the well known offsets of the boot sector where its LBA and size are
- // stored.
- //
- #define SETUP_BOOT_SECTOR_BLOCK_ADDRESS_OFFSET 0x5C
- #define SETUP_BOOT_SECTOR_BLOCK_LENGTH_OFFSET 0x60
- #define SETUP_SYMLINK_MAX 512
- //
- // Define away some things on Windows.
- //
- #ifdef _WIN32
- #define S_IRGRP 0
- #define S_ISLNK(_Mode) (((_Mode) & S_IFMT) == S_IFLNK)
- #define S_IFLNK 0x0000A000
- #define O_NOFOLLOW 0
- #endif
- //
- // ------------------------------------------------------ Data Type Definitions
- //
- //
- // Define setup recipe IDs, alphabetized by config file name.
- //
- typedef enum _SETUP_RECIPE_ID {
- SetupRecipeNone,
- SetupRecipeBeagleBoneBlack,
- SetupRecipeCommon,
- SetupRecipeGalileo,
- SetupRecipeInstallArmv6,
- SetupRecipeInstallArmv7,
- SetupRecipeInstallX86,
- SetupRecipeIntegratorCpRamDisk,
- SetupRecipePandaBoard,
- SetupRecipePandaBoardUsb,
- SetupRecipePc,
- SetupRecipePcEfi,
- SetupRecipePcTiny,
- SetupRecipeRaspberryPi,
- SetupRecipeRaspberryPi2,
- SetupRecipeVeyron,
- SetupRecipeCount
- } SETUP_RECIPE_ID, *PSETUP_RECIPE_ID;
- typedef enum _SETUP_DESTINATION_TYPE {
- SetupDestinationInvalid,
- SetupDestinationDisk,
- SetupDestinationPartition,
- SetupDestinationDirectory,
- SetupDestinationImage,
- SetupDestinationFile,
- } SETUP_DESTINATION_TYPE, *PSETUP_DESTINATION_TYPE;
- typedef enum _SETUP_VOLUME_FORMAT_CHOICE {
- SetupVolumeFormatInvalid,
- SetupVolumeFormatAlways,
- SetupVolumeFormatNever,
- SetupVolumeFormatIfIncompatible,
- } SETUP_VOLUME_FORMAT_CHOICE, *PSETUP_VOLUME_FORMAT_CHOICE;
- typedef enum _SETUP_SCRIPT_ORDER {
- SetupScriptOrderNow,
- SetupScriptOrderInitialization,
- SetupScriptOrderUserInitialization,
- SetupScriptOrderPlatform,
- SetupScriptOrderUserCustomization
- } SETUP_SCRIPT_ORDER, *PSETUP_SCRIPT_ORDER;
- typedef struct _SETUP_CONFIGURATION SETUP_CONFIGURATION, *PSETUP_CONFIGURATION;
- /*++
- Structure Description:
- This structure defines a destination for setup.
- Members:
- Type - Stores the type of object this destination refers to.
- Path - Stores a pointer to a heap-allocated path to the destination. If
- this is NULL, then the destination is assumed to point to a device ID.
- IsDeviceId - Stores a boolean indicating if the destination is a device ID
- (TRUE) or a path (FALSE).
- DeviceId - Stores the device ID of the destination.
- --*/
- typedef struct _SETUP_DESTINATION {
- SETUP_DESTINATION_TYPE Type;
- PSTR Path;
- ULONGLONG DeviceId;
- } SETUP_DESTINATION, *PSETUP_DESTINATION;
- /*++
- Structure Description:
- This structure describes a partition.
- Members:
- Partition - Stores the partition information.
- Destination - Stores a pointer to the destination needed to open this
- partition.
- Flags - Stores a bitfield of flags about the device. See
- SETUP_DEVICE_FLAG_* definitions.
- --*/
- typedef struct _SETUP_PARTITION_DESCRIPTION {
- PARTITION_DEVICE_INFORMATION Partition;
- PSETUP_DESTINATION Destination;
- ULONG Flags;
- } SETUP_PARTITION_DESCRIPTION, *PSETUP_PARTITION_DESCRIPTION;
- /*++
- Structure Description:
- This structure describes setup's application context.
- Members:
- Flags - Stores a bitfield of flags governing the behavior. See
- SETUP_FLAG_* definitions.
- PartitionContext - Stores a pointer to the partition library context for
- the disk layout.
- CurrentPartitionOffset - Stores the offset in blocks to the partition
- being actively read from and written to.
- CurrentPartitionSize - Stores the size in blocks of the partition being
- actively read from and written to.
- DiskPath - Stores an optional pointer to the disk to install to.
- PartitionPath - Stores an optional pointer to the partition to install to.
- DirectoryPath - Stores an optional pointer to the directory to install to.
- BootPartitionPath - Stores an optional pointer to the boot partition to
- update.
- DiskSize - Stores the override disk size.
- Disk - Stores a pointer to the install disk.
- SourceVolume - Stores a pointer to the install source volume.
- HostFileSystem - Stores an open volume pointer to an empty host path.
- RecipeIndex - Stores the recipe index to follow.
- PageFileSize - Stores the size in megabytes of the page file.
- Interpreter - Stores the interpreter context.
- Configuration - Stores the installation configuration.
- --*/
- typedef struct _SETUP_CONTEXT {
- ULONG Flags;
- PARTITION_CONTEXT PartitionContext;
- LONGLONG CurrentPartitionOffset;
- ULONGLONG CurrentPartitionSize;
- PSETUP_DESTINATION DiskPath;
- PSETUP_DESTINATION PartitionPath;
- PSETUP_DESTINATION DirectoryPath;
- PSETUP_DESTINATION BootPartitionPath;
- ULONGLONG DiskSize;
- PVOID Disk;
- PVOID SourceVolume;
- PVOID HostFileSystem;
- LONG RecipeIndex;
- ULONGLONG PageFileSize;
- CHALK_INTERPRETER Interpreter;
- PSETUP_CONFIGURATION Configuration;
- } SETUP_CONTEXT, *PSETUP_CONTEXT;
- /*++
- Structure Description:
- This structure describes a handle to a volume in the setup app.
- Members:
- Context - Stores a pointer back to tha application context.
- DestinationType - Stores the destination type of the open volume.
- PathPrefix - Stores the path to prefix onto every open file operation.
- BlockHandle - Stores a pointer to the native OS handle to the disk,
- partition, or image.
- VolumeToken - Stores the mounted file system token.
- OpenFiles - Stores the number of files opened against this volume.
- --*/
- typedef struct _SETUP_VOLUME {
- PSETUP_CONTEXT Context;
- SETUP_DESTINATION_TYPE DestinationType;
- PSTR PathPrefix;
- PVOID BlockHandle;
- PVOID VolumeToken;
- ULONG OpenFiles;
- } SETUP_VOLUME, *PSETUP_VOLUME;
- //
- // -------------------------------------------------------------------- Globals
- //
- extern UCHAR SetupZeroDiskIdentifier[DISK_IDENTIFIER_SIZE];
- extern UCHAR SetupZeroPartitionIdentifier[PARTITION_IDENTIFIER_SIZE];
- //
- // -------------------------------------------------------- Function Prototypes
- //
- //
- // OS specific functions
- //
- INT
- SetupOsEnumerateDevices (
- PSETUP_PARTITION_DESCRIPTION *DeviceArray,
- PULONG DeviceCount
- );
- /*++
- Routine Description:
- This routine enumerates all the disks and partitions on the system.
- Arguments:
- DeviceArray - Supplies a pointer where an array of partition structures
- will be returned on success.
- DeviceCount - Supplies a pointer where the number of elements in the
- partition array will be returned on success.
- Return Value:
- 0 on success.
- Returns an error code on failure.
- --*/
- INT
- SetupOsGetPartitionInformation (
- PSETUP_DESTINATION Destination,
- PPARTITION_DEVICE_INFORMATION Information
- );
- /*++
- Routine Description:
- This routine returns the partition information for the given destination.
- Arguments:
- Destination - Supplies a pointer to the partition to query.
- Information - Supplies a pointer where the information will be returned
- on success.
- Return Value:
- 0 on success.
- Returns an error code on failure.
- --*/
- PVOID
- SetupOsOpenBootVolume (
- PSETUP_CONTEXT Context
- );
- /*++
- Routine Description:
- This routine opens the boot volume on the current machine.
- Arguments:
- Context - Supplies a pointer to the application context.
- Return Value:
- Returns the open handle to the boot volume on success.
- NULL on failure.
- --*/
- //
- // OS specific native file interface.
- //
- INT
- SetupOsReadLink (
- PSTR Path,
- PSTR *LinkTarget,
- INT *LinkTargetSize
- );
- /*++
- Routine Description:
- This routine attempts to read a symbolic link.
- Arguments:
- Path - Supplies a pointer to the path to open.
- LinkTarget - Supplies a pointer where an allocated link target will be
- returned on success. The caller is responsible for freeing this memory.
- LinkTargetSize - Supplies a pointer where the size of the link target will
- be returned on success.
- Return Value:
- 0 on success.
- Returns an error number on failure.
- --*/
- INT
- SetupOsSymlink (
- PSTR Path,
- PSTR LinkTarget,
- INT LinkTargetSize
- );
- /*++
- Routine Description:
- This routine creates a symbolic link.
- Arguments:
- Path - Supplies a pointer to the path of the symbolic link to create.
- LinkTarget - Supplies a pointer to the target of the link.
- LinkTargetSize - Supplies a the size of the link target buffer in bytes.
- Return Value:
- Returns the link size on success.
- -1 on failure.
- --*/
- PVOID
- SetupOsOpenDestination (
- PSETUP_DESTINATION Destination,
- INT Flags,
- INT CreatePermissions
- );
- /*++
- Routine Description:
- This routine opens a handle to a given destination.
- Arguments:
- Destination - Supplies a pointer to the destination to open.
- Flags - Supplies open flags. See O_* definitions.
- CreatePermissions - Supplies optional create permissions.
- Return Value:
- Returns a pointer to an opaque context on success.
- NULL on failure.
- --*/
- VOID
- SetupOsClose (
- PVOID Handle
- );
- /*++
- Routine Description:
- This routine closes a handle.
- Arguments:
- Handle - Supplies a pointer to the destination to open.
- Return Value:
- None.
- --*/
- ssize_t
- SetupOsRead (
- PVOID Handle,
- void *Buffer,
- size_t ByteCount
- );
- /*++
- Routine Description:
- This routine reads from an open handle.
- Arguments:
- Handle - Supplies the handle.
- Buffer - Supplies a pointer where the read bytes will be returned.
- ByteCount - Supplies the number of bytes to read.
- Return Value:
- Returns the number of bytes read.
- -1 on failure.
- --*/
- ssize_t
- SetupOsWrite (
- PVOID Handle,
- void *Buffer,
- size_t ByteCount
- );
- /*++
- Routine Description:
- This routine writes data to an open handle.
- Arguments:
- Handle - Supplies the handle.
- Buffer - Supplies a pointer to the bytes to write.
- ByteCount - Supplies the number of bytes to read.
- Return Value:
- Returns the number of bytes written.
- -1 on failure.
- --*/
- LONGLONG
- SetupOsSeek (
- PVOID Handle,
- LONGLONG Offset
- );
- /*++
- Routine Description:
- This routine seeks in the current file or device.
- Arguments:
- Handle - Supplies the handle.
- Offset - Supplies the new offset to set.
- Return Value:
- Returns the resulting file offset after the operation.
- -1 on failure, and errno will contain more information. The file offset
- will remain unchanged.
- --*/
- LONGLONG
- SetupOsTell (
- PVOID Handle
- );
- /*++
- Routine Description:
- This routine returns the current offset in the given file or device.
- Arguments:
- Handle - Supplies the handle.
- Return Value:
- Returns the file offset on success.
- -1 on failure, and errno will contain more information. The file offset
- will remain unchanged.
- --*/
- INT
- SetupOsFstat (
- PVOID Handle,
- PULONGLONG FileSize,
- time_t *ModificationDate,
- mode_t *Mode
- );
- /*++
- Routine Description:
- This routine gets details for the given open file.
- Arguments:
- Handle - Supplies the handle.
- FileSize - Supplies an optional pointer where the file size will be
- returned on success.
- ModificationDate - Supplies an optional pointer where the file's
- modification date will be returned on success.
- Mode - Supplies an optional pointer where the file's mode information will
- be returned on success.
- Return Value:
- 0 on success.
- Non-zero on failure.
- --*/
- INT
- SetupOsFtruncate (
- PVOID Handle,
- ULONGLONG NewSize
- );
- /*++
- Routine Description:
- This routine sets the file size of the given file.
- Arguments:
- Handle - Supplies the handle.
- NewSize - Supplies the new file size.
- Return Value:
- 0 on success.
- Non-zero on failure.
- --*/
- INT
- SetupOsEnumerateDirectory (
- PVOID Handle,
- PSTR DirectoryPath,
- PSTR *Enumeration
- );
- /*++
- Routine Description:
- This routine enumerates the contents of a given directory.
- Arguments:
- Handle - Supplies the open volume handle.
- DirectoryPath - Supplies a pointer to a string containing the path to the
- directory to enumerate.
- Enumeration - Supplies a pointer where a pointer to a sequence of
- strings will be returned containing the files in the directory. The
- sequence will be terminated by an empty string. The caller is
- responsible for freeing this memory when done.
- Return Value:
- 0 on success.
- Non-zero on failure.
- --*/
- INT
- SetupOsCreateDirectory (
- PSTR Path,
- mode_t Permissions
- );
- /*++
- Routine Description:
- This routine creates a new directory.
- Arguments:
- Path - Supplies the path string of the directory to create.
- Permissions - Supplies the permission bits to create the file with.
- Return Value:
- 0 on success.
- Non-zero on failure.
- --*/
- INT
- SetupOsSetAttributes (
- PSTR Path,
- time_t ModificationDate,
- mode_t Permissions
- );
- /*++
- Routine Description:
- This routine sets attributes on a given path.
- Arguments:
- Path - Supplies the path string of the file to modify.
- ModificationDate - Supplies the new modification date to set.
- Permissions - Supplies the new permissions to set.
- Return Value:
- 0 on success.
- Non-zero on failure.
- --*/
- VOID
- SetupOsDetermineExecuteBit (
- PVOID Handle,
- PSTR Path,
- mode_t *Mode
- );
- /*++
- Routine Description:
- This routine determines whether the open file is executable.
- Arguments:
- Handle - Supplies the open file handle.
- Path - Supplies the path the file was opened from (sometimes the file name
- is used as a hint).
- Mode - Supplies a pointer to the current mode bits. This routine may add
- the executable bit to user/group/other if it determines this file is
- executable.
- Return Value:
- None.
- --*/
- INT
- SetupOsReboot (
- VOID
- );
- /*++
- Routine Description:
- This routine reboots the machine.
- Arguments:
- None.
- Return Value:
- 0 on success.
- Non-zero on failure.
- --*/
- INT
- SetupOsGetPlatformName (
- PSTR *Name,
- PSETUP_RECIPE_ID Fallback
- );
- /*++
- Routine Description:
- This routine gets the platform name.
- Arguments:
- Name - Supplies a pointer where a pointer to an allocated string containing
- the SMBIOS system information product name will be returned if
- available. The caller is responsible for freeing this memory when done.
- Fallback - Supplies a fallback platform to use if the given platform
- string was not returned or did not match a known platform.
- Return Value:
- 0 on success.
- Non-zero on failure.
- --*/
- INT
- SetupOsGetSystemMemorySize (
- PULONGLONG Megabytes
- );
- /*++
- Routine Description:
- This routine returns the number of megabytes of memory installed on the
- currently running system.
- Arguments:
- Megabytes - Supplies a pointer to where the system memory capacity in
- megabytes will be returned on success.
- Return Value:
- 0 on success.
- Non-zero on failure.
- --*/
- //
- // Cache wrapper functions for OS layer functionality.
- //
- PVOID
- SetupOpenDestination (
- PSETUP_DESTINATION Destination,
- INT Flags,
- INT CreatePermissions
- );
- /*++
- Routine Description:
- This routine opens a handle to a given destination.
- Arguments:
- Destination - Supplies a pointer to the destination to open.
- Flags - Supplies open flags. See O_* definitions.
- CreatePermissions - Supplies optional create permissions.
- Return Value:
- Returns a pointer to an opaque context on success.
- NULL on failure.
- --*/
- VOID
- SetupClose (
- PVOID Handle
- );
- /*++
- Routine Description:
- This routine closes a handle.
- Arguments:
- Handle - Supplies a pointer to the destination to open.
- Return Value:
- None.
- --*/
- ssize_t
- SetupRead (
- PVOID Handle,
- void *Buffer,
- size_t ByteCount
- );
- /*++
- Routine Description:
- This routine reads from an open handle.
- Arguments:
- Handle - Supplies the handle.
- Buffer - Supplies a pointer where the read bytes will be returned.
- ByteCount - Supplies the number of bytes to read.
- Return Value:
- Returns the number of bytes read.
- -1 on failure.
- --*/
- ssize_t
- SetupWrite (
- PVOID Handle,
- void *Buffer,
- size_t ByteCount
- );
- /*++
- Routine Description:
- This routine writes data to an open handle.
- Arguments:
- Handle - Supplies the handle.
- Buffer - Supplies a pointer to the bytes to write.
- ByteCount - Supplies the number of bytes to read.
- Return Value:
- Returns the number of bytes written.
- -1 on failure.
- --*/
- LONGLONG
- SetupSeek (
- PVOID Handle,
- LONGLONG Offset
- );
- /*++
- Routine Description:
- This routine seeks in the current file or device.
- Arguments:
- Handle - Supplies the handle.
- Offset - Supplies the new offset to set.
- Return Value:
- Returns the resulting file offset after the operation.
- -1 on failure, and errno will contain more information. The file offset
- will remain unchanged.
- --*/
- INT
- SetupFstat (
- PVOID Handle,
- PULONGLONG FileSize,
- time_t *ModificationDate,
- mode_t *Mode
- );
- /*++
- Routine Description:
- This routine gets details for the given open file.
- Arguments:
- Handle - Supplies the handle.
- FileSize - Supplies an optional pointer where the file size will be
- returned on success.
- ModificationDate - Supplies an optional pointer where the file's
- modification date will be returned on success.
- Mode - Supplies an optional pointer where the file's mode information will
- be returned on success.
- Return Value:
- 0 on success.
- Non-zero on failure.
- --*/
- INT
- SetupFtruncate (
- PVOID Handle,
- ULONGLONG NewSize
- );
- /*++
- Routine Description:
- This routine sets the file size of the given file.
- Arguments:
- Handle - Supplies the handle.
- NewSize - Supplies the new file size.
- Return Value:
- 0 on success.
- Non-zero on failure.
- --*/
- INT
- SetupEnumerateDirectory (
- PVOID VolumeHandle,
- PSTR DirectoryPath,
- PSTR *Enumeration
- );
- /*++
- Routine Description:
- This routine enumerates the contents of a given directory.
- Arguments:
- VolumeHandle - Supplies the open volume handle.
- DirectoryPath - Supplies a pointer to a string containing the path to the
- directory to enumerate.
- Enumeration - Supplies a pointer where a pointer to a sequence of
- strings will be returned containing the files in the directory. The
- sequence will be terminated by an empty string. The caller is
- responsible for freeing this memory when done.
- Return Value:
- 0 on success.
- Non-zero on failure.
- --*/
- VOID
- SetupDetermineExecuteBit (
- PVOID Handle,
- PSTR Path,
- mode_t *Mode
- );
- /*++
- Routine Description:
- This routine determines whether the open file is executable.
- Arguments:
- Handle - Supplies the open file handle.
- Path - Supplies the path the file was opened from (sometimes the file name
- is used as a hint).
- Mode - Supplies a pointer to the current mode bits. This routine may add
- the executable bit to user/group/other if it determines this file is
- executable.
- Return Value:
- None.
- --*/
- //
- // File I/O functions
- //
- PVOID
- SetupVolumeOpen (
- PSETUP_CONTEXT Context,
- PSETUP_DESTINATION Destination,
- SETUP_VOLUME_FORMAT_CHOICE Format,
- BOOL CompatibilityMode
- );
- /*++
- Routine Description:
- This routine opens a handle to a given volume.
- Arguments:
- Context - Supplies a pointer to the application context.
- Destination - Supplies a pointer to the destination to open.
- Format - Supplies the disposition for formatting the volume.
- CompatibilityMode - Supplies a boolean indicating whether to run the
- file system in the most compatible way possible.
- Return Value:
- Returns a pointer to an opaque context on success.
- NULL on failure.
- --*/
- VOID
- SetupVolumeClose (
- PSETUP_CONTEXT Context,
- PVOID Handle
- );
- /*++
- Routine Description:
- This routine closes a volume.
- Arguments:
- Context - Supplies a pointer to the application context.
- Handle - Supplies a pointer to the open volume handle.
- Return Value:
- None.
- --*/
- INT
- SetupFileReadLink (
- PVOID Handle,
- PSTR Path,
- PSTR *LinkTarget,
- INT *LinkTargetSize
- );
- /*++
- Routine Description:
- This routine attempts to read a symbolic link.
- Arguments:
- Handle - Supplies the volume handle.
- Path - Supplies a pointer to the path to open.
- LinkTarget - Supplies a pointer where an allocated link target will be
- returned on success. The caller is responsible for freeing this memory.
- LinkTargetSize - Supplies a pointer where the size of the link target will
- be returned on success.
- Return Value:
- Returns the link size on success.
- -1 on failure.
- --*/
- INT
- SetupFileSymlink (
- PVOID Handle,
- PSTR Path,
- PSTR LinkTarget,
- INT LinkTargetSize
- );
- /*++
- Routine Description:
- This routine creates a symbolic link.
- Arguments:
- Handle - Supplies the volume handle.
- Path - Supplies a pointer to the path of the symbolic link to create.
- LinkTarget - Supplies a pointer to the target of the link.
- LinkTargetSize - Supplies a the size of the link target buffer in bytes.
- Return Value:
- Returns the link size on success.
- -1 on failure.
- --*/
- PVOID
- SetupFileOpen (
- PVOID Handle,
- PSTR Path,
- INT Flags,
- INT CreatePermissions
- );
- /*++
- Routine Description:
- This routine opens a handle to a file in a volume.
- Arguments:
- Handle - Supplies the volume handle.
- Path - Supplies a pointer to the path to open.
- Flags - Supplies open flags. See O_* definitions.
- CreatePermissions - Supplies optional create permissions.
- Return Value:
- Returns a pointer to an opaque context on success.
- NULL on failure.
- --*/
- VOID
- SetupFileClose (
- PVOID Handle
- );
- /*++
- Routine Description:
- This routine closes a file.
- Arguments:
- Handle - Supplies the handle to close.
- Return Value:
- None.
- --*/
- ssize_t
- SetupFileRead (
- PVOID Handle,
- void *Buffer,
- size_t ByteCount
- );
- /*++
- Routine Description:
- This routine reads from a file.
- Arguments:
- Handle - Supplies the handle.
- Buffer - Supplies a pointer where the read bytes will be returned.
- ByteCount - Supplies the number of bytes to read.
- Return Value:
- Returns the number of bytes read on success.
- --*/
- ssize_t
- SetupFileWrite (
- PVOID Handle,
- void *Buffer,
- size_t ByteCount
- );
- /*++
- Routine Description:
- This routine writes data to an open file handle.
- Arguments:
- Handle - Supplies the handle.
- Buffer - Supplies a pointer to the bytes to write.
- ByteCount - Supplies the number of bytes to read.
- Return Value:
- Returns the number of bytes written.
- -1 on failure.
- --*/
- LONGLONG
- SetupFileSeek (
- PVOID Handle,
- LONGLONG Offset
- );
- /*++
- Routine Description:
- This routine seeks in the given file.
- Arguments:
- Handle - Supplies the handle.
- Offset - Supplies the new offset to set.
- Return Value:
- Returns the resulting file offset after the operation.
- -1 on failure, and errno will contain more information. The file offset
- will remain unchanged.
- --*/
- INT
- SetupFileFileStat (
- PVOID Handle,
- PULONGLONG FileSize,
- time_t *ModificationDate,
- mode_t *Mode
- );
- /*++
- Routine Description:
- This routine gets details for the given open file.
- Arguments:
- Handle - Supplies the handle.
- FileSize - Supplies an optional pointer where the file size will be
- returned on success.
- ModificationDate - Supplies an optional pointer where the file's
- modification date will be returned on success.
- Mode - Supplies an optional pointer where the file's mode information will
- be returned on success.
- Return Value:
- 0 on success.
- Non-zero on failure.
- --*/
- INT
- SetupFileFileTruncate (
- PVOID Handle,
- ULONGLONG NewSize
- );
- /*++
- Routine Description:
- This routine sets the file size of the given file.
- Arguments:
- Handle - Supplies the handle.
- NewSize - Supplies the new file size.
- Return Value:
- 0 on success.
- Non-zero on failure.
- --*/
- INT
- SetupFileEnumerateDirectory (
- PVOID VolumeHandle,
- PSTR DirectoryPath,
- PSTR *Enumeration
- );
- /*++
- Routine Description:
- This routine enumerates the contents of a given directory.
- Arguments:
- VolumeHandle - Supplies the open volume handle.
- DirectoryPath - Supplies a pointer to a string containing the path to the
- directory to enumerate.
- Enumeration - Supplies a pointer where a pointer to a sequence of
- strings will be returned containing the files in the directory. The
- sequence will be terminated by an empty string. The caller is
- responsible for freeing this memory when done.
- Return Value:
- 0 on success.
- Non-zero on failure.
- --*/
- INT
- SetupFileCreateDirectory (
- PVOID VolumeHandle,
- PSTR Path,
- mode_t Permissions
- );
- /*++
- Routine Description:
- This routine creates a new directory.
- Arguments:
- VolumeHandle - Supplies a pointer to the volume handle.
- Path - Supplies the path string of the directory to create.
- Permissions - Supplies the permission bits to create the file with.
- Return Value:
- 0 on success.
- Non-zero on failure.
- --*/
- INT
- SetupFileSetAttributes (
- PVOID VolumeHandle,
- PSTR Path,
- time_t ModificationDate,
- mode_t Permissions
- );
- /*++
- Routine Description:
- This routine sets attributes on a given path.
- Arguments:
- VolumeHandle - Supplies a pointer to the volume handle.
- Path - Supplies the path string of the file to modify.
- ModificationDate - Supplies the new modification date to set.
- Permissions - Supplies the new permissions to set.
- Return Value:
- 0 on success.
- Non-zero on failure.
- --*/
- VOID
- SetupFileDetermineExecuteBit (
- PVOID Handle,
- PSTR Path,
- mode_t *Mode
- );
- /*++
- Routine Description:
- This routine determines whether the open file is executable.
- Arguments:
- Handle - Supplies the open file handle.
- Path - Supplies the path the file was opened from (sometimes the file name
- is used as a hint).
- Mode - Supplies a pointer to the current mode bits. This routine may add
- the executable bit to user/group/other if it determines this file is
- executable.
- Return Value:
- None.
- --*/
- //
- // Partition I/O functions
- //
- PVOID
- SetupPartitionOpen (
- PSETUP_CONTEXT Context,
- PSETUP_DESTINATION Destination,
- PPARTITION_DEVICE_INFORMATION PartitionInformation
- );
- /*++
- Routine Description:
- This routine opens a handle to a given partition destination.
- Arguments:
- Context - Supplies a pointer to the application context.
- Destination - Supplies a pointer to the destination to open.
- PartitionInformation - Supplies an optional pointer where the partition
- information will be returned on success.
- Return Value:
- Returns a pointer to an opaque context on success.
- NULL on failure.
- --*/
- VOID
- SetupPartitionClose (
- PSETUP_CONTEXT Context,
- PVOID Handle
- );
- /*++
- Routine Description:
- This routine closes a partition.
- Arguments:
- Context - Supplies a pointer to the application context.
- Handle - Supplies the open handle.
- Return Value:
- None.
- --*/
- ssize_t
- SetupPartitionRead (
- PSETUP_CONTEXT Context,
- PVOID Handle,
- void *Buffer,
- size_t ByteCount
- );
- /*++
- Routine Description:
- This routine reads from a partition.
- Arguments:
- Context - Supplies a pointer to the application context.
- Handle - Supplies the handle.
- Buffer - Supplies a pointer where the read bytes will be returned.
- ByteCount - Supplies the number of bytes to read.
- Return Value:
- Returns the number of bytes read on success.
- --*/
- ssize_t
- SetupPartitionWrite (
- PSETUP_CONTEXT Context,
- PVOID Handle,
- void *Buffer,
- size_t ByteCount
- );
- /*++
- Routine Description:
- This routine writes to a partition.
- Arguments:
- Context - Supplies a pointer to the application context.
- Handle - Supplies the handle.
- Buffer - Supplies a pointer to the data to write.
- ByteCount - Supplies the number of bytes to read.
- Return Value:
- Returns the number of bytes written.
- --*/
- LONGLONG
- SetupPartitionSeek (
- PSETUP_CONTEXT Context,
- PVOID Handle,
- LONGLONG Offset
- );
- /*++
- Routine Description:
- This routine seeks in the current file or device.
- Arguments:
- Context - Supplies a pointer to the application context.
- Handle - Supplies the handle.
- Offset - Supplies the offset in blocks to seek to.
- Return Value:
- Returns the resulting file offset in blocks after the operation.
- -1 on failure, and errno will contain more information. The file offset
- will remain unchanged.
- --*/
- //
- // Disk functions
- //
- INT
- SetupFormatDisk (
- PSETUP_CONTEXT Context
- );
- /*++
- Routine Description:
- This routine partitions a disk.
- Arguments:
- Context - Supplies a pointer to the application context.
- Return Value:
- 0 on success.
- Non-zero on failure.
- --*/
- //
- // Platform support functions
- //
- BOOL
- SetupParsePlatformString (
- PSETUP_CONTEXT Context,
- PSTR PlatformString
- );
- /*++
- Routine Description:
- This routine converts a platform string into a platform identifier, and
- sets it in the setup context.
- Arguments:
- Context - Supplies a pointer to the setup context.
- PlatformString - Supplies a pointer to the string to convert to a
- platform identifier.
- Return Value:
- TRUE if the platform name was successfully converted.
- FALSE if the name was invalid.
- --*/
- VOID
- SetupPrintPlatformList (
- VOID
- );
- /*++
- Routine Description:
- This routine prints the supported platform list.
- Arguments:
- None.
- Return Value:
- None.
- --*/
- INT
- SetupDeterminePlatform (
- PSETUP_CONTEXT Context
- );
- /*++
- Routine Description:
- This routine finalizes the setup platform recipe to use.
- Arguments:
- Context - Supplies a pointer to the setup context.
- Return Value:
- 0 on success.
- Non-zero on failure.
- --*/
- INT
- SetupAddRecipeScript (
- PSETUP_CONTEXT Context
- );
- /*++
- Routine Description:
- This routine adds the platform recipe script.
- Arguments:
- Context - Supplies a pointer to the setup context.
- Return Value:
- 0 on success.
- Non-zero on failure.
- --*/
- INT
- SetupAddCommonScripts (
- PSETUP_CONTEXT Context
- );
- /*++
- Routine Description:
- This routine adds the common scripts that are added no matter what.
- Arguments:
- Context - Supplies a pointer to the setup context.
- Return Value:
- 0 on success.
- Non-zero on failure.
- --*/
- //
- // Utility functions
- //
- PSETUP_DESTINATION
- SetupCreateDestination (
- SETUP_DESTINATION_TYPE Type,
- PSTR Path,
- DEVICE_ID DeviceId
- );
- /*++
- Routine Description:
- This routine creates a setup destination structure.
- Arguments:
- Type - Supplies the destination type.
- Path - Supplies an optional pointer to the path. A copy of this string will
- be made.
- DeviceId - Supplies an optional device ID.
- Return Value:
- Returns a pointer to the newly created destination on success.
- NULL on allocation failure.
- --*/
- VOID
- SetupDestroyDestination (
- PSETUP_DESTINATION Destination
- );
- /*++
- Routine Description:
- This routine destroys a setup destination structure.
- Arguments:
- Destination - Supplies a pointer to the destination structure to free.
- Return Value:
- None.
- --*/
- VOID
- SetupDestroyDeviceDescriptions (
- PSETUP_PARTITION_DESCRIPTION Devices,
- ULONG DeviceCount
- );
- /*++
- Routine Description:
- This routine destroys an array of device descriptions.
- Arguments:
- Devices - Supplies a pointer to the array to destroy.
- DeviceCount - Supplies the number of elements in the array.
- Return Value:
- None.
- --*/
- VOID
- SetupPrintDeviceDescription (
- PSETUP_PARTITION_DESCRIPTION Device,
- BOOL PrintHeader
- );
- /*++
- Routine Description:
- This routine prints a device description.
- Arguments:
- Device - Supplies a pointer to the device description.
- PrintHeader - Supplies a boolean indicating if the column descriptions
- should be printed.
- Return Value:
- None.
- --*/
- ULONG
- SetupPrintSize (
- PCHAR String,
- ULONG StringSize,
- ULONGLONG Value
- );
- /*++
- Routine Description:
- This routine prints a formatted size a la 5.8M (M for megabytes).
- Arguments:
- String - Supplies a pointer to the string buffer to print to.
- StringSize - Supplies the total size of the string buffer in bytes.
- Value - Supplies the value in bytes to print.
- Return Value:
- Returns the number of bytes successfully converted.
- --*/
- VOID
- SetupPrintDestination (
- PSETUP_DESTINATION Destination
- );
- /*++
- Routine Description:
- This routine prints a destination structure.
- Arguments:
- Destination - Supplies a pointer to the destination.
- Return Value:
- None.
- --*/
- PSETUP_DESTINATION
- SetupParseDestination (
- SETUP_DESTINATION_TYPE DestinationType,
- PSTR Argument
- );
- /*++
- Routine Description:
- This routine converts a string argument into a destination. Device ID
- destinations can start with "0x", and everything else is treated as a
- path. An empty string is not valid.
- Arguments:
- DestinationType - Supplies the destination type.
- Argument - Supplies the string argument.
- Return Value:
- Returns a pointer to a newly created destination on success. The caller
- is responsible for destroying this structure.
- NULL if the argument is not valid.
- --*/
- PSTR
- SetupAppendPaths (
- PSTR Path1,
- PSTR Path2
- );
- /*++
- Routine Description:
- This routine appends two paths to one another.
- Arguments:
- Path1 - Supplies a pointer to the first path.
- Path2 - Supplies a pointer to the second path.
- Return Value:
- Returns a pointer to a newly created combined path on success. The caller
- is responsible for freeing this new path.
- NULL on allocation failure.
- --*/
- INT
- SetupConvertStringArrayToLines (
- PSTR *StringArray,
- PSTR *ResultBuffer,
- PUINTN ResultBufferSize
- );
- /*++
- Routine Description:
- This routine converts a null-terminated array of strings into a single
- buffer where each element is separated by a newline.
- Arguments:
- StringArray - Supplies a pointer to the array of strings. The array must be
- terminated by a NULL entry.
- ResultBuffer - Supplies a pointer where a string will be returned
- containing all the lines. The caller is responsible for freeing this
- buffer.
- ResultBufferSize - Supplies a pointer where size of the buffer in bytes
- will be returned, including the null terminator.
- Return Value:
- 0 on success.
- ENOMEM on allocation failure.
- --*/
- INT
- SetupCopyFile (
- PSETUP_CONTEXT Context,
- PVOID Destination,
- PVOID Source,
- PSTR DestinationPath,
- PSTR SourcePath,
- ULONG Flags
- );
- /*++
- Routine Description:
- This routine copies the given path from the source to the destination. If
- the source is a directory, the contents of that directory are recursively
- copied to the destination.
- Arguments:
- Context - Supplies a pointer to the applicaton context.
- Destination - Supplies a pointer to the open destination volume
- handle.
- Source - Supplies a pointer to the open source volume handle.
- DestinationPath - Supplies a pointer to the path of the file to create at
- the destination.
- SourcePath - Supplies the source path of the copy.
- Flags - Supplies a bitfield of flags governing the operation. See
- SETUP_COPY_FLAG_* definitions.
- Return Value:
- 0 on success.
- Non-zero on failure.
- --*/
- INT
- SetupCreateAndWriteFile (
- PSETUP_CONTEXT Context,
- PVOID Destination,
- PSTR DestinationPath,
- PVOID Contents,
- ULONG ContentsSize
- );
- /*++
- Routine Description:
- This routine creates a file and writes the given contents out to it.
- Arguments:
- Context - Supplies a pointer to the applicaton context.
- Destination - Supplies a pointer to the open destination volume
- handle.
- DestinationPath - Supplies a pointer to the path of the file to create at
- the destination.
- Contents - Supplies the buffer containing the file contents to write.
- ContentsSize - Supplies the size of the buffer in bytes.
- Return Value:
- 0 on success.
- Non-zero on failure.
- --*/
- INT
- SetupCreateDirectories (
- PSETUP_CONTEXT Context,
- PVOID Volume,
- PSTR Path
- );
- /*++
- Routine Description:
- This routine creates directories up to but not including the final
- component of the given path.
- Arguments:
- Context - Supplies a pointer to the applicaton context.
- Volume - Supplies a pointer to the open destination volume handle.
- Path - Supplies the full file path. The file itself won't be created, but
- all directories leading up to it will. If the path ends in a slash,
- all components will be created.
- Return Value:
- 0 on success.
- Non-zero on failure.
- --*/
|