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