Rocket Division Software
http://www.starburnsoftware.com/forum/

UDF Samples will be nice
http://www.starburnsoftware.com/forum/starburn-sdk-f3/udf-samples-will-nice-t87.html
Page 1 of 1

Author:  GerardLuc [ Wed Aug 11, 2004 2:04 pm ]
Post subject:  UDF Samples will be nice

Hi

I have not seen a sample using UDF.

Do you know if that exists ?

At moment, I backup my data on DVD-R using TrackAtOncefromxxx.

Can I use UDF to burn data not Video on a DVD+/-R ?

Someone can briefly explain the usage of UDF ?

Regards

Gerard

Author:  alexey (staff) [ Thu Aug 12, 2004 3:00 pm ]
Post subject:  UDF Sample

Code:
/*++

Copyright (c) Rocket Division Software 2001-2004. All rights reserved.

Module Name:

    UDFBuildImage.c

Abstract:

    UDFBuildImage is StarBurn sample application - Pure UDF file system image generation.

    [ This is external sample that has StarBurn toolkit in a separate DLL ]

Author:

    Anton A. Kolomyeytsev   

Environment:

    Windows 95/98/ME/NT/2K/XP/2003 UserMode only

Notes:

Known bugs/Illegal behavior:

ToDo:

Revision/Development History:

    2002-01-14 : * Project restarted "from the scratch".

        2004-02-28 : * Rocket Division Software port.

--*/


//
// Define this file __BUILDIMAGE_C__ (begin)
//

#ifndef __UDFBuildImage_C__
#define __UDFBuildImage_C__


//
// Own includes (begin)
//


#ifndef _WINDOWS_
#include <windows.h>        // Target OS
#endif


#ifndef _INC_STDIO
#include <stdio.h>          // Generic I/O stuff
#endif


#ifndef __STARBURN_H__
#include "inc\StarBurn.h"       // Our public header
#endif


//
// Own includes (end)
//


//
// Own definitions (begin)
//


//
// Store packet size in UCHARs
//

#define STORE_PACKET_SIZE_IN_UCHARS         65536


//
// Own definitions (end)
//


//
// Own global data region (begin)
//


UCHAR g__UCHAR__DataBuffer[ STORE_PACKET_SIZE_IN_UCHARS ];


unsigned char g__UCHAR__FileSystemHead[ ( UDF_HEAD_SIZE_IN_LOGICAL_BLOCKS * UDF_LOGICAL_BLOCK_SIZE_IN_UCHARS ) ];


unsigned char g__UCHAR__FileSystemTail[ ( UDF_TAIL_SIZE_IN_LOGICAL_BLOCKS * UDF_LOGICAL_BLOCK_SIZE_IN_UCHARS ) ];


unsigned char g__UCHAR__FileSystemStructures[ ( 1024 * UDF_LOGICAL_BLOCK_SIZE_IN_UCHARS ) ];


unsigned char g__UCHAR__IsIfoPatch = 0x00; // 0x01; // Assume IFO patch present by default


UDF_TREE_ITEM g__UDF_TREE_ITEM__File[ 200 ]; // File[ 0 ] is not used


//
// Own global data region (end)
//


//
// Own global function bodies (begin)
//


VOID
__cdecl
Callback(
    IN CALLBACK_NUMBER p__CALLBACK_NUMBER,
    IN PVOID p__PVOID__CallbackContext,
    IN PVOID p__PVOID__CallbackSpecial1,
    IN PVOID p__PVOID__CallbackSpecial2
    )

/*++

Routine Description:

    Callback passed to library objects to show progress indication (tree node item added or removed, LBA assigned, file
    opened etc)

Arguments:

    Callback number,
    Passed callback context,
    Parameter 1,
    Parameter 2

Return Value:

    Nothing

--*/

{
    //
    // Process depending of callback number.
    //
    switch ( p__CALLBACK_NUMBER )
    {
        //
        // Unhandled callback number
        //
        default:
        {
            /*

            printf(
                "UDFBuildImage:Callback(): Unhandled callback number 0x%08X, parameter 0x%08X\n",
                ( ULONG )( p__CALLBACK_NUMBER ),
                ( ULONG )( p__PVOID__CallbackContext )
                );

            */
        }
    }
}


ULONG
__cdecl
main(
    IN INT p__INT__Argc,
    IN PCHAR p__PCHAR__Argv[]
    )

/*++

Routine Description:

    Main application entry called by OS loader

Arguments:

    Number of virtual arguments,
    Virtual arguments list

Return Value:

    Execution status

--*/

