Browse Source

Fixed automounting of NTFS and removable media

Synthetic "change" events coming from ntfs-3g are now ignored, which
allows for mounting an NTFS filesystem read-write or read-only,
depending on whether ntfs-3g allows that (e.g., read-only for hibernation).

Also fixed handling of "change" events for removable media: mount
point path is left unchanged, and all CD/DVD drives are added
to the list during boot (previous reliance on SCSI drives sending
events on disk insertion was incorrect).
Maxim Kammerer 14 năm trước cách đây
mục cha
commit
2c4291debe

+ 2 - 2
src/lib/udev/rules.d/61-persistent-storage-mount.rules

@@ -3,5 +3,5 @@ ENV{ID_FS_USAGE}=="filesystem|crypto", KERNEL!="loop[0-9]*", RUN+="/usr/local/sb
 ACTION=="change", SUBSYSTEM=="block",  KERNEL!="loop[0-9]*", RUN+="/usr/local/sbin/ps-mount"
 
 # Permanent autofs entries for floppies and IDE cdroms
-ACTION=="add", KERNEL=="fd[0-9]",                      RUN+="/usr/local/sbin/ps-mount"
-ACTION=="add", ENV{ID_CDROM}=="1", ENV{ID_BUS}=="ata", RUN+="/usr/local/sbin/ps-mount"
+ACTION=="add", KERNEL=="fd[0-9]",  RUN+="/usr/local/sbin/ps-mount"
+ACTION=="add", ENV{ID_CDROM}=="1", RUN+="/usr/local/sbin/ps-mount"

+ 20 - 30
src/usr/local/sbin/ps-mount

@@ -153,6 +153,11 @@ if [ "$1" = fork ]; then
                 ;;
             ntfs)
                 type="${ID_FS_TYPE}-3g,${opts_ntfs}"
+
+                # Possibly make mount point read-only for NTFS (e.g., hibernated Windows)
+                if ! ntfs-3g.probe -w "${DEVNAME}"; then
+                    type="${ID_FS_TYPE}-3g,${opts_ntfs_ro}"
+                fi
                 ;;
             *)
                 # Fallback, shouldn't happen
@@ -164,30 +169,25 @@ if [ "$1" = fork ]; then
         fixlabel
         echo "${ID_FS_LABEL} -fstype=${type} :${DEVNAME}" >> ${mounts}
         autokeys="${autokeys}${ID_FS_LABEL} "
-
-        # Make a read-only twin for NTFS (for hibernated Windows)
-        # "ntfs-3g.probe -w" is unusable here, since it causes "change" actions
-        if [ ${ID_FS_TYPE} = ntfs ]; then
-            ID_FS_LABEL="${ID_FS_LABEL}-readonly"
-            type="${ID_FS_TYPE}-3g,${opts_ntfs_ro}"
-
-            fixlabel
-            echo "${ID_FS_LABEL} -fstype=${type} :${DEVNAME}" >> ${mounts}
-            autokeys="${autokeys}${ID_FS_LABEL} "
-        fi
     }
 
-    # Unmount and remove existing auto.media entry (or entries, if NTFS)
+    # Unmount and remove existing auto.media entry (or entries)
     # (also update autokeys for fixlabel after ACTION=change, and for reload_autofs)
     remove_entry() {
         # Unmount mount points, not devices (since there can be several per device)
         local keys=`awk '!/^#/ && $3 == ":'"${DEVNAME}"'" { print $1 }' ${mounts}`
         local key
+        local kl="$1"
 
         for key in ${keys}; do
             # NOTE: lazy unmount
-            umount -l ${prefix}/${key} 2>/dev/null || true
+            umount -l ${prefix}/"${key}" 2>/dev/null || true
             autokeys="${autokeys/ ${key} / }"
+
+            if [ "${kl}" = keeplabel ]; then
+                ID_FS_LABEL="${key}"
+                kl=
+            fi
         done
 
         # Remove entries (will be removed from dir after autofs reload)
@@ -210,23 +210,13 @@ if [ "$1" = fork ]; then
                 reload_autofs
             fi
         fi
-    # For "change" action, a line is replaced
-    elif [ "${ACTION}" = change ]; then
-        if [ -z "${autodevs/* ${DEVNAME} */}" ]; then
-            remove_entry
-            updated_autofs=1
-        fi
-
-        if [ -n "${ID_FS_TYPE}" ]; then
-            # Add an entry only if not still mounted
-            fscheck=`fstab_check`
-            if [ "${fscheck}" != mtab ]; then
-                add_entry
-                updated_autofs=1
-            fi
-        fi
-
-        if [ "${updated_autofs}" = 1 ]; then
+    # For "change" action (non-fuse-generated), a line is replaced,
+    # but label is not changed
+    elif [ "${ACTION}" = change -a "${DISK_MEDIA_CHANGE}" = 1 ]; then
+        # Update if present in autofs, and is a filesystem
+        if [ -z "${autodevs/* ${DEVNAME} */}" -a -n "${ID_FS_TYPE}" ]; then
+            remove_entry keeplabel
+            add_entry
             reload_autofs
         fi
     # For "remove" action, the line corresponding to the device is removed