Subversion Repositories Kolibri OS

Rev

Rev 2455 | Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;                                                              ;;
  3. ;; Copyright (C) KolibriOS team 2004-2011. All rights reserved. ;;
  4. ;; Distributed under terms of the GNU General Public License    ;;
  5. ;;                                                              ;;
  6. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  7.  
  8. $Revision: 2643 $
  9.  
  10.  
  11. ;*************************************************************
  12. ;* 13.02.2010 Find all partition and check supported FS
  13. ;* 12.07.2007 Check all 4 entry of MBR and EMBR
  14. ;* 29.04.2006 Elimination of hangup after the
  15. ;*             expiration hd_wait_timeout -  Mario79
  16. ;* 28.01.2006 find all Fat16/32 partition in all input point
  17. ;*            to MBR - Mario79
  18. ;*************************************************************
  19.  
  20. uglobal
  21. align 4
  22.  
  23. ;******************************************************
  24. ; Please do not change this place - variables  in text
  25. ; Mario79
  26. ; START place
  27. ;******************************************************
  28. PARTITION_START      dd 0x3f
  29. PARTITION_END        dd 0
  30. fs_type              db 0       ; 1=NTFS, 2=EXT2/3, 16=FAT16, 32=FAT32
  31. align 4
  32.  
  33. fs_dependent_data_start:
  34. ; FATxx data
  35.  
  36. .partition      dd      ?
  37.                 rb      80
  38.  
  39. fs_dependent_data_end:
  40. file_system_data_size = $ - PARTITION_START
  41. if file_system_data_size > 96
  42. ERROR:
  43.        sizeof(file system data) too big!
  44. end if
  45.  
  46. virtual at fs_dependent_data_start
  47. ; NTFS data
  48. ntfs_data:
  49. .sectors_per_cluster    dd      ?
  50. .mft_cluster            dd      ?
  51. .mftmirr_cluster        dd      ?
  52. .frs_size               dd      ?       ; FRS size in bytes
  53. .iab_size               dd      ?       ; IndexAllocationBuffer size in bytes
  54. .frs_buffer             dd      ?
  55. .iab_buffer             dd      ?
  56. .mft_retrieval          dd      ?
  57. .mft_retrieval_size     dd      ?
  58. .mft_retrieval_alloc    dd      ?
  59. .mft_retrieval_end      dd      ?
  60. .cur_index_size         dd      ?
  61. .cur_index_buf          dd      ?
  62. if $ > fs_dependent_data_end
  63. ERROR:
  64.        increase sizeof(fs_dependent_data)!
  65. end if
  66. end virtual
  67.  
  68. virtual at fs_dependent_data_start
  69. ; EXT2 data
  70. ext2_data:
  71.     .log_block_size                 dd ?
  72.     .block_size                     dd ?
  73.     .count_block_in_block           dd ?
  74.     .blocks_per_group               dd ?
  75.     .inodes_per_group               dd ?
  76.     .global_desc_table              dd ?
  77.     .root_inode                     dd ?        ; pointer to root inode in memory
  78.     .inode_size                     dd ?
  79.     .count_pointer_in_block         dd ?        ;  block_size / 4
  80.     .count_pointer_in_block_square  dd ?        ; (block_size / 4)**2
  81.     .ext2_save_block                dd ?    ; ¡«®ª ­  £«®¡ «ì­ãî 1 ¯à®æ¥¤ãàã
  82.     .ext2_temp_block                dd ?    ; ¡«®ª ¤«ï ¬¥«ª¨å ¯à®æ¥¤ãà
  83.     .ext2_save_inode                dd ?    ; inode ­  £«®¡ «ì­ãî ¯à®æ¥¤ãàã
  84.     .ext2_temp_inode                dd ?    ; inode ¤«ï ¬¥«ª¨å ¯à®æ¥¤ãà
  85.     .sb                             dd ?    ; superblock
  86.     .groups_count                   dd ?
  87. if $ > fs_dependent_data_end
  88. ERROR:
  89.        increase sizeof(fs_dependent_data)!
  90. end if
  91. end virtual
  92.  
  93. ;***************************************************************************
  94. ; End place
  95. ; Mario79
  96. ;***************************************************************************
  97. endg
  98. iglobal
  99.  
  100.   partition_types:              ; list of fat16/32 partitions
  101.     db    0x04                  ; DOS: fat16 <32M
  102.     db    0x06                  ; DOS: fat16 >32M
  103.     db    0x0b                  ; WIN95: fat32
  104.     db    0x0c                  ; WIN95: fat32, LBA-mapped
  105.     db    0x0e                  ; WIN95: fat16, LBA-mapped
  106.     db    0x14                  ; Hidden DOS: fat16 <32M
  107.     db    0x16                  ; Hidden DOS: fat16 >32M
  108.     db    0x1b                  ; Hidden WIN95: fat32
  109.     db    0x1c                  ; Hidden WIN95: fat32, LBA-mapped
  110.     db    0x1e                  ; Hidden WIN95: fat16, LBA-mapped
  111.     db    0xc4                  ; DRDOS/secured: fat16 <32M
  112.     db    0xc6                  ; DRDOS/secured: fat16 >32M
  113.     db    0xcb                  ; DRDOS/secured: fat32
  114.     db    0xcc                  ; DRDOS/secured: fat32, LBA-mapped
  115.     db    0xce                  ; DRDOS/secured: fat16, LBA-mapped
  116.     db    0xd4                  ; Old Multiuser DOS secured: fat16 <32M
  117.     db    0xd6                  ; Old Multiuser DOS secured: fat16 >32M
  118.     db    0x07                  ; NTFS
  119.     db    0x27                  ; NTFS, hidden
  120.     db    0x83                  ; Linux native file system (ext2fs)
  121.   partition_types_end:
  122.  
  123.  
  124.   extended_types:               ; list of extended partitions
  125.     db    0x05                  ; DOS: extended partition
  126.     db    0x0f                  ; WIN95: extended partition, LBA-mapped
  127.     db    0xc5                  ; DRDOS/secured: extended partition
  128.     db    0xd5                  ; Old Multiuser DOS secured: extended partition
  129.   extended_types_end:
  130.  
  131. endg
  132.  
  133. ; Partition chain used:
  134. ; MBR <---------------------
  135. ; |                         |
  136. ; |-> PARTITION1          |
  137. ; |-> EXTENDED PARTITION -        ;not need be second partition
  138. ; |-> PARTITION3
  139. ; |-> PARTITION4
  140.  
  141. set_PARTITION_variables:
  142. set_FAT32_variables:        ;deprecated
  143.         and     [problem_partition], 0
  144.         call    reserve_hd1
  145.         call    reserve_hd_channel
  146.  
  147.         pushad
  148.  
  149.         cmp     dword [hdpos], 0
  150.         je      problem_hd
  151.  
  152.         xor     ecx, ecx        ; partition count
  153.     ;or    edx,-1                ; flag for partition
  154.         xor     eax, eax        ; address MBR
  155.         xor     ebp, ebp        ; extended partition start
  156.  
  157. new_mbr:
  158.         test    ebp, ebp        ; is there extended partition? (MBR or EMBR)
  159.         jnz     extended_already_set; yes
  160.         xchg    ebp, eax        ; no. set it now
  161.  
  162. extended_already_set:
  163.         add     eax, ebp        ; mbr=mbr+0, ext_part=ext_start+relat_start
  164.         mov     ebx, buffer
  165.         call    hd_read
  166.         cmp     [hd_error], 0
  167.         jne     problem_hd
  168.  
  169.         cmp     word [ebx+0x1fe], 0xaa55; is it valid boot sector?
  170.         jnz     end_partition_chain
  171.         push    eax                ; push only one time
  172.         cmp     dword [ebx+0x1be+0xc], 0; skip over empty partition
  173.         jnz     test_primary_partition_0
  174.         cmp     dword [ebx+0x1be+0xc+16], 0
  175.         jnz     test_primary_partition_1
  176.         cmp     dword [ebx+0x1be+0xc+16+16], 0
  177.         jnz     test_primary_partition_2
  178.         cmp     dword [ebx+0x1be+0xc+16+16+16], 0
  179.         jnz     test_primary_partition_3
  180.         pop     eax
  181.         jmp     end_partition_chain
  182.  
  183. test_primary_partition_0:
  184.         mov     al, [ebx+0x1be+4]; get primary partition type
  185.         call    scan_partition_types
  186.         jnz     test_primary_partition_1; no. skip over
  187.  
  188.         inc     ecx
  189.         cmp     ecx, [known_part]; is it wanted partition?
  190.         jnz     test_primary_partition_1; no
  191.  
  192.         pop     eax
  193.         ;mov     edx, eax                ; start sector
  194.         add     eax, [ebx+0x1be+8]      ; add relative start
  195.         ;mov     [PARTITON_START],edx
  196.         ;push    edx
  197.         mov     edx, [ebx+0x1be+12]     ; length
  198.         ;add     edx, eax                ; add length
  199.         ;dec     edx                     ; PARTITION_END is inclusive
  200.         ;mov     [PARTITION_END], edx    ; note that this can be changed
  201.                                         ; when file system data will be available
  202.         mov     cl, [ebx+0x1be+4]       ; fs_type
  203.         ;mov     [fs_type], dl           ; save for FS recognizer (separate FAT vs NTFS)
  204.         ;pop     edx
  205.         jmp     hd_and_partition_ok
  206.  
  207. test_primary_partition_1:
  208.         mov     al, [ebx+0x1be+4+16]; get primary partition type
  209.         call    scan_partition_types
  210.         jnz     test_primary_partition_2  ; no. skip over
  211.  
  212.         inc     ecx
  213.         cmp     ecx, [known_part]; is it wanted partition?
  214.         jnz     test_primary_partition_2  ; no
  215.  
  216.         pop     eax
  217.         add     eax, [ebx+0x1be+8+16]
  218.         mov     edx, [ebx+0x1be+12+16]
  219.         mov     cl, [ebx+0x1be+4+16]
  220.         jmp     hd_and_partition_ok
  221.  
  222.         ;mov     edx, eax
  223.         ;add     edx, [ebx+0x1be+8+16]
  224.         ;push    edx
  225.         ;add     edx, [ebx+0x1be+12+16]
  226.         ;dec     edx
  227.         ;mov     [PARTITION_END], edx
  228.         ;mov     al, [ebx+0x1be+4+16]
  229.         ;mov     [fs_type], dl
  230.         ;pop     edx
  231.  
  232. test_primary_partition_2:
  233.         mov     al, [ebx+0x1be+4+16+16]; get primary partition type
  234.         call    scan_partition_types
  235.         jnz     test_primary_partition_3  ; no. skip over
  236.  
  237.         inc     ecx
  238.         cmp     ecx, [known_part]; is it wanted partition?
  239.         jnz     test_primary_partition_3  ; no
  240.  
  241.         pop     eax
  242.         add     eax, [ebx+0x1be+8+16+16]
  243.         mov     edx, [ebx+0x1be+12+16+16]
  244.         mov     cl, [ebx+0x1be+4+16+16]
  245.         jmp     hd_and_partition_ok
  246.         ;mov     edx, eax
  247.         ;add     edx, [ebx+0x1be+8+16+16]
  248.         ;push    edx
  249.         ;add     edx, [ebx+0x1be+12+16+16]
  250.         ;dec     edx
  251.         ;mov     [PARTITION_END], edx
  252.         ;mov     al, [ebx+0x1be+4+16+16]
  253.         ;mov     [fs_type], dl
  254.         ;pop     edx
  255.  
  256. test_primary_partition_3:
  257.         mov     al, [ebx+0x1be+4+16+16+16]; get primary partition type
  258.         call    scan_partition_types
  259.         jnz     test_ext_partition_0  ; no. skip over
  260.  
  261.         inc     ecx
  262.         cmp     ecx, [known_part]; is it wanted partition?
  263.         jnz     test_ext_partition_0; no
  264.  
  265.         pop     eax
  266.         add     eax, [ebx+0x1be+8+16+16+16]
  267.         mov     edx, [ebx+0x1be+12+16+16+16]
  268.         mov     cl, [ebx+0x1be+4+16+16+16]
  269.         jmp     hd_and_partition_ok
  270.  
  271.         ;mov     edx, eax
  272.         ;add     edx, [ebx+0x1be+8+16+16+16]
  273.         ;push    edx
  274.         ;add     edx, [ebx+0x1be+12+16+16+16]
  275.         ;dec     edx
  276.         ;mov     [PARTITION_END], edx
  277.         ;mov     al, [ebx+0x1be+4+16+16+16]
  278.         ;mov     [fs_type], dl
  279.         ;pop     edx
  280.  
  281. test_ext_partition_0:
  282.         pop     eax         ; ¯à®áâ® ¢ëª¨¤ë¢ ¥¬ ¨§ á⥪ 
  283.         mov     al, [ebx+0x1be+4]; get extended partition type
  284.         call    scan_extended_types
  285.         jnz     test_ext_partition_1
  286.  
  287.         mov     eax, [ebx+0x1be+8]; add relative start
  288.         test    eax, eax        ; is there extended partition?
  289.         jnz     new_mbr         ; yes. read it
  290.  
  291. test_ext_partition_1:
  292.         mov     al, [ebx+0x1be+4+16]; get extended partition type
  293.         call    scan_extended_types
  294.         jnz     test_ext_partition_2
  295.  
  296.         mov     eax, [ebx+0x1be+8+16]; add relative start
  297.         test    eax, eax        ; is there extended partition?
  298.         jnz     new_mbr         ; yes. read it
  299.  
  300. test_ext_partition_2:
  301.         mov     al, [ebx+0x1be+4+16+16]; get extended partition type
  302.         call    scan_extended_types
  303.         jnz     test_ext_partition_3
  304.  
  305.         mov     eax, [ebx+0x1be+8+16+16]; add relative start
  306.         test    eax, eax        ; is there extended partition?
  307.         jnz     new_mbr         ; yes. read it
  308.  
  309. test_ext_partition_3:
  310.         mov     al, [ebx+0x1be+4+16+16+16]; get extended partition type
  311.         call    scan_extended_types
  312.         jnz     end_partition_chain; no. end chain
  313.  
  314.         mov     eax, [ebx+0x1be+8+16+16+16]; get start of extended partition
  315.         test    eax, eax        ; is there extended partition?
  316.         jnz     new_mbr         ; yes. read it
  317.  
  318. end_partition_chain:
  319.     ;mov   [partition_count],ecx
  320.  
  321.     ;cmp   edx,-1                ; found wanted partition?
  322.     ;jnz   hd_and_partition_ok   ; yes. install it
  323.     ;jmp   problem_partition_or_fat
  324. problem_hd:
  325.         or      [problem_partition], 2
  326.         jmp     return_from_part_set
  327.  
  328.  
  329. scan_partition_types:
  330.         push    ecx
  331.         mov     edi, partition_types
  332.         mov     ecx, partition_types_end-partition_types
  333.         cld
  334.         repne scasb             ; is partition type ok?
  335.         pop     ecx
  336.         ret
  337.  
  338. scan_extended_types:
  339.         push    ecx
  340.         mov     edi, extended_types
  341.         mov     ecx, extended_types_end-extended_types
  342.         cld
  343.         repne scasb             ; is it extended partition?
  344.         pop     ecx
  345.         ret
  346.  
  347. problem_fat_dec_count:          ; bootsector is missing or another problem
  348. ;    dec   [partition_count]     ; remove it from partition_count
  349.  
  350. problem_partition_or_fat:
  351.         or      [problem_partition], 1
  352.  
  353. return_from_part_set:
  354.         popad
  355.     ;mov   [fs_type],0
  356.         call    free_hd_channel
  357.         mov     [hd1_status], 0 ; free
  358.         ret
  359.  
  360. hd_and_partition_ok:
  361.  
  362. ;eax = PARTITION_START edx=PARTITION_LENGTH cl=fs_type
  363.         mov     [fs_type], cl
  364.     ;mov   eax,edx
  365.         mov     [PARTITION_START], eax
  366.         add     edx, eax
  367.         dec     edx
  368.         mov     [PARTITION_END], edx
  369.  
  370.    ;     mov     edx, [PARTITION_END]
  371.    ;     sub     edx, eax
  372.    ;     inc     edx     ; edx = length of partition § ç¥¬ ®­® ­ ¬??
  373.  
  374. ;    mov   [hd_setup],1
  375.         mov     ebx, buffer
  376.         call    hd_read         ; read boot sector of partition
  377.         cmp     [hd_error], 0
  378.         jz      boot_read_ok
  379.         cmp     [fs_type], 7
  380.         jnz     problem_fat_dec_count
  381. ; NTFS duplicates bootsector:
  382. ; NT4/2k/XP+ saves bootsector copy in the end of disk
  383. ; NT 3.51 saves bootsector copy in the middle of disk
  384.         and     [hd_error], 0
  385.         mov     eax, [PARTITION_END]
  386.         call    hd_read
  387.         cmp     [hd_error], 0
  388.         jnz     @f
  389.         call    ntfs_test_bootsec
  390.         jnc     boot_read_ok
  391. @@:
  392.         and     [hd_error], 0
  393.         mov     eax, edx
  394.         shr     eax, 1
  395.         add     eax, [PARTITION_START]
  396.         call    hd_read
  397.         cmp     [hd_error], 0
  398.         jnz     problem_fat_dec_count   ; no chance...
  399. boot_read_ok:
  400.  
  401. ; if we are running on NTFS, check bootsector
  402.  
  403.         call    ntfs_test_bootsec      ; test ntfs
  404.         jnc     ntfs_setup
  405.  
  406.         call    ext2_test_superblock   ; test ext2fs
  407.         jnc     ext2_setup
  408.  
  409.         mov     eax, [PARTITION_START]  ;ext2 test changes [buffer]
  410.         call    hd_read
  411.         cmp     [hd_error], 0
  412.         jnz     problem_fat_dec_count
  413.  
  414.         push    0
  415.         mov     eax, [PARTITION_END]
  416.         sub     eax, [PARTITION_START]
  417.         inc     eax
  418.         push    eax
  419.         push    0
  420.         push    [PARTITION_START]
  421.         push    ebp
  422.         push    ebp
  423.         mov     ebp, esp
  424.         mov     esi, 'old'      ; special value: there is no DISK structure
  425.         push    1       ; bootsector read successfully
  426.         call    fat_create_partition
  427.         add     esp, 4*7
  428.         test    eax, eax
  429.         jz      problem_fat_dec_count
  430.         mov     [fs_dependent_data_start.partition], eax
  431.         mov     al, [eax+FAT.fs_type]
  432.         mov     [fs_type], al
  433.  
  434.         popad
  435.         call    free_hd_channel
  436.         mov     [hd1_status], 0 ; free
  437.         ret
  438.