{
    LARGE_INTEGER l__LARGE_INTEGER__CurrentUnstoredSizeInUCHARs;

    LARGE_INTEGER l__LARGE_INTEGER__TotalSizeInUCHARs;

    LARGE_INTEGER l__LARGE_INTEGER__IoTransferSizeInUCHARs;

    LARGE_INTEGER l__LARGE_INTEGER__LastPrintedPercent;

    LARGE_INTEGER l__LARGE_INTEGER__CurrentPercent;

    LARGE_INTEGER l__LARGE_INTEGER__ProcessedUCHARs;

    HANDLE l__HANDLE = INVALID_HANDLE_VALUE;

    ULONG l__ULONG__UCHARsWritten = 0;

    LONG l__LONG__Index = 0;

    CHAR l__CHAR__DirName[ MAX_PATH ];
   
    ULARGE_INTEGER l__ULARGE_INTEGER__FreeUCHARs;

    ULARGE_INTEGER l__ULARGE_INTEGER__TotalUCHARs;

    ULARGE_INTEGER l__ULARGE_INTETER__FreeTotalUCHARs;

    ULONG l__ULONG__Status = ERROR_GEN_FAILURE;

    CHAR l__CHAR__ExceptionText[ 1024 ];

    EXCEPTION_NUMBER l__EXCEPTION_NUMBER = EN_SUCCESS; // Assume success by default

    UDF_TREE_ITEM l__UDF_TREE_ITEM__Directory[ 20 ]; // Directory[ 0 ] is not used

    ULONG l__ULONG__GUID = 0; // Start assigning GUIDs with zero

    UDF_CONTROL_BLOCK l__UDF_CONTROL_BLOCK;

    printf(
        "\nUDFBuildImage:main(): ENTERed for %ld argument(s)\n",
        p__INT__Argc
        );

    //
    // Check are there enough input parameters
    //
    if ( p__INT__Argc < 2 )
    {
        printf( "\nUDFBuildImage:main(): EXITing with failure!!!\n\n" );

        printf( "UDFBuildImage:main(): Target UDF image name required!!!\n" );

        printf( "UDFBuildImage:main(): Example: UDFBuildImage.exe c:\\UDFImage.iso\n" );

        //
        // Return invalid status
        //
        return ERROR_INVALID_PARAMETER;
    }

    //
    // Prepare some memory buffers
    //

    memset(
        &g__UCHAR__FileSystemHead,
        0,
        sizeof( g__UCHAR__FileSystemHead )
        );

    memset(
        &g__UCHAR__FileSystemTail,
        0,
        sizeof( g__UCHAR__FileSystemTail )
        );

    memset(
        &g__UCHAR__FileSystemStructures,
        0,
        sizeof( g__UCHAR__FileSystemStructures )
        );         

    memset(
        &l__UDF_TREE_ITEM__Directory[ 0 ],
        0,
        sizeof( l__UDF_TREE_ITEM__Directory )
        );

    memset(
        &g__UDF_TREE_ITEM__File[ 0 ],
        0,
        sizeof( g__UDF_TREE_ITEM__File )
        );     

    memset(
        &l__UDF_CONTROL_BLOCK,
        0,
        sizeof( UDF_CONTROL_BLOCK )
        );

    RtlZeroMemory(
        &l__CHAR__ExceptionText,
        sizeof( l__CHAR__ExceptionText )
        );

    //
    // Try to create output file
    //
    l__HANDLE =
        CreateFile(
            p__PCHAR__Argv[ 1 ],
            GENERIC_WRITE,
            FILE_SHARE_READ,
            NULL,
            CREATE_ALWAYS,
            0,
            NULL
            );

    //
    // Check for success
    //
    if ( l__HANDLE == INVALID_HANDLE_VALUE )
    {
        printf( "\nUDFBuildImage:main(): EXITing with failure!!!\n\n" );

        //
        // Get last error
        //
        l__ULONG__Status = GetLastError();

        printf(
            "UDFBuildImage:main(): CreateFile( '%s' ) failed, status %ld!!!\n",
            p__PCHAR__Argv[ 1 ],
            l__ULONG__Status
            );

        //
        // Return invalid status
        //
        return l__ULONG__Status;
    }

    //
    // Start processing cleanup
    //
    __try
    {
        printf( "\nUDFBuildImage:main(): Formatting directories...\n" );

        //
        // Format Directory[ 1 ] as root
        //
        StarBurn_UDF_FormatTreeItemAsDirectory(
            &l__UDF_TREE_ITEM__Directory[ 1 ],
            ( ++l__ULONG__GUID ),
            "",
            NULL
            );

        //
        // Format some directory
        //
        StarBurn_UDF_FormatTreeItemAsDirectory(
            &l__UDF_TREE_ITEM__Directory[ 2 ],
            ( ++l__ULONG__GUID ),
            "UDF_FOLDER",
            &l__UDF_TREE_ITEM__Directory[ 1 ]
            );



        printf( "\nUDFBuildImage:main(): Formatting files...\n" );


        //
        // Format files (begin)
        //

        l__ULONG__Status =
            StarBurn_UDF_FormatTreeItemAsFile(
                &g__UDF_TREE_ITEM__File[ 1 ],
                ( ++l__ULONG__GUID ),
                "my_file.bin",
                "c:\\my_file.bin",
                &l__UDF_TREE_ITEM__Directory[ 2 ]
                );

        //
        // Check for success
        //
        if ( l__ULONG__Status != 0 )
        {
            printf(
                "\nUDFBuildImage:main(): EXITing with failure, StarBurn_UDF_FormatTreeItemAsFile( %p, %ld, '%s', '%s', %p ) failed, status %ld ( 0x%X )\n",
                &g__UDF_TREE_ITEM__File[ 1 ],
                l__ULONG__GUID,
                "my_file.bin",
                "c:\\my_file.bin",
                &l__UDF_TREE_ITEM__Directory[ 2 ],
                l__ULONG__Status,
                l__ULONG__Status
                );

            //
            // Get out of here
            //
            __leave;
        }

                //
        // Try to create UDF
        //
        l__EXCEPTION_NUMBER =
            StarBurn_UDF_Create(
                ( PUCHAR )( &g__UCHAR__FileSystemHead ),
                sizeof( g__UCHAR__FileSystemHead ),
                ( PUCHAR )( &g__UCHAR__FileSystemTail ),
                sizeof( g__UCHAR__FileSystemTail ),
                ( PUCHAR )( &g__UCHAR__FileSystemStructures ),
                &l__UDF_TREE_ITEM__Directory[ 1 ], // This is ROOT
                NULL,
                NULL,
                &l__UDF_CONTROL_BLOCK,
                ( CHAR * )( &l__CHAR__ExceptionText ),
                sizeof( l__CHAR__ExceptionText ),
                &l__ULONG__Status,
                "VolumeLabel"
                );

        //
        // Check for success
        //
        if ( l__EXCEPTION_NUMBER != EN_SUCCESS )
        {
            printf(
                "\nUDFBuildImage:main(): StarBurn_UDF_Create() failed, exception %ld, status %ld, text '%s'\n",
                l__EXCEPTION_NUMBER,
                l__ULONG__Status,
                l__CHAR__ExceptionText
                );

            //
            // Get out of here
            //
            __leave;
        }

        //
        // Get size of image we'll store
        //
        l__LARGE_INTEGER__CurrentUnstoredSizeInUCHARs.LowPart =
            StarBurn_ISO9660JolietFileTree_GetSizeInUCHARs(
                l__UDF_CONTROL_BLOCK.m__PVOID__Body,
                &l__LARGE_INTEGER__CurrentUnstoredSizeInUCHARs.HighPart
                );             

        //
        // Generate target directory name
        //

        RtlZeroMemory(
            l__CHAR__DirName,
            sizeof( l__CHAR__DirName )
            );

        strcpy(
            l__CHAR__DirName,
            p__PCHAR__Argv[ 1 ]         
            );

        //
        // Check is this UNC or absolute path
        //
        if (
            ( ( UCHAR )( l__CHAR__DirName[ 0 ] ) == ( UCHAR )( '\\' ) ) ||
            ( ( UCHAR )( l__CHAR__DirName[ 1 ] ) == ( UCHAR )( ':' ) )
        )
        {
            //
            // Process name UCHAR by UCHAR
            //
            for ( l__LONG__Index = strlen( l__CHAR__DirName ); l__LONG__Index > 0; l__LONG__Index-- )
            {
                //
                // Check is current UCHAR is '\\'
                //
                if ( l__CHAR__DirName[ l__LONG__Index ] == '\\' )
                {
                    //
                    // Put terminating symbol
                    //
                    l__CHAR__DirName[ l__LONG__Index ] = 0;

                    //
                    // Get out of here
                    //
                    break;
                }

                //
                // Reset current symbol
                //
                l__CHAR__DirName[ l__LONG__Index ] = 0;
            }
        }
        else
        {
            //
            // Generate current directory name
            //

            RtlZeroMemory(
                &l__CHAR__DirName,
                sizeof( l__CHAR__DirName )
                );

            //
            // Try to get current directory name, no need to check for return code if this function will fail next call to
            // GetDiskFreeSpaceEx will fail as well with exception '' invalid path
            //
            GetCurrentDirectory(
                sizeof( l__CHAR__DirName ),
                ( PCHAR )( &l__CHAR__DirName )
                );
        }

        //
        // Try to get amount of free disk space in the target directory
        //
        if (
            GetDiskFreeSpaceEx(
                l__CHAR__DirName,
                &l__ULARGE_INTEGER__FreeUCHARs,
                &l__ULARGE_INTEGER__TotalUCHARs,
                &l__ULARGE_INTETER__FreeTotalUCHARs
                ) == FALSE
        )
        {
            //
            // Get error code
            //
            l__ULONG__Status = GetLastError();

            printf(
                "\nUDFBuildImage:main(): GetDiskFreeSpaceEx( '%s' ) failed, status %ld!!!",
                l__CHAR__DirName,
                l__ULONG__Status
                );

            //
            // Get out of here
            //
            __leave;
        }

        printf(
            "\nUDFBuildImage:main(): Free %I64d UCHARs of %I64d UCHARs in directory '%s'\n",
            l__ULARGE_INTEGER__FreeUCHARs,
            l__ULARGE_INTEGER__TotalUCHARs,
            l__CHAR__DirName
            );

        //
        // Check does the generating image will fit into free space
        //
        if ( l__LARGE_INTEGER__CurrentUnstoredSizeInUCHARs.QuadPart > l__ULARGE_INTEGER__FreeUCHARs.QuadPart )
        {
            //
            // Set error code
            // 
            l__ULONG__Status = ERROR_DISK_FULL;

            printf(
                "\nUDFBuildImage:main(): %I64d UCHARs of UDF image will not fit into %I64d UCHARs of free space in '%s'!!!\n",
                l__LARGE_INTEGER__CurrentUnstoredSizeInUCHARs,
                l__ULARGE_INTEGER__FreeUCHARs,
                l__CHAR__DirName
                );

            //
            // Get out of here
            //
            __leave;
        }

        printf(
            "\nUDFBuildImage:main(): Storing %I64d UCHARs of UDF image to file '%s'\n",
            l__LARGE_INTEGER__CurrentUnstoredSizeInUCHARs,
            p__PCHAR__Argv[ 1 ]
            );

        l__LARGE_INTEGER__TotalSizeInUCHARs.LowPart =
            StarBurn_ISO9660JolietFileTree_GetSizeInUCHARs(
                l__UDF_CONTROL_BLOCK.m__PVOID__Body,
                &l__LARGE_INTEGER__TotalSizeInUCHARs.HighPart
                );

        //
        // Reset last printed percent
        //
        l__LARGE_INTEGER__LastPrintedPercent.QuadPart = 0;

        printf( "\nUDFBuildImage:main(): Progress: " );

        //
        // Process until something will be in the file
        //
        for ( ; ; )
        {
            //
            // Calculate currently processed size
            //
            l__LARGE_INTEGER__ProcessedUCHARs.QuadPart =
                ( l__LARGE_INTEGER__TotalSizeInUCHARs.QuadPart - l__LARGE_INTEGER__CurrentUnstoredSizeInUCHARs.QuadPart );

            //
            // Calculate currently processed percent
            //
            l__LARGE_INTEGER__CurrentPercent.QuadPart =
                ( l__LARGE_INTEGER__ProcessedUCHARs.QuadPart * 100 / l__LARGE_INTEGER__TotalSizeInUCHARs.QuadPart );

            //
            // Check do we need to print this percent
            //
            if (
                ( l__LARGE_INTEGER__LastPrintedPercent.QuadPart == l__LARGE_INTEGER__CurrentPercent.QuadPart ) ||
                ( l__LARGE_INTEGER__CurrentPercent.QuadPart == 100 )
            )
            {
                //
                // Do nothing
                //
            }
            else
            {
                //
                // Update last printed percent
                //
                l__LARGE_INTEGER__LastPrintedPercent.QuadPart = l__LARGE_INTEGER__CurrentPercent.QuadPart;

                printf(
                    "%I64d%% ",
                    l__LARGE_INTEGER__LastPrintedPercent
                    );
            }

            //
            // Check do we need to exit
            //
            if ( l__LARGE_INTEGER__CurrentUnstoredSizeInUCHARs.QuadPart == 0 )
            {
                //
                // Get out of here
                //
                break;
            }

            //
            // Check if the number of UCHARs till end is less then our packet size
            //
            if ( l__LARGE_INTEGER__CurrentUnstoredSizeInUCHARs.QuadPart < STORE_PACKET_SIZE_IN_UCHARS )
            {
                //
                // Set current I/O transfer size to number of UCHARs till the end of the image
                //
                l__LARGE_INTEGER__IoTransferSizeInUCHARs.QuadPart = l__LARGE_INTEGER__CurrentUnstoredSizeInUCHARs.QuadPart;
            }
            else
            {
                //
                // Set current I/O transfer size to default store packet size
                //
                l__LARGE_INTEGER__IoTransferSizeInUCHARs.QuadPart = STORE_PACKET_SIZE_IN_UCHARS;
            }

            //
            // Try to read current data
            //
            l__EXCEPTION_NUMBER =
                StarBurn_ISO9660JolietFileTree_Read(
                    l__UDF_CONTROL_BLOCK.m__PVOID__Body,
                    ( PCHAR )( &l__CHAR__ExceptionText ),
                    sizeof( l__CHAR__ExceptionText ),
                    &l__ULONG__Status,
                    l__LARGE_INTEGER__IoTransferSizeInUCHARs.LowPart,
                    ( PUCHAR )( &g__UCHAR__DataBuffer )
                    );

            //
            // Check for success
            //
            if ( l__EXCEPTION_NUMBER != EN_SUCCESS )
            {
                printf(
                    "\nUDFBuildImage:main(): StarBurn_ISO9660FileTree_Read( loop ) failed, exception %ld, status %ld, text '%s'\n",
                    l__EXCEPTION_NUMBER,
                    l__ULONG__Status,
                    l__CHAR__ExceptionText
                    );

                //
                // Get out of here
                //
                __leave;
            }

            //
            // Try to write
            //
            if (
                WriteFile(
                    l__HANDLE,
                    &g__UCHAR__DataBuffer,
                    ( ULONG )( l__LARGE_INTEGER__IoTransferSizeInUCHARs.QuadPart ),
                    &l__ULONG__UCHARsWritten,
                    NULL
                    ) == FALSE
            )
            {
                //
                // Get error code
                //
                l__ULONG__Status = GetLastError();

                printf(
                    "\nUDFBuildImage:main(): WriteFile( %I64d ) failed, status %ld!!!",
                    l__LARGE_INTEGER__IoTransferSizeInUCHARs,
                    l__ULONG__Status
                    );

                //
                // Get out of here
                //
                __leave;
            }

            //
            // Check for number of UCHARs written here
            //
               
            //
            // Update current unstored size
            //
            l__LARGE_INTEGER__CurrentUnstoredSizeInUCHARs.QuadPart -= l__LARGE_INTEGER__IoTransferSizeInUCHARs.QuadPart;
        }

        printf( "100%%... Done!\n\n" );

        //
        // Set status to good one
        //
        l__ULONG__Status = ERROR_SUCCESS;
    }
    __finally
    {
        //
        // Flush file to the disk
        //
        FlushFileBuffers( l__HANDLE );

        //
        // Close file
        //
        CloseHandle( l__HANDLE );

        //
        // UDF clean up here
        //
        StarBurn_UDF_CleanUp(
            &g__UDF_TREE_ITEM__File[ 0 ],
            20
            );

        //
        // UDF tree kill here
        //
        if ( l__UDF_CONTROL_BLOCK.m__PVOID__Body != NULL )
        {
            //
            // Destroy UDF
            //
            StarBurn_UDF_Destroy(
                &l__UDF_TREE_ITEM__Directory[ 1 ], // Root
                &l__UDF_CONTROL_BLOCK
                );
        }
    }

    //
    // Check for success
    //
    if ( l__ULONG__Status == ERROR_SUCCESS )
    {
        printf( "\nUDFBuildImage:main(): EXITing with success\n" );
    }
    else
    {
        printf( "\nUDFBuildImage:main(): EXITing with failure\n" );
    }

    //
    // Return execution status
    //
    return l__ULONG__Status;
}


