- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在寻找一个 C++ 程序来将一些模式写入磁盘设备,但是当我尝试设置大于 0 的偏移量时遇到了问题。请参见下面的示例和代码。
谁能告诉我我做错了什么?
谢谢,
root@solaris:~/# CC simple_test.cc
root@solaris:~/# ./a.out
Insert device name, for example: /dev/rdsk/c2t600A0B800011238000001D3D45DA78A7d0s1
/dev/rdsk/c0t6000402E5000000035969F0C97324D24d0s2
iteration: 0. offset: 0
offset: 1048577
iteration: 1. offset: 1048577
WRITE operation error: 22; offset: 1048577
offset: 2097154
iteration: 2. offset: 2097154
WRITE operation error: 22; offset: 2097154
offset: 3145731
iteration: 3. offset: 3145731
WRITE operation error: 22; offset: 3145731
offset: 4194308
iteration: 4. offset: 4194308
WRITE operation error: 22; offset: 4194308
offset: 5242885
Test completed
root@solaris:~/# cat simple_test.cc
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <sstream>
#define BS 1048576
using namespace std;
const char PATTERN[ ] = { 'A' };
int main(int argc, char **argv)
{
char dev[ 100 ];
printf( "Insert device name, for example: /dev/rdsk/c2t600A0B800011238000001D3D45DA78A7d0s1\n" );
scanf( "%s", dev );
int fd;
if ( ( fd = open( dev, O_RDWR ) ) == -1 )
{
printf( "error opening device: %s\n", dev );
return 1;
}
char* pattern = new char[ BS ];
memset ( pattern, PATTERN[0], BS );
int offset = 0;
int nbytes = 0;
for (int i=0; i<5; i++ ) {
cout << "iteration: " << i << ". offset: " << offset << endl;
nbytes = pwrite( fd, pattern, BS, offset );
if ( nbytes != BS )
printf( "WRITE operation error: %d; offset: %ld\n", errno, offset );
offset += BS + 1;
cout << "offset: " << offset << endl;
}
delete pattern;
printf( "Test completed\n" );
return 0;
}
最佳答案
我不确定,但是你不需要以 block 的形式写入 block 设备吗?所以你的偏移量必须是 block 大小的倍数。但是您将它增加 BS + 1。为什么是 +1?我认为如果您坚持使用 += BS,它可能会起作用。
关于C++ pwrite() 偏移量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21149793/
我正在寻找一个 C++ 程序来将一些模式写入磁盘设备,但是当我尝试设置大于 0 的偏移量时遇到了问题。请参见下面的示例和代码。 谁能告诉我我做错了什么? 谢谢, root@solaris:~/# CC
如果我的代码执行类似fd = open("/dev/sdXY", ...) 和pwrite(fd, ...)/pread(fd, ...),I/O 操作是否跳过缓冲区或磁盘缓存?假设 /dev/sdX
我必须将 pwrite() 字符写入文本文件,每个字符代表 1 个字节。另外,我需要将整数写入文本文件,因此 12 也必须是一个字节,而不是 2 个字节(即使是两个字符)。 我正在为字符和整数使用 c
当我对文件执行 pwrite 结构时,我遇到了一个奇怪的问题。它在结构中的 char 条目旁边添加一个字节。当我尝试将 char 单独写入文件时,它正确地写入了一个字节。有人能告诉我为什么要添加单字节
我正在尝试使用 pread 和 pwrite,以便我可以查找到文件的开头并在一个原子操作中开始读取或写入。这两个函数都会为我做,但是,我遇到的问题是编译器给我 warning: implicit de
在 Linux 上,pwrite 操作(即 seek+write)是原子的,这意味着在多个线程中使用一个文件描述符执行 pwrite-s 是安全的。我想使用 dup() 创建文件描述符拷贝。现在,有了
我使用 NFS 在我的系统上安装了远程磁盘,并且我正在尝试使用 pwrite() API 写入已安装的远程磁盘上的文件。 这种情况并非每次都会发生,但在某些情况下,在执行 I/O 时 pwrite()
我通过 ioprofile 检查了 MYSQL 的 IO 事件,发现 binlog 使用了大部分 write 系统调用,但是 transaction log 使用了大部分 write 类型 pwrit
我有一个糟糕的问题。我正在尝试通过 filedescriptor 和 memalign 写入文件。我可以写入它,但只有类似错误编码字符的内容会写入文件。 这是我的代码: fdOutputFile =
我正在尝试学习 linux api,但有些函数名称(至少对我而言)似乎很麻烦。 谁能给我解释一下 pwrite/pread 中的首字母 p 代表什么? 最佳答案 我只是猜测,但是由于 pread()
什么叫最好的模仿 pread/pwrite在 MSVC 10 中? 最佳答案 在 C 运行时库级别,查看 fread , fwrite和 fseek . 在 Win32 API 级别,查看 ReadF
我的程序(如下)将文本(使用 pwrite())写入文件并从文件中读取(使用 pread())。我的问题是 pread 函数没有从文件中读取我的文本,而 close 函数有什么问题(程序的最后一部分)
当尝试写入超过 2GB 的偏移量时,我似乎遇到了 OSX 10.6.8 上 pwrite() 的奇怪问题。我不断捕捉到 SIGXFSZ 信号,这意味着已超过文件大小限制。忽略信号没有帮助,因为 pwr
嘿,如果我问的是琐碎的问题,请不要介意,但是,请有人帮我解决这个问题.. 最佳答案 分为两部分: pread/pwrite和read/write的区别: 它们都处于同一级别,即系统调用。有两个区别:
我想 fwrite() 是将数据从用户应用程序传递到用户模式下的缓冲区,但是 write() 是将数据从用户模式下的缓冲区传递到内核模式下的缓冲区,而 fsync () 是在内核模式下将数据从缓冲区传
我是一名优秀的程序员,十分优秀!