xboxscene.org forums

Author Topic: Lba48 Custom Partitioning - Oz_paulb, Help!  (Read 121 times)

DarkManX4lf

  • Archived User
  • Jr. Member
  • *
  • Posts: 97
Lba48 Custom Partitioning - Oz_paulb, Help!
« on: January 30, 2004, 08:59:00 PM »

has anyone had any new developments on this? This is what ive been looking for, trying to resize the partitions.
Logged

DarkManX4lf

  • Archived User
  • Jr. Member
  • *
  • Posts: 97
Lba48 Custom Partitioning - Oz_paulb, Help!
« Reply #1 on: January 31, 2004, 06:14:00 AM »

anyone?
Logged

DarkManX4lf

  • Archived User
  • Jr. Member
  • *
  • Posts: 97
Lba48 Custom Partitioning - Oz_paulb, Help!
« Reply #2 on: January 31, 2004, 10:32:00 AM »

bump
Logged

DarkManX4lf

  • Archived User
  • Jr. Member
  • *
  • Posts: 97
Lba48 Custom Partitioning - Oz_paulb, Help!
« Reply #3 on: January 31, 2004, 06:06:00 PM »

bump again
Logged

Softco

  • Archived User
  • Newbie
  • *
  • Posts: 36
Lba48 Custom Partitioning - Oz_paulb, Help!
« Reply #4 on: September 29, 2003, 06:13:00 PM »

I think that this would be a great feature, and in XBTool, you could define the sizes of certain drives.  I would use G for games, F for apps, E for the XDK, and H for GentooX! w00t w00t!
Logged

oz_paulb

  • Recovered User
  • Full Member
  • *
  • Posts: 172
Lba48 Custom Partitioning - Oz_paulb, Help!
« Reply #5 on: September 29, 2003, 06:30:00 PM »

QUOTE (SilntBob @ Sep 30 2003, 03:03 AM)
Okay, this question has been asked in a couple of places, but mostly in threads where it is a bit off-topic and hasn't gotten the attention it needs.

Looking at XBtool and speaking with the author, XBtool will first look at the hard drive to get partition table information.

So there MUST be some sort of way to modify a partition table and make partitions 6 and 7 (drives F and G) specific sizes.  I need to know if there is either a manual way to safely modify the partition table or if there is a tool somewhere out there to let us do it.

Instead of trying to explain the motivation for this, I will just quote from one of the other threads.....

Thanks

Hi -

Sorry, I haven't really had time to be actively involved in this stuff recently.

I've never really documented how to create a 'partition table' on the hard drive (which is recognized by the LBA48 patch, unless you check the 'ignore hard drive partition table' option).  I've also intended to release tools to help make the partition table-editing process easier.

But, I haven't done this so far.  Again, I'm sorry - I've really just been too busy at my job.

I'll try to release something soon - it may not be 'polished' (for time reasons), but it may be enough for someone else to clean-up/turn into a working utility.

- Paulb

Logged

SilntBob

  • Archived User
  • Newbie
  • *
  • Posts: 6
Lba48 Custom Partitioning - Oz_paulb, Help!
« Reply #6 on: September 29, 2003, 08:29:00 PM »

Softco, I believe that there is currently only support in Evox for the "G" drive as partition 7, and as far as I know, Gentoox needs the F drive to be partition 6, so from that respect, you wouldn't have the ability to make separate drives for different functions (nor would you really want to)  The main motivating factor for customizing the size of F vs. G is that when you allow Gentoox to use the F drive as a "native" format, the F drive and all data on it becomes inaccessible to everything other than Gentoox.

Additionally, in my e-mail conversation with the author of XBtool, it is apparently oz_paulb's excellent BIOS patch which defines the partition sizing options,  XBtool is simply a vehicle for applying that patch, thus he does not have much control over the settings.   That might be a possible option for oz_paulb to incorporate into a future version of XBFlash, but he would have to answer on that one.


oz_paulb:  Thank you for all that you have done and thank you for your quick response to my plea for help even though you are busy.  I don't really know what is involved in creating a custom partition table, but I will take whatever information I can get and try to make sense of it.  I am sure that there are others here who would be willing to contribute their time and brainpower to whatever rough nuggets of information or code you can pass our way....Thanks.
Logged