//
// Own global function bodies (end)
//


#endif // Define this file __UDFBuildImage_C__ (end)

Author:  GerardLuc [ Mon Aug 16, 2004 2:03 pm ]
Post subject:  Merci beaucoup

I really appriacate your software and your support

Thanks a lot.

Gùrard

Author:  anton (staff) [ Mon Aug 16, 2004 6:26 pm ]
Post subject:  Re: Merci beaucoup

Ready to serve! This sample is expected to be included to future StarBurn SDK releases. You was not the first (and single) one who had asked for it :)

GerardLuc wrote:
I really appriacate your software and your support

Thanks a lot.

Gùrard

Author:  Gerard LAUMOSNE [ Wed Aug 25, 2004 6:19 pm ]
Post subject:  Udf sample fails

I took your sample. It give le an erreor because of my_file.bin

This is the area into the sample :

printf( "\nUDFBuildImage:main(): Formatting files...\n" );

//
// Format files (begin)
//

l__ULONG__Status =
StarBurn_UDF_FormatTreeItemAsFile(
&g__UDF_TREE_ITEM__File[ 1 ],
( ++l__ULONG__GUID ),
"my_file.bin",
"c:\\my_file.bin",
&l__UDF_TREE_ITEM__Directory[ 2 ]
);

Could you explain why you need this file ?

