KolibriOS kernel
disk.inc File Reference

Classes

struct  DISKFUNC
 ============================================================================= More...
 
struct  DISKMEDIAINFO
 This structure holds information on a medium. Objects with this structure are allocated by the kernel as a part of the DISK structure and are filled by a driver in the 'querymedia' callback. More...
 
struct  DISKCACHE
 This structure represents the disk cache. To follow the old implementation, there are two distinct caches for a disk, one for "system" data,and the other for "application" data. More...
 
struct  DISK
 This structure represents a disk device and its media for the kernel. This structure is allocated by the kernel in the 'disk_add' function, freed in the 'disk_dereference' function. More...
 
struct  PARTITION
 This structure represents one partition for the kernel. This is a base template, the actual contents after common fields is determined by the file system code for this partition. More...
 
struct  PARTITION_TABLE_ENTRY
 This is an external structure, it represents an entry in the partition table. More...
 
struct  GPTH
 GUID Partition Table Header, UEFI 2.6, Table 18. More...
 
struct  GPE
 GPT Partition Entry, UEFI 2.6, Table 19. More...
 

Functions

void disk_scan_gpt ()
 This function is called from disk_scan_partitions to validate and parse primary and backup GPTs. More...
 
void scan_gpt (qword _mylba)
 This function is called from disk_scan_gpt to process a single GPT. More...
 
void disk_add_partition (qword start, qword length, dword disk)
 This is an internal function called from disk_scan_partitions and process_partition_table_entry. It adds one partition to the list of partitions for the media. Important note: start, length, disk MUST be present and MUST be in the same order as in PARTITION structure. esi duplicates [disk]. More...
 
void default_fs_get_file_info ()
 

Variables

label disk_list
 The pseudo-item for the list of all DISK structures. Initialized to the empty list. More...
 
MUTEX disk_list_mutex
 This mutex guards all operations with the global list of DISK structures. More...
 
dd partition_buffer_users
 The function 'disk_scan_partitions' needs three sector-sized buffers for MBR, bootsector and fs-temporary sector data. It can not use the static buffers always, since it can be called for two or more disks in parallel. However, this case is not typical. We reserve three static 512-byte buffers and a flag that these buffers are currently used. If 'disk_scan_partitions' detects that the buffers are currently used, it allocates buffers from the heap. Also, the heap is used when sector size is other than 512. The flag is implemented as a global dword variable. When the static buffers are not used, the value is -1. When the static buffers are used, the value is normally 0 and temporarily can become greater. The function increments this value. If the resulting value is zero, it uses the buffers and decrements the value when the job is done. Otherwise, it immediately decrements the value and uses buffers from the heap, allocated in the beginning and freed in the end. More...
 
rb mbr_buffer
 The static buffers for MBR, bootsector and fs-temporary sector data. More...
 
rb bootsect_buffer
 
rb fs_tmp_buffer
 
label disk_default_callbacks
 This is the array of default implementations of driver callbacks. Same as DRIVERFUNC structure except for the first field; all functions must have the default implementations. More...
 
label disk_add
 This function registers a disk device. This includes: More...
 
label disk_del
 This function deletes a disk device from the global filesystem. This includes: More...
 
label disk_dereference
 This is an internal function which removes a previously obtained reference to the disk. If this is the last reference, this function lets the driver finalize all associated data, and afterwards frees the DISK structure. esi = pointer to DISK structure. More...
 
label disk_media_dereference
 This is an internal function which removes a previously obtained reference to the media. If this is the last reference, this function calls 'closemedia' callback to signal the driver that the processing has finished and it is safe to inform about a new media. esi = pointer to DISK structure. More...
 
label disk_media_changed
 This function is called by the driver and informs the kernel that the media has changed. If the media is non-removable, it is called exactly once immediately after 'disk_add' and once from 'disk_del'. Parameters: [esp+4] = handle of the disk, i.e. the pointer to the DISK structure. [esp+8] = new status of the media: zero = no media, nonzero = media inserted. More...
 
label disk_call_driver
 This function is a thunk for all functions of a disk driver. It checks whether the referenced function is implemented in the driver. If so, this function jumps to the function in the driver. Otherwise, it jumps to the default implementation. al = offset of function in the DISKFUNC structure; esi = pointer to the DISK structure; stack is the same as for the corresponding function except that the first parameter (void* userdata) is prepended automatically. More...
 
label disk_default_querymedia
 The default implementation of DISKFUNC.querymedia. More...
 
