Author Topic: HOWTO Drag-and-Drop files with CD-RW disks  (Read 1894 times)

Offline pbowyer

  • PCLinuxOS Tester
  • Full Member
  • *******
  • Posts: 175
HOWTO Drag-and-Drop files with CD-RW disks
« on: April 24, 2010, 06:05:11 PM »
                      UDF on CD-RW HowTo

I wanted easy drag-and-drop file operations similar to those I was accustomed to using in MSWindows with floppy disks, but I also wanted more file space on the media because floppy disks are too limited in file space. I didn't want to have to use K3B each time I needed to copy something to a CD-RW disk, so I began searching for a Linux solution to the problem.

I stumbled across "kdvd-ram-tools" and, after much fooling around and lots of help from the forum, I got it working with DVD-RAM disks, but the cost per disk was more than I wanted to pay and I had to order them because no one locally had them in stock. I didn't want to use USB sticks (I call them thumb drives) because I've known them to lose data and I find them expensive too.

While I was doing all of that fooling around trying to get "kdvd-ram-tools" working I learned about "cdrwtool", thanks to a tip from JohnBoy. I found "cdrwtool" in "udftools" in the repositories. I spent more time fiddling around trying to get that working and I came up with a solution, finally, that I posted here "http://www.pclinuxos.com/forum/index.php/topic,65358.msg534964.html#msg534964" but after awhile I noticed that my script files sometimes didn't work (I'm not much of a bash programmer). I also discovered that "kdvd-ram-tools" was no longer available in PCLinuxOS-2010 so I could only use it in my PCLinuxOS-2009.x installations which I keep for some work I do. I decided to put some more effort into my script files because I also wanted to automate the UDF creation process for the CD-RW disks. Now, after too much explaining, here's what I finally came up with.

Make the following directory as root
Code: [Select]
/mnt/UdfCD
The UDF creation script:
Code: [Select]
#! /bin/bash
# script name: formatUdfCD

mntPath="/mnt/udfCD"
cdpktdvc="/dev/pktcdvd/pktcdvd0"
ismounted=`mount | grep $mntPath`

device="/dev/sr0"
speed=4
blocks=295264

if [[ -n $ismounted ]]; then
  guiMessageDlg "$mntPath cannot be mounted. Exiting..."
  exit 1
fi

zenity --question --title "Alert" --text "All data on the CDRW will be erased! OK to continue?"
err="$?"
if [[ $err -ne "0" ]]; then
 guiMessageDlg "cdrwtool user cancelled. Exiting..." "5"
 exit 1
fi

#: <<"COMMENTBLOCK"

#Do a fast blank of the disk
guiMessageDlg "Blanking the CDRW" "5"
cdrwtool -d$device -bfast -t$speed
err="$?"
if [[ $err -ne "0" ]]; then
  guiMessageDlg "cdrwtool blank error. Exiting..."
  exit 1
fi

#Do a format of the disk
guiMessageDlg "Formatting the CDRW" "5"
cdrwtool -d$device -m$blocks -t$speed
err="$?"
if [[ $err -ne "0" ]]; then
  guiMessageDlg "cdrwtool format error. Exiting..."
  exit 1
fi

#Build the udf file system on the disk
guiMessageDlg "Building the UDF file system on the CDRW" "5"
cdrwtool -d$device -u$blocks -t$speed
err="$?"
if [[ $err -ne "0" ]]; then
  guiMessageDlg "cdrwtool udf build error. Exiting..."
  exit 1
fi

#COMMENTBLOCK

if [[ ! -b $cdpktdvc ]]; then
  err="999"
  count=0
  until [[ -b $cdpktdvc ]]; do
    # Associate pktcdvd0 with hardware
    pktsetup pktcdvd0 $device
    err="$?"
    [[ $count -gt 9 ]] && break
    usleep 3333333
    (( count++ ))
  done
  [[ $err -ne "0" ]] && ( guiMessageDlg "$cdpktdvc not mounted"; exit 1 )
fi