NghtShd

  • Archived User
  • Full Member
  • *
  • Posts: 192
Lba48 Custom Partitioning - Oz_paulb, Help!
« Reply #7 on: September 29, 2003, 10:53:00 PM »

I took a quick peek at Paul's lba48 code, it appears that it takes your chosen partition scheme and intelligently fills in the blanks to give you a proper partition table for your disk. It wouldn't be a good idea to mess with that. It all seems to be working well as it is.

Besides, since the partition table applies to disks, not BIOS's it makes more sense to have the table on the disk it goes with when we start doing custom partitioning schemes. The built-in partition options are fine for getting started, but you should ultimately be able to partition and format your drives with software, and not need to bother with flashing new firmware to change the partition setup.
Logged

oz_paulb

  • Recovered User
  • Full Member
  • *
  • Posts: 172
Lba48 Custom Partitioning - Oz_paulb, Help!
« Reply #8 on: September 30, 2003, 04:08:00 AM »

QUOTE (NghtShd @ Sep 30 2003, 07:53 AM)
I took a quick peek at Paul's lba48 code, it appears that it takes your chosen partition scheme and intelligently fills in the blanks to give you a proper partition table for your disk. It wouldn't be a good idea to mess with that. It all seems to be working well as it is.

Besides, since the partition table applies to disks, not BIOS's it makes more sense to have the table on the disk it goes with when we start doing custom partitioning schemes. The built-in partition options are fine for getting started, but you should ultimately be able to partition and format your drives with software, and not need to bother with flashing new firmware to change the partition setup.

I agree - custom partition tables belong on the drive (not in the BIOS).  The LBA48 patch code creates a 'default partition table' in memory if there isn't one on the drive, but any further customizations should be done via a partition table on the hard drive.

- Paulb
Logged

oz_paulb

  • Recovered User
  • Full Member
  • *
  • Posts: 172
Lba48 Custom Partitioning - Oz_paulb, Help!
« Reply #9 on: September 30, 2003, 07:04:00 AM »

Since I'm not sure when I'll get to this, below is a piece of code that'll read the 'active partition table' from the LBA48 code (the 'active' table is either the 'default' one, or the one read from the hard drive (if there was one)).  Hopefully, a developer out there can throw together some simple partitioning utilities.

There's also some #ifdef'd-out code that shows the general structure of a partition table.

If you write a partition table to the first sector of the hard drive (byte offset 0), it'll be recognized by the LBA48 code and used instead of the 'default' (assuming you haven't checked the 'ignore hard drive partition table' option in Xbtool).

Keep in mind that the 'default' partition table that's created by the LBA48 code is built-up knowing the size of your hard drive.  If you're creating a partition table to put onto the boot sector of the hard drive, you may want to start with the code below, read the 'active/default' partition table from memory, make your changes, then write it to the boot sector.  The next reboot will use that partition table instead.

Also keep in mind that just changing the partition table doesn't actually change the data in the partitions - you can't (for example) move/resize the "E:" partition just by changing the partition table.  You should first backup E: (and any other partitions that may be affected by a move/re-size of E:), then change your partition table, reboot, re-format E:, and then restore all of the backed-up files.

Moving/resizing existing partitions "in place" is very complicated - programs like 'Partition Magic' exist on the PC for this.  There's nothing similar for Xbox right now.

I hope this info helps.  I'll try to get some simple utilities thrown together soon, but in the meantime, maybe someone else can use this info.

- Paulb


CODE
#include

