Bugfix: Mounting devices as images

Here you can discuss the development of patches.

Bugfix: Mounting devices as images

Postby Malvineous » 2015-12-29 @ 06:58

Hi all,

I'm not sure where to submit patches for DOSBox - is here ok or should they go to the SF page?

Either way I recently tried to install DOS onto an SD card via DOSBox, but IMGMOUNT was complaining that /dev/sdd was a folder so I needed to use the MOUNT command instead. The MOUNT command of course didn't work because /dev/sdd is not actually a folder.

I tracked the problem down to a bug in the folder test code, and the following patch fixes it:

Code: Select all
Index: src/dos/dos_programs.cpp
===================================================================
--- src/dos/dos_programs.cpp    (revision 3911)
+++ src/dos/dos_programs.cpp    (working copy)
@@ -298,7 +298,7 @@
                                return;
                        }
                        /* Not a switch so a normal directory/file */
-                       if (!(test.st_mode & S_IFDIR)) {
+                       if (!S_ISDIR(test.st_mode)) {
 #ifdef OS2
                                HFILE cdrom_fd = 0;
                                ULONG ulAction = 0;
@@ -1216,7 +1216,7 @@
                                                }
                                        }
                                }
-                               if ((test.st_mode & S_IFDIR)) {
+                               if (S_ISDIR(test.st_mode)) {
                                        WriteOut(MSG_Get("PROGRAM_IMGMOUNT_MOUNT"));
                                        return;
                                }
@@ -1377,6 +1377,10 @@
 
                        } else {
                                FILE *newDisk = fopen(temp_line.c_str(), "rb+");
+                               if (!newDisk) {
+                                       WriteOut(MSG_Get("PROGRAM_IMGMOUNT_FILE_NOT_FOUND"));
+                                       return;
+                               }
                                fseek(newDisk,0L, SEEK_END);
                                imagesize = (ftell(newDisk) / 1024);

According to the docs you aren't supposed to test the bits directly, but use comparison macros instead, which is what this patch does. After this I have no problem using IMGMOUNT to pass /dev/sdd through as a raw DOSBox hard disk.

The last bit of code at the end of the patch prevents a crash if you try to IMGMOUNT a file or device that you don't have read access to.
User avatar
Malvineous
Member
 
Posts: 475
Joined: 2006-6-11 @ 02:24
Location: Brisbane, Australia

Re: Bugfix: Mounting devices as images

Postby Dominus » 2015-12-29 @ 08:14

Thanks ;) I'm not sure myself whether SF or Vogons is abetter place. I tend to use SF more.
I moved the topic into the patches subforum. Normal users are not allowed to start new topics there, you did nothing wrong ;)
User avatar
Dominus
DOSBox Moderator
 
Posts: 7372
Joined: 2002-10-03 @ 09:54
Location: Vienna

Re: Bugfix: Mounting devices as images

Postby Malvineous » 2015-12-29 @ 22:15

Oh phew, thought I stuffed up for a minute there :-) Thanks!
User avatar
Malvineous
Member
 
Posts: 475
Joined: 2006-6-11 @ 02:24
Location: Brisbane, Australia

Re: Bugfix: Mounting devices as images

Postby Qbix » 2016-2-11 @ 15:47

commited in 3965, with changed error message.
Thanks!
Water flows down the stream
How to ask questions the smart way!
User avatar
Qbix
DOSBox Author
 
Posts: 10436
Joined: 2002-11-27 @ 14:50
Location: Fryslan

Re: Bugfix: Mounting devices as images

Postby Malvineous » 2016-2-11 @ 21:43

Excellent, many thanks!
User avatar
Malvineous
Member
 
Posts: 475
Joined: 2006-6-11 @ 02:24
Location: Brisbane, Australia

Re: Bugfix: Mounting devices as images

Postby acd2001 » 2016-2-12 @ 01:29

In visual studio S_ISDIR (a posix function) throw an error.
You must define it:

#ifndef S_ISDIR
#define S_ISDIR(m) (((m)&S_IFDIR)==S_IFDIR)
#endif
acd2001
Newbie
 
Posts: 5
Joined: 2013-10-19 @ 16:29

Re: Bugfix: Mounting devices as images

Postby Qbix » 2016-2-12 @ 08:01

*sigh*

Thanks for the report. The joys of multi platform.

I went with this:
Code: Select all
#if defined(WIN32)
#ifndef S_ISDIR
#define S_ISDIR(m) (((m)&S_IFMT)==S_IFDIR)
#endif
#endif
Water flows down the stream
How to ask questions the smart way!
User avatar
Qbix
DOSBox Author
 
Posts: 10436
Joined: 2002-11-27 @ 14:50
Location: Fryslan


Return to DOSBox Patches

Who is online

Users browsing this forum: No registered users and 1 guest