Skip to content

Commit 07a49ac

Browse files
authored
Add Minimal CD support (#6)
* Add initial cdX support * format * Add missing includes * Simplify CD handler * Simple rename * Update checklist * Fix format * Bump version to 0.3.0 * Update license year
1 parent 9ef3a0e commit 07a49ac

File tree

12 files changed

+123
-11
lines changed

12 files changed

+123
-11
lines changed

CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ cmake_minimum_required(VERSION 3.16.0)
22

33
# Version setup
44
set(OPENBSDISKS_VERSION_MAJOR "0")
5-
set(OPENBSDISKS_VERSION_MINOR "2")
6-
set(OPENBSDISKS_VERSION_PATCH "3")
5+
set(OPENBSDISKS_VERSION_MINOR "3")
6+
set(OPENBSDISKS_VERSION_PATCH "0")
77
set(OPENBSDISKS_VERSION "${OPENBSDISKS_VERSION_MAJOR}.${OPENBSDISKS_VERSION_MINOR}.${OPENBSDISKS_VERSION_PATCH}")
88

99
project(openbsdisks2
@@ -40,6 +40,7 @@ set(SOURCE
4040
src/manageradaptor.cpp
4141
src/objectmanager.cpp
4242

43+
src/cd_handler.cpp
4344
src/disk_thread.cpp
4445
src/disk_label.cpp
4546
)

LICENSE.TXT

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Copyright 2016 Gleb Popov <[email protected]>
2-
Copyright 2020 Rafael Sadowski <[email protected]>
2+
Copyright 2020-2021 Rafael Sadowski <[email protected]>
33

44
Redistribution and use in source and binary forms, with or without
55
modification, are permitted provided that the following conditions are met:

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ An UDisks2 service implementation for OpenBSD forked from FreeBSD (bsdutils/bsdi
66
The sourcecode based on commit [3d3439348ba00ae972e146c5bf28cb42949e24f](https://foss.heptapod.net/bsdutils/bsdisks/-/commit/93d3439348ba00ae972e146c5bf28cb42949e24f) from [bsdutils/bsdisks](https://foss.heptapod.net/bsdutils/bsdisks).
77

88
### Feature List
9-
- [x] Simple DBus org.freedesktop.UDisks2.service
9+
- [X] Simple DBus org.freedesktop.UDisks2.service
1010
- [X] Provides `org.freedesktop.UDisks2.Block`
1111
- [X] Provides `org.freedesktop.UDisks2.Drive`
1212
- [X] Provides `org.freedesktop.UDisks2.Filesystem` (Not all information yet)
1313
- [X] Logging via `stdout` and syslog
14-
- [ ] cd(4) support
15-
- [x] mount(2), umount(2) support (ffs only)
14+
- [X] cd(4) support
15+
- [X] mount(2), umount(2) support (ffs only)
1616
- [ ] Privilege separation
1717
- [ ] Device information updates
1818

src/blockfilesystem.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ void BlockFilesystem::setFilesystem(const QString& fs)
231231
bool BlockFilesystem::isFilesystemSupportedToMount() const
232232
{
233233
return (filesystem == "ffs" || filesystem == "ext2fs" || filesystem == "ntfs" ||
234-
filesystem == "msdos");
234+
filesystem == "msdos" || filesystem == "cd9660");
235235
}
236236

237237
const QString BlockFilesystem::getMountCommand() const
@@ -245,6 +245,8 @@ const QString BlockFilesystem::getMountCommand() const
245245
mountProg = QStringLiteral("/sbin/mount_ntfs");
246246
} else if (filesystem == "ntfs") {
247247
mountProg = QStringLiteral("/sbin/mount_msdos");
248+
} else if (filesystem == "cd9660") {
249+
mountProg = QStringLiteral("/sbin/mount_cd9660");
248250
}
249251
return mountProg;
250252
}
@@ -260,6 +262,8 @@ const QStringList BlockFilesystem::getMountOptions() const
260262
mountOps << QStringLiteral("-orw");
261263
} else if (filesystem == "ntfs") {
262264
mountOps << QStringLiteral("-oro");
265+
} else if (filesystem == "cd9660") {
266+
mountOps << QStringLiteral("-oro");
263267
}
264268
return mountOps;
265269
}