extern "C" {
#define   STATUS_SUCCESS   0
#define   STATUS_UNSUCCESSFUL   -1

   typedef ULONG   ACCESS_MASK;
   typedef struct tagANSI_STRING {
 unsigned short   Length;
 unsigned short   MaximumLength;
 PCHAR   Buffer;
   } ANSI_STRING;

   typedef struct tagOBJECT_ATTRIBUTES {
 HANDLE   RootDirectory;
 ANSI_STRING   *ObjectName;
 ULONG   Attributes;
   } OBJECT_ATTRIBUTES;
#define   OBJ_CASE_INSENSITIVE   0x00000040

   typedef struct tagIO_STATUS_BLOCK {
 union {
    unsigned int   Status;
    PVOID   Pointer;
 } u1;
 ULONG_PTR   Information;
   } IO_STATUS_BLOCK;

   extern unsigned int WINAPI NtDeviceIoControlFile(HANDLE handle, HANDLE event, PVOID pApcRoutine, PVOID pApcContext, IO_STATUS_BLOCK *pIoStatusBlock, ULONG IoControlCode, PVOID pInBuf, ULONG InBufLen, PVOID pOutBuf, ULONG OutBufLen);

   extern unsigned int WINAPI NtCreateFile(HANDLE *pHandle, ACCESS_MASK DesiredAccess, OBJECT_ATTRIBUTES *pObjectAttributes, IO_STATUS_BLOCK *pIOStatusBlock, ULONG ShareAccess, ULONG CreateDisposition, ULONG CreateOptions);
   extern unsigned int WINAPI NtOpenFile(HANDLE *pHandle, ACCESS_MASK DesiredAccess, OBJECT_ATTRIBUTES *pObjectAttributes, IO_STATUS_BLOCK *pIOStatusBlock, ULONG ShareAccess, ULONG OpenOptions);
   extern unsigned int WINAPI NtReadFile(HANDLE Handle, HANDLE Event, PVOID pApcRoutine, PVOID pApcContext, PVOID pIoStatusBlock, PVOID pBuffer, ULONG Length, PLARGE_INTEGER pByteOffset);
   extern unsigned int WINAPI NtWriteFile(HANDLE Handle, HANDLE Event, PVOID pApcRoutine, PVOID pApcContext, PVOID pIoStatusBlock, PVOID pBuffer, ULONG Length, PLARGE_INTEGER pByteOffset);
   extern unsigned int WINAPI NtClose(HANDLE Handle);

   extern unsigned int WINAPI MmMapIoSpace(unsigned int, unsigned int, unsigned int);
   extern void WINAPI MmUnmapIoSpace(unsigned int, unsigned int);
   extern void WINAPI HalInitiateShutdown(void);
   extern void WINAPI HalWriteSMBusValue(unsigned int, unsigned int, unsigned int, unsigned int);
   extern void *XboxHDKey;
   extern void *LaunchDataPage;
   extern void WINAPI HalReturnToFirmware(unsigned int);
   extern void WINAPI RtlInitAnsiString(void *destp, void *srcp);
}


#define     MAX_PARTITIONS     14

typedef struct tagPARTITION_ENTRY {
   char   pe_name[16];
   unsigned long   pe_flags;   // bitmask
   unsigned long   pe_lba_start;
   unsigned long   pe_lba_size;
   unsigned long   pe_reserved;
} PARTITION_ENTRY;


// This flag (part of PARTITION_ENTRY.pe_flags) tells you whether/not a
// partition is being used (whether/not drive G is active, for example)
#define   PE_PARTFLAGS_IN_USE   0x80000000

typedef struct tagPARTITION_TABLE {
   char   pt_magic[16];
   unsigned char   pt_reserved[32];
   PARTITION_ENTRY   pt_entries[MAX_PARTITIONS];
} PARTITION_TABLE;


#define   IOCTL_CMD_LBA48_ACCESS   0xcafebabe
#define   IOCTL_SUBCMD_GET_INFO   0

#define   LBA48_GET_INFO_MAGIC1_IDX   0
#define   LBA48_GET_INFO_MAGIC1_VAL   0xcafebabe
#define   LBA48_GET_INFO_MAGIC2_IDX   1
#define   LBA48_GET_INFO_MAGIC2_VAL   0xbabeface
#define   LBA48_GET_INFO_PATCHCODE_VERSION_IDX   2
#define   LBA48_GET_INFO_LOWCODE_BASE_IDX  3
#define   LBA48_GET_INFO_HIGHCODE_BASE_IDX   4
#define   LBA48_GET_INFO_PATCHSEG_SIZE_IDX   5
#define   LBA48_GET_INFO_PART_TABLE_OFS_IDX   6

