Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

How to fix / enable floppy drive in udisks 1.x

Share your HowTo, Documentation, Tips and Tricks. Not for support questions!.
Post Reply
Message
Author
Hralgmir
Posts: 48
Joined: 2012-07-16 01:05

How to fix / enable floppy drive in udisks 1.x

#1 Post by Hralgmir »

Compile udisks 1.0.4-7 in Debian 7 Wheezy to fix floppy drive operation.
This also worked in Debian 6 Squeeze, but is not applicable for udisks 2.x, only for udisks 1.x series.

Download udisks_1.0.4-7wheezy1.debian.tar.gz udisks_1.0.4-7wheezy1.dsc udisks_1.0.4.orig.tar.gz
Unpack and apply all debian patches in one command:

Code: Select all

$ dpkg-source -x udisks_1.0.4-7wheezy1.dsc
Install build dependencies, there are several.
This command checks the list in the debian/control file and says which of them are not already installed:

Code: Select all

$ dpkg-checkbuilddeps udisks-1.04/debian/control
# aptitude install (the packages shown by dpkg-checkbuilddeps)
In my case this meant:

Code: Select all

# aptitude install xsltproc gtk-doc-tools intltool libdbus-glib-1-dev  libdbus-1-dev  libglib2.0-dev  libgudev-1.0-dev  libpolkit-gobject-1-dev  libparted0-dev  
libdevmapper-dev liblvm2-dev libatasmart-dev libsgutils2-dev zlib1g-dev libudev-dev uuid-dev libselinux-dev
Patch for 'configure' script, otherwise some files are installed over Debian package ones and deleted by 'make uninstall'.
Note it is possible moving the location might mean some parts of udisks are reading the Debian package ones, but using the same version of source package avoids this being a problem. It avoids the risk of problems that could occur. Not modifying 'configure' and running 'aptitude reinstall udisks' after 'make uninstall' also works, but it was annoying to do on every test and could cause reboot issues if it got forgotten. Save this following patch as a file called configure.patch then apply it with 'patch' :

Code: Select all

$ patch udisks-1.0.4/configure configure.patch
patching file udisks-1.0.4/configure


diff --git a/configure b/configure
index de363c4..4d5be6d 100755
--- a/configure
+++ b/configure
@@ -14813,7 +14813,7 @@ if test "x$GCC" = "xyes"; then
   LDFLAGS="-Wl,--as-needed $LDFLAGS"
 fi
 
-if test "$prefix" = "/usr" -o "$prefix" = "/usr/local" ; then
+if test "$prefix" = "/usr" ; then
   slashlibdir=/lib
   slashsbindir=/sbin
 else
Patch to enable floppy drive, adds a simple way to turn this support on and off by creating or deleting the file /etc/udisks_enable _floppy_drive
which is applied in the same manner as above. Save the patch below as device.patch then:

Code: Select all

$ patch udisks-1.0.4/src/device.c device.patch
patching file udisks-1.0.4/src/device.c


diff --git a/src/device.c b/src/device.c
index a7f8880..eccae78 100644
--- a/src/device.c
+++ b/src/device.c
@@ -4411,6 +4411,8 @@ update_info (Device *device)
   gint major;
   gint minor;
   gboolean media_available;
+  int enable_floppy_flag = 0;
+  struct stat enable_floppy_sts;
 
   ret = FALSE;
 
