void SolidHwTest::testDeviceBasicFeatures() { // Retrieve a valid Device object Solid::Device valid_dev("/org/kde/solid/fakehw/storage_model_solid_writer"); QCOMPARE(valid_dev.isValid(), true); // A few attempts at creating invalid Device objects Solid::Device invalid_dev("uhoh? doesn't exist, I guess"); QCOMPARE(invalid_dev.isValid(), false); invalid_dev = Solid::Device(QString()); QCOMPARE(invalid_dev.isValid(), false); invalid_dev = Solid::Device(); QCOMPARE(invalid_dev.isValid(), false); QCOMPARE(valid_dev.udi(), QString("/org/kde/solid/fakehw/storage_model_solid_writer")); QCOMPARE(invalid_dev.udi(), QString()); // Query properties QCOMPARE(valid_dev.as<Solid::GenericInterface>()->propertyExists("name"), true); QCOMPARE(valid_dev.as<Solid::GenericInterface>()->propertyExists("foo.bar"), false); QCOMPARE((QObject *)invalid_dev.as<Solid::GenericInterface>(), (QObject *)0); QCOMPARE(valid_dev.as<Solid::GenericInterface>()->property("name"), QVariant("Solid IDE DVD Writer")); QVERIFY(!valid_dev.as<Solid::GenericInterface>()->property("foo.bar").isValid()); Solid::Backends::Fake::FakeDevice *fake_device = fakeManager->findDevice("/org/kde/solid/fakehw/storage_model_solid_writer"); QMap<QString, QVariant> expected_properties = fake_device->allProperties(); QCOMPARE(valid_dev.as<Solid::GenericInterface>()->allProperties(), expected_properties); // Query device interfaces QCOMPARE(valid_dev.isDeviceInterface(Solid::DeviceInterface::StorageDrive), true); QCOMPARE(valid_dev.isDeviceInterface(Solid::DeviceInterface::OpticalDrive), true); QCOMPARE(valid_dev.isDeviceInterface(Solid::DeviceInterface::StorageVolume), false); QCOMPARE(invalid_dev.isDeviceInterface(Solid::DeviceInterface::Unknown), false); QCOMPARE(invalid_dev.isDeviceInterface(Solid::DeviceInterface::StorageDrive), false); // Query parent QCOMPARE(valid_dev.parentUdi(), QString("/org/kde/solid/fakehw/pci_002_ide_1_0")); QCOMPARE(valid_dev.parent().udi(), Solid::Device("/org/kde/solid/fakehw/pci_002_ide_1_0").udi()); QVERIFY(!invalid_dev.parent().isValid()); QVERIFY(invalid_dev.parentUdi().isEmpty()); // Query vendor/product QCOMPARE(valid_dev.vendor(), QString("Acme Corporation")); QCOMPARE(valid_dev.product(), QString("Solid IDE DVD Writer")); QCOMPARE(invalid_dev.vendor(), QString()); QCOMPARE(invalid_dev.product(), QString()); }
static int cp_new_stat(struct kstat *stat, struct stat __user *statbuf) { struct stat tmp; if (!valid_dev(stat->dev) || !valid_dev(stat->rdev)) return -EOVERFLOW; #if BITS_PER_LONG == 32 if (stat->size > MAX_NON_LFS) return -EOVERFLOW; #endif INIT_STRUCT_STAT_PADDING(tmp); tmp.st_dev = encode_dev(stat->dev); tmp.st_ino = stat->ino; if (sizeof(tmp.st_ino) < sizeof(stat->ino) && tmp.st_ino != stat->ino) return -EOVERFLOW; tmp.st_mode = stat->mode; tmp.st_nlink = stat->nlink; if (tmp.st_nlink != stat->nlink) return -EOVERFLOW; SET_UID(tmp.st_uid, from_kuid_munged(current_user_ns(), stat->uid)); SET_GID(tmp.st_gid, from_kgid_munged(current_user_ns(), stat->gid)); tmp.st_rdev = encode_dev(stat->rdev); tmp.st_size = stat->size; tmp.st_atime = stat->atime.tv_sec; tmp.st_mtime = stat->mtime.tv_sec; tmp.st_ctime = stat->ctime.tv_sec; #ifdef STAT_HAVE_NSEC tmp.st_atime_nsec = stat->atime.tv_nsec; tmp.st_mtime_nsec = stat->mtime.tv_nsec; tmp.st_ctime_nsec = stat->ctime.tv_nsec; #endif tmp.st_blocks = stat->blocks; tmp.st_blksize = stat->blksize; return copy_to_user(statbuf,&tmp,sizeof(tmp)) ? -EFAULT : 0; }