if [[ -z $ismounted && -b $cdpktdvc ]]; then
  err="999"
  count=0
  until [[ -n $ismounted ]]; do
    mount -t udf -o noatime,rw,user $cdpktdvc $mntPath
    err="$?"
    [[ $count -gt 9 ]] && break
    usleep 3333333
    ismounted=`mount | grep $mntPath`
    (( count++ ))
  done
  if [[ $err -ne "0" ]]; then
    guiMessageDlg "mount unsuccessful"
    exit 1
  else
    chown -R root:cdwriter $mntPath/.
    chmod g+w $mntPath/.
    guiMessageDlg "UfdCD permissions set for read/write"
  fi

  if [ -n "$ismounted" ]; then
    # Unmount /mnt/udfCD
    umount $mntPath
    # add error check
    if [ $? -eq 0 ]; then
      # Dis-associate pktcdvd0 from hardware
      pktsetup -d pktcdvd0
      if [ $? -eq 0 ]; then
        cdrecord -dev=$device -dummy -eject >/dev/null
      fi
    else
      guiMessageDlg "unmount $mntPath unsucessful"
    fi
  fi

else
  guiMessageDlg "There was an error"
fi


The mount script
Code: [Select]
#! /bin/bash
# script name: mountUdfCD

mntPath="/mnt/udfCD"
cdpktdvc="/dev/pktcdvd/pktcdvd0"
ismounted=`mount | grep $mntPath`
device="/dev/sr0"

if [[ ! -b $cdpktdvc ]]; then
  err="999"
  count=0
  until [[ -b $cdpktdvc ]]; do
    # Associate pktcdvd0 with hardware
    pktsetup pktcdvd0 $device
    err="$?"
    [[ $count -gt 9 ]] && break
    usleep 3333333
    (( count++ ))
  done
  if [[ $err -ne "0" ]]; then
    guiMessageDlg "$cdpktdvc not mounted"
    exit 1
  fi
fi

if [[ -z $ismounted && -b $cdpktdvc ]]; then
  err="999"
  count=0
  until [[ -n $ismounted ]]; do
    mount -t udf -o noatime,rw,user $cdpktdvc $mntPath
    err="$?"
    [[ $count -gt 9 ]] && break
    usleep 3333333
    ismounted=`mount | grep $mntPath`
    (( count++ ))
  done
  if [[ $err -ne "0" ]]; then
    guiMessageDlg "mount unsuccessful"
    exit 1
  else
    guiMessageDlg "mount successful"
  fi
else
  guiMessageDlg "There was an error"
fi


The unmount script
Code: [Select]
#! /bin/bash
# script name: unmountUdfCD

mntPath="/mnt/udfCD"
ismounted=`mount | grep $mntPath`
device="/dev/sr0"

if [ -n "$ismounted" ]; then
  umount $mntPath
  # add error check
  if [ $? -eq 0 ]; then
    # Dis-associate pktcdvd0 from hardware
    pktsetup -d pktcdvd0
    if [ $? -eq 0 ]; then
      cdrecord -dev=$device -dummy -eject >/dev/null
    fi
  else
    guiMessageDlg "unmount $mntPath unsucessful"
  fi
fi


The message dialog script
Code: [Select]
#! /bin/bash
# script name: guiMessageDlg

if [ -n "$1" ]; then
  DIALOG=${DIALOG=zenity --info --title="Note " }
  if [ -n "$2" ]; then
    $DIALOG --text="$1" --timeout="$2"
  else
    $DIALOG --text="$1"
  fi
fi

In the above scripts the line
Code: [Select]
device="/dev/sr0" should be modified to fit the requirements of your system. In my PCLinuxOS-2009.x installations the line would read
Code: [Select]
device="/dev/hdc" and I placed the scripts in
Code: [Select]
/usr/local/bin
The entry in /etc/fstab
Code: [Select]
# ufdCD (Needed for KwikDisk to recognise mount point)
/dev/pktcdvd/pktcdvd0 /mnt/udfCD none noatime,rw,user,noauto 0 0

I would have preferred to use kdesudo in PCLinuxOS-2010 but it wasn't available so I used kdesu instead. It requires you to enter your root password.
The KwikDisk mount command for PCLinuxOS-2010
Code: [Select]
kdesu -c mountUdfCD
The KwikDisk unmount command for PCLinuxOS-2010
Code: [Select]
kdesu -c unmountUdfCD
In the following, I used kdesudo which is available for PCLinuxOS-2009.x in the repositories. I like it because I can use my user password to run privileged commands after editing /etc/sudoers with visudo (vim-minimal required) as root to setup sudo.

