/packages/os2units/src/lvm.pas

https://github.com/slibre/freepascal · Pascal · 5232 lines · 723 code · 189 blank · 4320 comment · 0 complexity · 28c7140800a34d5da5d8fd98da9400c0 MD5 · raw file

Large files are truncated click here to view the full file

  1. {
  2. Copyright (c) International Business Machines Corp., 2000
  3. Copyright (c) 2003 Yuri Prokushev
  4. This module defines the interface to LVM.DLL, which is the
  5. engine that performs all of the disk partitioning/volume
  6. creation work.
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2 of the License, or
  10. (at your option) any later version.
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
  14. the GNU General Public License for more details.
  15. You should have received a copy of the GNU General Public License
  16. along with this program; if not, write to the Free Software
  17. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. }
  19. Unit LVM;
  20. {$PACKRECORDS C}
  21. Interface
  22. {$ifdef os2}
  23. {$define lvm1}
  24. {$endif}
  25. {$ifdef linux}
  26. {$define lvm2}
  27. {$endif}
  28. // The number of bytes in a sector on the disk.
  29. const
  30. BYTES_PER_SECTOR=512;
  31. //The maximum number of cylinders, heads, and sectors that a partition table entry can accomodate.
  32. //Cylinders are numbered 0 - 1023, for a maximum of 1024 cylinders.
  33. //eads are numbered 0 - 255, for a maximum of 256 heads.
  34. //Sectors are numbered 1 - 63, for a maximum of 63 sectors per track.
  35. const
  36. MAX_CYLINDERS= 1024;
  37. MAX_HEADS = 256;
  38. MAX_SECTORS = 63;
  39. // The following define the values used to indicate that a partition table entry is for an EBR, not a partition.
  40. const
  41. EBR_BOOT_INDICATOR = 0;
  42. EBR_FORMAT_INDICATOR = 5;
  43. // The following define is used as the default Format_Indicator for new non-primary partitions.
  44. const
  45. NEW_LOGICAL_DRIVE_FORMAT_INDICATOR = $6;
  46. // The following define is used as the default Format_Indicator for a new non-active primary partitions.
  47. const
  48. NEW_PRIMARY_PARTITION_FORMAT_INDICATOR = $16;
  49. // The following define is used as the default Format_Indicator for a new active primary partition.
  50. const
  51. NEW_ACTIVE_PRIMARY_PARTITION_FORMAT_INDICATOR = $06;
  52. // The following define is used to hold the value of the Boot_Indicator for active partitions.
  53. const
  54. ACTIVE_PARTITION = $80;
  55. // Define the size of a Partition Name. Partition Names are user defined names given to a partition.
  56. const
  57. PARTITION_NAME_SIZE = 20;
  58. // Define the size of a volume name. Volume Names are user defined names given to a volume.
  59. const
  60. VOLUME_NAME_SIZE = 20;
  61. // Define the size of a disk name. Disk Names are user defined names given to physical disk drives in the system.
  62. const
  63. DISK_NAME_SIZE = 20;
  64. // The name of the filesystem in use on a partition. This name may be up to 12 ( + NULL terminator) characters long.
  65. const
  66. FILESYSTEM_NAME_SIZE = 20;
  67. // The comment field is reserved but is not currently used. This is for future expansion and use.
  68. const
  69. COMMENT_SIZE = 81;
  70. // Define the minimum number of sectors to reserve on the disk for Boot Manager.
  71. const
  72. BOOT_MANAGER_SIZE = 2048;
  73. // An INTEGER number is a whole number, either + or -.
  74. //The number appended to the INTEGER key word indicates the number of bits
  75. //used to represent an INTEGER of that type.
  76. type
  77. INTEGER16=SmallInt;
  78. INTEGER32=LongInt;
  79. INTEGER=LongInt;
  80. // A CARDINAL number is a positive integer >= 0.
  81. //The number appended to the CARDINAL key word indicates the number of bits
  82. //used to represent a CARDINAL of that type.
  83. type
  84. CARDINAL16=Word;
  85. CARDINAL32 = Cardinal;
  86. (*
  87. /* A REAL number is a floating point number. */
  88. typedef float REAL32;
  89. typedef double REAL64;
  90. *)
  91. REAL32 = double;
  92. REAL64 = double;
  93. // An ADDRESS variable is one which holds an address. The address can contain
  94. //anything, or even be invalid. It is just an address which is presumed to
  95. //hold some kind of data.
  96. Type
  97. ADDRESS=Pointer;
  98. Type
  99. pSTRING=PChar;
  100. // 4 bytes
  101. Type
  102. DoubleWord=Cardinal;
  103. //* The following types are used in the declaration of disk structures. Disk structures
  104. //have a defined size and internal structure which must be matched exactly. */
  105. //* 8 bytes. */
  106. type
  107. QuadWord=QWord;
  108. // The following types are used internally by LVM. */
  109. // Define a Partition Sector Number. A Partition Sector Number is relative to the start of a partition.
  110. //The first sector in a partition is PSN 0.
  111. type
  112. PSN=Cardinal;
  113. // Define a Logical Sector Number. A Logical Sector Number is relative to the start of a volume.
  114. //The first sector in a volume is LSN 0.
  115. type
  116. LSN=Cardinal;
  117. // Define a Logical Block Address. A Logical Block Address is relative to the start of a
  118. //physical device - a disk drive. The first sector on a disk drive is LBA 0.
  119. type
  120. LBA=Cardinal;
  121. // The following define sets the maximum number of LVM classes for which structures and storage will be reserved.
  122. const
  123. MAXIMUM_LVM_CLASSES = 3;
  124. // The following enum defines the various LVM classes to which a "feature" may belong.
  125. // An LVM Plugin is used to implement a "feature", so "plugin" and "feature" are really synonyms.
  126. type
  127. _LVM_Classes = (
  128. Partition_Class, // For "features" which must operate on a partition level - i.e. Bad Block Relocation.
  129. Aggregate_Class, // For "features" which combine partitions into a single logical entity - i.e. Drive Linking.
  130. Volume_Class // For "features" which operate best on a volume level - i.e. encryption, mirroring etc.
  131. );
  132. LVM_Classes = _LVM_Classes;
  133. // An LVM plugin may belong to one or more classes. For each class to which it belongs, certain attributes must be defined.
  134. //This structure tracks those attributes for a class.
  135. type
  136. _LVM_Class_Attributes=record
  137. ClassMember: BOOLEAN; // TRUE if a member of this class, FALSE otherwise.
  138. GlobalExclusive: BOOLEAN; // TRUE if this plugin can not work with any other plugin - i.e. it
  139. //must be the only "feature" on the volume, besides the built in feature of BBR.
  140. TopExclusive: BOOLEAN; // TRUE if this plugin must be the topmost plugin in this class.
  141. BottomExclusive: BOOLEAN; // TRUE if this plugin must be the bottommost plugin in this class.
  142. ClassExclusive: BOOLEAN; // TRUE if this plugin will not work with any other plugin in this class.
  143. Weight_Factor: CARDINAL32; // A value between 1 and 100 which is used to guide the LVM interfaces when attempting to
  144. //establish a default ordering for plugins within this class. A value of 1
  145. //indicates that this plugin wants to be as close to the bottom of the plugins
  146. //in this class as possible. A value of 100 means that this plugin wants to
  147. //be as close to being the topmost plugin in this class as possible. This value
  148. //is only used if none of the "exclusive" flags are set.
  149. end;
  150. LVM_Class_Attributes=_LVM_Class_Attributes;
  151. // The following enum specifies the interface types that LVM supports, and hence any plugin must support.
  152. _LVM_Interface_Types= (
  153. PM_Interface,
  154. VIO_Interface, // LVM.EXE is a VIO app. since it is used during install, and during recovery scenarios where PM/Java may not be available.
  155. Java_Interface // The LVM GUI is written in Java.
  156. );
  157. LVM_Interface_Types=_LVM_Interface_Types;
  158. const
  159. MAXIMUM_LVM_INTERFACE_TYPES = 3;
  160. //* The following structures define what functions must be supported for each interface type.
  161. type
  162. PADDRESS=^ADDRESS;
  163. PCARDINAL32=^CARDINAL32;
  164. _LVM_OS2_Native_Support=record
  165. //void (* _System Create_and_Configure) ( CARDINAL32 ID, ADDRESS InputBuffer, CARDINAL32 InputBufferSize, ADDRESS * OutputBuffer, CARDINAL32 * OutputBufferSize, CARDINAL32 * Error_Code);
  166. Create_and_Configure: procedure(ID: CARDINAL32; InputBuffer: ADDRESS; InputBufferSize: CARDINAL32; OutputBuffer: PADDRESS; OutputBufferSize: PCARDINAL32; Error_Code: PCARDINAL32);
  167. //void (* _System Display_Status) ( ADDRESS Volume_Handle, CARDINAL32 * Error_Code );
  168. Display_Status: procedure(Volume_Handle: ADDRESS; Error_Code: PCARDINAL32 );
  169. //void (* _System Control_Panel) (ADDRESS Volume_Handle, CARDINAL32 * Error_Code );
  170. Control_Panel: procedure(Volume_Handle: ADDRESS; Error_Code: PCARDINAL32 );
  171. //void (* _System Help_Panel) (CARDINAL32 Help_Index, CARDINAL32 * Error_Code);
  172. Help_Panel: procedure(Help_Index: CARDINAL32; Error_Code: PCARDINAL32);
  173. end;
  174. LVM_OS2_Native_Support=_LVM_OS2_Native_Support;
  175. type
  176. _LVM_Interface_Support=record
  177. Interface_Supported: BOOLEAN;
  178. case longint of
  179. 0 : ( Java_Interface_Class : ^char );
  180. 1 : ( VIO_PM_Calls : LVM_OS2_Native_Support );
  181. end;
  182. LVM_Interface_Support=_LVM_Interface_Support;
  183. //* The following define the default help indicies which must be supported by the Help_Panel function. NOTE: Index
  184. //values from 0 to 100 are reserved by LVM. The Plugin may, for its own use, use any values above 100.
  185. const
  186. HELP_PLUGIN_DESCRIPTION = 0;
  187. // The following define the maximum length of the names which can be used to represent a feature in LVM. The
  188. //maximum name length for a feature is 30 characters plus the trailing NULL character. For command line parsing,
  189. //though, a shorter name is preferable! Thus, the "short" name for a feature will be limited to 10 characters
  190. //plus the trailing NULL character. The "short" name will be used for command line purposes, while the regular
  191. //name will be used by all other interfaces.
  192. const
  193. MAX_FEATURE_NAME_LENGTH = 31;
  194. MAX_FEATURE_SHORT_NAME_LENGTH = 11;
  195. MAX_OEM_INFO_LENGTH =255;
  196. // The following definitions are used to control and access the various "features" available through the LVM Engine, such as Drive Linking and BBR.
  197. type
  198. _Feature_ID_Data=record
  199. Name: Array[0..MAX_FEATURE_NAME_LENGTH-1] of char; // Feature Name, for use in menus and command line parsing.
  200. Short_Name: Array[0..MAX_FEATURE_SHORT_NAME_LENGTH-1] of char; // The name/code used to represent this feature during command line parsing.
  201. OEM_Info: Array[0..MAX_OEM_INFO_LENGTH-1] of char; // Name and copyright info. of the manufacturer, i.e. IBM, Vinca, etc.
  202. ID: CARDINAL32; // Numeric Feature ID.
  203. Major_Version_Number: CARDINAL32; // The version number of this feature.
  204. Minor_Version_Number: CARDINAL32; // The version number of this feature.
  205. LVM_Major_Version_Number: CARDINAL32; // The version of LVM that this feature was designed to work with.
  206. LVM_Minor_Version_Number: CARDINAL32; // The version of LVM that this feature was designed to work with.
  207. Preferred_Class: LVM_Classes; // The class from which this "feature" prefers to be chosen. Encryption can be performed
  208. //at the partition level or the volume level, and may therefore belong to both the
  209. //Partition_Class and the Volume_Class. However, it is preferrable for it to be used
  210. //on the volume level instead of at the partition level. Thus, its perferred class would
  211. //be the Volume_Class, but it would still be a member of both the Volume_Class and the
  212. //Partition_Class.
  213. ClassData: Array[0..MAXIMUM_LVM_CLASSES-1] of LVM_Class_Attributes; // The attributes for each of the LVM classes that this "feature" is in.
  214. Interface_Support: Array[0..MAXIMUM_LVM_INTERFACE_TYPES-1] of LVM_Interface_Support; // The functions and classes for each of the video modes that LVM can run it.
  215. end;
  216. Feature_ID_Data=_Feature_ID_Data;
  217. // The following defines the TAG value used to identify an item of type Feature_ID_Data in a DLIST.
  218. const
  219. FEATURE_ID_DATA_TAG = 354385972;
  220. // The following are invariant for a disk drive.
  221. Type
  222. Drive_Control_Record = record
  223. Drive_Number: CARDINAL32; // OS/2 Drive Number for this drive.
  224. Drive_Size: CARDINAL32; // The total number of sectors on the drive.
  225. Drive_Serial_Number: DoubleWord; // The serial number assigned to this drive. For info. purposes only.
  226. Drive_Handle: ADDRESS; // Handle used for operations on the disk that this record corresponds to.
  227. Cylinder_Count: CARDINAL32; // The number of cylinders on the drive.
  228. Heads_Per_Cylinder: CARDINAL32; // The number of heads per cylinder for this drive.
  229. Sectors_Per_Track: CARDINAL32; // The number of sectors per track for this drive.
  230. Drive_Is_PRM: BOOLEAN; // Set to TRUE if this drive is a PRM.
  231. Reserved: Array[0..3-1] of BYTE; // Alignment.
  232. end;
  233. // The following structure is returned by the Get_Drive_Control_Data function.
  234. Drive_Control_Array=record
  235. Drive_Control_Data: ^Drive_Control_Record; // An array of drive control records.
  236. Count: CARDINAL32; // The number of entries in the array of drive control records.
  237. end;
  238. // The following structure defines the information that can be changed for a specific disk drive.
  239. Drive_Information_Record=record
  240. Total_Available_Sectors: CARDINAL32; // The number of sectors on the disk which are not currently assigned to a partition.
  241. Largest_Free_Block_Of_Sectors: CARDINAL32; // The number of sectors in the largest contiguous block of available sectors.
  242. Corrupt_Partition_Table: BOOLEAN; // If TRUE, then the partitioning information found on the drive is incorrect!
  243. Unusable: BOOLEAN; // If TRUE, the drive's MBR is not accessible and the drive can not be partitioned.
  244. IO_Error: BOOLEAN; // If TRUE, then the last I/O operation on this drive failed!
  245. Is_Big_Floppy: BOOLEAN; // If TRUE, then the drive is a PRM formatted as a big floppy (i.e. the old style removable media support).
  246. Drive_Name: Array[0..DISK_NAME_SIZE-1] of Char; // User assigned name for this disk drive.
  247. end;
  248. Partition_Information_Record=record
  249. Partition_Handle: ADDRESS; // The handle used to perform operations on this partition.
  250. Volume_Handle: ADDRESS; // If this partition is part of a volume, this will be the handle of
  251. //the volume. If this partition is NOT part of a volume, then this
  252. //handle will be 0.
  253. Drive_Handle: ADDRESS; // The handle for the drive this partition resides on.
  254. Partition_Serial_Number: DoubleWord; // The serial number assigned to this partition.
  255. Partition_Start: CARDINAL32; // The LBA of the first sector of the partition.
  256. True_Partition_Size: CARDINAL32; // The total number of sectors comprising the partition.
  257. Usable_Partition_Size: CARDINAL32; // The size of the partition as reported to the IFSM. This is the
  258. //size of the partition less any LVM overhead.
  259. Boot_Limit: CARDINAL32; // The maximum number of sectors from this block of free space that can be used to
  260. //create a bootable partition if you allocate from the beginning of the block of
  261. //free space.
  262. Spanned_Volume: BOOLEAN; // TRUE if this partition is part of a multi-partition volume.
  263. Primary_Partition: BOOLEAN; // True or False. Any non-zero value here indicates that
  264. //this partition is a primary partition. Zero here indicates
  265. //that this partition is a "logical drive" - i.e. it resides
  266. //inside of an extended partition.
  267. Active_Flag: BYTE; // 80 = Partition is marked as being active.
  268. // 0 = Partition is not active.
  269. OS_Flag: BYTE; // This field is from the partition table. It is known as the
  270. //OS flag, the Partition Type Field, Filesystem Type, and
  271. //various other names.
  272. //Values of interest
  273. //If this field is: (values are in hex)
  274. //07 = The partition is a compatibility partition formatted for use
  275. //with an installable filesystem, such as HPFS or JFS.
  276. //00 = Unformatted partition
  277. //01 = FAT12 filesystem is in use on this partition.
  278. //04 = FAT16 filesystem is in use on this partition.
  279. //0A = OS/2 Boot Manager Partition
  280. //35 = LVM partition
  281. //84 = OS/2 FAT16 partition which has been relabeled by Boot Manager to "Hide" it.
  282. Partition_Type: BYTE; // 0 = Free Space
  283. //1 = LVM Partition (Part of an LVM Volume.)
  284. //2 = Compatibility Partition
  285. //All other values are reserved for future use.
  286. Partition_Status: BYTE; // 0 = Free Space
  287. //1 = In Use - i.e. already assigned to a volume.
  288. //2 = Available - i.e. not currently assigned to a volume.
  289. On_Boot_Manager_Menu: BOOLEAN; // Set to TRUE if this partition is not part of a Volume yet is on the Boot Manager Menu.
  290. Reserved: BYTE; // Alignment.
  291. Volume_Drive_Letter: char; // The drive letter assigned to the volume that this partition is a part of.
  292. Drive_Name: Array[0..DISK_NAME_SIZE-1] of char; // User assigned name for this disk drive.
  293. File_System_Name: Array[0..FILESYSTEM_NAME_SIZE-1] of char;// The name of the filesystem in use on this partition, if it is known.
  294. Partition_Name: Array[0..PARTITION_NAME_SIZE-1] of char; // The user assigned name for this partition.
  295. Volume_Name: Array[0..VOLUME_NAME_SIZE-1] of char; // If this partition is part of a volume, then this will be the
  296. //name of the volume that this partition is a part of. If this
  297. //record represents free space, then the Volume_Name will be
  298. //"FREE SPACE xx", where xx is a unique numeric ID generated by
  299. //LVM.DLL. Otherwise it will be an empty string.
  300. end;
  301. // The following defines are for use with the Partition_Type field in the Partition_Information_Record.
  302. const
  303. pt_FREE_SPACE_PARTITION = 0;
  304. pt_LVM_PARTITION = 1;
  305. pt_COMPATIBILITY_PARTITION = 2;
  306. // The following defines are for use with the Partition_Status field in the Partition_Information_Record.
  307. const
  308. PARTITION_IS_IN_USE = 1;
  309. PARTITION_IS_AVAILABLE = 2;
  310. PARTITION_IS_FREE_SPACE = 0;
  311. // The following structure is returned by various functions in the LVM Engine.
  312. type
  313. Partition_Information_Array=record
  314. Partition_Array: ^Partition_Information_Record; // An array of Partition_Information_Records.
  315. Count: CARDINAL32; // The number of entries in the Partition_Array.
  316. end;
  317. // The following items are invariant for a volume.
  318. type
  319. Volume_Control_Record=record
  320. Volume_Serial_Number: DoubleWord; // The serial number assigned to this volume.
  321. Volume_Handle: ADDRESS; // The handle used to perform operations on this volume.
  322. Compatibility_Volume: BOOLEAN; // TRUE indicates that this volume is compatible with older versions of OS/2.
  323. //FALSE indicates that this is an LVM specific volume and can not be used without OS2LVM.DMD.
  324. Device_Type: BYTE; // Indicates what type of device the Volume resides on:
  325. //0 = Hard Drive under LVM Control
  326. //1 = PRM under LVM Control
  327. //2 = CD-ROM
  328. //3 = Network drive
  329. //4 = Unknown device NOT under LVM Control
  330. Reserved: Array[0..2-1] of BYTE; // Alignment.
  331. end;
  332. // The following define the device types used in the Device_Type field of the Volume_Control_Record.
  333. const
  334. LVM_HARD_DRIVE = 0;
  335. LVM_PRM = 1;
  336. NON_LVM_CDROM = 2;
  337. NETWORK_DRIVE = 3;
  338. NON_LVM_DEVICE = 4;
  339. // The following structure is returned by the Get_Volume_Control_Data function.
  340. type
  341. Volume_Control_Array=record
  342. Volume_Control_Data: ^Volume_Control_Record; // An array of volume control records.
  343. Count: CARDINAL32; // The number of entries in the array of volume control records.
  344. end;
  345. // The following information about a volume can (and often does) vary.
  346. type
  347. Volume_Information_Record=record
  348. Volume_Size: CARDINAL32; // The number of sectors comprising the volume.
  349. Partition_Count: CARDINAL32; // The number of partitions which comprise this volume.
  350. Drive_Letter_Conflict: CARDINAL32; // 0 indicates that the drive letter preference for this volume is unique.
  351. //1 indicates that the drive letter preference for this volume
  352. //is not unique, but this volume got its preferred drive letter anyway.
  353. //2 indicates that the drive letter preference for this volume
  354. //is not unique, and this volume did NOT get its preferred drive letter.
  355. //4 indicates that this volume is currently "hidden" - i.e. it has
  356. //no drive letter preference at the current time.
  357. Compatibility_Volume: BOOLEAN; // TRUE if this is for a compatibility volume, FALSE otherwise.
  358. Bootable: BOOLEAN; // Set to TRUE if this volume appears on the Boot Manager menu, or if it is
  359. //a compatibility volume and its corresponding partition is the first active
  360. //primary partition on the first drive.
  361. Drive_Letter_Preference: char; // The drive letter that this volume desires to be.
  362. Current_Drive_Letter: char; // The drive letter currently used to access this volume. May be different than
  363. //Drive_Letter_Preference if there was a conflict ( i.e. Drive_Letter_Preference
  364. //is already in use by another volume ).
  365. Initial_Drive_Letter: char; // The drive letter assigned to this volume by the operating system when LVM was started.
  366. //This may be different from the Drive_Letter_Preference if there were conflicts, and
  367. //may be different from the Current_Drive_Letter. This will be 0x0 if the Volume did
  368. //not exist when the LVM Engine was opened (i.e. it was created during this LVM session).
  369. New_Volume: BOOLEAN; // Set to FALSE if this volume existed before the LVM Engine was opened. Set to
  370. //TRUE if this volume was created after the LVM Engine was opened.
  371. Status: BYTE; // 0 = None.
  372. //1 = Bootable
  373. //2 = Startable
  374. //3 = Installable.
  375. Reserved_1: BYTE;
  376. Volume_Name: Array[0..VOLUME_NAME_SIZE-1] of char; // The user assigned name for this volume.
  377. File_System_Name: Array[0..FILESYSTEM_NAME_SIZE-1] of char;// The name of the filesystem in use on this partition, if it is known.
  378. end;
  379. // The following structure is used to return the feature information for the installed features, or the features on a volume.
  380. type
  381. Feature_Information_Array=record
  382. Count: CARDINAL32;
  383. Feature_Data: ^Feature_ID_Data;
  384. end;
  385. // The following structure defines an item on the Boot Manager Menu.
  386. type
  387. Boot_Manager_Menu_Item=record
  388. Handle: ADDRESS; // A Volume or Partition handle.
  389. Volume: BOOLEAN; // If TRUE, then Handle is the handle of a Volume. Otherwise, Handle is the handle of a partition.
  390. end;
  391. // The following structure is used to get a list of the items on the partition manager menu.
  392. type
  393. Boot_Manager_Menu=record
  394. Menu_Items: ^Boot_Manager_Menu_Item;
  395. Count: CARDINAL32;
  396. end;
  397. // The following structure is used to specify an LVM Feature when creating a volume. Since LVM Features may be part of
  398. //more than one LVM Class, the specific class to be used with the feature must also be specified.
  399. type
  400. LVM_Feature_Specification_Record=record
  401. Feature_ID: CARDINAL32; // The feature ID of the feature to use.
  402. Actual_Class: LVM_Classes; // The LVM Class (supported by the specified feature) to use.
  403. Init_Data: ADDRESS; // The address of a buffer containing initialization data for this feature.
  404. //NULL if there is no initialization data being provided for this feature.
  405. end;
  406. // The following structure is used with the Get_Child_Handles function.
  407. Type
  408. LVM_Handle_Array_Record=record
  409. Count: CARDINAL32;
  410. Handles: ^ADDRESS;
  411. end;
  412. // The following preprocessor directives define the operations that can be performed on a partition, volume, or a block of free space.
  413. // These definitions represent bits in a 32 bit value returned by the Get_Valid_Options function.
  414. const
  415. CREATE_PRIMARY_PARTITION = 1;
  416. CREATE_LOGICAL_DRIVE = 2;
  417. DELETEPARTITION = 4;
  418. SET_ACTIVE_PRIMARY = 8;
  419. SET_PARTITION_ACTIVE = $10;
  420. SET_PARTITION_INACTIVE = $20;
  421. SETSTARTABLE = $40;
  422. INSTALLBOOTMANAGER = $80;
  423. REMOVEBOOTMANAGER = $100;
  424. SET_BOOT_MANAGER_DEFAULTS = $200;
  425. ADD_TO_BOOT_MANAGER_MENU = $400;
  426. REMOVE_FROM_BOOT_MANAGER_MENU = $800;
  427. DELETEVOLUME = $1000;
  428. HIDEVOLUME = $2000;
  429. EXPANDVOLUME = $4000;
  430. SET_VOLUME_INSTALLABLE = $8000;
  431. ASSIGNDRIVELETTER = $10000;
  432. CAN_BOOT_PRIMARY = $20000; // If a primary is created from this block of free space, then it can be made bootable.
  433. CAN_BOOT_LOGICAL = $40000; // If a logical drive is created from this block of free space, then OS/2 can boot from it by adding it to the boot manager menu.
  434. CAN_SET_NAME = $80000;
  435. SET_BOOT_MANAGER_STARTABLE = $100000;
  436. // The following enumeration defines the allocation strategies used by the Create_Partition function.
  437. type
  438. _Allocation_Algorithm =(
  439. Automatic, // Let LVM decide which block of free space to use to create the partition.
  440. Best_Fit, // Use the block of free space which is closest in size to the partition being created.
  441. First_Fit, // Use the first block of free space on the disk which is large enough to hold a partition of the specified size.
  442. Last_Fit, // Use the last block of free space on the disk which is large enough to hold a partition of the specified size.
  443. From_Largest, // Find the largest block of free space and allocate the partition from that block of free space.
  444. From_Smallest, // Find the smallest block of free space that can accommodate a partition of the size specified.
  445. All // Turn the specified drive or block of free space into a single partition.
  446. );
  447. Allocation_Algorithm=_Allocation_Algorithm;
  448. // Error codes returned by the LVM Engine.
  449. const
  450. LVM_ENGINE_NO_ERROR = 0;
  451. LVM_ENGINE_OUT_OF_MEMORY = 1;
  452. LVM_ENGINE_IO_ERROR = 2;
  453. LVM_ENGINE_BAD_HANDLE = 3;
  454. LVM_ENGINE_INTERNAL_ERROR = 4;
  455. LVM_ENGINE_ALREADY_OPEN = 5;
  456. LVM_ENGINE_NOT_OPEN = 6;
  457. LVM_ENGINE_NAME_TOO_BIG = 7;
  458. LVM_ENGINE_OPERATION_NOT_ALLOWED = 8;
  459. LVM_ENGINE_DRIVE_OPEN_FAILURE = 9;
  460. LVM_ENGINE_BAD_PARTITION = 10;
  461. LVM_ENGINE_CAN_NOT_MAKE_PRIMARY_PARTITION = 11;
  462. LVM_ENGINE_TOO_MANY_PRIMARY_PARTITIONS = 12;
  463. LVM_ENGINE_CAN_NOT_MAKE_LOGICAL_DRIVE = 13;
  464. LVM_ENGINE_REQUESTED_SIZE_TOO_BIG = 14;
  465. LVM_ENGINE_1024_CYLINDER_LIMIT = 15;
  466. LVM_ENGINE_PARTITION_ALIGNMENT_ERROR = 16;
  467. LVM_ENGINE_REQUESTED_SIZE_TOO_SMALL = 17;
  468. LVM_ENGINE_NOT_ENOUGH_FREE_SPACE = 18;
  469. LVM_ENGINE_BAD_ALLOCATION_ALGORITHM = 19;
  470. LVM_ENGINE_DUPLICATE_NAME = 20;
  471. LVM_ENGINE_BAD_NAME = 21;
  472. LVM_ENGINE_BAD_DRIVE_LETTER_PREFERENCE = 22;
  473. LVM_ENGINE_NO_DRIVES_FOUND = 23;
  474. LVM_ENGINE_WRONG_VOLUME_TYPE = 24;
  475. LVM_ENGINE_VOLUME_TOO_SMALL = 25;
  476. LVM_ENGINE_BOOT_MANAGER_ALREADY_INSTALLED = 26;
  477. LVM_ENGINE_BOOT_MANAGER_NOT_FOUND = 27;
  478. LVM_ENGINE_INVALID_PARAMETER = 28;
  479. LVM_ENGINE_BAD_FEATURE_SET = 29;
  480. LVM_ENGINE_TOO_MANY_PARTITIONS_SPECIFIED = 30;
  481. LVM_ENGINE_LVM_PARTITIONS_NOT_BOOTABLE = 31;
  482. LVM_ENGINE_PARTITION_ALREADY_IN_USE = 32;
  483. LVM_ENGINE_SELECTED_PARTITION_NOT_BOOTABLE = 33;
  484. LVM_ENGINE_VOLUME_NOT_FOUND = 34;
  485. LVM_ENGINE_DRIVE_NOT_FOUND = 35;
  486. LVM_ENGINE_PARTITION_NOT_FOUND = 36;
  487. LVM_ENGINE_TOO_MANY_FEATURES_ACTIVE = 37;
  488. LVM_ENGINE_PARTITION_TOO_SMALL = 38;
  489. LVM_ENGINE_MAX_PARTITIONS_ALREADY_IN_USE = 39;
  490. LVM_ENGINE_IO_REQUEST_OUT_OF_RANGE = 40;
  491. LVM_ENGINE_SPECIFIED_PARTITION_NOT_STARTABLE = 41;
  492. LVM_ENGINE_SELECTED_VOLUME_NOT_STARTABLE = 42;
  493. LVM_ENGINE_EXTENDFS_FAILED = 43;
  494. LVM_ENGINE_REBOOT_REQUIRED = 44;
  495. LVM_ENGINE_CAN_NOT_OPEN_LOG_FILE = 45;
  496. LVM_ENGINE_CAN_NOT_WRITE_TO_LOG_FILE = 46;
  497. LVM_ENGINE_REDISCOVER_FAILED = 47;
  498. LVM_ENGINE_INTERNAL_VERSION_FAILURE = 48;
  499. LVM_ENGINE_PLUGIN_OPERATION_INCOMPLETE = 49;
  500. LVM_ENGINE_BAD_FEATURE_ID = 50;
  501. LVM_ENGINE_NO_INIT_DATA = 51;
  502. LVM_ENGINE_NO_CONTEXT_DATA = 52;
  503. LVM_ENGINE_WRONG_CLASS_FOR_FEATURE = 53;
  504. LVM_ENGINE_INCOMPATIBLE_FEATURES_SELECTED = 54;
  505. LVM_ENGINE_NO_CHILDREN = 55;
  506. LVM_ENGINE_FEATURE_NOT_SUPPORTED_BY_INTERFACE= 56;
  507. LVM_ENGINE_NO_PARENT = 57;
  508. LVM_ENGINE_VOLUME_HAS_NOT_BEEN_COMMITTED_YET = 58;
  509. LVM_ENGINE_UNABLE_TO_REFERENCE_VOLUME = 59;
  510. LVM_ENGINE_PARSING_ERROR = 60;
  511. LVM_ENGINE_INTERNAL_FEATURE_ERROR = 61;
  512. LVM_ENGINE_VOLUME_NOT_CONVERTED = 62;
  513. // The following definitions are used for command line processing. As the command line is processed,
  514. //the command line is first broken up into tokens. Each token has a "characterization", which indicates
  515. //what the token is thought to be.
  516. type
  517. Token_Characterizations=(
  518. LVM_AcceptableCharsStr,
  519. LVM_All,
  520. LVM_BestFit,
  521. LVM_BootDOS,
  522. LVM_BootOS2,
  523. LVM_Bootable,
  524. LVM_CR,
  525. LVM_CRI,
  526. LVM_Compatibility,
  527. LVM_Drive,
  528. LVM_Existing,
  529. LVM_Expand,
  530. LVM_FS,
  531. LVM_FirstFit,
  532. LVM_Freespace,
  533. LVM_FromEnd,
  534. LVM_FromLargest,
  535. LVM_FromSmallest,
  536. LVM_FromStart,
  537. LVM_LVM,
  538. LVM_LastFit,
  539. LVM_Logical,
  540. LVM_New,
  541. LVM_NoBoot,
  542. LVM_NonBootable,
  543. LVM_NotBootable,
  544. LVM_Partition,
  545. LVM_Primary,
  546. LVM_RB,
  547. LVM_Size,
  548. LVM_Unusable,
  549. LVM_Unused,
  550. LVM_Volume,
  551. LVM_Volumes,
  552. LVM_Comma,
  553. LVM_Number,
  554. LVM_Colon,
  555. LVM_Space,
  556. LVM_Tab,
  557. LVM_MultiSpace,
  558. LVM_MultiTab,
  559. LVM_String,
  560. LVM_FileNameStr,
  561. LVM_SemiColon,
  562. LVM_Eof,
  563. LVM_Separator,
  564. LVM_Open_Paren, //* ( */
  565. LVM_Close_Paren, //* ) */
  566. LVM_Open_Bracket, //* [ */
  567. LVM_Close_Bracket, //* ] */
  568. LVM_Open_Brace, //* { */
  569. LVM_Close_Brace, //* } */
  570. LVM_EQ_Sign, //* = */
  571. LVM_Bootmgr,
  572. LVM_Create,
  573. LVM_Delete,
  574. LVM_DriveLetter,
  575. LVM_File,
  576. LVM_Hide,
  577. LVM_Install,
  578. LVM_NewMBR,
  579. LVM_Query,
  580. LVM_RediscoverPRM,
  581. LVM_SetName,
  582. LVM_SetStartable,
  583. LVM_SI,
  584. LVM_SlashSize,
  585. LVM_StartLog
  586. );
  587. type
  588. _LVM_Token=record
  589. TokenText: PChar; // The actual text of the token.
  590. TokenType: Token_Characterizations; // What the token is thought to be.
  591. Position: CARDINAL32; // The position of the first character of the token on the command line.
  592. end;
  593. LVM_Token=_LVM_Token;
  594. const
  595. LVM_TOKEN_TAG = 28387473;
  596. // Function Prototypes
  597. //***************************************************************************
  598. //
  599. // Functions relating to the LVM Engine itself
  600. //
  601. //***************************************************************************
  602. //****************************************************************************************************/
  603. //* */
  604. //* Function Name: Open_LVM_Engine */
  605. //* */
  606. //* Descriptive Name: Opens the LVM Engine and readies it for use. */
  607. //* */
  608. //* Input: BOOLEAN Ignore_CHS : If TRUE, then the LVM engine will not check the CHS values in the */
  609. //* MBR/EBR partition tables for validity. This is useful if there */
  610. //* are drive geometry problems, such as the drive was partitioned and */
  611. //* formatted with one geometry and then moved to a different machine */
  612. //* which uses a different geometry for the drive. This would cause */
  613. //* the starting and ending CHS values in the partition tables to */
  614. //* be inconsistent with the size and partition offset entries in the */
  615. //* partition tables. Setting Ignore_CHS to TRUE will disable the */
  616. //* LVM Engine's CHS consistency checks, thereby allowing the drive */
  617. //* to be partitioned. */
  618. //* CARDINAL32 * Error_Code - The address of a CARDINAL32 in which to store an error code */
  619. //* should an error occur. */
  620. //* */
  621. //* Output: *Error_Code will be 0 if this function completes successfully. If an error occurs, */
  622. //* *Error_Code will contain a non-zero error code. */
  623. //* */
  624. //* Error Handling: If this function aborts with an error, all memory allocated during the course */
  625. //* of this function will be released. Disk read errors will be reported to the */
  626. //* user via pop-up error messages. Disk read errors will only cause this */
  627. //* function to abort if none of the disk drives in the system could be */
  628. //* successfully read. */
  629. //* */
  630. //* Side Effects: The LVM Engine will be initialized. The partition tables for all OS2DASD */
  631. //* controlled disk drives will be read into memory. Memory will be allocated for */
  632. //* the data structures used by the LVM Engine. */
  633. //* */
  634. //* Notes: This is provided for programs that used LVM Version 1. This function assumes an */
  635. //* LVM_Interface_Type of VIO_Interface. */
  636. //* */
  637. //****************************************************************************************************/
  638. procedure Open_LVM_Engine(Ignore_CHS: BOOLEAN; Error_Code: PCARDINAL32); external 'lvm' name 'Open_LVM_Engine';
  639. //****************************************************************************************************/
  640. //* */
  641. //* Function Name: Open_LVM_Engine2 */
  642. //* */
  643. //* Descriptive Name: Opens the LVM Engine and readies it for use. */
  644. //* */
  645. //* Input: BOOLEAN Ignore_CHS : If TRUE, then the LVM engine will not check the CHS values in the */
  646. //* MBR/EBR partition tables for validity. This is useful if there */
  647. //* are drive geometry problems, such as the drive was partitioned and */
  648. //* formatted with one geometry and then moved to a different machine */
  649. //* which uses a different geometry for the drive. This would cause */
  650. //* the starting and ending CHS values in the partition tables to */
  651. //* be inconsistent with the size and partition offset entries in the */
  652. //* partition tables. Setting Ignore_CHS to TRUE will disable the */
  653. //* LVM Engine's CHS consistency checks, thereby allowing the drive */
  654. //* to be partitioned. */
  655. //* LVM_Interface_Types Interface_Type - Indicate the type of user interface being used: */
  656. //* PM_Interface, VIO_Interface, or Java_Interface. This lets the */
  657. //* LVM Engine know which interface support routines to call in any */
  658. //* plugin modules which may be loaded. */
  659. //* CARDINAL32 * Error_Code - The address of a CARDINAL32 in which to store an error code */
  660. //* should an error occur. */
  661. //* */
  662. //* Output: *Error_Code will be 0 if this function completes successfully. If an error occurs, */
  663. //* *Error_Code will contain a non-zero error code. */
  664. //* */
  665. //* Error Handling: If this function aborts with an error, all memory allocated during the course */
  666. //* of this function will be released. Disk read errors will be reported to the */
  667. //* user via pop-up error messages. Disk read errors will only cause this */
  668. //* function to abort if none of the disk drives in the system could be */
  669. //* successfully read. */
  670. //* */
  671. //* Side Effects: The LVM Engine will be initialized. The partition tables for all OS2DASD */
  672. //* controlled disk drives will be read into memory. Memory will be allocated for */
  673. //* the data structures used by the LVM Engine. */
  674. //* */
  675. //* Notes: New in LVM Version 2 */
  676. //* */
  677. //****************************************************************************************************/
  678. {$ifdef lvm2}
  679. procedure Open_LVM_Engine2(Ignore_CHS: BOOLEAN; Interface_Type: LVM_Interface_Types; Error_Code: PCARDINAL32); external 'lvm' name 'Open_LVM_Engine2';
  680. {$endif}
  681. //*********************************************************************/
  682. //* */
  683. //* Function Name: Commit_Changes */
  684. //* */
  685. //* Descriptive Name: Saves any changes made to the partitioning */
  686. //* information of the OS2DASD controlled disk */
  687. //* drives in the system. */
  688. //* */
  689. //* Input: CARDINAL32 * Error_Code - The address of a CARDINAL32 in */
  690. //* in which to store an error code */
  691. //* should an error occur. */
  692. //* */
  693. //* Output: The function return value will be TRUE if all of the */
  694. //* partitioning/volume changes made were successfully */
  695. //* written to disk. Also, *Error_Code will be 0 if no */
  696. //* errors occur. */
  697. //* */
  698. //* If an error occurs, then the furnction return value */
  699. //* will be FALSE and *Error_Code will contain a non-zero */
  700. //* error code. */
  701. //* */
  702. //* Error Handling: If an error occurs, the function return value */
  703. //* will be false and *Error_Code will be > 0. */
  704. //* */
  705. //* Disk read and write errors will be indicated by*/
  706. //* setting the IO_Error field of the */
  707. //* Drive_Information_Record to TRUE. Thus, if */
  708. //* the function return value is FALSE, and */
  709. //* *Error_Code indicates an I/O error, the caller */
  710. //* of this function should call the */
  711. //* Get_Drive_Status function on each drive to */
  712. //* determine which drives had I/O errors. */
  713. //* */
  714. //* If a read or write error occurs, then the */
  715. //* engine may not have been able to create a */
  716. //* partition or volume. Thus, the caller */
  717. //* may want to refresh all partition and volume */
  718. //* data to see what the engine was and was not */
  719. //* able to create. */
  720. //* */
  721. //* Side Effects: The partitioning information of the disk drives */
  722. //* in the system may be altered. */
  723. //* */
  724. //* Notes: None. */
  725. //* */
  726. //*********************************************************************/
  727. function Commit_Changes(Error_Code: PCARDINAL32): BOOLEAN; external 'lvm' name 'Commit_Changes';
  728. //*********************************************************************/
  729. //* */
  730. //* Function Name: Set_Java_Call_Back */
  731. //* */
  732. //* Descriptive Name: This function allows the calling Java program */
  733. //* to set the call back address. The call back */
  734. //* address is used when the LVM Engine or one of */
  735. //* its plug-ins, needs to run a Java class to */
  736. //* gather information from the user. */
  737. //* */
  738. //* Input: void ( * Execute_Java_Class) ... - The address of a */
  739. //* function that the LVM */
  740. //* engine may call when */
  741. //* it needs a Java class */
  742. //* to be executed. This */
  743. //* is only required if the*/
  744. //* user interface being */
  745. //* used is written in Java*/
  746. //* CARDINAL32 * Error_Code - The address of a CARDINAL32 in */
  747. //* in which to store an error code */
  748. //* should an error occur. */
  749. //* */
  750. //* Output: If the function completes successfully, then *Error_Code*/
  751. //* will be set to LVM_ENGINE_NO_ERROR. Otherwise, */
  752. //* *Error_Code will be set to a non-zero error code. */
  753. //* */
  754. //* Error Handling: If an error occurs, the function will abort and*/
  755. //* *Error_Code will be set to a non-zero error */
  756. //* code. */
  757. //* */
  758. //* Side Effects: The Java call back address is set to point to the*/
  759. //* specified function. Once the Java call back */
  760. //* address is set, LVM plug-ins which require the */
  761. //* Java call back will be enabled and can be used */
  762. //* during the creation of LVM Volumes. */
  763. //* */
  764. //* Notes: If a Java interface is in use (as specified on the */
  765. //* Open_LVM_Engine call), then this function must be called*/
  766. //* in order to enable those LVM plug-ins which require */
  767. //* initialization information during the creation of an */
  768. //* LVM Volume. If these plug-ins are not enabled, then */
  769. //* they will not be reported by the Get_Available_Features */
  770. //* API, nor can they be used or accessed by any other LVM */
  771. //* Engine APIs. Thus, this function should be called */
  772. //* immediately after the Open_LVM_Engine API is called. */
  773. //* */
  774. //*********************************************************************/
  775. {$ifdef lvm2}
  776. type
  777. TJavaExecProc=procedure(
  778. Class_Name: PChar;
  779. InputBuffer: ADDRESS;
  780. InputBufferSize: CARDINAL32;
  781. OutputBuffer: PADDRESS;
  782. OutputBufferSize,
  783. Error_Code: PCARDINAL32);
  784. procedure Set_Java_Call_Back(
  785. Execute_Java_Class: TJAvaExecProc;
  786. Error_Code: PCARDINAL32); external 'lvm' name 'Set_Java_Call_Back';
  787. {$endif}
  788. //*********************************************************************/
  789. //* */
  790. //* Function Name: Close_LVM_Engine */
  791. //* */
  792. //* Descriptive Name: Closes the LVM Engine and frees any memory */
  793. //* held by the LVM Engine. */
  794. //* */
  795. //* Input: None. */
  796. //* */
  797. //* Output: None. */
  798. //* */
  799. //* Error Handling: N/A */
  800. //* */
  801. //* Side Effects: Any memory held by the LVM Engine is released. */
  802. //* */
  803. //* Notes: None. */
  804. //* */
  805. //*********************************************************************/
  806. procedure Close_LVM_Engine; external 'lvm' name 'Close_LVM_Engine';
  807. //*********************************************************************/
  808. //*…