Merci

Gerard

Author:  alexey (staff) [ Wed Aug 25, 2004 7:22 pm ]
Post subject:  my_file.bin - it was only our test-file.

Bonjour, Gùrard,

Vous n'avez pas besoin de ce fichier.
C'ùtait seulement l'exemple comment il faut ajouter les fichiers.

Au revoir,
Alexey Popov.

Author:  bernard [ Fri Oct 15, 2004 4:35 am ]
Post subject:  delphi code

can you give me in delphi code?

sorry and thankyou.

Author:  alexey (staff) [ Fri Oct 15, 2004 5:37 am ]
Post subject:  Re: delphi code

bernard wrote:
can you give me in delphi code?


Code:

{-----------------------------------------------------------------------------}
{                                                                             }
{ Copyright (c) Rocket Division Software 2001-2004. All rights reserved.      }
{                                                                             }
{ Module Name:                                                                }
{                                                                             }
{    UDFBuildImage.dpr                                                        }
{                                                                             }
{ Abstract:                                                                   }
{                                                                             }
{    UDFBuildImage is StarBurn sample application                             }
{    UDF file system image generation.                                        }
{                                                                             }
{    [ This is external sample that has StarBurn toolkit in a separate DLL ]  }
{                                                                             }
{ Author:                                                                     }
{                                                                             }
{    Anton A. Kolomyeytsev                                                    }
{                                                                             }
{    Alexey Popov                                                             }
{                                                                             }
{ Environment:                                                                }
{                                                                             }
{    Windows 95/98/ME/NT/2K/XP/2003 UserMode only                             }
{                                                                             }
{ Notes:                                                                      }
{                                                                             }
{ Known bugs/Illegal behavior:                                                }
{                                                                             }
{ ToDo:                                                                       }
{                                                                             }
{-----------------------------------------------------------------------------}