label disk_default_read
 The default implementation of DISKFUNC.read and DISKFUNC.write. More...
 
label disk_default_write
 
label disk_default_close
 The default implementation of DISKFUNC.close, DISKFUNC.closemedia and DISKFUNC.flush. More...
 
label disk_default_closemedia
 
label disk_default_flush
 
label disk_default_adjust_cache_size
 The default implementation of DISKFUNC.adjust_cache_size. More...
 
label disk_scan_partitions
 This is an internal function called from 'disk_media_changed' when a new media is detected. It creates the list of partitions for the media. If media is not partitioned, then the list consists of one partition which covers all the media. esi = pointer to the DISK structure. More...
 
dd GPEA_len
 Length of GPT Partition Entry Array in bytes. More...
 
label is_protective_mbr
 ecx = pointer to partition records array (MBR + 446) More...
 
label is_partition_table_entry
 This is an internal function called from disk_scan_partitions. It checks whether the entry pointed to by ecx is a valid entry of partition table. The entry is valid if the first byte is 0 or 80h, the first sector plus the length is less than twice the size of media. Multiplication by two is required since the size mentioned in the partition table can be slightly greater than the real size. More...
 
label process_partition_table_entry
 This is an internal function called from disk_scan_partitions. It processes the entry pointed to by ecx. If the entry is invalid, just ignore this entry. If the type is zero, just ignore this entry. If the type is one of types for extended partition, store the address of this partition as the new MBR in [esp+4]. Otherwise, add the partition to the list of partitions for this disk. We don't use the type from the entry to identify the file system; fs-specific checks do this more reliably. More...
 
type irp
 
  1. Check for extended partition. If extended, go to 6. Old Multiuser DOS secured: extended partition
More...
 
label disk_detect_partition
 This is an internal function called from disk_add_partition. It tries to recognize the file system on the partition and allocates the corresponding PARTITION structure with filesystem-specific fields. More...
 
dq _start
 
dq _length
 
dd _disk
 
label default_fs_functions
 
label default_fs_functions_end
 
label dyndisk_handler
 This function is called from file_system_lfn. This handler gets the control each time when fn 70 is called with unknown item of root subdirectory. in: esi = ebp -> path string out: if the handler processes path, it must not return in file_system_lfn, but instead pop return address and return directly to the caller otherwise simply return. More...
 
label fs_dyndisk_next
 This is a callback for enumerating partitions called from file_system_lfn.maindir in the case of inserted media. It just increments eax until DISK.NumPartitions reached and then cleans up. More...
 
label fs_dyndisk_next_nomedia
 This is a callback for enumerating partitions called from file_system_lfn.maindir in the case of missing media. In this case we create one pseudo-partition. More...
 
label dyndisk_enum_root
 This function is called from file_system_lfn. This handler is called when virtual root is enumerated and must return all items which can be handled by this. It is called several times, first time with eax=0 in: eax = 0 for first call, previously returned value for subsequent calls out: eax = 0 => no more items eax != 0 => buffer pointed to by edi contains name of item. More...
 
label eject_disk_media
 void fastcall eject_disk_media(const char* str, uint32_t code); for load/eject drive ecx -> asciiz string disk name (sd0, usbhd0) edx = code command(0 - LoadTray 1-EjectTray) More...
 

Function Documentation

◆ default_fs_get_file_info()

void default_fs_get_file_info ( )

◆ disk_add_partition()

void disk_add_partition ( qword  start,
qword  length,
dword  disk 
)

This is an internal function called from disk_scan_partitions and process_partition_table_entry. It adds one partition to the list of partitions for the media. Important note: start, length, disk MUST be present and MUST be in the same order as in PARTITION structure. esi duplicates [disk].

Source
blkdev/disk.inc:1138

◆ disk_scan_gpt()

void disk_scan_gpt ( )

This function is called from disk_scan_partitions to validate and parse primary and backup GPTs.

Source
blkdev/disk.inc:858

◆ scan_gpt()

void scan_gpt ( qword  _mylba)

This function is called from disk_scan_gpt to process a single GPT.

Source
blkdev/disk.inc:884

Variable Documentation

◆ _disk

dd _disk
Initial value
?
Source
blkdev/disk.inc:1243

◆ _length

dq _length
Initial value
?
Source
blkdev/disk.inc:1242

◆ _start

dq _start
Initial value
?
Source
blkdev/disk.inc:1241

