1 ; **************************************************************************** 2 ; mount386.s (mount1.s) - by Erdogan Tan - 08/05/2022 3 ; ---------------------------------------------------------------------------- 4 ; Retro UNIX 386 v1 - mount -- mount file system 5 ; 6 ; [ Last Modification: 14/05/2022 ] 7 ; 8 ; **************************************************************************** 9 ; (/etc/mount) 10 11 ; mount0.s - Retro UNIX 8086 v1 (16 bit version of 'mount1.s') 12 ; mount1.s - Retro UNIX 386 v1 (& v1.1 & v1.2) 13 14 ; UNIX v1 system calls 15 _rele equ 0 16 _exit equ 1 17 _fork equ 2 18 _read equ 3 19 _write equ 4 20 _open equ 5 21 _close equ 6 22 _wait equ 7 23 _creat equ 8 24 _link equ 9 25 _unlink equ 10 26 _exec equ 11 27 _chdir equ 12 28 _time equ 13 29 _mkdir equ 14 30 _chmod equ 15 31 _chown equ 16 32 _break equ 17 33 _stat equ 18 34 _seek equ 19 35 _tell equ 20 36 _mount equ 21 37 _umount equ 22 38 _setuid equ 23 39 _getuid equ 24 40 _stime equ 25 41 _quit equ 26 42 _intr equ 27 43 _fstat equ 28 44 _emt equ 29 45 _mdate equ 30 46 _stty equ 31 47 _gtty equ 32 48 _ilgins equ 33 49 _sleep equ 34 ; Retro UNIX 8086 v1 feature only ! 50 _msg equ 35 ; Retro UNIX 386 v1 feature only ! 51 _geterr equ 36 ; Retro UNIX 386 v1 feature only ! 52 53 ;;; 54 ESCKey equ 1Bh 55 EnterKey equ 0Dh 56 57 %macro sys 1-4 58 ; 03/09/2015 59 ; 13/04/2015 60 ; Retro UNIX 386 v1 system call. 61 %if %0 >= 2 62 mov ebx, %2 63 %if %0 >= 3 64 mov ecx, %3 65 %if %0 = 4 66 mov edx, %4 67 %endif 68 %endif 69 %endif 70 mov eax, %1 71 int 30h 72 %endmacro 73 74 ; Retro UNIX 386 v1 system call format: 75 ; sys systemcall (eax) , , 76 77 [BITS 32] ; 32-bit intructions (for 80386 protected mode) 78 79 [ORG 0] 80 81 START_CODE: 82 ; 14/05/2022 83 ; 08/05/2022 84 00000000 59 pop ecx ; ecx = number of arguments 85 ; 86 00000001 58 pop eax ; eax = argument 0 = executable file name 87 ; 88 ;cmp ecx, 3 89 00000002 80F903 cmp cl, 3 90 00000005 7533 jne short mnt_0 91 92 00000007 5F pop edi ; argument 1 = device name 93 00000008 5D pop ebp ; argument 2 = mounting directory 94 95 00000009 89EE mov esi, ebp 96 97 ; 14/05/2022 98 ; ; 08/05/2022 99 ; ;lodsd ; lodsd gives gpf if dir name length < 4 100 ; lodsb ; *! 101 ; cmp al, '/' 102 ; jne short mnt_2 103 ;mnt_u: 104 ; lodsb 105 ; cmp al, 'u' 106 ; jne short mnt_m 107 ; lodsb 108 ; cmp al, 's' 109 ; jne short mnt_2 110 ; lodsb 111 ; cmp al, 'r' 112 ; je short mnt_1 113 ; jmp short mnt_2 114 ;mnt_m: 115 ; cmp al, 'm' 116 ; jne short mnt_2 117 ; lodsb 118 ; cmp al, 'n' 119 ; jne short mnt_2 120 ; lodsb 121 ; cmp al, 't' 122 ; jne short mnt_2 123 124 ; 14/05/2022 125 ;; ; 08/05/2022 126 ;; ; 'pwd' command compatibility restriction ! 127 ;; ; --- 128 ;; ; Only '/usr' or '/mnt' directories can be used 129 ;; ; with current mount version (otherwise current 130 ;; ; 'pwd' will not recognize mounting directory 131 ;; ; as correct). 132 ;; 133 ;; ; short way... 134 ;; cmp eax, '/usr' 135 ;; je short mnt_1 136 ;; cmp eax, '/mnt' 137 ;; jne short mnt_2 138 ;mnt_1: 139 ; cmp byte [esi], 0 ; 140 ; jna short mnt_5 ; '/usr' or '/mnt', continue 141 ; 142 ; ; neither '/usr' or '/mnt' 143 ; 144 ; ; print usage message and then exit 145 ;mnt_0: 146 ; mov eax, usage_msg 147 ; 148 ; jmp mnt_7 149 150 ;p_msg_exit: 151 ; call print_msg 152 ;exit: 153 ; sys _exit 154 ;hang: 155 ; nop 156 ; jmp short hang 157 158 mnt_2: 159 ; long way... 160 sys _stat, ebp, stbuf 58 <1> 59 <1> 60 <1> 61 <1> %if %0 >= 2 62 0000000B 89EB <1> mov ebx, %2 63 <1> %if %0 >= 3 64 0000000D B9[34010000] <1> mov ecx, %3 65 <1> %if %0 = 4 66 <1> mov edx, %4 67 <1> %endif 68 <1> %endif 69 <1> %endif 70 00000012 B812000000 <1> mov eax, %1 71 00000017 CD30 <1> int 30h 161 00000019 7244 jc short mnt_dir_err 162 ; 14/05/2022 163 ; eax = device number (in AL) 164 165 ; 14/05/2022 166 ; mov dx, [stbuf] ; inode number 167 ; 168 ; sys _stat, usr, stbuf 169 ; jc short mnt_4 170 ; 171 ; ; check if it is '/usr' inode 172 ; cmp dx, [stbuf] ; same inode number 173 ; je short mnt_5 174 ;mnt_4: 175 ; sys _stat, mnt, stbuf 176 ; jc short mnt_dir_err 177 ; 178 ; ; check if it is '/mnt' inode 179 ; cmp dx, [stbuf] ; same inode number 180 ; jne short mnt_dir_err 181 182 ; 14/05/2022 183 ; is directory ? (check inode mode) 184 0000001B F605[37010000]40 test byte [stbuf+3], 40h ; directory 185 00000022 743B jz short mnt_dir_err 186 187 ; is already mounted ? 188 00000024 08C0 or al, al 189 ;or eax, eax 190 00000026 7537 jnz short mnt_dir_err 191 192 mnt_5: 193 ; only superuser (root) can do mount/umount 194 sys _getuid 58 <1> 59 <1> 60 <1> 61 <1> %if %0 >= 2 62 <1> mov ebx, %2 63 <1> %if %0 >= 3 64 <1> mov ecx, %3 65 <1> %if %0 = 4 66 <1> mov edx, %4 67 <1> %endif 68 <1> %endif 69 <1> %endif 70 00000028 B818000000 <1> mov eax, %1 71 0000002D CD30 <1> int 30h 195 0000002F 21C0 and eax, eax ; uid = 0 -> root 196 00000031 7418 jz short mnt_6 197 00000033 B8[D2000000] mov eax, deny_msg 198 00000038 EB05 jmp short mnt_7 199 200 ; 14/05/2022 201 ; print usage message and then exit 202 mnt_0: 203 0000003A B8[87000000] mov eax, usage_msg 204 mnt_7: 205 0000003F E829000000 call print_msg 206 exit: 207 sys _exit 58 <1> 59 <1> 60 <1> 61 <1> %if %0 >= 2 62 <1> mov ebx, %2 63 <1> %if %0 >= 3 64 <1> mov ecx, %3 65 <1> %if %0 = 4 66 <1> mov edx, %4 67 <1> %endif 68 <1> %endif 69 <1> %endif 70 00000044 B801000000 <1> mov eax, %1 71 00000049 CD30 <1> int 30h 208 ;hang: 209 ; nop 210 ; jmp short hang 211 212 mnt_6: 213 ; edi = device name address 214 ; ebp = mounting directory path/name address 215 ; 216 sys _mount, edi, ebp 58 <1> 59 <1> 60 <1> 61 <1> %if %0 >= 2 62 0000004B 89FB <1> mov ebx, %2 63 <1> %if %0 >= 3 64 0000004D 89E9 <1> mov ecx, %3 65 <1> %if %0 = 4 66 <1> mov edx, %4 67 <1> %endif 68 <1> %endif 69 <1> %endif 70 0000004F B815000000 <1> mov eax, %1 71 00000054 CD30 <1> int 30h 217 00000056 720E jc short mnt_err 218 ; 219 00000058 B8[2B010000] mov eax, ok_msg 220 ; 14/05/2022 221 0000005D EBE0 jmp short mnt_7 222 223 ;mnt_7: 224 ; call print_msg 225 ;exit: 226 ; sys _exit 227 ;;hang: 228 ;; nop 229 ;; jmp short hang 230 231 mnt_dir_err: 232 0000005F B8[10010000] mov eax, dir_err_msg 233 00000064 EBD9 jmp short mnt_7 234 235 mnt_err: 236 ; 14/05/2022 237 ;; Temporary! 08/05/2022 238 ;; Lets do not recognize 'invalid file system' 239 ;; error for now! (for current version and for 240 ;; current kernel response to sysmount system call) 241 ;; 242 ;; ((DOS FAT file system disk or another/new/old 243 ;; type retro unix fs or invalid free map size 244 ;; or invalid/unexpected superblock content)) 245 ;; 246 ;; Note: (08/05/2022) 247 ;; [drv.size] is calculated with cylinders-1 248 ;; for floppy disks ('diskinit.s' ,'set_disk_parms') 249 ;; So, free map size and [drv.size]/8 is not same. 250 ;; This is sysmount error return reason 251 ;; (as a bug in current Retro Unix 386 kernel). 252 ; 253 ;sub ebx, ebx 254 ;sys _geterr ; (get last error in eax) 255 ; 256 ;; (eax = error code from sysmount system call) 257 ;cmp eax, 28 ; ERR_INV_FS ('sysmnt_5:', 'u7.s') 258 ;jne short mnt_8 259 ;;'invalid fs/superblock !' error 260 ;; (exit without 'oK.' message) 261 ;jmp exit 262 ;mnt_8: 263 00000066 B8[04010000] mov eax, err_msg 264 0000006B EBD2 jmp short mnt_7 265 266 ;----------------------------------------------------------------- 267 268 print_msg: 269 ; 08/05/2022 270 ; eax = asciiz string address 271 0000006D 89C2 mov edx, eax 272 0000006F 4A dec edx 273 nextchr: 274 00000070 42 inc edx 275 00000071 803A00 cmp byte [edx], 0 276 00000074 77FA ja short nextchr 277 ;cmp [edx], 0Dh 278 ;ja short nextchr 279 00000076 29C2 sub edx, eax 280 ; edx = asciiz string length 281 ; 282 sys _write, 1, eax 58 <1> 59 <1> 60 <1> 61 <1> %if %0 >= 2 62 00000078 BB01000000 <1> mov ebx, %2 63 <1> %if %0 >= 3 64 0000007D 89C1 <1> mov ecx, %3 65 <1> %if %0 = 4 66 <1> mov edx, %4 67 <1> %endif 68 <1> %endif 69 <1> %endif 70 0000007F B804000000 <1> mov eax, %1 71 00000084 CD30 <1> int 30h 283 ; 284 00000086 C3 retn 285 286 ;----------------------------------------------------------------- 287 ; data - initialized data 288 ;----------------------------------------------------------------- 289 290 ; 14/05/2022 291 ;; 08/05/2022 292 293 ;; default mounting directories (for current retro unix version) 294 ;usr: db '/usr', 0 295 ;mnt: db '/mnt', 0 296 297 usage_msg: 298 00000087 0D0A db 0Dh, 0Ah 299 ;db "Usage: mount " 300 ;db 0Dh, 0Ah 301 ;db " or mount " 302 00000089 55736167653A206D6F- db "Usage: mount " 302 00000092 756E74203C626C6F63- 302 0000009B 6B2064657669636520- 302 000000A4 6E616D653E203C6469- 302 000000AD 723E20 303 ;db 0Dh, 0Ah 304 000000B0 0D0A db 0Dh, 0Ah 305 000000B2 4578616D706C653A20- db "Example: mount /dev/fd1 /usr " 305 000000BB 6D6F756E74202F6465- 305 000000C4 762F666431202F7573- 305 000000CD 7220 306 000000CF 0D0A00 db 0Dh, 0Ah, 0 307 308 deny_msg: 309 000000D2 0D0A db 0Dh, 0Ah 310 000000D4 4D6F756E743A204F6E- db "Mount: Only superuser/root can mount devices!" 310 000000DD 6C7920737570657275- 310 000000E6 7365722F726F6F7420- 310 000000EF 63616E206D6F756E74- 310 000000F8 206465766963657321 311 00000101 0D0A00 db 0Dh, 0Ah, 0 312 err_msg: 313 00000104 0D0A db 0Dh, 0Ah 314 00000106 4572726F722120 db 'Error! ' 315 0000010D 0D0A00 db 0Dh, 0Ah, 0 316 dir_err_msg: 317 00000110 0D0A db 0Dh, 0Ah 318 00000112 4D6F756E7420446972- db 'Mount Directory Error!' 318 0000011B 6563746F7279204572- 318 00000124 726F7221 319 ;db 0Dh, 0Ah 320 ;db "(Mounting directory must exist " 321 ;db "and be '/usr' or '/mnt'.) " 322 00000128 0D0A00 db 0Dh, 0Ah, 0 323 ok_msg: 324 0000012B 0D0A db 0Dh, 0Ah 325 0000012D 4F4B2E20 db 'OK. ' 326 nextline: 327 00000131 0D0A00 db 0Dh, 0Ah, 0 328 329 ;----------------------------------------------------------------- 330 ; bss - uninitialized data 331 ;----------------------------------------------------------------- 332 333 align 4 334 335 bss_start: 336 337 ABSOLUTE bss_start 338 339 ; 08/05/2022 340 341 ;stbuf: resb 34 ; (Retro UNIX v1 and v1.1) 342 00000134 stbuf: resb 66 ; stat(us) buffer 343 ; (Retro UNIX v1, v1.1 and v1.2) 344 345 ;-----------------------------------------------------------------