Rev 78 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 78 | Rev 83 | ||
---|---|---|---|
Line 5... | Line 5... | ||
5 | ;; FAT16/32 functions for MenuetOS ;; |
5 | ;; FAT16/32 functions for MenuetOS ;; |
6 | ;; ;; |
6 | ;; ;; |
7 | ;; Copyright 2002 Paolo Minazzi, paolo.minazzi@inwind.it ;; |
7 | ;; Copyright 2002 Paolo Minazzi, paolo.minazzi@inwind.it ;; |
8 | ;; ;; |
8 | ;; ;; |
9 | ;; See file COPYING for details ;; |
9 | ;; See file COPYING for details ;; |
- | 10 | ;; 27.05.2006 LFN create/rewrite file - diamond ;; |
|
10 | ;; 04.05.2006 LFN read folder - diamond ;; |
11 | ;; 04.05.2006 LFN read folder - diamond ;; |
11 | ;; 29.04.2006 Elimination of hangup after the ;; |
12 | ;; 29.04.2006 Elimination of hangup after the ;; |
12 | ;; expiration hd_wait_timeout - Mario79 ;; |
13 | ;; expiration hd_wait_timeout - Mario79 ;; |
13 | ;; 23.04.2006 LFN read file - diamond ;; |
14 | ;; 23.04.2006 LFN read file - diamond ;; |
14 | ;; 28.01.2006 find all Fat16/32 partition in all input point ;; |
15 | ;; 28.01.2006 find all Fat16/32 partition in all input point ;; |
Line 2932... | Line 2933... | ||
2932 | ; \begin{diamond} |
2933 | ; \begin{diamond} |
2933 | hd_find_lfn: |
2934 | hd_find_lfn: |
2934 | ; in: esi->name |
2935 | ; in: esi->name |
2935 | ; out: CF=1 - file not found |
2936 | ; out: CF=1 - file not found |
2936 | ; else CF=0 and edi->direntry |
2937 | ; else CF=0 and edi->direntry |
2937 | pusha |
2938 | ; destroys eax |
2938 | sub esp, 262*2 ; allocate space for LFN |
- | |
2939 | mov ebp, esp |
2939 | push esi edi |
2940 | push 0 ; for fat_get_name: read ASCII name |
- | |
2941 | mov eax, [ROOT_CLUSTER] ; start from root |
- | |
2942 | .mainloop: |
- | |
2943 | .new_cluster: |
- | |
2944 | mov [cluster_tmp], eax |
- | |
2945 | mov [fat16_root], 0 |
- | |
2946 | cmp eax, [LAST_CLUSTER] |
- | |
2947 | ja .notfound |
2940 | push 0 |
2948 | cmp eax, 2 |
2941 | push 0 |
2949 | jae .data_cluster |
2942 | push fat16_root_first |
2950 | cmp [fat_type], 16 |
2943 | push fat16_root_next |
2951 | jnz .notfound |
- | |
2952 | mov eax, [ROOT_START] |
2944 | mov eax, [ROOT_CLUSTER] |
2953 | mov ecx, [ROOT_SECTORS] |
- | |
2954 | mov [fat16_root], 1 |
2945 | cmp [fat_type], 32 |
2955 | jmp .new_sector |
- | |
2956 | .data_cluster: |
- | |
2957 | dec eax |
- | |
2958 | dec eax |
- | |
2959 | mov ecx, [SECTORS_PER_CLUSTER] |
- | |
2960 | mul ecx |
- | |
2961 | add eax, [DATA_START] |
- | |
2962 | .new_sector: |
- | |
2963 | mov ebx, buffer |
- | |
2964 | call hd_read |
- | |
2965 | cmp [hd_error],0 |
- | |
2966 | jne .notfound |
- | |
2967 | - | ||
2968 | mov edi, ebx |
- | |
2969 | add ebx, 512 |
2946 | jz .fat32 |
2970 | push eax |
- | |
2971 | .l1: |
2947 | .loop: |
2972 | call fat_get_name |
2948 | call fat_find_lfn |
2973 | jc .l2 |
2949 | jc .notfound |
2974 | call fat_compare_name |
2950 | cmp byte [esi], 0 |
2975 | jz .found |
2951 | jz .found |
2976 | .l2: |
- | |
2977 | add edi, 0x20 |
- | |
2978 | cmp edi, ebx |
- | |
2979 | jb .l1 |
- | |
2980 | pop eax |
- | |
2981 | inc eax |
- | |
2982 | loop .new_sector |
- | |
2983 | cmp [fat16_root], 0 |
2952 | test byte [edi+11], 10h |
2984 | jnz .notfound |
2953 | jz .notfound |
2985 | mov eax, [cluster_tmp] |
2954 | and dword [esp+12], 0 |
2986 | call get_FAT |
- | |
2987 | cmp [hd_error],0 |
2955 | movzx eax, word [edi+26] ; cluster |
2988 | jne .notfound |
2956 | .fat32: |
2989 | - | ||
2990 | cmp eax, 2 |
2957 | mov [esp+8], eax |
2991 | jb .notfound |
2958 | mov dword [esp+4], fat_notroot_first |
2992 | cmp eax, [fatRESERVED] |
2959 | mov dword [esp], fat_notroot_next |
2993 | jb .new_cluster |
2960 | jmp .loop |
2994 | .notfound: |
2961 | .notfound: |
2995 | add esp, 262*2+4 |
2962 | add esp, 16 |
2996 | popa |
2963 | pop edi esi |
2997 | stc |
2964 | stc |
2998 | ret |
2965 | ret |
2999 | .found: |
2966 | .found: |
3000 | pop eax |
- | |
3001 | ; if this is LFN entry, advance to true entry |
- | |
3002 | cmp byte [edi+11], 0xF |
- | |
3003 | jnz .entryfound |
- | |
3004 | add edi, 0x20 |
- | |
3005 | cmp edi, ebx |
- | |
3006 | jb .entryfound |
- | |
3007 | inc eax |
- | |
3008 | dec ecx |
- | |
3009 | jnz .read_entry |
- | |
3010 | cmp [fat16_root], 0 |
- | |
3011 | jnz .notfound |
- | |
3012 | mov eax, [cluster_tmp] |
- | |
3013 | call get_FAT |
- | |
3014 | cmp [hd_error],0 |
- | |
3015 | jne .notfound |
- | |
3016 | - | ||
3017 | cmp eax, 2 |
- | |
3018 | jb .notfound |
- | |
3019 | cmp eax, [fatRESERVED] |
- | |
3020 | jae .notfound |
- | |
3021 | dec eax |
- | |
3022 | dec eax |
- | |
3023 | mul [SECTORS_PER_CLUSTER] |
- | |
3024 | add eax, [DATA_START] |
- | |
3025 | .read_entry: |
- | |
3026 | mov ebx, [buffer] |
- | |
3027 | call hd_read |
- | |
3028 | cmp [hd_error],0 |
- | |
3029 | jne .notfound |
- | |
3030 | - | ||
3031 | mov edi, ebx |
- | |
3032 | .entryfound: |
- | |
3033 | cmp byte [esi], 0 |
- | |
3034 | jz .done |
- | |
3035 | test byte [edi+11], 10h ; is a directory? |
- | |
3036 | jz .notfound |
- | |
3037 | mov eax, [edi+20-2] |
- | |
3038 | mov ax, [edi+26] |
- | |
3039 | jmp .mainloop |
- | |
3040 | .done: |
- | |
3041 | add esp, 262*2+4+4 ; CF=0 |
2967 | add esp, 20 ; CF=0 |
3042 | push edi |
2968 | pop esi |
3043 | popad |
- | |
3044 | ret |
2969 | ret |
Line 3045... | Line 2970... | ||
3045 | 2970 | ||
3046 | ;---------------------------------------------------------------- |
2971 | ;---------------------------------------------------------------- |
3047 | ; |
2972 | ; |
Line 3364... | Line 3289... | ||
3364 | mov al, ERROR_END_OF_FILE |
3289 | mov al, ERROR_END_OF_FILE |
3365 | @@: |
3290 | @@: |
3366 | pop ecx esi edi |
3291 | pop ecx esi edi |
3367 | ret |
3292 | ret |
Line -... | Line 3293... | ||
- | 3293 | ||
- | 3294 | fat16_root_next: |
|
- | 3295 | cmp edi, buffer+0x200-0x20 |
|
- | 3296 | jae fat16_root_next_sector |
|
- | 3297 | add edi, 0x20 |
|
- | 3298 | ret ; CF=0 |
|
- | 3299 | fat16_root_next_sector: |
|
- | 3300 | ; read next sector |
|
- | 3301 | push ecx |
|
- | 3302 | mov ecx, [eax+4] |
|
- | 3303 | inc ecx |
|
- | 3304 | mov [eax+4], ecx |
|
- | 3305 | cmp ecx, [ROOT_SECTORS] |
|
- | 3306 | pop ecx |
|
- | 3307 | jae fat16_root_first.readerr |
|
- | 3308 | fat16_root_first: |
|
- | 3309 | mov eax, [eax+4] |
|
- | 3310 | add eax, [ROOT_START] |
|
- | 3311 | push ebx |
|
- | 3312 | mov edi, buffer |
|
- | 3313 | mov ebx, edi |
|
- | 3314 | call hd_read |
|
- | 3315 | pop ebx |
|
- | 3316 | cmp [hd_error], 0 |
|
- | 3317 | jnz .readerr |
|
- | 3318 | ret ; CF=0 |
|
- | 3319 | .readerr: |
|
- | 3320 | stc |
|
- | 3321 | ret |
|
- | 3322 | fat16_root_begin_write: |
|
- | 3323 | push edi eax |
|
- | 3324 | call fat16_root_first |
|
- | 3325 | pop eax edi |
|
- | 3326 | ret |
|
- | 3327 | fat16_root_end_write: |
|
- | 3328 | pusha |
|
- | 3329 | mov eax, [eax+4] |
|
- | 3330 | add eax, [ROOT_START] |
|
- | 3331 | mov ebx, buffer |
|
- | 3332 | call hd_write |
|
- | 3333 | popa |
|
- | 3334 | ret |
|
- | 3335 | fat16_root_next_write: |
|
- | 3336 | cmp edi, buffer+0x200 |
|
- | 3337 | jae @f |
|
- | 3338 | ret |
|
- | 3339 | @@: |
|
- | 3340 | call fat16_root_end_write |
|
- | 3341 | jmp fat16_root_next_sector |
|
- | 3342 | fat16_root_extend_dir: |
|
- | 3343 | stc |
|
- | 3344 | ret |
|
- | 3345 | ||
- | 3346 | fat_notroot_next: |
|
- | 3347 | cmp edi, buffer+0x200-0x20 |
|
- | 3348 | jae fat_notroot_next_sector |
|
- | 3349 | add edi, 0x20 |
|
- | 3350 | ret ; CF=0 |
|
- | 3351 | fat_notroot_next_sector: |
|
- | 3352 | push ecx |
|
- | 3353 | mov ecx, [eax+4] |
|
- | 3354 | inc ecx |
|
- | 3355 | cmp ecx, [SECTORS_PER_CLUSTER] |
|
- | 3356 | jae fat_notroot_next_cluster |
|
- | 3357 | mov [eax+4], ecx |
|
- | 3358 | jmp @f |
|
- | 3359 | fat_notroot_next_cluster: |
|
- | 3360 | push eax |
|
- | 3361 | mov eax, [eax] |
|
- | 3362 | call get_FAT |
|
- | 3363 | mov ecx, eax |
|
- | 3364 | pop eax |
|
- | 3365 | cmp [hd_error], 0 |
|
- | 3366 | jnz fat_notroot_next_err |
|
- | 3367 | cmp ecx, [fatRESERVED] |
|
- | 3368 | jae fat_notroot_next_err |
|
- | 3369 | mov [eax], ecx |
|
- | 3370 | and dword [eax+4], 0 |
|
- | 3371 | @@: |
|
- | 3372 | pop ecx |
|
- | 3373 | fat_notroot_first: |
|
- | 3374 | call fat_get_sector |
|
- | 3375 | push ebx |
|
- | 3376 | mov edi, buffer |
|
- | 3377 | mov ebx, edi |
|
- | 3378 | call hd_read |
|
- | 3379 | pop ebx |
|
- | 3380 | cmp [hd_error], 0 |
|
- | 3381 | jnz @f |
|
- | 3382 | ret ; CF=0 |
|
- | 3383 | fat_notroot_next_err: |
|
- | 3384 | pop ecx |
|
- | 3385 | @@: |
|
- | 3386 | stc |
|
- | 3387 | ret |
|
- | 3388 | fat_notroot_begin_write: |
|
- | 3389 | push eax edi |
|
- | 3390 | call fat_notroot_first |
|
- | 3391 | pop edi eax |
|
- | 3392 | ret |
|
- | 3393 | fat_notroot_end_write: |
|
- | 3394 | call fat_get_sector |
|
- | 3395 | push ebx |
|
- | 3396 | mov ebx, buffer |
|
- | 3397 | call hd_write |
|
- | 3398 | pop ebx |
|
- | 3399 | ret |
|
- | 3400 | fat_notroot_next_write: |
|
- | 3401 | cmp edi, buffer+0x200 |
|
- | 3402 | jae @f |
|
- | 3403 | ret |
|
- | 3404 | @@: |
|
- | 3405 | push eax |
|
- | 3406 | call fat_notroot_end_write |
|
- | 3407 | pop eax |
|
- | 3408 | jmp fat_notroot_next_sector |
|
- | 3409 | fat_notroot_extend_dir: |
|
- | 3410 | push eax |
|
- | 3411 | mov eax, [eax] |
|
- | 3412 | call get_free_FAT |
|
- | 3413 | jnc .found |
|
- | 3414 | pop eax |
|
- | 3415 | ret ; CF=1 |
|
- | 3416 | .found: |
|
- | 3417 | push edx |
|
- | 3418 | mov edx, [fatEND] |
|
- | 3419 | call set_FAT |
|
- | 3420 | mov edx, eax |
|
- | 3421 | mov eax, [esp+4] |
|
- | 3422 | mov eax, [eax] |
|
- | 3423 | push edx |
|
- | 3424 | mov [f_del], 1 |
|
- | 3425 | call set_FAT |
|
- | 3426 | pop edx |
|
- | 3427 | cmp [hd_error], 0 |
|
- | 3428 | jz @f |
|
- | 3429 | pop edx |
|
- | 3430 | pop eax |
|
- | 3431 | stc |
|
- | 3432 | ret |
|
- | 3433 | @@: |
|
- | 3434 | push ecx |
|
- | 3435 | or ecx, -1 |
|
- | 3436 | call add_disk_free_space |
|
- | 3437 | ; zero new cluster |
|
- | 3438 | mov ecx, 512/4 |
|
- | 3439 | mov edi, buffer |
|
- | 3440 | push edi |
|
- | 3441 | xor eax, eax |
|
- | 3442 | rep stosd |
|
- | 3443 | pop edi |
|
- | 3444 | pop ecx |
|
- | 3445 | mov eax, [esp+4] |
|
- | 3446 | mov [eax], edx |
|
- | 3447 | and dword [eax+4], 0 |
|
- | 3448 | pop edx |
|
- | 3449 | mov eax, [eax] |
|
- | 3450 | dec eax |
|
- | 3451 | dec eax |
|
- | 3452 | push ebx ecx |
|
- | 3453 | mov ecx, [SECTORS_PER_CLUSTER] |
|
- | 3454 | imul eax, ecx |
|
- | 3455 | add eax, [DATA_START] |
|
- | 3456 | mov ebx, edi |
|
- | 3457 | @@: |
|
- | 3458 | call hd_write |
|
- | 3459 | inc eax |
|
- | 3460 | loop @b |
|
- | 3461 | pop ecx ebx eax |
|
- | 3462 | clc |
|
- | 3463 | ret |
|
- | 3464 | ||
- | 3465 | fat_get_sector: |
|
- | 3466 | push ecx |
|
- | 3467 | mov ecx, [eax] |
|
- | 3468 | dec ecx |
|
- | 3469 | dec ecx |
|
- | 3470 | imul ecx, [SECTORS_PER_CLUSTER] |
|
- | 3471 | add ecx, [DATA_START] |
|
- | 3472 | add ecx, [eax+4] |
|
- | 3473 | mov eax, ecx |
|
- | 3474 | pop ecx |
|
- | 3475 | ret |
|
- | 3476 | ||
- | 3477 | ;---------------------------------------------------------------- |
|
- | 3478 | ; |
|
- | 3479 | ; fs_HdRewrite - LFN variant for writing hard disk |
|
- | 3480 | ; |
|
- | 3481 | ; esi points to filename |
|
- | 3482 | ; ebx ignored (reserved) |
|
- | 3483 | ; ecx number of bytes to write, 0+ |
|
- | 3484 | ; edx mem location to data |
|
- | 3485 | ; |
|
- | 3486 | ; ret ebx = number of written bytes |
|
- | 3487 | ; eax = 0 ok read or other = errormsg |
|
- | 3488 | ; |
|
- | 3489 | ;-------------------------------------------------------------- |
|
- | 3490 | fshrad: |
|
- | 3491 | mov eax, ERROR_ACCESS_DENIED |
|
- | 3492 | xor ebx, ebx |
|
- | 3493 | ret |
|
- | 3494 | fshrfs: |
|
- | 3495 | mov eax, ERROR_UNKNOWN_FS |
|
- | 3496 | xor ebx, ebx |
|
- | 3497 | ret |
|
- | 3498 | ||
- | 3499 | fs_HdRewrite: |
|
- | 3500 | cmp [fat_type], 0 |
|
- | 3501 | jz fshrfs |
|
- | 3502 | cmp byte [esi], 0 |
|
- | 3503 | jz fshrad |
|
- | 3504 | pushad |
|
- | 3505 | xor ebp, ebp |
|
- | 3506 | push esi |
|
- | 3507 | @@: |
|
- | 3508 | lodsb |
|
- | 3509 | test al, al |
|
- | 3510 | jz @f |
|
- | 3511 | cmp al, '/' |
|
- | 3512 | jnz @b |
|
- | 3513 | lea ebp, [esi-1] |
|
- | 3514 | jmp @b |
|
- | 3515 | @@: |
|
- | 3516 | pop esi |
|
- | 3517 | test ebp, ebp |
|
- | 3518 | jnz .noroot |
|
- | 3519 | mov ebp, [ROOT_CLUSTER] |
|
- | 3520 | cmp [fat_type], 32 |
|
- | 3521 | jz .pushnotroot |
|
- | 3522 | push fat16_root_extend_dir |
|
- | 3523 | push fat16_root_end_write |
|
- | 3524 | push fat16_root_next_write |
|
- | 3525 | push fat16_root_begin_write |
|
- | 3526 | xor ebp, ebp |
|
- | 3527 | push ebp |
|
- | 3528 | push ebp |
|
- | 3529 | push fat16_root_first |
|
- | 3530 | push fat16_root_next |
|
- | 3531 | jmp .common1 |
|
- | 3532 | .noroot: |
|
- | 3533 | ; check existence |
|
- | 3534 | mov byte [ebp], 0 |
|
- | 3535 | call hd_find_lfn |
|
- | 3536 | mov byte [ebp], '/' |
|
- | 3537 | lea esi, [ebp+1] |
|
- | 3538 | jnc @f |
|
- | 3539 | mov eax, ERROR_FILE_NOT_FOUND |
|
- | 3540 | .ret1: |
|
- | 3541 | mov [esp+28], eax |
|
- | 3542 | popad |
|
- | 3543 | xor ebx, ebx |
|
- | 3544 | ret |
|
- | 3545 | @@: |
|
- | 3546 | test byte [edi+11], 0x10 ; must be directory |
|
- | 3547 | mov eax, ERROR_ACCESS_DENIED |
|
- | 3548 | jz .ret1 |
|
- | 3549 | mov ebp, [edi+20-2] |
|
- | 3550 | mov bp, [edi+26] ; ebp=cluster |
|
- | 3551 | mov eax, ERROR_FAT_TABLE |
|
- | 3552 | cmp ebp, 2 |
|
- | 3553 | jb .ret1 |
|
- | 3554 | .pushnotroot: |
|
- | 3555 | push fat_notroot_extend_dir |
|
- | 3556 | push fat_notroot_end_write |
|
- | 3557 | push fat_notroot_next_write |
|
- | 3558 | push fat_notroot_begin_write |
|
- | 3559 | push 0 |
|
- | 3560 | push ebp |
|
- | 3561 | push fat_notroot_first |
|
- | 3562 | push fat_notroot_next |
|
- | 3563 | .common1: |
|
- | 3564 | call fat_find_lfn |
|
- | 3565 | jc .notfound |
|
- | 3566 | ; found, delete FAT chain |
|
- | 3567 | push edi |
|
- | 3568 | xor eax, eax |
|
- | 3569 | mov dword [edi+28], eax ; zero size |
|
- | 3570 | xor ecx, ecx |
|
- | 3571 | mov eax, [edi+20-2] |
|
- | 3572 | mov ax, [edi+26] |
|
- | 3573 | mov word [edi+20], cx |
|
- | 3574 | mov word [edi+26], cx |
|
- | 3575 | test eax, eax |
|
- | 3576 | jz .done1 |
|
- | 3577 | mov [f_del], 1 |
|
- | 3578 | @@: |
|
- | 3579 | cmp eax, [fatRESERVED] |
|
- | 3580 | jae .done1 |
|
- | 3581 | push edx |
|
- | 3582 | xor edx, edx |
|
- | 3583 | call set_FAT |
|
- | 3584 | mov eax, edx |
|
- | 3585 | pop edx |
|
- | 3586 | inc ecx |
|
- | 3587 | jmp @b |
|
- | 3588 | .done1: |
|
- | 3589 | pop edi |
|
- | 3590 | call get_time_for_file |
|
- | 3591 | mov [edi+22], ax |
|
- | 3592 | call get_date_for_file |
|
- | 3593 | mov [edi+24], ax |
|
- | 3594 | mov [edi+18], ax |
|
- | 3595 | or byte [edi+11], 20h ; set 'archive' attribute |
|
- | 3596 | jmp .doit |
|
- | 3597 | .notfound: |
|
- | 3598 | ; file is not found; generate short name |
|
- | 3599 | call fat_name_is_legal |
|
- | 3600 | jc @f |
|
- | 3601 | add esp, 32 |
|
- | 3602 | popad |
|
- | 3603 | mov eax, ERROR_FILE_NOT_FOUND |
|
- | 3604 | xor ebx, ebx |
|
- | 3605 | ret |
|
- | 3606 | @@: |
|
- | 3607 | sub esp, 12 |
|
- | 3608 | mov edi, esp |
|
- | 3609 | call fat_gen_short_name |
|
- | 3610 | .test_short_name_loop: |
|
- | 3611 | push esi edi ecx |
|
- | 3612 | mov esi, edi |
|
- | 3613 | lea eax, [esp+12+12+8] |
|
- | 3614 | mov [eax], ebp |
|
- | 3615 | and dword [eax+4], 0 |
|
- | 3616 | call dword [eax-4] |
|
- | 3617 | jc .found |
|
- | 3618 | .test_short_name_entry: |
|
- | 3619 | cmp byte [edi+11], 0xF |
|
- | 3620 | jz .test_short_name_cont |
|
- | 3621 | mov ecx, 11 |
|
- | 3622 | push esi edi |
|
- | 3623 | repz cmpsb |
|
- | 3624 | pop edi esi |
|
- | 3625 | jz .short_name_found |
|
- | 3626 | .test_short_name_cont: |
|
- | 3627 | lea eax, [esp+12+12+8] |
|
- | 3628 | call dword [eax-8] |
|
- | 3629 | jnc .test_short_name_entry |
|
- | 3630 | jmp .found |
|
- | 3631 | .short_name_found: |
|
- | 3632 | pop ecx edi esi |
|
- | 3633 | call fat_next_short_name |
|
- | 3634 | jnc .test_short_name_loop |
|
- | 3635 | .disk_full: |
|
- | 3636 | add esp, 12+32 |
|
- | 3637 | popa |
|
- | 3638 | mov eax, ERROR_DISK_FULL |
|
- | 3639 | xor ebx, ebx |
|
- | 3640 | ret |
|
- | 3641 | .found: |
|
- | 3642 | pop ecx edi esi |
|
- | 3643 | ; now find space in directory |
|
- | 3644 | ; we need to save LFN <=> LFN is not equal to short name <=> generated name contains '~' |
|
- | 3645 | mov al, '~' |
|
- | 3646 | push ecx edi |
|
- | 3647 | mov ecx, 8 |
|
- | 3648 | repnz scasb |
|
- | 3649 | push 1 |
|
- | 3650 | pop eax ; 1 entry |
|
- | 3651 | jnz .notilde |
|
- | 3652 | ; we need ceil(strlen(esi)/13) additional entries = floor((strlen(esi)+12+13)/13) total |
|
- | 3653 | xor eax, eax |
|
- | 3654 | @@: |
|
- | 3655 | cmp byte [esi], 0 |
|
- | 3656 | jz @f |
|
- | 3657 | inc esi |
|
- | 3658 | inc eax |
|
- | 3659 | jmp @b |
|
- | 3660 | @@: |
|
- | 3661 | sub esi, eax |
|
- | 3662 | add eax, 12+13 |
|
- | 3663 | mov ecx, 13 |
|
- | 3664 | push edx |
|
- | 3665 | cdq |
|
- | 3666 | div ecx |
|
- | 3667 | pop edx |
|
- | 3668 | .notilde: |
|
- | 3669 | push -1 |
|
- | 3670 | push -1 |
|
- | 3671 | push -1 |
|
- | 3672 | ; find |
|
- | 3673 | xor ecx, ecx |
|
- | 3674 | push eax |
|
- | 3675 | lea eax, [esp+16+8+12+8] |
|
- | 3676 | mov [eax], ebp |
|
- | 3677 | and dword [eax+4], 0 |
|
- | 3678 | call dword [eax-4] |
|
- | 3679 | pop eax |
|
- | 3680 | jnc .scan_dir |
|
- | 3681 | .fsfrfe3: |
|
- | 3682 | add esp, 12+8+12+32 |
|
- | 3683 | popad |
|
- | 3684 | mov eax, 11 |
|
- | 3685 | xor ebx, ebx |
|
- | 3686 | ret |
|
- | 3687 | .scan_dir: |
|
- | 3688 | cmp byte [edi], 0 |
|
- | 3689 | jz .free |
|
- | 3690 | cmp byte [edi], 0xE5 |
|
- | 3691 | jz .free |
|
- | 3692 | xor ecx, ecx |
|
- | 3693 | .scan_cont: |
|
- | 3694 | push eax |
|
- | 3695 | lea eax, [esp+16+8+12+8] |
|
- | 3696 | call dword [eax-8] |
|
- | 3697 | pop eax |
|
- | 3698 | jnc .scan_dir |
|
- | 3699 | cmp [hd_error], 0 |
|
- | 3700 | jnz .fsfrfe3 |
|
- | 3701 | push eax |
|
- | 3702 | lea eax, [esp+16+8+12+8] |
|
- | 3703 | call dword [eax+20] ; extend directory |
|
- | 3704 | pop eax |
|
- | 3705 | jnc .scan_dir |
|
- | 3706 | add esp, 12+8+12+32 |
|
- | 3707 | popad |
|
- | 3708 | mov eax, ERROR_DISK_FULL |
|
- | 3709 | xor ebx, ebx |
|
- | 3710 | ret |
|
- | 3711 | .free: |
|
- | 3712 | test ecx, ecx |
|
- | 3713 | jnz @f |
|
- | 3714 | mov [esp], edi |
|
- | 3715 | mov ecx, [esp+12+8+12+8] |
|
- | 3716 | mov [esp+4], ecx |
|
- | 3717 | mov ecx, [esp+12+8+12+12] |
|
- | 3718 | mov [esp+8], ecx |
|
- | 3719 | xor ecx, ecx |
|
- | 3720 | @@: |
|
- | 3721 | inc ecx |
|
- | 3722 | cmp ecx, eax |
|
- | 3723 | jb .scan_cont |
|
- | 3724 | ; found! |
|
- | 3725 | ; calculate name checksum |
|
- | 3726 | push esi ecx |
|
- | 3727 | mov esi, [esp+8+12] |
|
- | 3728 | mov ecx, 11 |
|
- | 3729 | xor eax, eax |
|
- | 3730 | @@: |
|
- | 3731 | ror al, 1 |
|
- | 3732 | add al, [esi] |
|
- | 3733 | inc esi |
|
- | 3734 | loop @b |
|
- | 3735 | pop ecx esi |
|
- | 3736 | pop edi |
|
- | 3737 | pop dword [esp+8+12+12] |
|
- | 3738 | pop dword [esp+8+12+12] |
|
- | 3739 | ; edi points to first entry in free chunk |
|
- | 3740 | dec ecx |
|
- | 3741 | jz .nolfn |
|
- | 3742 | push esi |
|
- | 3743 | push eax |
|
- | 3744 | lea eax, [esp+8+8+12+8] |
|
- | 3745 | call dword [eax+8] ; begin write |
|
- | 3746 | mov al, 40h |
|
- | 3747 | .writelfn: |
|
- | 3748 | or al, cl |
|
- | 3749 | mov esi, [esp+4] |
|
- | 3750 | push ecx |
|
- | 3751 | dec ecx |
|
- | 3752 | imul ecx, 13 |
|
- | 3753 | add esi, ecx |
|
- | 3754 | stosb |
|
- | 3755 | mov cl, 5 |
|
- | 3756 | call fs_RamdiskRewrite.read_symbols |
|
- | 3757 | mov ax, 0xF |
|
- | 3758 | stosw |
|
- | 3759 | mov al, [esp+4] |
|
- | 3760 | stosb |
|
- | 3761 | mov cl, 6 |
|
- | 3762 | call fs_RamdiskRewrite.read_symbols |
|
- | 3763 | xor eax, eax |
|
- | 3764 | stosw |
|
- | 3765 | mov cl, 2 |
|
- | 3766 | call fs_RamdiskRewrite.read_symbols |
|
- | 3767 | pop ecx |
|
- | 3768 | lea eax, [esp+8+8+12+8] |
|
- | 3769 | call dword [eax+12] ; next write |
|
- | 3770 | xor eax, eax |
|
- | 3771 | loop .writelfn |
|
- | 3772 | pop eax |
|
- | 3773 | pop esi |
|
- | 3774 | ; lea eax, [esp+8+12+8] |
|
- | 3775 | ; call dword [eax+16] ; end write |
|
- | 3776 | .nolfn: |
|
- | 3777 | xchg esi, [esp] |
|
- | 3778 | mov ecx, 11 |
|
- | 3779 | rep movsb |
|
- | 3780 | mov word [edi], 20h ; attributes |
|
- | 3781 | sub edi, 11 |
|
- | 3782 | pop esi ecx |
|
- | 3783 | add esp, 12 |
|
- | 3784 | mov byte [edi+13], 0 ; tenths of a second at file creation time |
|
- | 3785 | call get_time_for_file |
|
- | 3786 | mov [edi+14], ax ; creation time |
|
- | 3787 | mov [edi+22], ax ; last write time |
|
- | 3788 | call get_date_for_file |
|
- | 3789 | mov [edi+16], ax ; creation date |
|
- | 3790 | mov [edi+24], ax ; last write date |
|
- | 3791 | mov [edi+18], ax ; last access date |
|
- | 3792 | xor ecx, ecx |
|
- | 3793 | mov word [edi+20], cx ; high word of cluster |
|
- | 3794 | mov word [edi+26], cx ; low word of cluster - to be filled |
|
- | 3795 | mov dword [edi+28], ecx ; file size - to be filled |
|
- | 3796 | .doit: |
|
- | 3797 | lea eax, [esp+8] |
|
- | 3798 | call dword [eax+16] ; flush directory |
|
- | 3799 | push ecx |
|
- | 3800 | mov ecx, [esp+4+32+24] |
|
- | 3801 | push ecx |
|
- | 3802 | push edi |
|
- | 3803 | mov esi, edx |
|
- | 3804 | test ecx, ecx |
|
- | 3805 | jz .done |
|
- | 3806 | mov eax, 2 |
|
- | 3807 | call get_free_FAT |
|
- | 3808 | jc .diskfull |
|
- | 3809 | push eax |
|
- | 3810 | mov [edi+26], ax |
|
- | 3811 | shr eax, 16 |
|
- | 3812 | mov [edi+20], ax |
|
- | 3813 | lea eax, [esp+16+8] |
|
- | 3814 | call dword [eax+16] ; flush directory |
|
- | 3815 | pop eax |
|
- | 3816 | push edx |
|
- | 3817 | mov edx, [fatEND] |
|
- | 3818 | call set_FAT |
|
- | 3819 | pop edx |
|
- | 3820 | .write_cluster: |
|
- | 3821 | push eax |
|
- | 3822 | dec eax |
|
- | 3823 | dec eax |
|
- | 3824 | mov ebp, [SECTORS_PER_CLUSTER] |
|
- | 3825 | imul eax, ebp |
|
- | 3826 | add eax, [DATA_START] |
|
- | 3827 | ; write data |
|
- | 3828 | .write_sector: |
|
- | 3829 | mov ecx, 512 |
|
- | 3830 | cmp dword [esp+8], ecx |
|
- | 3831 | jb .writeshort |
|
- | 3832 | ; we can write directly from given buffer |
|
- | 3833 | mov ebx, esi |
|
- | 3834 | add esi, ecx |
|
- | 3835 | jmp .writecommon |
|
- | 3836 | .writeshort: |
|
- | 3837 | mov ecx, [esp+8] |
|
- | 3838 | push ecx |
|
- | 3839 | mov edi, buffer |
|
- | 3840 | mov ebx, edi |
|
- | 3841 | rep movsb |
|
- | 3842 | mov ecx, buffer+0x200 |
|
- | 3843 | sub ecx, edi |
|
- | 3844 | push eax |
|
- | 3845 | xor eax, eax |
|
- | 3846 | rep stosb |
|
- | 3847 | pop eax |
|
- | 3848 | pop ecx |
|
- | 3849 | .writecommon: |
|
- | 3850 | call hd_write |
|
- | 3851 | cmp [hd_error], 0 |
|
- | 3852 | jnz .writeerr |
|
- | 3853 | inc eax |
|
- | 3854 | sub dword [esp+8], ecx |
|
- | 3855 | jz .writedone |
|
- | 3856 | dec ebp |
|
- | 3857 | jnz .write_sector |
|
- | 3858 | ; allocate new cluster |
|
- | 3859 | pop eax |
|
- | 3860 | mov ecx, eax |
|
- | 3861 | call get_free_FAT |
|
- | 3862 | jc .diskfull |
|
- | 3863 | mov [f_del], 1 |
|
- | 3864 | push edx |
|
- | 3865 | mov edx, [fatEND] |
|
- | 3866 | call set_FAT |
|
- | 3867 | xchg eax, ecx |
|
- | 3868 | mov edx, ecx |
|
- | 3869 | call set_FAT |
|
- | 3870 | pop edx |
|
- | 3871 | xchg eax, ecx |
|
- | 3872 | jmp .write_cluster |
|
- | 3873 | .diskfull: |
|
- | 3874 | mov eax, ERROR_DISK_FULL |
|
- | 3875 | jmp .ret |
|
- | 3876 | .writeerr: |
|
- | 3877 | pop eax |
|
- | 3878 | sub esi, ecx |
|
- | 3879 | mov eax, 11 |
|
- | 3880 | jmp .ret |
|
- | 3881 | .writedone: |
|
- | 3882 | pop eax |
|
- | 3883 | .done: |
|
- | 3884 | xor eax, eax |
|
- | 3885 | .ret: |
|
- | 3886 | pop edi ecx |
|
- | 3887 | mov ebx, esi |
|
- | 3888 | sub ebx, edx |
|
- | 3889 | pop ebp |
|
- | 3890 | mov [esp+32+28], eax |
|
- | 3891 | lea eax, [esp+8] |
|
- | 3892 | call dword [eax+8] |
|
- | 3893 | mov [edi+28], ebx |
|
- | 3894 | call dword [eax+16] |
|
- | 3895 | mov [esp+32+16], ebx |
|
- | 3896 | lea eax, [ebx+511] |
|
- | 3897 | shr eax, 9 |
|
- | 3898 | mov ecx, [SECTORS_PER_CLUSTER] |
|
- | 3899 | lea eax, [eax+ecx-1] |
|
- | 3900 | xor edx, edx |
|
- | 3901 | div ecx |
|
- | 3902 | mov ecx, ebp |
|
- | 3903 | sub ecx, eax |
|
- | 3904 | call add_disk_free_space |
|
- | 3905 | add esp, 32 |
|
- | 3906 | call update_disk |
|
- | 3907 | popad |
|
- | 3908 | ret |
|
3368 | 3909 |