unsigned int
read_active_partition_table(PARTITION_TABLE *p_table)
{
   ANSI_STRING   a_file;
   OBJECT_ATTRIBUTES   obj_attr;
   IO_STATUS_BLOCK   io_stat_block;
   HANDLE   handle;
   unsigned int   stat;
   unsigned int   ioctl_cmd_in_buf[100];
   unsigned int   ioctl_cmd_out_buf[100];
   unsigned int   partition_table_addr;

   memset(p_table, 0, sizeof(PARTITION_TABLE));

   RtlInitAnsiString(&a_file, "\\Device\\Harddisk0\\partition0");
   obj_attr.RootDirectory = 0;
   obj_attr.ObjectName = &a_file;
   obj_attr.Attributes = OBJ_CASE_INSENSITIVE;

   stat = NtOpenFile(&handle, (GENERIC_READ|0x00100000),
    &obj_attr, &io_stat_block, (FILE_SHARE_READ|FILE_SHARE_WRITE), 0x10);

   if (stat != STATUS_SUCCESS) {
 return stat;
   }

   memset(ioctl_cmd_in_buf, 0, sizeof(ioctl_cmd_in_buf));
   ioctl_cmd_in_buf[0] = IOCTL_SUBCMD_GET_INFO;

   memset(ioctl_cmd_out_buf, 0, sizeof(ioctl_cmd_out_buf));

   stat = NtDeviceIoControlFile(handle, 0, 0, 0, &io_stat_block,
 IOCTL_CMD_LBA48_ACCESS,
 ioctl_cmd_in_buf, sizeof(ioctl_cmd_in_buf),
 ioctl_cmd_out_buf, sizeof(ioctl_cmd_out_buf));

   NtClose(handle);
   if (stat != STATUS_SUCCESS) {
 return stat;
   }

   if ((ioctl_cmd_out_buf[LBA48_GET_INFO_MAGIC1_IDX] != LBA48_GET_INFO_MAGIC1_VAL) ||
 (ioctl_cmd_out_buf[LBA48_GET_INFO_MAGIC2_IDX] != LBA48_GET_INFO_MAGIC2_VAL)) {

 return STATUS_UNSUCCESSFUL;
   }

   partition_table_addr = ioctl_cmd_out_buf[LBA48_GET_INFO_LOWCODE_BASE_IDX];
   partition_table_addr += ioctl_cmd_out_buf[LBA48_GET_INFO_PART_TABLE_OFS_IDX];

   memcpy(p_table, (void *)partition_table_addr, sizeof(PARTITION_TABLE));

   return STATUS_SUCCESS;
}


#if   0
//
// Xbox standard partition definitions
//

#define   XBOX_SWAPPART1_LBA_START   0x400
#define   XBOX_SWAPPART_LBA_SIZE  0x177000
#define   XBOX_SWAPPART2_LBA_START   (XBOX_SWAPPART1_LBA_START + XBOX_SWAPPART_LBA_SIZE)
#define   XBOX_SWAPPART3_LBA_START   (XBOX_SWAPPART2_LBA_START + XBOX_SWAPPART_LBA_SIZE)

#define   XBOX_SYSPART_LBA_START  (XBOX_SWAPPART3_LBA_START + XBOX_SWAPPART_LBA_SIZE)
#define   XBOX_SYSPART_LBA_SIZE  0xfa000

#define   XBOX_MUSICPART_LBA_START   (XBOX_SYSPART_LBA_START + XBOX_SYSPART_LBA_SIZE)
#define   XBOX_MUSICPART_LBA_SIZE  0x9896b0

#define   XBOX_STANDARD_MAX_LBA  (XBOX_MUSICPART_LBA_START + XBOX_MUSICPART_LBA_SIZE)

#define   MAX_LBA28_SECTOR  0xfffffff

// The following is read from the drive at boot-up time.  I've just
// put my 200GB Maxtor's size here as a default
#define   MY_DRIVE_LBA48_SIZE  0x17bd8800   // 200GB Maxtor