src/blockfilesystem.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
#include <QStringList>
3434
#include <QVariantMap>
3535

36+
#include <memory>
37+
3638
class Block;
3739

3840
class BlockFilesystem

src/blockparttable.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
#include <QString>
3131
#include <QStringList>
3232

33+
#include <memory>
34+
3335
class BlockPartTable
3436
{
3537
public:

src/cd_handler.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright 2021 Rafael Sadowski <[email protected]>
3+
*
4+
* Permission to use, copy, modify, and/or distribute this software for any
5+
* purpose with or without fee is hereby granted, provided that the above
6+
* copyright notice and this permission notice appear in all copies.
7+
*
8+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9+
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10+
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
11+
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12+
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13+
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14+
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15+
*
16+
*/
17+
18+
#include "cd_handler.h"
19+
20+
#include "drive.h"
21+
22+
#include <QStringList>
23+
24+
CdHandler::CdHandler(const QString& dev)
25+
: DiskLabel(dev)
26+
{
27+
analyseDev(dev);
28+
}
29+
30+
void CdHandler::analyseDev(const QString& dev)
31+
{
32+
DiskLabel::analyseDev(dev);
33+
if (getDrive())
34+
getDrive()->setRemovable(true);
35+
}
36+
37+
/**
38+
* return a list of all possible device names
39+
* /dev/cd[0-9][a-p] block mode CD-ROM devices
40+
*/
41+
QStringList const CdHandler::getBlockCDROMdevices()
42+
{
43+
QStringList devs;
44+
for (const QString& dev : QStringList({"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}))
45+
devs << "rcd" + dev;
46+
return devs;
47+
}

src/cd_handler.h

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright 2021 Rafael Sadowski <[email protected]>
3+
*
4+
* Permission to use, copy, modify, and/or distribute this software for any
5+
* purpose with or without fee is hereby granted, provided that the above
6+
* copyright notice and this permission notice appear in all copies.
7+
*
8+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9+
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10+
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
11+
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12+
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13+
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14+
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15+
*
16+
*/
17+
18+
#pragma once
19+
20+
#include "drive.h"
21+
22+
#include "disk_label.h"
23+
24+
class QString;
25+
26+
/**
27+
* disklabel – read disk pack label
28+
*/
29+
class CdHandler : public DiskLabel
30+
{
31+
public:
32+
CdHandler(const QString&);
33+
34+
CdHandler() = default;
35+
~CdHandler() = default;
36+
37+
static QStringList const getBlockCDROMdevices();
38+
39+
private:
40+
void analyseDev(const QString&) override;
41+
};
42+
43+
using TCdHandler = std::shared_ptr<CdHandler>;
44+
using TCdHandlerVec = std::vector<TCdHandler>;

src/disk_label.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,16 @@ class DiskLabel
2929
{
3030
public:
3131
DiskLabel() = default;
32+
virtual ~DiskLabel() = default;
33+
3234
DiskLabel(const QString&);
3335

3436
bool isValid() const;
3537
TDrive getDrive() const;
3638
QString getDeviceName() const;
3739

38-
private:
39-
void analyseDev(const QString&);
40+
protected:
41+
virtual void analyseDev(const QString&);
4042
bool isValidFileSysetem(u_int8_t) const;
4143

4244
void createDrive(const QString&);

src/disk_thread.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,14 @@ void DiskThread::run()
7373

7474
void DiskThread::check()
7575
{
76+
for (auto const& name : CdHandler::getBlockCDROMdevices()) {
77+
auto cd = std::make_shared<CdHandler>(name);
78+
if (cd->isValid()) {
79+
m_cds.push_back(cd);
80+
emit deviceAdded(cd->getDrive());
81+
}
82+
}
83+
7684
// "sd0:6e6c992178f67d41,sd2:0f191ebc5bc2aa61,sd1:"
7785
const QString disks = readDisknames();
7886
const auto devNameUuids = getCurrentDev(disks);

0 commit comments

Comments
 (0)