# Problems closing a CD

**URL:** <https://www.ruby-forum.com/t/problems-closing-a-cd/130907>\
**Category:** Ruby\
**Created:** [March 4, 2008, 11:59am UTC](https://www.ruby-forum.com/t/problems-closing-a-cd/130907 "2008-03-04T11:59:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![tbcox23](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/b9bd4f/32.png) [@tbcox23](https://www.ruby-forum.com/u/tbcox23)\
**Post date:** [March 4, 2008, 11:59am UTC](https://www.ruby-forum.com/t/problems-closing-a-cd/130907/1 "2008-03-04T11:59:36Z")

</div>

I’m utterly baffled by this simple problem in a ruby program I’ve run a  
number of time on Windows. I’m now running Kubuntu Linux, and things  
work differently (!).

This program reads a series of data CDs, cataloging their contents. To  
stop the process, I input a zero length volume label (well, on Windows I  
do, anyway; on Linux this errors off, but that’s not my current  
problem).

What I can’t do is get the CD just read in to be released by the program  
so I can read in the next one.

Code:

> archive\_source\_dir = ‘/cdrom’ # this is where the CD appears when I  
> put it in the drive

Processing begins when the program has the volume label of the CD (this  
is used as the key in a hash containing an array of the tree paths).  
When it has traversed the directory tree on the CD, it asks for the next  
volume label. In Windows, I just punch the open button on the drive,  
replaced the CD with a new one, close the drive, keyed in the new volume  
label, and kept going. Linux won’t release the CD.

I’ve tried many things to get the CD to go release, including…

> archive\_source\_dir.close  
> IO.close(archive\_source\_dir)  
> File.close(archive\_source\_dir)

I get “undefined method” errors on everything. I have no idea why. Isn’t  
everything a file in linux? Guess not.

Plainly I’m missing some simple concept here, but I can’t see it.

Would appreciate any help.

Tom

---

<div class="post-metadata">

**Author:** ![tbcox23](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/b9bd4f/32.png) [@tbcox23](https://www.ruby-forum.com/u/tbcox23)\
**Post date:** [March 4, 2008, 12:30pm UTC](https://www.ruby-forum.com/t/problems-closing-a-cd/130907/2 "2008-03-04T12:30:13Z")

</div>

On Tue, Mar 4, 2008 at 11:58 AM, Tom C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> label, and kept going. Linux won’t release the CD.
> 
> Would appreciate any help.
> 
> Tom

I guess this has something to do with mounting/umounting, though I  
don’t know too much about automatic mounting in kubuntu.  
Try using `umount /cdrom` after you are done. (Don’t forget to close  
any open files and move away from that dir).  
You might encounter some privileges problems (“only root can do”) -  
try sudo in that case, or modify /etc/fstab to allow users to  
mount/umount.

`eject` and `eject -t` might be useful as well.

---

<div class="post-metadata">

**Author:** ![tbcox23](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/b9bd4f/32.png) [@tbcox23](https://www.ruby-forum.com/u/tbcox23)\
**Post date:** [March 4, 2008, 1:16pm UTC](https://www.ruby-forum.com/t/problems-closing-a-cd/130907/3 "2008-03-04T13:16:17Z")

</div>

Jano S. wrote:

> > What I can’t do is get the CD just read in to be released by the program  
> > volume label. In Windows, I just punch the open button on the drive,
> 
> any open files and move away from that dir).  
> You might encounter some privileges problems (“only root can do”) -  
> try sudo in that case, or modify /etc/fstab to allow users to  
> mount/umount.
> 
> `eject` and `eject -t` might be useful as well.

The problem is that I need an unmount WHILE the program is running, and  
it won’t let go of the device. When I tried to close it, ruby refuses to  
acknowledge knowing anything about “close”. It appears that there is no  
kernal#close, suddenly. Nothing works. I open the device and cannot shut  
it down. If I try to do this through Linux, while my program is running,  
I get “umount: /media/cdrom0: device is busy”. It’s a ruby problem - or  
rather my problem in using ruby.

So, again…having done this

> archive\_source\_dir = ‘/cdrom’  
> how do I “undo” it?

Any more ideas?

Thanks,

Tom

---

<div class="post-metadata">

**Author:** ![tbcox23](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/b9bd4f/32.png) [@tbcox23](https://www.ruby-forum.com/u/tbcox23)\
**Post date:** [March 7, 2008, 6:06am UTC](https://www.ruby-forum.com/t/problems-closing-a-cd/130907/4 "2008-03-07T06:06:08Z")

</div>

Jano S. wrote:

> > > > stop the process, I input a zero length volume label (well, on Windows I  
> > > > Processing begins when the program has the volume label of the CD (this
> > > 
> > > I guess this has something to do with mounting/umounting, though I
> > 
> > how do I “undo” it?  
> > need to chdir into  
> > /cdrom
> 
> 1. if you could post minimal program that makes trouble, maybe some  
> more ideas will pop up. (e.g. strip as much as you can while it still  
> causes the problem - I guess just traversing the CD will be enough)

Jano,  
I’m slow getting back to this, but will in the next couple of hours.  
Thank you for your promising ideas. I can see that they are likely to  
get things moving on this problem, which I do need to solve. I’m  
grateful for your help, and will get back to you with what I learn. I’m  
thinking I’m close to a solution at this point.

Tom

–

```auto
Tom C., MS MA, LMHC
Private practice Psychotherapist
Bellingham, Washington, U.S.A: (360) 920-1226
<< removed_email_address@domain.invalid >> (email)
<< TomCloyd.com >> (website & psychotherapy weblog)
<< sleightmind.wordpress.com >> (mental health issues weblog)
<< directpathdesign.com >> (web site design & consultation)

```

---

<div class="post-metadata">

**Author:** ![tbcox23](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/b9bd4f/32.png) [@tbcox23](https://www.ruby-forum.com/u/tbcox23)\
**Post date:** [March 4, 2008, 2:08pm UTC](https://www.ruby-forum.com/t/problems-closing-a-cd/130907/5 "2008-03-04T14:08:24Z")

</div>

On Tue, Mar 4, 2008 at 1:15 PM, Tom C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > > do, anyway; on Linux this errors off, but that’s not my current problem).  
> > > is used as the key in a hash containing an array of the tree paths).  
> > > I get “undefined method” errors on everything. I have no idea why. Isn’t  
> > > don’t know too much about automatic mounting in kubuntu.  
> > > The problem is that I need an unmount WHILE the program is running, and
> 
> Any more ideas?

1. lsof will show you your process’ open files.
2. Make sure to use block form of File.open instead of File.new - it  
will close the file when you’re done with it.
3. Instead of archive\_source\_dir.close() do Dir.chdir(‘/’) or  
somewhere else. Or even better, use block form of Dir.chdir if you  
need to chdir into  
/cdrom
4. if you could post minimal program that makes trouble, maybe some  
more ideas will pop up. (e.g. strip as much as you can while it still  
causes the problem - I guess just traversing the CD will be enough)