PARTITION_TABLE     Partition_table = {
   {'*','*','*','*','P','A','R','T','I','N','F','O','*','*','*','*'},
   {0},

   {
   { {'X','B','O','X',' ','M','U','S','I','C',' ',' ',' ',' ',' ',' '},
 PE_PARTFLAGS_IN_USE,
 XBOX_MUSICPART_LBA_START,XBOX_MUSICPART_LBA_SIZE,0 },
   { {'X','B','O','X',' ','S','Y','S','T','E','M',' ',' ',' ',' ',' '},
 PE_PARTFLAGS_IN_USE,
 XBOX_SYSPART_LBA_START,XBOX_SYSPART_LBA_SIZE,0 },
   { {'X','B','O','X',' ','G','A','M','E',' ','S','W','A','P',' ','1'},
 PE_PARTFLAGS_IN_USE,
 XBOX_SWAPPART1_LBA_START,XBOX_SWAPPART_LBA_SIZE,0 },
   { {'X','B','O','X',' ','G','A','M','E',' ','S','W','A','P',' ','2'},
 PE_PARTFLAGS_IN_USE,
 XBOX_SWAPPART2_LBA_START,XBOX_SWAPPART_LBA_SIZE,0 },
   { {'X','B','O','X',' ','G','A','M','E',' ','S','W','A','P',' ','3'},
 PE_PARTFLAGS_IN_USE,
 XBOX_SWAPPART3_LBA_START,XBOX_SWAPPART_LBA_SIZE,0 },
   { {'D','R','I','V','E',' ','F',':',' ',' ',' ',' ',' ',' ',' ',' '},
 PE_PARTFLAGS_IN_USE,
 XBOX_STANDARD_MAX_LBA, (MAX_LBA28_SECTOR-XBOX_STANDARD_MAX_LBA),0 },
   { {'D','R','I','V','E',' ','G',':',' ',' ',' ',' ',' ',' ',' ',' '},
 PE_PARTFLAGS_IN_USE,
 MAX_LBA28_SECTOR, (MY_DRIVE_LBA48_SIZE-MAX_LBA28_SECTOR),0 },
   { {' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '},
 0,0,0,0 },
   { {' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '},
 0,0,0,0 },
   { {' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '},
 0,0,0,0 },
   { {' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '},
 0,0,0,0 },
   { {' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '},
 0,0,0,0 },
   { {' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '},
 0,0,0,0 },
   { {' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '},
 0,0,0,0 },
   },
};

#endif
Logged

oz_paulb

  • Recovered User
  • Full Member
  • *
  • Posts: 172
Lba48 Custom Partitioning - Oz_paulb, Help!
« Reply #10 on: September 30, 2003, 07:06:00 AM »

One more thing: when reading a partition table, be sure to check the partition flags for 'PE_PARTFLAGS_IN_USE' being set.  If it's not set, then that particular partition entry is invalid.

Of course, when creating a new partition table, be sure to set 'PE_PARTFLAGS_IN_USE' as appropriate.

- Paulb
Logged

SilntBob

  • Archived User
  • Newbie
  • *
  • Posts: 6
Lba48 Custom Partitioning - Oz_paulb, Help!
« Reply #11 on: September 30, 2003, 08:34:00 AM »

Thanks PaulB, I'll start working through the code to see what I can figure out.

I knew from the begining that trying to accomplish any sort of "partition magic" style of utility would be more trouble than it is worth.  I have always assumed that this would be like the old fdisk/format options from the early DOS days, but even that is fine with me.

And after thinking about it more, I agree that it makes much more sense to change partitioning info on the drive vs. in the BIOS, I was being tunnel visioned, looking for a quick solution when I thought about that previously.

Thanks.

Logged

SilntBob

  • Archived User
  • Newbie
  • *
  • Posts: 6
Lba48 Custom Partitioning - Oz_paulb, Help!
« Reply #12 on: October 04, 2003, 12:16:00 PM »

Well, PaulB I have been working through your code....while I have done software development, I have never written any XBox programs....this probably isn't the place for me to start.

I will continue working on it, but for the time being, I will probably have to wait until you have the time to finish writing the partitioning tool you talked about.

Thanks for your help.
Logged