The KwikDisk mount command for PCLinuxOS-2009.x
Code: [Select]
kdesudo mountUdfCD
The KwikDisk unmount command for PCLinuxOS-2009.x
Code: [Select]
kdesudo unmountUdfCD
In PCLinuxOS-2010, after a CD-RW is setup for UDF file use, the device notifier recognizes it as "LinuxUDF" and you can open it for file use by clicking on the entry in the device notifier but even though you can copy files to the disk this way, they don't seem to actually be written to the CD-RW disk. After the disk is ejected by using the eject button in the device notifier and then re-inserting the disk the data just written is not visible. I found it necessary to just ignore the device notifier in PCLinuxOS-2010 and use KwikDisk to mount/unmount the CD-RW using the scripts listed above.

In PCLinuxOS-2009.x, just select "Do Nothing" when the dialog pops up asking what should be done with the CD-RW just inserted and use KwikDisk to do the mount/unmount.

After the CD-RW is mounted, drag-and-drop file access is available in Konqueror as a non-root user. I've been using this method for awhile in PCLinusOS and I haven't had any difficulties with CD-RW disks. I've been using some Memorex 4X disks that I've had around for awhile. NOTE: it may be necessary after mounting to do a reload in Konqueror before the data on the CD-RW can be seen, but after that it works as expected.

I understand that "cdrwtool" will create a UDF file system on a DVD-RW, but not with these scripts. I tried it one time by setting a DVD-RW up manually that I used for a short while but then it came up with errors that I didn't know how to clear so I destroyed the DVD-RW and I haven't tried it since.

Offline Was_Just19

  • Hero Member
  • *****
  • Posts: 6852
  • MLU
Re: HOWTO Drag-and-Drop files with CD-RW disks
« Reply #1 on: April 24, 2010, 06:34:57 PM »
pbowyer,
                  congrats and thanks for the write up and scripts.
All that took some doing!

Two questions if I may ......

it seems the CD will have owner as root and group as cdwriter ..... I think that is what I read .... and I just wondered if there was a better owner:group scheme that might be applied? I don't have a suggestion, just a question  :D

Would you consider re-writing the title?
The post contains so much more than the present heading implies.

***

To moderator/admin ..............  is it possible please to have this thread 'Stickied'?  This is very valuable information for anyone wishing to use CDRW media as true RW disks.
Thanks.

Offline jaydot

  • Administrator
  • Super Villain
  • *****
  • Posts: 15569
  • there is no limitation on imagination
Re: HOWTO Drag-and-Drop files with CD-RW disks
« Reply #2 on: April 24, 2010, 07:09:05 PM »
done stickied. ;D
PCLinuxOS  Get it?  Got it?  Good!!   8)

We don't have any millionare angels or corporate backers paying the bills here, PLEASE DONATE.
http://pclinuxos.com/?page_id=7

Offline pbowyer

  • PCLinuxOS Tester
  • Full Member
  • *******
  • Posts: 175
Re: HOWTO Drag-and-Drop files with CD-RW disks
« Reply #3 on: April 24, 2010, 07:29:47 PM »

Two questions if I may ......

it seems the CD will have owner as root and group as cdwriter ..... I think that is what I read .... and I just wondered if there was a better owner:group scheme that might be applied? I don't have a suggestion, just a question  :D

Would you consider re-writing the title?
The post contains so much more than the present heading implies.


I don't know what might be a better owner:group scheme. Feel free to experiment. I selected group as cdwriter after examining /etc/group to see what groups my user login was a member of related to cd writing. Note that I changed the mode so group "cdwriter" has write access in "formatUdfCD". I suppose it could be root:floppy which is what /dev/sr0 has, but I don't remember what /dev/hdc is in PCLinuxOS-2009.x. What I have is working for me and if it's necessary to change it in another system, it's easy to do.

I'm open to suggestions about the title. Anything you feel works better is OK by me.

Offline Was_Just19

  • Hero Member
  • *****
  • Posts: 6852
  • MLU
How To: Set up CD-RW UDF Disks for Drag & Drop use
« Reply #4 on: April 25, 2010, 04:47:13 AM »
Heck I don't know man!  Just blown away by the 'how to'   :D  (I tried above  :-\ )

@ jaydot ......  thanks ....  but did it take?
« Last Edit: April 25, 2010, 04:48:58 AM by JohnBoy »

Offline pbowyer

  • PCLinuxOS Tester
  • Full Member
  • *******
  • Posts: 175
Re: How To: Set up CD-RW UDF Disks for Drag & Drop use
« Reply #5 on: April 25, 2010, 02:18:42 PM »
Heck I don't know man!  Just blown away by the 'how to'   :D  (I tried above  :-\ )

@ jaydot ......  thanks ....  but did it take?