Program UDFBuildImage;

{$APPTYPE CONSOLE}

Uses
  Windows, SysUtils, StarBurn, SamplesTools;

Const
//
// Store packet size in Bytes
//
  STORE_PACKET_SIZE_IN_BYTES    = 65536;

Var
    g__UCHAR__DataBuffer : Packed Array[ 1..STORE_PACKET_SIZE_IN_BYTES ] Of Byte;

    g__LONG__TreeNodes   : LongInt;

    g__UCHAR__Signature : Packed Array[ 1..STORE_PACKET_SIZE_IN_BYTES ] Of Byte;

    l__LARGE_INTEGER__CurrentUnstoredSizeInUCHARs : LARGE_INTEGER;

    l__LARGE_INTEGER__TotalSizeInUCHARs : LARGE_INTEGER;

    l__LARGE_INTEGER__IoTransferSizeInUCHARs,

    l__LARGE_INTEGER__LastPrintedPercent,

    l__LARGE_INTEGER__CurrentPercent,

    l__LARGE_INTEGER__ProcessedUCHARs : Int64;

    l__LONG__TreeLevel : Integer;

    l__LONG__SystemStructuresSizeInUCHARs : Integer;

    l__HANDLE : THandle;

    l__ULONG__UCHARsWritten : DWord;

    l__LONG__Index : Integer;

    l__String__DirName: String;

    l__CHAR__DirName : Packed Array[ 1..1024 ] Of Char;

    l__ULARGE_INTEGER__FreeUCHARs : Int64;

    l__ULARGE_INTEGER__TotalUCHARs : Int64;

    l__ULARGE_INTETER__FreeTotalUCHARs : LARGE_INTEGER;

    l__ULONG__Status : DWORD;

    l__CHAR__ExceptionText : Packed Array[ 1..1024 ] Of Char;

    l__EXCEPTION_NUMBER : EXCEPTION_NUMBER;

    l__LONG__DirectoriesToAdd,

    l__LONG__AddIndex : Integer;

    l__PVOID__Root : Pointer;

    l__LARGE_INTEGER__SignatureSizeInUCHARs : Int64;

    l__LONG__SignIndex : Integer;

    l__PULONG__Sign : PDWORD;

    l__PVOID__FirstKidNode : Pointer;

    l__CHAR__AbsolutePathAndFileName : Packed Array[ 1..MAX_PATH ] Of Char;

    l__CHAR__LongName : Packed Array[ 1..MAX_PATH ] Of Char;

    l__CHAR__ShortName : Packed Array[ 1..MAX_PATH ] Of Char;

    l__String : String;

    l__String__LongName, l__String__ShortName : String;

    g__UCHAR__FileSystemHead : Packed Array[ 1.. ( UDF_HEAD_SIZE_IN_LOGICAL_BLOCKS * UDF_LOGICAL_BLOCK_SIZE_IN_UCHARS ) ] Of Byte;

    g__UCHAR__FileSystemTail: Packed Array[ 1.. ( UDF_TAIL_SIZE_IN_LOGICAL_BLOCKS * UDF_LOGICAL_BLOCK_SIZE_IN_UCHARS ) ] Of Byte;

    g__UCHAR__FileSystemStructures: Packed Array[ 1.. ( 1024 * UDF_LOGICAL_BLOCK_SIZE_IN_UCHARS ) ] Of Byte;

    g__UDF_TREE_ITEM__File : Packed Array[ 1.. 200 ] Of UDF_TREE_ITEM; // File[ 0 ] is not used

    l__ULONG__GUID : DWORD = 0; // Start assigning GUIDs with zero

    l__UDF_CONTROL_BLOCK : UDF_CONTROL_BLOCK;

    l__UDF_TREE_ITEM__Directory : Packed Array[1..20] Of UDF_TREE_ITEM; // [ 0 ] is not used