◆ bootsect_buffer

rb bootsect_buffer
Initial value
512
Source
blkdev/disk.inc:348

◆ default_fs_functions

label default_fs_functions

◆ default_fs_functions_end

label default_fs_functions_end

◆ disk_add

label disk_add

This function registers a disk device. This includes:

  • allocating an internal structure describing this device;
  • registering this structure in the global filesystem. The function initializes the disk as if there is no media. If a media is present, the function 'disk_media_changed' should be called after this function succeeds. Parameters: [esp+4] = pointer to DISKFUNC structure with the callbacks [esp+8] = pointer to name (ASCIIZ string) [esp+12] = userdata to be passed to the callbacks as is. [esp+16] = flags, bitfield. Currently only DISK_NO_INSERT_NOTIFICATION bit is defined. Return value: NULL = operation has failed non-NULL = handle of the disk. This handle can be used in the operations with other Disk* functions. The handle is the pointer to the internal structure DISK.
    Source
    blkdev/disk.inc:389

◆ disk_call_driver

label disk_call_driver

This function is a thunk for all functions of a disk driver. It checks whether the referenced function is implemented in the driver. If so, this function jumps to the function in the driver. Otherwise, it jumps to the default implementation. al = offset of function in the DISKFUNC structure; esi = pointer to the DISK structure; stack is the same as for the corresponding function except that the first parameter (void* userdata) is prepended automatically.

Source
blkdev/disk.inc:643

◆ disk_default_adjust_cache_size

label disk_default_adjust_cache_size

The default implementation of DISKFUNC.adjust_cache_size.

Source
blkdev/disk.inc:683

◆ disk_default_callbacks

label disk_default_callbacks

This is the array of default implementations of driver callbacks. Same as DRIVERFUNC structure except for the first field; all functions must have the default implementations.

Source
blkdev/disk.inc:357

◆ disk_default_close

label disk_default_close

The default implementation of DISKFUNC.close, DISKFUNC.closemedia and DISKFUNC.flush.

Source
blkdev/disk.inc:676

◆ disk_default_closemedia

label disk_default_closemedia

◆ disk_default_flush

label disk_default_flush

◆ disk_default_querymedia

label disk_default_querymedia

The default implementation of DISKFUNC.querymedia.

Source
blkdev/disk.inc:664

◆ disk_default_read

label disk_default_read

The default implementation of DISKFUNC.read and DISKFUNC.write.

Source
blkdev/disk.inc:669

◆ disk_default_write

label disk_default_write

◆ disk_del

label disk_del

This function deletes a disk device from the global filesystem. This includes:

  • removing a media including all partitions;
  • deleting this structure from the global filesystem;
  • dereferencing the DISK structure and possibly destroying it. Parameters: [esp+4] = handle of the disk, i.e. the pointer to the DISK structure. Return value: none.
    Source
    blkdev/disk.inc:472

◆ disk_dereference

label disk_dereference

This is an internal function which removes a previously obtained reference to the disk. If this is the last reference, this function lets the driver finalize all associated data, and afterwards frees the DISK structure. esi = pointer to DISK structure.

Source
blkdev/disk.inc:501

◆ disk_detect_partition

label disk_detect_partition

This is an internal function called from disk_add_partition. It tries to recognize the file system on the partition and allocates the corresponding PARTITION structure with filesystem-specific fields.

Source
blkdev/disk.inc:1236

◆ disk_list

label disk_list

The pseudo-item for the list of all DISK structures. Initialized to the empty list.

Source
blkdev/disk.inc:278

◆ disk_list_mutex

MUTEX disk_list_mutex

This mutex guards all operations with the global list of DISK structures.

Initial value
Source
blkdev/disk.inc:284

◆ disk_media_changed

label disk_media_changed

This function is called by the driver and informs the kernel that the media has changed. If the media is non-removable, it is called exactly once immediately after 'disk_add' and once from 'disk_del'. Parameters: [esp+4] = handle of the disk, i.e. the pointer to the DISK structure. [esp+8] = new status of the media: zero = no media, nonzero = media inserted.

Source
blkdev/disk.inc:581

◆ disk_media_dereference

label disk_media_dereference

This is an internal function which removes a previously obtained reference to the media. If this is the last reference, this function calls 'closemedia' callback to signal the driver that the processing has finished and it is safe to inform about a new media. esi = pointer to DISK structure.

Source
blkdev/disk.inc:527

◆ disk_scan_partitions

