The Pedigree Project 0.1
Iso9660Filesystem.h
1/*
2 * Copyright (c) 2008-2014, Pedigree Developers
3 *
4 * Please see the CONTRIB file in the root of the source tree for a full
5 * list of contributors.
6 *
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 */
19
20#ifndef ISO9660FILESYSTEM_H
21#define ISO9660FILESYSTEM_H
22
23#include "pedigree/kernel/processor/types.h"
24#include "pedigree/kernel/time/Time.h"
25#include "pedigree/kernel/utilities/String.h"
26
27#include "iso9660.h"
28#include "modules/system/vfs/Filesystem.h"
29
30class Disk;
31class File;
32
35 friend class Iso9660File;
36 friend class Iso9660Directory;
37
38 public:
40
41 virtual ~Iso9660Filesystem();
42
43 //
44 // Filesystem interface.
45 //
46
47 virtual bool initialise(Disk* pDisk);
48 static Filesystem* probe(Disk* pDisk);
49 virtual File* getRoot() const;
50 virtual const String& getVolumeLabel() const;
51
52 protected:
53 uintptr_t readBlock(File* pFile, uint64_t location);
54 size_t getBlockSize() {
55 return 2048;
56 }
57
58 virtual bool createFile(File* parent, const String& filename, uint32_t mask);
59 virtual bool createDirectory(File* parent, const String& filename, uint32_t mask);
60 virtual bool createSymlink(File* parent, const String& filename, const String& value);
61 virtual bool removeNode(File* parent, const String& filename, File* file);
62
63 virtual Disk* getDisk() {
64 return m_pDisk;
65 }
66
67 String parseName(Iso9660DirRecord& name);
68 String parseJolietName(Iso9660DirRecord& name);
69
71 bool readSector(uint64_t location, void* destination);
72
73 inline bool isLeap(uint32_t year) {
74 if (year % 400 == 0)
75 return true;
76 else if (year % 100 == 0)
77 return false;
78 else if (year % 4 == 0)
79 return true;
80 else
81 return false;
82 }
83
84 Time::Timestamp timeToUnix(Iso9660DirTimestamp& time) {
85 Time::Timestamp ret = 0;
86
87 ret += time.Second;
88 ret += time.Minute * 60;
89 ret += time.Hour * 60 * 60;
90 ret += (time.Day - 1) * 24 * 60 * 60;
91
92 static uint16_t cumulativeDays[] = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365};
93 ret += cumulativeDays[time.Month - 1] * 24 * 60 * 60;
94
95 uint32_t year = time.Year + 1900;
96 if ((time.Month) > 2 && isLeap(year))
97 ret += 24 * 60 * 60;
98
99 // Add leap days
100 uint32_t realYear = year;
101 uint32_t leapDays = ((realYear / 4) - (realYear / 100) + (realYear / 400));
102 leapDays -= ((1970 / 4) - (1970 / 100) + (1970 / 400));
103
104 ret += leapDays * 24 * 60 * 60;
105 ret += (year - 1970) * 365 * 24 * 60 * 60;
106
107 return ret;
108 }
109
110 File* fileFromDirRecord(Iso9660DirRecord& dir, size_t inodeNum, File* parent,
111 bool bDirectory = false);
112
114 void operator=(const Iso9660Filesystem&);
115
118
121 Iso9660VolumeDescriptorPrimary m_SuppVolDesc;
122 Iso9660VolumeDescriptor m_VolDesc;
123 Iso9660DirRecord* m_RootDir;
124
127
130 size_t m_BlockNumber;
131
134
137};
138
139#endif
Definition Disk.h:35
Definition File.h:74
virtual const String & getVolumeLabel() const
virtual bool createFile(File *parent, const String &filename, uint32_t mask)
virtual bool createSymlink(File *parent, const String &filename, const String &value)
bool readSector(uint64_t location, void *destination)
virtual bool removeNode(File *parent, const String &filename, File *file)
virtual File * getRoot() const
virtual bool initialise(Disk *pDisk)
Iso9660VolumeDescriptorPrimary m_PrimaryVolDesc
virtual bool createDirectory(File *parent, const String &filename, uint32_t mask)