xref: /haiku/src/add-ons/kernel/file_systems/udf/Volume.cpp (revision 29008bcfd8aa94b0d16ad2f259618200b67c42da)
1*29008bcfSTyler Dauwalder //----------------------------------------------------------------------
2*29008bcfSTyler Dauwalder //  This software is part of the OpenBeOS distribution and is covered
3*29008bcfSTyler Dauwalder //  by the OpenBeOS license.
4*29008bcfSTyler Dauwalder //
5*29008bcfSTyler Dauwalder //  Copyright (c) 2003 Tyler Dauwalder, tyler@dauwalder.net
6*29008bcfSTyler Dauwalder //  Mad props to Axel Dörfler and his BFS implementation, from which
7*29008bcfSTyler Dauwalder //  this UDF implementation draws much influence (and a little code :-P).
8*29008bcfSTyler Dauwalder //----------------------------------------------------------------------
9*29008bcfSTyler Dauwalder #include "Volume.h"
10*29008bcfSTyler Dauwalder 
11*29008bcfSTyler Dauwalder #include "Block.h"
12*29008bcfSTyler Dauwalder #include "Debug.h"
13*29008bcfSTyler Dauwalder 
14*29008bcfSTyler Dauwalder using namespace UDF;
15*29008bcfSTyler Dauwalder 
16*29008bcfSTyler Dauwalder //----------------------------------------------------------------------
17*29008bcfSTyler Dauwalder // Volume
18*29008bcfSTyler Dauwalder //----------------------------------------------------------------------
19*29008bcfSTyler Dauwalder 
20*29008bcfSTyler Dauwalder /*! \brief Creates an unmounted volume with the given id.
21*29008bcfSTyler Dauwalder */
22*29008bcfSTyler Dauwalder Volume::Volume(nspace_id id)
23*29008bcfSTyler Dauwalder 	: fID(id)
24*29008bcfSTyler Dauwalder 	, fDevice(0)
25*29008bcfSTyler Dauwalder 	, fReadOnly(false)
26*29008bcfSTyler Dauwalder {
27*29008bcfSTyler Dauwalder }
28*29008bcfSTyler Dauwalder 
29*29008bcfSTyler Dauwalder status_t
30*29008bcfSTyler Dauwalder Volume::Identify(int device, off_t base)
31*29008bcfSTyler Dauwalder {
32*29008bcfSTyler Dauwalder 	return B_ERROR;
33*29008bcfSTyler Dauwalder }
34*29008bcfSTyler Dauwalder 
35*29008bcfSTyler Dauwalder /*! \brief Attempts to mount the given device.
36*29008bcfSTyler Dauwalder */
37*29008bcfSTyler Dauwalder status_t
38*29008bcfSTyler Dauwalder Volume::Mount(const char *deviceName, uint32 flags)
39*29008bcfSTyler Dauwalder {
40*29008bcfSTyler Dauwalder 	if (!deviceName)
41*29008bcfSTyler Dauwalder 		RETURN_ERROR(B_BAD_VALUE);
42*29008bcfSTyler Dauwalder 
43*29008bcfSTyler Dauwalder 	fReadOnly = flags & B_READ_ONLY;
44*29008bcfSTyler Dauwalder 
45*29008bcfSTyler Dauwalder 	// Open the device, trying read only if readwrite fails
46*29008bcfSTyler Dauwalder 	fDevice = open(deviceName, fReadOnly ? O_RDONLY : O_RDWR);
47*29008bcfSTyler Dauwalder 	if (fDevice < B_OK && !fReadOnly) {
48*29008bcfSTyler Dauwalder 		fReadOnly = true;
49*29008bcfSTyler Dauwalder 		fDevice = open(deviceName, O_RDONLY);
50*29008bcfSTyler Dauwalder 	}
51*29008bcfSTyler Dauwalder 	if (fDevice < B_OK)
52*29008bcfSTyler Dauwalder 		RETURN_ERROR(fDevice);
53*29008bcfSTyler Dauwalder 
54*29008bcfSTyler Dauwalder 	// If the device is actually a normal file, try to disable the cache
55*29008bcfSTyler Dauwalder 	// for the file in the parent filesystem
56*29008bcfSTyler Dauwalder 	struct stat stat;
57*29008bcfSTyler Dauwalder 	status_t err = fstat(fDevice, &stat) < 0 ? B_OK : B_ERROR;
58*29008bcfSTyler Dauwalder 	if (!err) {
59*29008bcfSTyler Dauwalder 		if (stat.st_mode & S_IFREG && ioctl(fDevice, IOCTL_FILE_UNCACHED_IO, NULL) < 0) {
60*29008bcfSTyler Dauwalder 			// Probably should die some sort of painful death here.
61*29008bcfSTyler Dauwalder 		}
62*29008bcfSTyler Dauwalder 	}
63*29008bcfSTyler Dauwalder 
64*29008bcfSTyler Dauwalder 	// Now identify the volume
65*29008bcfSTyler Dauwalder 
66*29008bcfSTyler Dauwalder 	return B_ERROR;
67*29008bcfSTyler Dauwalder }
68*29008bcfSTyler Dauwalder 
69