Begin
    l__LONG__SystemStructuresSizeInUCHARs := 0;

    l__HANDLE := INVALID_HANDLE_VALUE;

    l__ULONG__UCHARsWritten := 0;

    l__LONG__Index := 0;

    l__ULONG__Status := ERROR_GEN_FAILURE;

    l__EXCEPTION_NUMBER := EN_SUCCESS; // Assume success by default

    l__LONG__DirectoriesToAdd := 0;

    l__PVOID__Root := NIL;

    l__LONG__SignIndex := 0;

    l__PULONG__Sign := NIL;

    l__PVOID__FirstKidNode := NIL;

    g__LONG__TreeNodes := 0;

    WriteLn(Format(
        'UDFBuildImage: ENTERed for %d argument(s)',
        [
        ParamCount
        ])
        );

    //
    // Check are there enough input parameters
    //
    If ParamCount < 1 Then Begin

        WriteLn('UDFBuildImage: EXITing with failure!!!' );

        WriteLn('UDFBuildImage: Target UDF image name required!!!' );

        WriteLn('UDFBuildImage: Example: UDFBuildImage.exe c:\Movies\Movie.iso' );
        //
        // Return invalid status
        //
        Halt(ERROR_INVALID_PARAMETER);
    End;

    ZeroMemory(
        @l__CHAR__ExceptionText,
        sizeof( l__CHAR__ExceptionText )
        );

    //
    // Prepare some memory buffers
    //
    ZeroMemory(
        @g__UCHAR__FileSystemHead,
        sizeof( g__UCHAR__FileSystemHead )
        );

    ZeroMemory(
        @g__UCHAR__FileSystemTail,
        sizeof( g__UCHAR__FileSystemTail )
        );

    ZeroMemory(
        @g__UCHAR__FileSystemStructures,
        sizeof( g__UCHAR__FileSystemStructures )
        );

    ZeroMemory(
        @l__UDF_TREE_ITEM__Directory[ 1 ],
        sizeof( l__UDF_TREE_ITEM__Directory )
        );

    ZeroMemory(
        @g__UDF_TREE_ITEM__File[ 1 ],
        sizeof( g__UDF_TREE_ITEM__File )
        );

    ZeroMemory(
        @l__UDF_CONTROL_BLOCK,
        sizeof( UDF_CONTROL_BLOCK )
        );

    //
    // Try to create output file
    //
    l__HANDLE :=
        THandle(
        CreateFile(
            PAnsiChar(ParamStr(1)),
            GENERIC_WRITE,
            FILE_SHARE_READ,
            NIL,
            CREATE_ALWAYS,
            0,
            0
            )
            );

    //
    // Check for success
    //
    if l__HANDLE = INVALID_HANDLE_VALUE Then Begin

        WriteLn('UDFBuildImage: EXITing with failure!!!' );

        //
        // Get last error
        //
        l__ULONG__Status := GetLastError();

        WriteLn(Format(
            'UDFBuildImage: CreateFile( "%s" ) failed, status %d!!!',
            [
            ParamStr(1),
            l__ULONG__Status
            ])
            );

        //
        // Return invalid status
        //
        Halt(l__ULONG__Status);
    End;


    //
    // Start processing cleanup
    //
    Try

        WriteLn( 'UDFBuildImage: Formatting directories...' );

        Inc(l__ULONG__GUID);
        //
        // Format Directory[ 1 ] as root
        //
        StarBurn_UDF_FormatTreeItemAsDirectory(
            @l__UDF_TREE_ITEM__Directory[ 1 ],
            l__ULONG__GUID,
            '',
            NIL
            );

        Inc(l__ULONG__GUID);
        //
        // Format UDF_Folder directory
        //
        StarBurn_UDF_FormatTreeItemAsDirectory(
            @l__UDF_TREE_ITEM__Directory[ 2 ],
            l__ULONG__GUID,
            'UDF_Folder',
            @l__UDF_TREE_ITEM__Directory[ 1 ]
            );


        WriteLn( 'UDFBuildImage: Formatting files...' );


        //
        // Format files (begin)
        //



        Inc(l__ULONG__GUID);

        l__ULONG__Status :=
            StarBurn_UDF_FormatTreeItemAsFile(
                @g__UDF_TREE_ITEM__File[ 1 ],
                l__ULONG__GUID,
                'UDF_File.bin',
                'c:\my_file.bin',
                @l__UDF_TREE_ITEM__Directory[ 2 ]
                );

        //
        // Check for success
        //
        If l__ULONG__Status <> 0 Then Begin

            WriteLn( Format(
                'UDFBuildImage: EXITing with failure, StarBurn_UDF_FormatTreeItemAsFile( %p, %d, "%s", "%s", %p ) failed, status %d ( 0x%X )',
                [
                @g__UDF_TREE_ITEM__File[ 1 ],
                l__ULONG__GUID,
                PChar('UDF_File.bin'),
                PChar('c:\my_file.bin'),
                @l__UDF_TREE_ITEM__Directory[ 2 ],
                l__ULONG__Status,
                l__ULONG__Status
                ])
                );

            //
            // Get out of here
            //
            Raise Exception.Create('Error');
        End;

        //
        // Try to create UDF
        //
        l__EXCEPTION_NUMBER :=
            StarBurn_UDF_Create(
                @g__UCHAR__FileSystemHead,
                sizeof( g__UCHAR__FileSystemHead ),
                @g__UCHAR__FileSystemTail,
                sizeof( g__UCHAR__FileSystemTail ),
                @g__UCHAR__FileSystemStructures,
                @l__UDF_TREE_ITEM__Directory[ 1 ], // This is ROOT
                NIL,
                NIL,
                @l__UDF_CONTROL_BLOCK,
                PCHAR( @l__CHAR__ExceptionText[1] ),
                sizeof( l__CHAR__ExceptionText ),
                l__ULONG__Status,
                PChar('VolumeLabel')
                );

        //
        // Check for success
        //
        If l__EXCEPTION_NUMBER <> EN_SUCCESS Then Begin

            WriteLn(Format(
                'UDFBuildImage: StarBurn_UDF_Create() failed, exception %d, status %d, text "%s"',
                [
                Integer(l__EXCEPTION_NUMBER),
                l__ULONG__Status,
                PAnsiChar(@l__CHAR__ExceptionText[1])
                ])
                );

            //
            // Get out of here
            //
            Raise Exception.Create('Error');
        End;

        //
        // Get size of image we'll store
        //
        l__LARGE_INTEGER__CurrentUnstoredSizeInUCHARs.LowPart :=
            StarBurn_ISO9660JolietFileTree_GetSizeInUCHARs(
                l__UDF_CONTROL_BLOCK.m__PVOID__Body,
                l__LARGE_INTEGER__CurrentUnstoredSizeInUCHARs.HighPart
                );

        //
        // Generate target directory name
        //
        l__String__DirName :=ParamStr( 1 );

        //
        // Check is this UNC or absolute path
        //
        If  ( l__String__DirName[ 1 ] =  '\') Or
            ( l__String__DirName[ 2 ] =  ':') Then Begin

            //
            // Process name UCHAR by UCHAR
            //
            For l__LONG__Index := Length( l__String__DirName ) Downto 1 Do Begin
                //
                // Check is current UCHAR is '\'
                //
                If l__String__DirName[ l__LONG__Index ] = '\' Then Begin
                    //
                    // Get out of here
                    //
                    break;
                End;
            End;
           
            Delete(l__String__DirName,l__LONG__Index,Length(l__String__DirName) - l__LONG__Index + 1);
            For l__LONG__Index := 1 To Length(l__String__DirName) Do l__CHAR__DirName[l__LONG__Index] := l__String__DirName[l__LONG__Index];
        End
        Else Begin
            //
            // Try to get current directory name, no need to check for return code If this function will fail next call to
            // GetDiskFreeSpaceEx will fail as well with exception invalid path
            //
            GetCurrentDirectory(
                sizeof( l__CHAR__DirName ),
                PCHAR( @l__CHAR__DirName[1] )
                );
        End;

        //
        // Try to get amount of free disk space in the target directory
        //
        If
            GetDiskFreeSpaceEx(
                PAnsiChar(@l__CHAR__DirName[1]),
                l__ULARGE_INTEGER__FreeUCHARs,
                l__ULARGE_INTEGER__TotalUCHARs,
                @l__ULARGE_INTETER__FreeTotalUCHARs
                ) = FALSE
        Then Begin
            //
            // Get error code
            //
            l__ULONG__Status := GetLastError();

            WriteLn(Format(
                'UDFBuildImage: GetDiskFreeSpaceEx( "%s" ) failed, status %d!!!',
                [
                PAnsiChar(@l__CHAR__DirName[1]),
                l__ULONG__Status
                ])
                );

            //
            // Get out of here
            //
            Raise Exception.Create('Error');
        End;

        WriteLn(
            'UDFBuildImage: Free ',l__ULARGE_INTEGER__FreeUCHARs,' UCHARs of ',
            l__ULARGE_INTEGER__TotalUCHARs,
            Format(
            ' UCHARs in directory "%s"',
            [
            PAnsiChar(@l__CHAR__DirName[1])
            ])
            );

        //
        // Check does the generating image will fit into free space
        //
        If
            l__LARGE_INTEGER__CurrentUnstoredSizeInUCHARs.QuadPart >
            l__ULARGE_INTEGER__FreeUCHARs
        Then Begin
            //
            // Set error code
            //
            l__ULONG__Status := ERROR_DISK_FULL;

            WriteLn(Format(
                'UDFBuildImage: %d UCHARs of UDF image will not fit into %d UCHARs of free space in "%s"!!!',
                [
                l__LARGE_INTEGER__CurrentUnstoredSizeInUCHARs.QuadPart,
                l__ULARGE_INTEGER__FreeUCHARs,
                PAnsiChar(@l__CHAR__DirName[1])
                ])
                );

            //
            // Get out of here
            //
            Raise Exception.Create('Error');
        End;

        WriteLn(Format(
            'UDFBuildImage: Storing %d UCHARs of UDF image to file "%s"',
            [
            l__LARGE_INTEGER__CurrentUnstoredSizeInUCHARs.QuadPart,
            ParamStr( 1 )
            ])
            );

        l__LARGE_INTEGER__TotalSizeInUCHARs.LowPart :=
            StarBurn_ISO9660JolietFileTree_GetSizeInUCHARs(
                l__UDF_CONTROL_BLOCK.m__PVOID__Body,
                l__LARGE_INTEGER__TotalSizeInUCHARs.HighPart
                );

        //
        // Reset last printed percent
        //
        l__LARGE_INTEGER__LastPrintedPercent := 0;

        Write('UDFBuildImage: Progress: ' );

        //
        // Process until something will be in the file
        //
        While True Do Begin

            //
            // Calculate currently processed size
            //
            l__LARGE_INTEGER__ProcessedUCHARs :=
                ( l__LARGE_INTEGER__TotalSizeInUCHARs.QuadPart - l__LARGE_INTEGER__CurrentUnstoredSizeInUCHARs.QuadPart );

            //
            // Calculate currently processed percent
            //
            l__LARGE_INTEGER__CurrentPercent :=
                ( l__LARGE_INTEGER__ProcessedUCHARs * 100 Div l__LARGE_INTEGER__TotalSizeInUCHARs.QuadPart );

            //
            // Check do we need to print this percent
            //
            If  Not
              (
                ( l__LARGE_INTEGER__LastPrintedPercent = l__LARGE_INTEGER__CurrentPercent ) Or
                ( l__LARGE_INTEGER__CurrentPercent = 100 )
              )
            Then Begin
                //
                // Update last printed percent
                //
                l__LARGE_INTEGER__LastPrintedPercent := l__LARGE_INTEGER__CurrentPercent;

                Write(l__LARGE_INTEGER__LastPrintedPercent,'% ');
            End;

            //
            // Check do we need to exit
            //
            If l__LARGE_INTEGER__CurrentUnstoredSizeInUCHARs.QuadPart = 0 Then
                //
                // Get out of here
                //
                break;

            //
            // Check If the number of UCHARs till end is less then our packet size
            //
            If l__LARGE_INTEGER__CurrentUnstoredSizeInUCHARs.QuadPart < STORE_PACKET_SIZE_IN_BYTES Then

                //
                // Set current I/O transfer size to number of UCHARs till the end of the image
                //
                l__LARGE_INTEGER__IoTransferSizeInUCHARs := l__LARGE_INTEGER__CurrentUnstoredSizeInUCHARs.QuadPart

            Else

                //
                // Set current I/O transfer size to default store packet size
                //
                l__LARGE_INTEGER__IoTransferSizeInUCHARs := STORE_PACKET_SIZE_IN_BYTES;


            //
            // Try to read current data
            //
            l__EXCEPTION_NUMBER :=
                StarBurn_ISO9660JolietFileTree_Read(
                    l__UDF_CONTROL_BLOCK.m__PVOID__Body,
                    PCHAR( @l__CHAR__ExceptionText[1] ),
                    sizeof( l__CHAR__ExceptionText ),
                    l__ULONG__Status,
                    Integer(l__LARGE_INTEGER__IoTransferSizeInUCHARs),
                    @g__UCHAR__DataBuffer
                    );

            //
            // Check for success
            //
            If l__EXCEPTION_NUMBER <> EN_SUCCESS Then Begin

                WriteLn(Format(
                    'UDFBuildImage: StarBurn_ISO9660FileTree_Read( loop ) failed, exception %d, status %d, text "%s"',
                    [
                    Integer(l__EXCEPTION_NUMBER),
                    l__ULONG__Status,
                    PAnsiChar(@l__CHAR__ExceptionText[1])
                    ])
                    );

                //
                // Get out of here
                //
                Raise Exception.Create('Error');
            End;

            //
            // Try to write
            //
            If
                WriteFile(
                    l__HANDLE,
                    g__UCHAR__DataBuffer,
                    DWORD( l__LARGE_INTEGER__IoTransferSizeInUCHARs ),
                    l__ULONG__UCHARsWritten,
                    NIL
                    ) = FALSE
            Then Begin
                //
                // Get error code
                //
                l__ULONG__Status := GetLastError();

                WriteLn(Format(
                    'UDFBuildImage: WriteFile( %d ) failed, status %d!!!',
                    [
                    l__LARGE_INTEGER__IoTransferSizeInUCHARs,
                    l__ULONG__Status
                    ])
                    );

                //
                // Get out of here
                //
                Raise Exception.Create('Error');
            End;

            //
            // Check for number of UCHARs written here
            //

            //
            // Update current unstored size
            //
            Dec(l__LARGE_INTEGER__CurrentUnstoredSizeInUCHARs.QuadPart,l__LARGE_INTEGER__IoTransferSizeInUCHARs);
        End;

        WriteLn('100%... Done!' );

        //
        // Set status to good one
        //
        l__ULONG__Status := ERROR_SUCCESS;
    Except
    End;
    //
    // Flush file to the disk
    //
    FlushFileBuffers( l__HANDLE );

    //
    // Close file
    //
    CloseHandle( l__HANDLE );

    //
    // UDF clean up here
    //
    StarBurn_UDF_CleanUp(
        @g__UDF_TREE_ITEM__File[ 1 ],
        20
        );

    //
    // Chech was file tree allocated
    //
    If l__UDF_CONTROL_BLOCK.m__PVOID__Body <> NIL Then
            //
            // Destroy UDF
            //
            StarBurn_UDF_Destroy(
                @l__UDF_TREE_ITEM__Directory[ 1 ], // Root
                @l__UDF_CONTROL_BLOCK
                );


    //
    // Check for success
    //
    If l__ULONG__Status = ERROR_SUCCESS Then
        WriteLn('UDFBuildImage: EXITing with success' )
    Else
        WriteLn('UDFBuildImage: EXITing with failure. Status = ', l__ULONG__Status);

    //
    // Return execution status
    //
    Halt(l__ULONG__Status);
End.

Author:  bernard [ Wed Oct 20, 2004 2:25 pm ]
Post subject:  thanks

thank you
that's will be useful

Author:  Guest [ Wed Oct 20, 2004 7:13 pm ]
Post subject:  Re: thanks

These samples (and some other mostly UI ones) are expected to be part of StarBurn SDK quite soon. Hold on :-)

