小编Stu*_*ook的帖子

如何在不弹出CDROM的情况下更新Linux中的CDROM大小?

如何在不弹出CD的情况下让Linux更新其对CDROM大小的想法?换句话说,如何在不先弹出CDROM的情况下安装新烧录的CDROM?

我正在无人值守的增量备份到CDROM上.我的脚本每天使用"wodim -msinfo"和"genisoimage -C"生成一个使用"wodim -multi"附加到CDROM的图像.然后我的脚本安装CDROM以检查是否正确附加了新文件.如果Linux在安装之前更新了CDROM大小的想法,则脚本只能读取新文件.大小在/ sys/block/sr2/size和/ proc/partitions中.以前我的脚本使用"eject"然后"eject -t"让Linux重新读取CDROM."eject -t"在我的新CDROM刻录机上不起作用.如何在不弹出CDROM的情况下更新/ proc /分区?

似乎"wodim -msinfo"和"genisoimage -C"步骤还要求CDROM从上一次刻录到CDROM后被弹出,否则我收到消息"genisoimage:无效的参数.在旧图像上寻找错误".

有人在2003年提出了这个问题,但他们收到的答案并没有为我更新CDROM大小.http://compgroups.net/comp.os.linux.questions/rescan-cdrom-frm-command-line/456190

#include <fcntl.h>
#include <stdio.h>
#include <linux/cdrom.h>
int main(void)
{
    int i = 0;
    int fd = open("/dev/cdrom", O_RDWR);
    if (fd == -1)
    {
            perror("Could not open cdrom");
            return 1;
    }
    if (ioctl(fd, CDROM_MEDIA_CHANGED)) perror("ioctl");
    if (ioctl(fd, CDROMRESET)) perror("ioctl CDROMRESET");
    if (ioctl(fd, CDROM_NEXT_WRITABLE, &i))
            perror("ioctl CDROM_NEXT_WRITABLE,");
    else
            printf("CDROM_NEXT_WRITABLE %d\n", i);
    if (ioctl(fd, CDROM_LAST_WRITTEN, &i))
            perror("ioctl CDROM_LAST_WRITTEN,");
    else
            printf("CDROM_LAST_WRITTEN %d\n", i);
    return 0;
} …
Run Code Online (Sandbox Code Playgroud)

linux

12
推荐指数
1
解决办法
628
查看次数

如何使用 C++ STL 和 boost 判断两个排序向量是否相交

我有两个没有重复的排序 C++ std::vector (你可以称它们为集合),我想知道它们是否相交。我不需要公共元素的向量。

我在这个问题的末尾使用 boost“range”库中的 boost::set_intersection 算法编写了代码 (http://www.boost.org/doc/libs/1_50_0/libs/range/doc/html/range /reference/algorithms/set.html)。此代码避免构建公共元素集,但会扫描向量的所有元素。

是否可以在不使用循环的情况下使用 boost 和 C++ STL 改进我的函数“相交”?我想在向量中的第一个公共元素处停下来,或者至少避免我的计数器类。

boost range 库提供“includes”和“set_intersection”,但不提供“intersects”。这让我认为“相交”是微不足道的或在其他地方提供,但我找不到它。

谢谢!

#include <vector>
#include <string>
#include <boost/assign/list_of.hpp>
#include <boost/function_output_iterator.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/algorithm_ext/erase.hpp>

template<typename T>
class counter
{
    size_t * _n;
public:
    counter(size_t * b) : _n(b) {}
    void operator()(const T & x) const
    {
        ++*_n;
    }
};

bool intersects(const std::vector<std::string> & a, const std::vector<std::string> & b)
{
    size_t found = 0;
    boost::set_intersection(a, b, boost::make_function_output_iterator(counter<std::string>(&found)));
    return found;
}

int main(int argc, …
Run Code Online (Sandbox Code Playgroud)

c++ boost set

5
推荐指数
1
解决办法
1753
查看次数

标签 统计

boost ×1

c++ ×1

linux ×1

set ×1