@@ -4502,7 +4504,21 @@ update_info (Device *device)
         }
       else
         {
-          if (g_udev_device_get_property_as_boolean (device->priv->d, "ID_CDROM_MEDIA"))
+          /* Add a test to see if the file /etc/udisks_enable_floppy_drive exists */
+          if ((stat ("/etc/udisks_enable_floppy_drive", &enable_floppy_sts) == -1)
+              && (errno == ENOENT))
+            {
+              /* File doesn't exist, always report no media detected in the floppy drive */
+              enable_floppy_flag = (int)(g_udev_device_get_property_as_boolean (device->priv->d, "ID_CDROM_MEDIA"));
+            }
+          else
+            {
+              /* File exists, always report media detected, which allows floppy drive to be mounted */
+              enable_floppy_flag = (int)(g_udev_device_get_property_as_boolean (device->priv->d, "ID_CDROM_MEDIA") ||
+                                         g_udev_device_get_property_as_boolean (device->priv->d, "ID_DRIVE_FLOPPY"));
+            }
+          if (enable_floppy_flag)
+          /* Back to the original code */
             {
               media_available = TRUE;
             }

Now run the configure script with appropriate arguments. dmmp and lvm2 are not enabled in the standard Debian binary package. You might add:
--enable-lvm2
to these if you installed with lvm. In Debian 6 Squeeze I installed with Grub and LVM. Using --enable-dmmp took a few seconds off my boot time. It made no difference at all in Debian 7 Wheezy which I installed with Lilo and the classic non LVM single disk HDD layout. --enable-lvm2 made no noticeable difference in either situation, but it could be relevant for LVM related operations. |tee log1conf.txt can be omitted, it just writes a record of the output for future reference, useful when I was working out the details of the procedure to get the files where I wanted them.

Code: Select all

$ cd udisks-1.0.4/
$ ./configure --prefix=/usr/local/ --exec-prefix=/usr/local/ --libexecdir=/usr/local/lib/udisks --enable-dmmp |tee log1conf.txt

Compile then install and strip using the makefile that was created by the configure script:

Code: Select all

$ make
# make install-strip
The output of 'make install' should confirm that everything was installed under /usr/local where it will take precedence over the pre-existing version of udisks.
Possibly this may not be the case with the files under /lib and /sbin but installing the same version will mean they are identical anyway.
Look out for upgrades to your original version of udisks though! This might cause trouble, but I have not seen udisks change in Debian Stable so far. The udisks 1.x versions have only minor differences that I am aware of, udisks 2.x is virtually a total rewrite though.

Turn on floppy support:

Code: Select all

# touch /etc/udisks_enable_floppy_drive
Reboot as the original version of udisks is still loaded in RAM even though the modified one is on the HDD.
Note the only odd effect is the floppy drive icon in Nautilus will always show a floppy disk icon instead as it is set to always think a disk is present, where previously it was set to never have a disk even if there was one.


Remove the file to turn off floppy support, and if required, uninstall the new version of udisks with:

Code: Select all

# rm /etc/udisks_enable_floppy_drive
# make uninstall
The original version of udisks is still there on the HDD and takes control again after rebooting.


Retrying this procedure recently to write this, it had been a while since I last used the floppy drive. The first disk I tried gave error messages when initially mounted by Nautilus and then opening files in Gedit, and also using cp in the terminal:

Code: Select all

$ cp  /media/floppy/Disk\ 4\ folder/Debiannotes.txt ./
cp: reading `/media/floppy/Disk 4 folder/Debiannotes.txt': Input/output error
cp: failed to extend `./Debiannotes.txt': Input/output error
The result was a truncated text file was copied from the floppy disk. But another disk worked correctly and retrying the first disk saw that working too. Allow the hardware time to waken from its slumber and shake off the accumulated dust if required!


Job done - some further discussion, and other background details:
It is interesting to see David Zeuthen credited as one of the authors of the controversial systemd, here is where efforts to fix this problem in udisks 1.x were apparently abandoned following an argument:
https://bugs.freedesktop.org/show_bug.cgi?id=30283
The 'simple patch' Atlant suggested works well when compiled in, and has since been adopted by Gentoo although not Debian, it stops udisks trying to check if there is a floppy disk in the drive and sets it permananently that there is a disk. It was generally misunderstood to relate to a different set of similar code lines than it does so has mostly been ignored. It is not similar at all to what was there before, I found the previous udisks version in a Gentoo archive after some searching. udisks 0.x caused premature floppy drive motor failure and annoying noise by constant polling of the drive so it was never very good apparently. My patch just adds a 'switch' to the original patch, which was suggested in another discussion in an Ubuntu bug report. The original problem was the crude manner in which udisks attempted to interface with the floppy driver, using a blocking open call rather than using ioctls, or forking and using signals or similar to report back later. The second issue is the floppy driver is designed to allow only one process access to avoid data corruption, so with udisks and the file manager trying to gain access together this caused strange effects. The long delays on modern computers came from the fitment of standardised multi function chipsets with built in floppy controllers that were unconnected, but were wrongly registered by the BIOS I believe. I could simulate this by removing my floppy drive module from my laptop and setting the BIOS to allow floppy hotplugging. What nobody apparently noticed was as well as creating a long ~40 second boot delay caused by the floppy driver setting a long timeout as it couldn't determine what type of drive was fitted, and udisks doing a blocking 'open' at a point when the boot sequence was dependent on udisks, there was also a 10 second delay from Grub doing a similar thing when it tried to access the nonexistent floppy drive with it's own Grub floppy driver - hence the shorter delay from this area. So if as was suggested in various discussions on the problem, there was a 'system lockup' problem, this most likely came from file managers hanging, (but this didn't happen using Gnome / Nautilus) otherwise nobody with that problem would get past Grub and it's earlier floppy drive access. There is no delay from an unplugged floppy drive when using Lilo, older code is generally better regarding floppies, fdutils code provides good examples of floppy use too.
The floppy driver was originally written by Linus Torvalds, it has since been further modified, but has been unchanged for several years now. It supports many types of floppy drive. It would be possible to alter it to not create /dev/fd0 if there was no device fitted but then it would not support hot plugging, so this is really a udisks issue. It might be possible to get it to output whether a disk is in the floppy drive as usually it keeps track of this internally, and in the few instances when it does not know could do a couple of 'seek' operations forwards and backwards to check for media, and make this available via sysfs when a process requested the information, which would provide udisks with the details it is trying to obtain. This is why when you take out a floppy disk and replace it with another without unmounting it in Nautilus, then try to copy a file to the disk, you get an error message to protect you from data corruption - providing the disk change line is working on the floppy drive. It is the floppy driver itself that keeps check on things. Kernel code is horrible, obfuscated, unstable and poorly documented though (a security feature probably), so I didn't get that far, especially when I saw udisks 2 was going to be soon available in Debian. Also udisks would then need altering and nobody seemed that keen on fixing it. The problem with compiling udisks 2 was that all the build dependencies needed to be upgraded to later versions than those available in Debian at the time. Probably the packages which interface with udisks then need to be upgraded too, so it would have taken ages. I'm not sure how udisks 2 handles the floppy driver, as the udisks 2 code calls a binary library function and I never got round to tracing it further. Now it seems udisks 1.x is still going to be around as an alternative package for a while so these notes could be useful to publish here.

Post Reply