JohnBoy:
 I assume by the smileys that you were less than successful in your trial. I'd appreciate some feedback on what occurred. If you have sudo set up, or just su to root, you can run the scripts from a terminal and maybe get a clue from the output. Also, you can try running the pertinent system commands from the scripts manually from a terminal to see what might be happening on your system. I wrote the scripts after doing everything manually so maybe there's something I missed that needs to be there for first-time use. It also might be necessary to adjust the time values for usleep to something different on your system. My dvd burner has DVD-RAM capability which was necessary, I think, for the use of that particular disk type. I don't know if it is necessary when using UDF formatted CD-RW disks.

On the subject of owner:group, I noticed after I first logged into PCLinuxOS-2010 this morning that doing "ls -l /dev/sr0" returned "root:root" and a little later after I inserted a UDF formatted CD-RW the same command returned "root:floppy" which I presume is the result of whatever is going on behind the scenes when certain types of media are inserted.

Offline Was_Just19

  • Hero Member
  • *****
  • Posts: 6852
  • MLU
Re: HOWTO Drag-and-Drop files with CD-RW disks
« Reply #6 on: April 25, 2010, 02:35:24 PM »
Sorry for not being clear .........  it was the heading I was referring to which I changed on my reply to see how it looked.

I have not tested your scripts as I am presently unable to locate my CD-RW discs .......  I know I have a couple somewhere .....  but it is so long since I used them ......  well you know the score .....   ;)

Offline menotu

  • PCLinuxOS Tester
  • Super Villain
  • *******
  • Posts: 15307
  • ┌∩┐(◕_◕)┌∩┐
Re: HOWTO Drag-and-Drop files with CD-RW disks
« Reply #7 on: April 25, 2010, 02:45:55 PM »
pbowyer; Superb work! Very impressed with the amount of time and effort you've put in.

I'm not very adept at scripts, is it okay to ask advice if necessary?
PCLinuxOS 32bit KDE 4.10.1; kernel-3.4.11-pclos1.bfs & 64bit 3.2.18bfs; NVidia GeForce 8400GS 1GB 310.19 driver

Sony Vaio SVE1513A4ESI Laptop, Intel Core i5, 2.6GHz, 6GB RAM, 750GB, 15.6" Intel HD Graphics 4000

Offline pbowyer

  • PCLinuxOS Tester
  • Full Member
  • *******
  • Posts: 175
Re: HOWTO Drag-and-Drop files with CD-RW disks
« Reply #8 on: April 25, 2010, 03:36:20 PM »
pbowyer;
I'm not very adept at scripts, is it okay to ask advice if necessary?

menotu:

Ask away, but don't expect too much. I'm not very adept with scripts either.

Offline wayne1932

  • PCLinuxOS Tester
  • Hero Member
  • *******
  • Posts: 1083
Re: HOWTO Drag-and-Drop files with CD-RW disks
« Reply #9 on: April 25, 2010, 04:16:48 PM »
I have a whole stack of CDRW and DVDRW that I haven;t been able to use much.  This sounds like the answer to the problems EXWINTECH has had.  I haven't tried it yet, still too much newbie in me about scripts. 

I think the procedure would be to copy from this thread to a file and make it executable?   
If it ain't broke, DON'T fix it!  If ya cain't fix it, ya gotta stand it.  If ya cain't stand it..............Visit the forum and search.

Offline pbowyer

  • PCLinuxOS Tester
  • Full Member
  • *******
  • Posts: 175
Re: HOWTO Drag-and-Drop files with CD-RW disks
« Reply #10 on: April 26, 2010, 01:39:01 PM »
I think the procedure would be to copy from this thread to a file and make it executable?  

The scripts I posted probably won't work for DVD-RW disks and, as I noted above, the one time I tried it with them didn't turn out very well.

The script names I used are shown on the second line of the listed code blocks. I put mine (with ownership "root:root") in "/usr/local/bin" because it's in my $PATH and then I set them executable by everyone (I used Konqueror as super-user for that). You can run them from a terminal as root, or you can setup sudo and run them from a terminal as your user login, or you can do what I did (after I had everything working) and use KwikDisk. Remember to change the line [device="/dev/sr0"] in the script files to suit your system.

I did a lot of fiddling around manually from a terminal before I got the scripts working as I wanted so I'm uncertain how they might work when run the first time without the manual fiddling that I did. If you try them, let me know how it turns out please.
« Last Edit: April 26, 2010, 01:50:43 PM by pbowyer »