Rev 4993 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4993 | Rev 5116 | ||
---|---|---|---|
Line 3... | Line 3... | ||
3 | ;; Copyright (C) KolibriOS team 2011-2014. All rights reserved. ;; |
3 | ;; Copyright (C) KolibriOS team 2011-2014. All rights reserved. ;; |
4 | ;; Distributed under terms of the GNU General Public License ;; |
4 | ;; Distributed under terms of the GNU General Public License ;; |
5 | ;; ;; |
5 | ;; ;; |
6 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
6 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
Line 7... | Line 7... | ||
7 | 7 | ||
Line 8... | Line 8... | ||
8 | $Revision: 4437 $ |
8 | $Revision: 5089 $ |
9 | 9 | ||
10 | ; ============================================================================= |
10 | ; ============================================================================= |
11 | ; ================================= Constants ================================= |
11 | ; ================================= Constants ================================= |
Line 106... | Line 106... | ||
106 | pointer dd ? |
106 | pointer dd ? |
107 | data_size dd ? ; unused |
107 | data_size dd ? ; unused |
108 | data dd ? |
108 | data dd ? |
109 | sad_size dd ? |
109 | sad_size dd ? |
110 | search_start dd ? |
110 | search_start dd ? |
- | 111 | sector_size_log dd ? |
|
111 | ends |
112 | ends |
Line 112... | Line 113... | ||
112 | 113 | ||
113 | ; This structure represents a disk device and its media for the kernel. |
114 | ; This structure represents a disk device and its media for the kernel. |
114 | ; This structure is allocated by the kernel in the 'disk_add' function, |
115 | ; This structure is allocated by the kernel in the 'disk_add' function, |
Line 269... | Line 270... | ||
269 | ; filesystem operations are referencing the same filesystem data, this is |
270 | ; filesystem operations are referencing the same filesystem data, this is |
270 | ; better resolved at the level of the filesystem. |
271 | ; better resolved at the level of the filesystem. |
271 | endg |
272 | endg |
Line 272... | Line 273... | ||
272 | 273 | ||
273 | iglobal |
274 | iglobal |
274 | ; The function 'disk_scan_partitions' needs three 512-byte buffers for |
275 | ; The function 'disk_scan_partitions' needs three sector-sized buffers for |
275 | ; MBR, bootsector and fs-temporary sector data. It can not use the static |
276 | ; MBR, bootsector and fs-temporary sector data. It can not use the static |
276 | ; buffers always, since it can be called for two or more disks in parallel. |
277 | ; buffers always, since it can be called for two or more disks in parallel. |
277 | ; However, this case is not typical. We reserve three static 512-byte buffers |
278 | ; However, this case is not typical. We reserve three static 512-byte buffers |
278 | ; and a flag that these buffers are currently used. If 'disk_scan_partitions' |
279 | ; and a flag that these buffers are currently used. If 'disk_scan_partitions' |
279 | ; detects that the buffers are currently used, it allocates buffers from the |
280 | ; detects that the buffers are currently used, it allocates buffers from the |
280 | ; heap. |
281 | ; heap. Also, the heap is used when sector size is other than 512. |
281 | ; The flag is implemented as a global dword variable. When the static buffers |
282 | ; The flag is implemented as a global dword variable. When the static buffers |
282 | ; are not used, the value is -1. When the static buffers are used, the value |
283 | ; are not used, the value is -1. When the static buffers are used, the value |
283 | ; is normally 0 and temporarily can become greater. The function increments |
284 | ; is normally 0 and temporarily can become greater. The function increments |
284 | ; this value. If the resulting value is zero, it uses the buffers and |
285 | ; this value. If the resulting value is zero, it uses the buffers and |
Line 636... | Line 637... | ||
636 | ; esi = pointer to the DISK structure. |
637 | ; esi = pointer to the DISK structure. |
637 | disk_scan_partitions: |
638 | disk_scan_partitions: |
638 | ; 1. Initialize .NumPartitions and .Partitions fields as zeros: empty list. |
639 | ; 1. Initialize .NumPartitions and .Partitions fields as zeros: empty list. |
639 | and [esi+DISK.NumPartitions], 0 |
640 | and [esi+DISK.NumPartitions], 0 |
640 | and [esi+DISK.Partitions], 0 |
641 | and [esi+DISK.Partitions], 0 |
641 | ; 2. Currently we can work only with 512-bytes sectors. Check this restriction. |
- | |
642 | ; The only exception is 2048-bytes CD/DVD, but they are not supported yet by |
- | |
643 | ; this code. |
- | |
644 | cmp [esi+DISK.MediaInfo.SectorSize], 512 |
- | |
645 | jz .doscan |
- | |
646 | DEBUGF 1,'K : sector size is %d, only 512 is supported\n',[esi+DISK.MediaInfo.SectorSize] |
- | |
647 | ret |
- | |
648 | .doscan: |
- | |
649 | ; 3. Acquire the buffer for MBR and bootsector tests. See the comment before |
642 | ; 2. Acquire the buffer for MBR and bootsector tests. See the comment before |
650 | ; the 'partition_buffer_users' variable. |
643 | ; the 'partition_buffer_users' variable. |
- | 644 | mov eax, [esi+DISK.MediaInfo.SectorSize] |
|
- | 645 | cmp eax, 512 |
|
- | 646 | jnz @f |
|
651 | mov ebx, mbr_buffer ; assume the global buffer is free |
647 | mov ebx, mbr_buffer ; assume the global buffer is free |
652 | lock inc [partition_buffer_users] |
648 | lock inc [partition_buffer_users] |
653 | jz .buffer_acquired ; yes, it is free |
649 | jz .buffer_acquired ; yes, it is free |
654 | lock dec [partition_buffer_users] ; no, we must allocate |
650 | lock dec [partition_buffer_users] ; no, we must allocate |
- | 651 | @@: |
|
- | 652 | lea eax, [eax*3] |
|
655 | stdcall kernel_alloc, 512*3 |
653 | stdcall kernel_alloc, eax |
656 | test eax, eax |
654 | test eax, eax |
657 | jz .nothing |
655 | jz .nothing |
658 | xchg eax, ebx |
656 | xchg eax, ebx |
659 | .buffer_acquired: |
657 | .buffer_acquired: |
660 | ; MBR/EBRs are organized in the chain. We use a loop over MBR/EBRs, but no |
658 | ; MBR/EBRs are organized in the chain. We use a loop over MBR/EBRs, but no |
661 | ; more than MAX_NUM_PARTITION times. |
659 | ; more than MAX_NUM_PARTITION times. |
662 | ; 4. Prepare things for the loop. |
660 | ; 3. Prepare things for the loop. |
663 | ; ebp will hold the sector number for current MBR/EBR. |
661 | ; ebp will hold the sector number for current MBR/EBR. |
664 | ; [esp] will hold the sector number for current extended partition, if there |
662 | ; [esp] will hold the sector number for current extended partition, if there |
665 | ; is one. |
663 | ; is one. |
666 | ; [esp+4] will hold the counter that prevents long loops. |
664 | ; [esp+4] will hold the counter that prevents long loops. |
667 | push ebp ; save ebp |
665 | push ebp ; save ebp |
668 | push MAX_NUM_PARTITIONS ; the counter of max MBRs to process |
666 | push MAX_NUM_PARTITIONS ; the counter of max MBRs to process |
669 | xor ebp, ebp ; start from sector zero |
667 | xor ebp, ebp ; start from sector zero |
670 | push ebp ; no extended partition yet |
668 | push ebp ; no extended partition yet |
- | 669 | ; 4. MBR is 512 bytes long. If sector size is less than 512 bytes, |
|
- | 670 | ; assume no MBR, no partitions and go to 10. |
|
- | 671 | cmp [esi+DISK.MediaInfo.SectorSize], 512 |
|
- | 672 | jb .notmbr |
|
671 | .new_mbr: |
673 | .new_mbr: |
672 | ; 5. Read the current sector. |
674 | ; 5. Read the current sector. |
673 | ; Note that 'read' callback operates with 64-bit sector numbers, so we must |
675 | ; Note that 'read' callback operates with 64-bit sector numbers, so we must |
674 | ; push additional zero as a high dword of sector number. |
676 | ; push additional zero as a high dword of sector number. |
675 | mov al, DISKFUNC.read |
677 | mov al, DISKFUNC.read |
Line 984... | Line 986... | ||
984 | ; 1. Read the bootsector to the buffer. |
986 | ; 1. Read the bootsector to the buffer. |
985 | ; When disk_add_partition is called, ebx contains a pointer to |
987 | ; When disk_add_partition is called, ebx contains a pointer to |
986 | ; a three-sectors-sized buffer. This function saves ebx in the stack |
988 | ; a three-sectors-sized buffer. This function saves ebx in the stack |
987 | ; immediately before ebp. |
989 | ; immediately before ebp. |
988 | mov ebx, [ebp-4] ; get buffer |
990 | mov ebx, [ebp-4] ; get buffer |
989 | add ebx, 512 ; advance over MBR data to bootsector data |
991 | add ebx, [esi+DISK.MediaInfo.SectorSize] ; advance over MBR data to bootsector data |
990 | add ebp, 8 ; ebp points to part of PARTITION structure |
992 | add ebp, 8 ; ebp points to part of PARTITION structure |
991 | xor eax, eax ; first sector of the partition |
993 | xor eax, eax ; first sector of the partition |
992 | call fs_read32_sys |
994 | call fs_read32_sys |
993 | push eax |
995 | push eax |
994 | ; 2. Run tests for all supported filesystems. If at least one test succeeded, |
996 | ; 2. Run tests for all supported filesystems. If at least one test succeeded, |
995 | ; go to 4. |
997 | ; go to 4. |
996 | ; For tests: |
998 | ; For tests: |
997 | ; ebp -> first three fields of PARTITION structure, .start, .length, .disk; |
999 | ; ebp -> first three fields of PARTITION structure, .start, .length, .disk; |
998 | ; [esp] = error code after bootsector read: 0 = ok, otherwise = failed, |
1000 | ; [esp] = error code after bootsector read: 0 = ok, otherwise = failed, |
999 | ; ebx points to the buffer for bootsector, |
1001 | ; ebx points to the buffer for bootsector, |
1000 | ; ebx+512 points to 512-bytes buffer that can be used for anything. |
1002 | ; ebx+[esi+DISK.MediaInfo.SectorSize] points to sector-sized buffer that can be used for anything. |
1001 | call fat_create_partition |
1003 | call fat_create_partition |
1002 | test eax, eax |
1004 | test eax, eax |
1003 | jnz .success |
1005 | jnz .success |
1004 | call ntfs_create_partition |
1006 | call ntfs_create_partition |
1005 | test eax, eax |
1007 | test eax, eax |