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 "iso9660.h"
24 #include "modules/system/vfs/Filesystem.h"
25 #include "pedigree/kernel/processor/types.h"
26 #include "pedigree/kernel/time/Time.h"
27 #include "pedigree/kernel/utilities/String.h"
28 
29 class Disk;
30 class File;
31 
34 {
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 String getVolumeLabel() const;
51 
52  protected:
53  uintptr_t readBlock(File *pFile, uint64_t location);
54  size_t getBlockSize()
55  {
56  return 2048;
57  }
58 
59  virtual bool
60  createFile(File *parent, const String &filename, uint32_t mask);
61  virtual bool
62  createDirectory(File *parent, const String &filename, uint32_t mask);
63  virtual bool
64  createSymlink(File *parent, const String &filename, const String &value);
65  virtual bool remove(File *parent, File *file);
66 
67  virtual Disk *getDisk()
68  {
69  return m_pDisk;
70  }
71 
72  String parseName(Iso9660DirRecord &name);
73  String parseJolietName(Iso9660DirRecord &name);
74 
75  inline bool isLeap(uint32_t year)
76  {
77  if (year % 400 == 0)
78  return true;
79  else if (year % 100 == 0)
80  return false;
81  else if (year % 4 == 0)
82  return true;
83  else
84  return false;
85  }
86 
87  Time::Timestamp timeToUnix(Iso9660DirTimestamp &time)
88  {
89  Time::Timestamp ret = 0;
90 
91  ret += time.Second;
92  ret += time.Minute * 60;
93  ret += time.Hour * 60 * 60;
94  ret += (time.Day - 1) * 24 * 60 * 60;
95 
96  static uint16_t cumulativeDays[] = {0, 31, 59, 90, 120, 151, 181,
97  212, 243, 273, 304, 334, 365};
98  ret += cumulativeDays[time.Month - 1] * 24 * 60 * 60;
99 
100  uint32_t year = time.Year + 1900;
101  if ((time.Month) > 2 && isLeap(year))
102  ret += 24 * 60 * 60;
103 
104  // Add leap days
105  uint32_t realYear = year;
106  uint32_t leapDays =
107  ((realYear / 4) - (realYear / 100) + (realYear / 400));
108  leapDays -= ((1970 / 4) - (1970 / 100) + (1970 / 400));
109 
110  ret += leapDays * 24 * 60 * 60;
111  ret += (year - 1970) * 365 * 24 * 60 * 60;
112 
113  return ret;
114  }
115 
116  File *fileFromDirRecord(
117  Iso9660DirRecord &dir, size_t inodeNum, File *parent,
118  bool bDirectory = false);
119 
121  void operator=(const Iso9660Filesystem &);
122 
125 
128  Iso9660VolumeDescriptorPrimary m_SuppVolDesc;
129  Iso9660VolumeDescriptor m_VolDesc;
130  Iso9660DirRecord *m_RootDir;
131 
134 
136  size_t m_BlockSize;
137  size_t m_BlockNumber;
138 
141 
144 };
145 
146 #endif
virtual bool createSymlink(File *parent, const String &filename, const String &value)
virtual bool createDirectory(File *parent, const String &filename, uint32_t mask)
virtual String getVolumeLabel() const
virtual size_t getBlockSize() const
Definition: File.cc:549
Definition: String.h:49
virtual bool initialise(Disk *pDisk)
Definition: Disk.h:32
virtual bool createFile(File *parent, const String &filename, uint32_t mask)
Iso9660VolumeDescriptorPrimary m_PrimaryVolDesc
virtual File * getRoot() const
virtual uintptr_t readBlock(uint64_t location)
Definition: File.cc:602
Definition: File.h:66