bernard wrote:
thank you
that's will be useful

Author:  anton (staff) [ Fri Oct 22, 2004 12:06 pm ]
Post subject:  Re: thanks

Damn! This was me! :-(

Anonymous wrote:
These samples (and some other mostly UI ones) are expected to be part of StarBurn SDK quite soon. Hold on :-)

bernard wrote:
thank you
that's will be useful

Author:  bernard [ Wed Nov 24, 2004 10:24 am ]
Post subject:  new version

does this delphi code works for latest version 4.7.3.
or I just put the starburn_upstart() and starburn_downshut()?

is there other udf sample, especially the one like trackatoncefromtree?
thank you.

Author:  anton (staff) [ Thu Nov 25, 2004 8:22 am ]
Post subject:  Re: new version

You don't need special code. Just add init/deinit calls to old sample and you'll be fine.

bernard wrote:
does this delphi code works for latest version 4.7.3.
or I just put the starburn_upstart() and starburn_downshut()?

is there other udf sample, especially the one like trackatoncefromtree?
thank you.

Author:  bernard [ Thu Nov 25, 2004 7:16 pm ]
Post subject:  ask

how about other udf sample ?, especially the one that has same function with trackatoncefromtree.

why udf sample was not inside of 4.7.3 ?

Author:  alexey (staff) [ Thu Nov 25, 2004 8:02 pm ]
Post subject:  Re: ask

bernard wrote:
how about other udf sample ?, especially the one that has same function with trackatoncefromtree.

why udf sample was not inside of 4.7.3 ?


We will add them to the new build

Page 1 of 1 All times are UTC
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/