xref: /haiku/src/add-ons/kernel/partitioning_systems/session/Disc.h (revision 1d9d47fc72028bb71b5f232a877231e59cfe2438)
1 //----------------------------------------------------------------------
2 //  This software is part of the OpenBeOS distribution and is covered
3 //  by the OpenBeOS license.
4 //
5 //  Copyright (c) 2003 Tyler Dauwalder, tyler@dauwalder.net
6 //---------------------------------------------------------------------
7 /*!
8 	\file Disc.cpp
9 
10 	Disc class, used to enumerate the CD/DVD sessions.
11 */
12 
13 #ifndef _DISC_H
14 #define _DISC_H
15 
16 #include <errno.h>
17 #include <new>
18 #include <stdlib.h>
19 #include <string.h>
20 #include <unistd.h>
21 
22 #include <ByteOrder.h>
23 #include <disk_scanner.h>
24 #include <KernelExport.h>
25 #include <scsi.h>
26 
27 #include "Debug.h"
28 #include "scsi-mmc.h"
29 
30 class List;
31 class Session;
32 
33 /*! \brief A class that encapsulates a complete, parsed, and error
34 	checked table of contents for a CD-ROM.
35 */
36 class Disc {
37 public:
38 	Disc(int fd);
39 	~Disc();
40 
41 	status_t InitCheck();
42 	Session* GetSession(int32 index);
43 
44 	void Dump();
45 
46 	// CDs and DVDs are required to have a block size of 2K by
47 	// the SCSI-3 standard
48 	static const int kBlockSize = 2048;
49 
50 private:
51 	status_t _ParseTableOfContents(cdrom_full_table_of_contents_entry entries[],
52 	                              uint32 count);
53 	void _SortAndRemoveDuplicates();
54 	status_t _CheckForErrorsAndWarnings();
55 
56 	status_t fInitStatus;
57 	List *fSessionList;
58 };
59 
60 /*! \brief Encapsulates the pertinent information for a given session
61 	on a Disc.
62 */
63 class Session {
64 public:
65 	~Session();
66 
67 	off_t Offset() { return fOffset; }
68 	off_t Size() { return fSize; }
69 	uint32 BlockSize() { return fBlockSize; }
70 	int32 Index() { return fIndex; }
71 	uint32 Flags() { return fFlags; }
72 	const char* Type() { return fType; }
73 private:
74 	friend class Disc;
75 	Session(off_t offset, off_t size, uint32 blockSize, int32 index,
76 	        uint32 flags, const char *type);
77 	Session(const Session &ref);			// not implemented
78 	Session& operator=(const Session &ref);	// not implemented
79 
80 	off_t fOffset;
81 	off_t fSize;
82 	uint32 fBlockSize;
83 	int32 fIndex;
84 	uint32 fFlags;
85 	char *fType;
86 };
87 
88 #endif	// _DISC_H
89