label disk_scan_partitions

This is an internal function called from 'disk_media_changed' when a new media is detected. It creates the list of partitions for the media. If media is not partitioned, then the list consists of one partition which covers all the media. esi = pointer to the DISK structure.

Source
blkdev/disk.inc:692

◆ dyndisk_enum_root

label dyndisk_enum_root

This function is called from file_system_lfn. This handler is called when virtual root is enumerated and must return all items which can be handled by this. It is called several times, first time with eax=0 in: eax = 0 for first call, previously returned value for subsequent calls out: eax = 0 => no more items eax != 0 => buffer pointed to by edi contains name of item.

Source
blkdev/disk.inc:1680

◆ dyndisk_handler

label dyndisk_handler

This function is called from file_system_lfn. This handler gets the control each time when fn 70 is called with unknown item of root subdirectory. in: esi = ebp -> path string out: if the handler processes path, it must not return in file_system_lfn, but instead pop return address and return directly to the caller otherwise simply return.

Source
blkdev/disk.inc:1377

◆ eject_disk_media

label eject_disk_media

void fastcall eject_disk_media(const char* str, uint32_t code); for load/eject drive ecx -> asciiz string disk name (sd0, usbhd0) edx = code command(0 - LoadTray 1-EjectTray)

Source
blkdev/disk.inc:1717

◆ fs_dyndisk_next

label fs_dyndisk_next

This is a callback for enumerating partitions called from file_system_lfn.maindir in the case of inserted media. It just increments eax until DISK.NumPartitions reached and then cleans up.

Source
blkdev/disk.inc:1639

◆ fs_dyndisk_next_nomedia

label fs_dyndisk_next_nomedia

This is a callback for enumerating partitions called from file_system_lfn.maindir in the case of missing media. In this case we create one pseudo-partition.

Source
blkdev/disk.inc:1658

◆ fs_tmp_buffer

rb fs_tmp_buffer
Initial value
512
Source
blkdev/disk.inc:349

◆ GPEA_len

dd GPEA_len

Length of GPT Partition Entry Array in bytes.

Initial value
?
Source
blkdev/disk.inc:886

◆ irp

type irp

  1. Check for extended partition. If extended, go to 6. Old Multiuser DOS secured: extended partition

Initial value
, 0x05, 0x0f, 0xc5, 0xd5
Source
blkdev/disk.inc:1104

◆ is_partition_table_entry

label is_partition_table_entry

This is an internal function called from disk_scan_partitions. It checks whether the entry pointed to by ecx is a valid entry of partition table. The entry is valid if the first byte is 0 or 80h, the first sector plus the length is less than twice the size of media. Multiplication by two is required since the size mentioned in the partition table can be slightly greater than the real size.

Source
blkdev/disk.inc:1056

◆ is_protective_mbr

label is_protective_mbr

ecx = pointer to partition records array (MBR + 446)

Source
blkdev/disk.inc:1022

◆ mbr_buffer

rb mbr_buffer

The static buffers for MBR, bootsector and fs-temporary sector data.

Initial value
512
Source
blkdev/disk.inc:347

◆ partition_buffer_users

dd partition_buffer_users

The function 'disk_scan_partitions' needs three sector-sized buffers for MBR, bootsector and fs-temporary sector data. It can not use the static buffers always, since it can be called for two or more disks in parallel. However, this case is not typical. We reserve three static 512-byte buffers and a flag that these buffers are currently used. If 'disk_scan_partitions' detects that the buffers are currently used, it allocates buffers from the heap. Also, the heap is used when sector size is other than 512. The flag is implemented as a global dword variable. When the static buffers are not used, the value is -1. When the static buffers are used, the value is normally 0 and temporarily can become greater. The function increments this value. If the resulting value is zero, it uses the buffers and decrements the value when the job is done. Otherwise, it immediately decrements the value and uses buffers from the heap, allocated in the beginning and freed in the end.

Initial value
-1
Source
blkdev/disk.inc:342

◆ process_partition_table_entry

label process_partition_table_entry

This is an internal function called from disk_scan_partitions. It processes the entry pointed to by ecx. If the entry is invalid, just ignore this entry. If the type is zero, just ignore this entry. If the type is one of types for extended partition, store the address of this partition as the new MBR in [esp+4]. Otherwise, add the partition to the list of partitions for this disk. We don't use the type from the entry to identify the file system; fs-specific checks do this more reliably.

Source
blkdev/disk.inc:1095