Rev 131 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 131 | Rev 133 | ||
---|---|---|---|
Line 88... | Line 88... | ||
88 | 88 | ||
89 | uglobal |
89 | uglobal |
90 | Sector512: ; label for dev_hdcd.inc |
90 | Sector512: ; label for dev_hdcd.inc |
91 | buffer: times 512 db 0 |
91 | buffer: times 512 db 0 |
- | 92 | deltree_buffer: times 512 db 0 |
|
92 | deltree_buffer: times 512 db 0 |
93 | fsinfo_buffer: times 512 db 0 |
Line 93... | Line 94... | ||
93 | endg |
94 | endg |
94 | 95 | ||
95 | iglobal |
96 | iglobal |
Line 1035... | Line 1036... | ||
1035 | cmp [fat_type],32 ; free disk space only used by fat32 |
1036 | cmp [fat_type],32 ; free disk space only used by fat32 |
1036 | jne add_dfs_no |
1037 | jne add_dfs_no |
Line 1037... | Line 1038... | ||
1037 | 1038 | ||
1038 | push eax ebx |
1039 | push eax ebx |
1039 | mov eax,[ADR_FSINFO] |
1040 | mov eax,[ADR_FSINFO] |
1040 | mov ebx,buffer |
1041 | mov ebx,fsinfo_buffer |
1041 | call hd_read |
1042 | call hd_read |
1042 | cmp [hd_error],0 |
1043 | cmp [hd_error],0 |
Line 1043... | Line 1044... | ||
1043 | jne add_not_fs |
1044 | jne add_not_fs |
1044 | 1045 | ||
Line 1045... | Line 1046... | ||
1045 | cmp dword [ebx+0x1fc],0xaa550000 ; check sector id |
1046 | cmp dword [ebx+0x1fc],0xaa550000 ; check sector id |
1046 | jne add_not_fs |
1047 | jne add_not_fs |
1047 | 1048 | ||
1048 | add [ebx+0x1e8],ecx |
1049 | add [ebx+0x1e8],ecx |
Line 1049... | Line 1050... | ||
1049 | call hd_write |
1050 | call hd_write |
1050 | cmp [hd_error],0 |
1051 | ; cmp [hd_error],0 |
Line 1051... | Line 1052... | ||
1051 | jne add_not_fs |
1052 | ; jne add_not_fs |
1052 | 1053 | ||
Line 1053... | Line -... | ||
1053 | add_not_fs: |
- | |
1054 | pop ebx eax |
- | |
1055 | - | ||
1056 | add_dfs_no: |
- | |
1057 | ret |
- | |
1058 | - | ||
1059 | - | ||
1060 | file_append: |
- | |
1061 | ;----------------------------------------------------- |
- | |
1062 | ; input : eax = file name |
- | |
1063 | ; edx = path |
- | |
1064 | ; ecx = pointer to buffer |
- | |
1065 | ; ebx = bytes to write (0 = truncate file) |
- | |
1066 | ; esi = start position (-1 = end of file) |
- | |
1067 | ; output : eax = 0 - ok |
- | |
1068 | ; 3 - unknown FS |
- | |
1069 | ; 5 - file not found |
- | |
1070 | ; 6 - end of file |
- | |
1071 | ; 8 - disk full |
- | |
1072 | ; 9 - fat table corrupted |
- | |
1073 | ; 10 - access denied |
- | |
1074 | ; ebx = bytes written |
- | |
1075 | ;----------------------------------------------------- |
- | |
1076 | cmp [fat_type],0 |
- | |
1077 | jnz append_fat_ok |
- | |
1078 | mov eax,ERROR_UNKNOWN_FS |
- | |
1079 | ret |
- | |
1080 | - | ||
1081 | append_fat_ok: |
- | |
1082 | ; call reserve_hd1 |
- | |
1083 | - | ||
1084 | pushad |
- | |
1085 | - | ||
1086 | mov ebx,edx |
- | |
1087 | call get_cluster_of_a_path |
- | |
1088 | jc append_not_found |
- | |
1089 | - | ||
1090 | mov ebx,PUSHAD_EAX ; file name |
- | |
1091 | call analyze_directory |
- | |
1092 | jc append_not_found |
- | |
1093 | - | ||
1094 | mov [sector_tmp],eax |
- | |
1095 | mov [entry_pos],ebx |
- | |
1096 | - | ||
1097 | test byte [ebx+11],0x10 ; is it directory? |
- | |
1098 | jnz append_access ; yes |
- | |
1099 | - | ||
1100 | mov ecx,[ebx+28] ; file size |
- | |
1101 | mov edi,PUSHAD_ESI ; write position |
- | |
1102 | cmp edi,-1 ; -1 = eof |
- | |
1103 | jnz append_inside_file |
- | |
1104 | mov edi,ecx ; file size |
- | |
1105 | - | ||
1106 | append_inside_file: |
- | |
1107 | cmp edi,ecx ; start above old file size? |
- | |
1108 | ja append_eof ; yes |
- | |
1109 | - | ||
1110 | mov [old_filesize],ecx |
- | |
1111 | mov [new_filepos],edi |
- | |
1112 | - | ||
1113 | mov ecx,PUSHAD_EBX ; bytes to write |
- | |
1114 | test ecx,ecx ; truncate? |
- | |
1115 | jz append_truncate ; yes |
- | |
1116 | - | ||
1117 | mov [bytes2write],ecx ; bytes to write |
- | |
1118 | mov esi,PUSHAD_ECX ; pointer to buffer |
- | |
1119 | mov eax,[ebx+20-2] ; FAT entry |
- | |
1120 | mov ax,[ebx+26] |
- | |
1121 | and eax,[fatMASK] |
- | |
1122 | jnz append_find_pos ; first cluster <> 0 |
- | |
1123 | - | ||
1124 | mov eax,2 |
- | |
1125 | call get_free_FAT |
- | |
1126 | jc append_disk_full |
- | |
1127 | mov ecx,eax ; set files first cluster |
- | |
1128 | mov [ebx+26],cx ; 16 bits low of cluster |
- | |
1129 | shr ecx,16 |
- | |
1130 | mov [ebx+20],cx ; 16 bits high of cluster (=0 fat16) |
- | |
1131 | mov edx,[fatEND] ; new end for cluster chain |
- | |
1132 | call set_FAT |
- | |
1133 | cmp [hd_error],0 |
- | |
1134 | jne append_access |
- | |
1135 | - | ||
1136 | push eax ; save first cluster |
- | |
1137 | mov eax,[sector_tmp] |
- | |
1138 | mov ebx,buffer |
- | |
1139 | call hd_write ; write new file entry back to disk |
- | |
1140 | cmp [hd_error],0 |
- | |
1141 | jne append_access_1 |
- | |
1142 | - | ||
1143 | pop eax |
- | |
1144 | - | ||
1145 | append_remove_free: |
- | |
1146 | mov ecx,-1 ; remove 1 cluster from free disk space |
- | |
1147 | call add_disk_free_space ; Note: uses buffer |
- | |
1148 | cmp [hd_error],0 |
- | |
1149 | jne append_access |
- | |
1150 | - | ||
1151 | append_found_cluster: |
- | |
1152 | mov [cluster],eax |
- | |
1153 | sub eax,2 |
- | |
1154 | mov ecx,[SECTORS_PER_CLUSTER] |
- | |
1155 | imul eax,ecx |
- | |
1156 | add eax,[DATA_START] |
- | |
1157 | xor edi,edi |
- | |
1158 | - | ||
1159 | append_new_sector: |
- | |
1160 | cmp [hd_error],0 |
- | |
1161 | jne append_access |
- | |
1162 | push ecx |
- | |
1163 | mov ecx,[bytes2write] ; bytes left in buffer |
- | |
1164 | mov ebx,512 |
- | |
1165 | sub ebx,edi ; bytes left in sector |
- | |
1166 | cmp ecx,ebx |
- | |
1167 | jb append_bytes_ok |
- | |
1168 | mov ecx,ebx |
- | |
1169 | - | ||
1170 | append_bytes_ok: |
- | |
1171 | cmp ecx,512 ; overwrite full sector? |
- | |
1172 | jz append_full_sector ; yes |
- | |
1173 | mov ebx,buffer ; overwrite part of sector |
- | |
1174 | call hd_read ; read old sector |
- | |
1175 | cmp [hd_error],0 |
- | |
1176 | jne append_access_1 |
- | |
1177 | - | ||
1178 | append_full_sector: |
- | |
1179 | sub [bytes2write],ecx |
- | |
1180 | add [new_filepos],ecx |
- | |
1181 | add edi,buffer |
- | |
1182 | cld |
- | |
1183 | rep movsb |
- | |
1184 | pop ecx |
- | |
1185 | - | ||
1186 | mov ebx,buffer |
- | |
1187 | call hd_write |
- | |
1188 | cmp [hd_error],0 |
- | |
1189 | jne append_access |
- | |
1190 | - | ||
1191 | cmp [bytes2write],0 ; is all done? |
- | |
1192 | jz append_done |
- | |
1193 | xor edi,edi |
- | |
1194 | inc eax |
- | |
1195 | dec ecx |
- | |
1196 | jnz append_new_sector |
- | |
1197 | - | ||
1198 | mov eax,[cluster] |
- | |
1199 | call get_FAT |
- | |
1200 | cmp [hd_error],0 |
- | |
1201 | jne append_access |
- | |
1202 | - | ||
1203 | cmp eax,2 |
- | |
1204 | jb append_fat |
- | |
1205 | cmp eax,[LAST_CLUSTER] |
- | |
1206 | jbe append_found_cluster |
- | |
1207 | - | ||
1208 | append_alloc_cluster: |
- | |
1209 | mov eax,2 ; ToDo: use temp array to keep track |
- | |
1210 | call get_free_FAT ; of last free cluster |
- | |
1211 | jc append_disk_full |
- | |
1212 | push eax ; save new cluster |
- | |
1213 | mov edx,[fatEND] ; new end for cluster chain |
- | |
1214 | call set_FAT |
- | |
1215 | cmp [hd_error],0 |
- | |
1216 | jne append_access_1 |
- | |
1217 | - | ||
1218 | mov edx,eax |
- | |
1219 | mov eax,[cluster] |
- | |
1220 | call set_FAT ; update previous cluster |
- | |
1221 | cmp [hd_error],0 |
- | |
1222 | jne append_access_1 |
- | |
1223 | - | ||
1224 | pop eax |
- | |
1225 | jmp append_remove_free |
- | |
1226 | - | ||
1227 | append_find_pos: |
- | |
1228 | call find_filepos |
- | |
1229 | mov [cluster],ebx |
- | |
1230 | jnc append_new_sector |
- | |
1231 | test edi,edi |
- | |
1232 | jz append_alloc_cluster |
- | |
1233 | - | ||
1234 | append_fat: |
- | |
1235 | mov eax,ERROR_FAT_TABLE |
- | |
1236 | jmp append_ret_code |
- | |
1237 | - | ||
1238 | append_disk_full: |
- | |
1239 | cmp [hd_error],0 |
- | |
1240 | jne append_access |
- | |
1241 | mov eax,ERROR_DISK_FULL |
- | |
1242 | jmp append_ret_code |
- | |
1243 | - | ||
1244 | append_done: |
- | |
1245 | xor eax,eax |
- | |
1246 | - | ||
1247 | append_ret_code: |
- | |
1248 | mov PUSHAD_EAX,eax ; return code |
- | |
1249 | - | ||
1250 | mov eax,[sector_tmp] ; update directory entry |
- | |
1251 | mov ebx,buffer |
- | |
1252 | call hd_read |
- | |
1253 | cmp [hd_error],0 |
- | |
1254 | jne append_access |
- | |
1255 | - | ||
1256 | mov ebx,[entry_pos] |
- | |
1257 | mov ecx,[new_filepos] |
- | |
1258 | cmp ecx,[old_filesize] ; is file pos above old size? |
- | |
1259 | jbe append_size_ok ; no |
- | |
1260 | mov [ebx+28],ecx ; new file size |
- | |
1261 | - | ||
1262 | append_size_ok: |
- | |
1263 | call set_current_time_for_entry |
- | |
1264 | mov ebx,buffer |
- | |
1265 | call hd_write ; write new file entry back to disk |
- | |
1266 | cmp [hd_error],0 |
- | |
1267 | jne append_access |
- | |
1268 | - | ||
1269 | sub ecx,PUSHAD_ESI ; start position |
- | |
1270 | mov PUSHAD_EBX,ecx ; bytes written |
- | |
1271 | popad |
- | |
1272 | call update_disk ; write all of cache and fat to hd |
- | |
1273 | cmp [hd_error],0 |
- | |
1274 | jne append_access_2 |
- | |
1275 | - | ||
1276 | mov [hd1_status],0 |
- | |
1277 | ret |
- | |
1278 | - | ||
1279 | append_eof: |
- | |
1280 | popad |
- | |
1281 | mov [hd1_status],0 |
- | |
1282 | xor ebx,ebx |
- | |
1283 | mov eax,ERROR_END_OF_FILE |
- | |
1284 | ret |
- | |
1285 | - | ||
1286 | append_not_found: |
- | |
1287 | cmp [hd_error],0 |
- | |
1288 | jne append_access |
- | |
1289 | popad |
- | |
1290 | mov [hd1_status],0 |
- | |
1291 | xor ebx,ebx |
- | |
1292 | mov eax,ERROR_FILE_NOT_FOUND |
- | |
1293 | ret |
- | |
1294 | append_access_1: |
- | |
1295 | add esp,4 |
- | |
1296 | append_access: |
- | |
1297 | popad |
- | |
1298 | append_access_2: |
- | |
1299 | mov [hd1_status],0 |
- | |
1300 | xor ebx,ebx |
- | |
1301 | mov eax,ERROR_ACCESS_DENIED |
- | |
1302 | ret |
- | |
1303 | - | ||
1304 | append_truncate: |
- | |
1305 | mov edx,[ebx+20-2] ; FAT entry |
- | |
1306 | mov dx,[ebx+26] |
- | |
1307 | and edx,[fatMASK] |
- | |
1308 | mov [ebx+28],edi ; set new file size |
- | |
1309 | test edi,edi ; 0 length file? |
- | |
1310 | jnz truncate_save_size ; no |
- | |
1311 | mov [ebx+20],di ; FAT entry = 0 |
- | |
1312 | mov [ebx+26],di |
- | |
1313 | - | ||
1314 | truncate_save_size: |
- | |
1315 | call set_current_time_for_entry |
- | |
1316 | mov ebx,buffer |
- | |
1317 | call hd_write |
- | |
1318 | cmp [hd_error],0 |
- | |
1319 | jne append_access |
- | |
1320 | - | ||
1321 | mov eax,edx ; first cluster |
- | |
1322 | test edi,edi ; 0 length file? |
- | |
1323 | jz truncate_clear_chain |
- | |
1324 | - | ||
1325 | imul esi,[SECTORS_PER_CLUSTER],512 ; esi = cluster size in bytes |
- | |
1326 | - | ||
1327 | truncate_new_cluster: |
- | |
1328 | cmp eax,2 ; incorrect fat chain? |
- | |
1329 | jb truncate_eof ; yes |
- | |
1330 | cmp eax,[fatRESERVED] ; is it end of file? |
- | |
1331 | jnb truncate_eof ; yes |
- | |
1332 | sub edi,esi |
- | |
1333 | jbe truncate_pos_found |
- | |
1334 | call get_FAT ; get next cluster |
- | |
1335 | cmp [hd_error],0 |
- | |
1336 | jne append_access |
- | |
1337 | - | ||
1338 | jmp truncate_new_cluster |
- | |
1339 | - | ||
1340 | truncate_pos_found: |
- | |
1341 | mov edx,[fatEND] ; new end for cluster chain |
- | |
1342 | call set_FAT |
- | |
1343 | cmp [hd_error],0 |
- | |
1344 | jne append_access |
- | |
1345 | - | ||
1346 | mov eax,edx ; clear rest of chain |
- | |
1347 | - | ||
1348 | truncate_clear_chain: |
- | |
1349 | call clear_cluster_chain |
- | |
1350 | cmp [hd_error],0 |
- | |
1351 | jne append_access |
- | |
1352 | - | ||
1353 | truncate_eof: |
- | |
1354 | popad |
- | |
1355 | call update_disk ; write all of cache and fat to hd |
- | |
1356 | cmp [hd_error],0 |
- | |
1357 | jne append_access_2 |
- | |
1358 | - | ||
1359 | mov [hd1_status],0 |
- | |
1360 | xor ebx,ebx |
- | |
1361 | xor eax,eax |
- | |
1362 | ret |
- | |
1363 | - | ||
1364 | - | ||
1365 | find_filepos: |
- | |
1366 | ;----------------------------------------------------- |
- | |
1367 | ; input : eax = first cluster |
- | |
1368 | ; edi = bytes to skip over (start position) |
- | |
1369 | ; output : if CARRY=0 file position found |
- | |
1370 | ; if CARRY=1 end of file found |
- | |
1371 | ; eax = current file sector |
- | |
1372 | ; ebx = last cluster |
- | |
1373 | ; ecx = sector count in last cluster |
- | |
1374 | ; edi = bytes to skip over (sector position) |
- | |
1375 | ;----------------------------------------------------- |
- | |
1376 | push esi |
- | |
1377 | mov ecx,[SECTORS_PER_CLUSTER] |
- | |
1378 | imul esi,ecx,512 ; esi = cluster size in bytes |
- | |
1379 | mov ebx,eax |
- | |
1380 | - | ||
1381 | filepos_new_cluster: |
- | |
1382 | cmp eax,2 ; incorrect fat chain? |
- | |
1383 | jb filepos_eof ; yes |
- | |
1384 | cmp eax,[fatRESERVED] ; is it end of file? |
- | |
1385 | jnb filepos_eof ; yes |
- | |
1386 | - | ||
1387 | mov ebx,eax |
- | |
1388 | cmp edi,esi ; skip over full cluster? |
- | |
1389 | jb filepos_cluster_ok ; no |
- | |
1390 | - | ||
1391 | sub edi,esi |
- | |
1392 | call get_FAT ; get next cluster |
- | |
1393 | cmp [hd_error],0 |
- | |
1394 | jne filepos_eof |
- | |
1395 | - | ||
1396 | jmp filepos_new_cluster |
- | |
1397 | - | ||
1398 | filepos_cluster_ok: |
- | |
1399 | sub eax,2 |
- | |
1400 | imul eax,ecx |
- | |
1401 | add eax,[DATA_START] |
- | |
1402 | - | ||
1403 | filepos_new_sector: |
- | |
1404 | cmp edi,512 ; skip over full sector? |
- | |
1405 | jb filepos_sector_ok ; no |
- | |
1406 | sub edi,512 |
- | |
1407 | inc eax |
- | |
1408 | dec ecx |
- | |
1409 | jnz filepos_new_sector |
- | |
1410 | - | ||
1411 | filepos_eof: |
- | |
1412 | pop esi |
- | |
1413 | stc |
- | |
1414 | ret |
- | |
1415 | 1054 | add_not_fs: |
|
1416 | filepos_sector_ok: |
1055 | pop ebx eax |
1417 | pop esi |
1056 | |
1418 | clc |
1057 | add_dfs_no: |
1419 | ret |
1058 | ret |
Line 3992... | Line 3631... | ||
3992 | xor eax, eax |
3631 | xor eax, eax |
3993 | jmp hd_extend_file.start_extend |
3632 | jmp hd_extend_file.start_extend |
Line 3994... | Line 3633... | ||
3994 | 3633 | ||
3995 | ; extends file on hd to given size (new data area is undefined) |
3634 | ; extends file on hd to given size (new data area is undefined) |
3996 | ; in: edi->direntry, ecx=new size |
3635 | ; in: edi->direntry, ecx=new size |
3997 | ; out: CF=0 => OK, eax destroyed |
3636 | ; out: CF=0 => OK, eax=0 |
3998 | ; CF=1 => error, eax=code (ERROR_FAT_TABLE or ERROR_DISK_FULL or 11) |
3637 | ; CF=1 => error, eax=code (ERROR_FAT_TABLE or ERROR_DISK_FULL or 11) |
3999 | hd_extend_file: |
3638 | hd_extend_file: |
4000 | push ebp |
3639 | push ebp |
4001 | mov ebp, [SECTORS_PER_CLUSTER] |
3640 | mov ebp, [SECTORS_PER_CLUSTER] |
Line 4070... | Line 3709... | ||
4070 | ror edx, 16 |
3709 | ror edx, 16 |
4071 | mov [edi+20], dx |
3710 | mov [edi+20], dx |
4072 | ror edx, 16 |
3711 | ror edx, 16 |
4073 | mov [edi+26], dx |
3712 | mov [edi+26], dx |
4074 | @@: |
3713 | @@: |
- | 3714 | push ecx |
|
- | 3715 | mov ecx, -1 |
|
- | 3716 | call add_disk_free_space |
|
- | 3717 | pop ecx |
|
4075 | mov eax, edx |
3718 | mov eax, edx |
4076 | cmp [hd_error], 0 |
3719 | cmp [hd_error], 0 |
4077 | jnz .device_err3 |
3720 | jnz .device_err3 |
4078 | add [edi+28], ebp |
3721 | add [edi+28], ebp |
4079 | jmp .extend_loop |
3722 | jmp .extend_loop |
4080 | .extend_done: |
3723 | .extend_done: |
4081 | mov [edi+28], ecx |
3724 | mov [edi+28], ecx |
4082 | pop edx ebp |
3725 | pop edx ebp |
4083 | clc |
3726 | xor eax, eax ; CF=0 |
4084 | ret |
3727 | ret |
4085 | .device_err3: |
3728 | .device_err3: |
4086 | pop edx |
3729 | pop edx |
4087 | jmp .device_err2 |
3730 | jmp .device_err2 |
4088 | .disk_full: |
3731 | .disk_full: |
Line 4093... | Line 3736... | ||
4093 | jz @f |
3736 | jz @f |
4094 | mov al, 11 |
3737 | mov al, 11 |
4095 | @@: stc |
3738 | @@: stc |
4096 | ret |
3739 | ret |
Line -... | Line 3740... | ||
- | 3740 | ||
- | 3741 | ;---------------------------------------------------------------- |
|
- | 3742 | ; |
|
- | 3743 | ; fs_HdSetFileEnd - set end of file on hard disk |
|
- | 3744 | ; |
|
- | 3745 | ; esi points to filename |
|
- | 3746 | ; ebx points to 64-bit number = new file size |
|
- | 3747 | ; ecx ignored (reserved) |
|
- | 3748 | ; edx ignored (reserved) |
|
- | 3749 | ; |
|
- | 3750 | ; ret eax = 0 ok or other = errormsg |
|
- | 3751 | ; |
|
- | 3752 | ;-------------------------------------------------------------- |
|
- | 3753 | fs_HdSetFileEnd: |
|
- | 3754 | cmp [fat_type], 0 |
|
- | 3755 | jnz @f |
|
- | 3756 | push ERROR_UNKNOWN_FS |
|
- | 3757 | .ret: |
|
- | 3758 | pop eax |
|
- | 3759 | ret |
|
- | 3760 | @@: |
|
- | 3761 | cmp byte [esi], 0 |
|
- | 3762 | jnz @f |
|
- | 3763 | .access_denied: |
|
- | 3764 | push ERROR_ACCESS_DENIED |
|
- | 3765 | jmp .ret |
|
- | 3766 | @@: |
|
- | 3767 | push edi |
|
- | 3768 | call hd_find_lfn |
|
- | 3769 | pushfd |
|
- | 3770 | cmp [hd_error], 0 |
|
- | 3771 | jz @f |
|
- | 3772 | popfd |
|
- | 3773 | push 11 |
|
- | 3774 | jmp .ret |
|
- | 3775 | @@: |
|
- | 3776 | popfd |
|
- | 3777 | jnc @f |
|
- | 3778 | pop edi |
|
- | 3779 | push ERROR_FILE_NOT_FOUND |
|
- | 3780 | jmp .ret |
|
- | 3781 | @@: |
|
- | 3782 | ; must not be directory |
|
- | 3783 | test byte [edi+11], 10h |
|
- | 3784 | jz @f |
|
- | 3785 | pop edi |
|
- | 3786 | jmp .access_denied |
|
- | 3787 | @@: |
|
- | 3788 | ; file size must not exceed 4 Gb |
|
- | 3789 | cmp dword [ebx+4], 0 |
|
- | 3790 | jz @f |
|
- | 3791 | pop edi |
|
- | 3792 | push ERROR_END_OF_FILE |
|
- | 3793 | jmp .ret |
|
- | 3794 | @@: |
|
- | 3795 | push eax ; save directory sector |
|
- | 3796 | ; set file modification date/time to current |
|
- | 3797 | call fat_update_datetime |
|
- | 3798 | mov eax, [ebx] |
|
- | 3799 | cmp eax, [edi+28] |
|
- | 3800 | jb .truncate |
|
- | 3801 | ja .expand |
|
- | 3802 | pop eax |
|
- | 3803 | mov ebx, buffer |
|
- | 3804 | call hd_write |
|
- | 3805 | pop edi |
|
- | 3806 | xor eax, eax |
|
- | 3807 | cmp [hd_error], 0 |
|
- | 3808 | jz @f |
|
- | 3809 | mov al, 11 |
|
- | 3810 | @@: |
|
- | 3811 | ret |
|
- | 3812 | .expand: |
|
- | 3813 | push ebx ebp ecx |
|
- | 3814 | push dword [edi+28] ; save old size |
|
- | 3815 | mov ecx, eax |
|
- | 3816 | call hd_extend_file |
|
- | 3817 | push eax ; return code |
|
- | 3818 | jnc .expand_ok |
|
- | 3819 | cmp al, ERROR_DISK_FULL |
|
- | 3820 | jz .disk_full |
|
- | 3821 | .pop_ret: |
|
- | 3822 | call update_disk |
|
- | 3823 | pop eax ecx ebp ebx ecx edi edi |
|
- | 3824 | ret |
|
- | 3825 | .expand_ok: |
|
- | 3826 | .disk_full: |
|
- | 3827 | ; save directory |
|
- | 3828 | mov eax, [edi+28] |
|
- | 3829 | xchg eax, [esp+20] |
|
- | 3830 | mov ebx, buffer |
|
- | 3831 | call hd_write |
|
- | 3832 | mov eax, [edi+20-2] |
|
- | 3833 | mov ax, [edi+26] |
|
- | 3834 | mov edi, eax |
|
- | 3835 | cmp [hd_error], 0 |
|
- | 3836 | jz @f |
|
- | 3837 | .pop_ret11: |
|
- | 3838 | mov byte [esp], 11 |
|
- | 3839 | jmp .pop_ret |
|
- | 3840 | @@: |
|
- | 3841 | ; now zero new data |
|
- | 3842 | xor ebp, ebp |
|
- | 3843 | ; edi=current cluster, ebp=sector in cluster |
|
- | 3844 | ; [esp+20]=new size, [esp+4]=old size, [esp]=return code |
|
- | 3845 | .zero_loop: |
|
- | 3846 | sub dword [esp+4], 0x200 |
|
- | 3847 | jae .next_cluster |
|
- | 3848 | lea eax, [edi-2] |
|
- | 3849 | imul eax, [SECTORS_PER_CLUSTER] |
|
- | 3850 | add eax, [DATA_START] |
|
- | 3851 | add eax, ebp |
|
- | 3852 | cmp dword [esp+4], -0x200 |
|
- | 3853 | jz .noread |
|
- | 3854 | mov ebx, buffer |
|
- | 3855 | call hd_read |
|
- | 3856 | cmp [hd_error], 0 |
|
- | 3857 | jnz .err_next |
|
- | 3858 | .noread: |
|
- | 3859 | mov ecx, [esp+4] |
|
- | 3860 | neg ecx |
|
- | 3861 | push edi |
|
- | 3862 | mov edi, buffer+0x200 |
|
- | 3863 | add edi, [esp+8] |
|
- | 3864 | push eax |
|
- | 3865 | xor eax, eax |
|
- | 3866 | mov [esp+12], eax |
|
- | 3867 | rep stosb |
|
- | 3868 | pop eax |
|
- | 3869 | pop edi |
|
- | 3870 | call hd_write |
|
- | 3871 | cmp [hd_error], 0 |
|
- | 3872 | jz .next_cluster |
|
- | 3873 | .err_next: |
|
- | 3874 | mov byte [esp], 11 |
|
- | 3875 | .next_cluster: |
|
- | 3876 | sub dword [esp+20], 0x200 |
|
- | 3877 | jbe .pop_ret |
|
- | 3878 | inc ebp |
|
- | 3879 | cmp ebp, [SECTORS_PER_CLUSTER] |
|
- | 3880 | jb .zero_loop |
|
- | 3881 | xor ebp, ebp |
|
- | 3882 | mov eax, edi |
|
- | 3883 | call get_FAT |
|
- | 3884 | mov edi, eax |
|
- | 3885 | cmp [hd_error], 0 |
|
- | 3886 | jnz .pop_ret11 |
|
- | 3887 | jmp .zero_loop |
|
- | 3888 | .truncate: |
|
- | 3889 | mov [edi+28], eax |
|
- | 3890 | push ecx |
|
- | 3891 | mov ecx, [edi+20-2] |
|
- | 3892 | mov cx, [edi+26] |
|
- | 3893 | push eax |
|
- | 3894 | test eax, eax |
|
- | 3895 | jz .zero_size |
|
- | 3896 | ; find new last cluster |
|
- | 3897 | @@: |
|
- | 3898 | mov eax, [SECTORS_PER_CLUSTER] |
|
- | 3899 | shl eax, 9 |
|
- | 3900 | sub [esp], eax |
|
- | 3901 | jbe @f |
|
- | 3902 | mov eax, ecx |
|
- | 3903 | call get_FAT |
|
- | 3904 | mov ecx, eax |
|
- | 3905 | cmp [hd_error], 0 |
|
- | 3906 | jz @b |
|
- | 3907 | .device_err3: |
|
- | 3908 | pop eax ecx eax edi |
|
- | 3909 | push 11 |
|
- | 3910 | pop eax |
|
- | 3911 | ret |
|
- | 3912 | @@: |
|
- | 3913 | ; we will zero data at the end of last sector - remember it |
|
- | 3914 | push ecx |
|
- | 3915 | ; terminate FAT chain |
|
- | 3916 | push edx |
|
- | 3917 | mov eax, ecx |
|
- | 3918 | mov edx, [fatEND] |
|
- | 3919 | call set_FAT |
|
- | 3920 | mov eax, edx |
|
- | 3921 | pop edx |
|
- | 3922 | cmp [hd_error], 0 |
|
- | 3923 | jz @f |
|
- | 3924 | .device_err4: |
|
- | 3925 | pop ecx |
|
- | 3926 | jmp .device_err3 |
|
- | 3927 | .zero_size: |
|
- | 3928 | and word [edi+20], 0 |
|
- | 3929 | and word [edi+26], 0 |
|
- | 3930 | push 0 |
|
- | 3931 | mov eax, ecx |
|
- | 3932 | @@: |
|
- | 3933 | ; delete FAT chain |
|
- | 3934 | call clear_cluster_chain |
|
- | 3935 | cmp [hd_error], 0 |
|
- | 3936 | jnz .device_err4 |
|
- | 3937 | ; save directory |
|
- | 3938 | mov eax, [esp+12] |
|
- | 3939 | push ebx |
|
- | 3940 | mov ebx, buffer |
|
- | 3941 | call hd_write |
|
- | 3942 | pop ebx |
|
- | 3943 | cmp [hd_error], 0 |
|
- | 3944 | jnz .device_err4 |
|
- | 3945 | ; zero last sector, ignore errors |
|
- | 3946 | pop ecx |
|
- | 3947 | pop eax |
|
- | 3948 | dec ecx |
|
- | 3949 | imul ecx, [SECTORS_PER_CLUSTER] |
|
- | 3950 | add ecx, [DATA_START] |
|
- | 3951 | push eax |
|
- | 3952 | sar eax, 9 |
|
- | 3953 | add ecx, eax |
|
- | 3954 | pop eax |
|
- | 3955 | and eax, 0x1FF |
|
- | 3956 | jz .truncate_done |
|
- | 3957 | push ebx eax |
|
- | 3958 | mov eax, ecx |
|
- | 3959 | mov ebx, buffer |
|
- | 3960 | call hd_read |
|
- | 3961 | pop eax |
|
- | 3962 | lea edi, [buffer+eax] |
|
- | 3963 | push ecx |
|
- | 3964 | mov ecx, 0x200 |
|
- | 3965 | sub ecx, eax |
|
- | 3966 | xor eax, eax |
|
- | 3967 | rep stosb |
|
- | 3968 | pop eax |
|
- | 3969 | call hd_write |
|
- | 3970 | pop ebx |
|
- | 3971 | .truncate_done: |
|
- | 3972 | pop ecx eax edi |
|
- | 3973 | call update_disk |
|
- | 3974 | xor eax, eax |
|
- | 3975 | cmp [hd_error], 0 |
|
- | 3976 | jz @f |
|
- | 3977 | mov al, 11 |
|
- | 3978 | @@: |
|
- | 3979 | ret |
|
4097 | 3980 | ||
4098 | fs_HdGetFileInfo: |
3981 | fs_HdGetFileInfo: |
4099 | cmp [fat_type], 0 |
3982 | cmp [fat_type], 0 |
4100 | jnz @f |
3983 | jnz @f |
4101 | mov eax, ERROR_UNKNOWN_FS |
3984 | mov eax, ERROR_UNKNOWN_FS |