注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

gmd20的个人空间

// 编程和生活

 
 
 

日志

 
 

虚拟光驱学习(一)  

2008-11-18 10:56:57|  分类: 程序设计 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

虚拟光驱到底是怎么样做出来的,很有意思的东西,我也来看看吧。
Linux好像已经在系统内部就支持了,具体可以看下面从wikepedia上面摘下来的说明。

Loop device 原文地址:http://en.wikipedia.org/wiki/Loop_device

In Unix-like operating systems, a loop device, vnd (vnode disk), or lofi (loopback file interface) is a pseudo-device that makes a file accessible as a block device.

Before use, a loop device must be connected to an existing file in the filesystem. The association provides the user with an API that allows the file to be used in place of a block special file (cf. device file system). Thus, if the file contains an entire file system, the file may then be mounted as if it were a disk device.

Files of this kind are often used for CD ISO images and floppy disc images. Mounting a file containing a filesystem via such a loop mount makes the files within that filesystem accessible as regular files, located in the mount point directory.

A loop device may allow some kind of data elaboration during this redirection; for example, the device may be the unencrypted version of an encrypted file. In such a case, the file associated with a loop device may be another pseudo-device. This is mostly useful when this device contains an encrypted file system. If supported, the loop device is in this case the decrypted version of the original encrypted file and can therefore be mounted as if it were a normal filesystem.

Contents

[hide]

[edit] Examples

Mounting a file on a directory requires two steps:

  1. the file is associated with a loop device node, which is a special file
  2. the loop device is mounted on the directory

These two operations can be performed either using two separate commands, or by letting the mount command perform the first step before actually doing the mount. The first operation can be executed by a specific command such as losetup[1] in Linux. As an example, if de<example.imgde< is a regular file containing a filesystem and de</home/you/dirde< is a directory on a Linux box, the root user can mount the file on the directory by executing the following two commands:

losetup /dev/loop0 example.imgmount /dev/loop0 /home/you/dir

The first command associates the loop device node de</dev/loop0de< with the regular file de<example.imgde<. This association can be later destroyed by executing de<losetup -d /dev/loop0de<. The second command mounts the device on the directory de</home/you/dirde<. The overall effect of executing these two commands is that the content of the file is used as the whole mounted directory. The system call used by losetup to associate and disassociate files with loop devices is an ioctl on the loop device.

An alternative way of doing the same is to let the mount utility handle the setting up of the loop device:

mount -o loop example.img /home/you/dir

In this case, the mount command performs both the association of the file with the loop device and the mount itself.

At the level of system calls, the association and disassociation of a file with a loop device are done via ioctl's on the loop device. Both losetup and mount therefore use such ioctl's to operate on loop devices. For example, de<losetup /dev/loop0 example.imgde< opens device de</dev/loop0de< and performs an ioctl on the resulting file descriptor, passing de<LOOP_SET_FDde< as the request number and the string de<example.imgde< as the third argument.

[edit] Uses of loop mounting

After mounting a file containing a filesystem, the files within the filesystem can be accessed through the usual filesystem interface of the operating system, without any need for special functionality, such as reading and writing to ISO images, in applications.

Uses include managing and editing filesystem images meant for later normal use (especially CD or DVD images or installation systems) or permanent segregation of data in actual use (for example simulating removable media on a faster and more convenient hard disk or encapsulating encrypted filesystems).

[edit] Availability

Some confusion exists about the naming of the loop device under various operating systems. Various Unix-like operating system provide the loop device functionality under different names.

In Linux[2], device names are encoded in the symbol table entries of their corresponding device drivers. The device is called "loop" device and device nodes in the device file system are named /dev/loop0, /dev/loop1, etc. and created by the makedev script. The management user interface for the loop device is losetup and is part of the util-linux package.

Sometimes, the loop device is erroneously referred to as 'loopback' device, but this term is reserved for a networking device in the Linux kernel (cf. loopback). The concept of the 'loop' device is distinct from that of 'loopback', although similar in name.

In BSD, the loop device is called "virtual node device" or "vnd", and generally located at /dev/vnd0, /dev/rvnd0 or /dev/svnd0, etc., in the file system. The configuration is called the vnconfig program.

In SunOS, it is called "loopback file interface" or lofi, and located at /dev/lofi/1, etc. SunOS has the lofiadm program for configuration.

Loop mounting is not natively available on Microsoft Windows operating systems; however, the facility is often added using third-party applications such as Daemon Tools and Alcohol 120%.

A freely-available [1] tool from VMware can also be used to achieve similar functionality

  评论这张
 
阅读(528)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017