3 #include <lib/base/rawfile.h>
4 #include <lib/base/eerror.h>
22 int eRawFile::open(const char *filename)
25 m_basename = filename;
28 m_fd = ::open(filename, O_RDONLY | O_LARGEFILE);
32 void eRawFile::setfd(int fd)
39 off_t eRawFile::lseek(off_t offset, int whence)
41 /* if there is only one file, use the native lseek - the file could be growing! */
43 return ::lseek(m_fd, offset, whence);
47 m_current_offset = offset;
50 m_current_offset += offset;
53 m_current_offset = m_totallength + offset;
56 if (m_current_offset < 0)
58 return m_current_offset;
63 int ret = ::close(m_fd);
68 ssize_t eRawFile::read(void *buf, size_t count)
70 switchOffset(m_current_offset);
71 int ret = ::read(m_fd, buf, count);
73 m_current_offset += ret;
86 while (m_nrfiles < 1000) /* .999 is the last possible */
88 int f = openFile(m_nrfiles);
92 m_splitsize = ::lseek(f, 0, SEEK_END);
93 m_totallength += ::lseek(f, 0, SEEK_END);
98 eDebug("found %d files, splitsize: %llx, totallength: %llx", m_nrfiles, m_splitsize, m_totallength);
101 int eRawFile::switchOffset(off_t off)
105 int filenr = off / m_splitsize;
106 if (filenr >= m_nrfiles)
107 filenr = m_nrfiles - 1;
109 if (filenr != m_current_file)
112 setfd(openFile(filenr));
113 m_base_offset = m_splitsize * filenr;
114 eDebug("switched to file %d", filenr);
119 return ::lseek(m_fd, off - m_base_offset, SEEK_SET) + m_base_offset;
122 int eRawFile::openFile(int nr)
124 std::string filename = m_basename;
128 snprintf(suffix, 5, ".%03d", nr);
131 return ::open(filename.c_str(), O_RDONLY);