Skip to content

Instantly share code, notes, and snippets.

@yaozongyou
Created September 21, 2017 12:32
Show Gist options
  • Save yaozongyou/5f5ed0d362ccef97942a09496f4e2a8c to your computer and use it in GitHub Desktop.
Save yaozongyou/5f5ed0d362ccef97942a09496f4e2a8c to your computer and use it in GitHub Desktop.
test for rgw file
#include <errno.h>
#include <iostream>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
int32_t main(int32_t argc, char* argv[]) {
if (argc != 2) {
std::cout << "Usage: " << argv[0] << " file " << std::endl;
return -1;
}
int32_t fd = open(argv[1], O_CREAT | O_TRUNC | O_WRONLY, 0600);
if (fd == -1) {
std::cerr << "failed to open: errno " << errno << " error " << strerror(errno) << std::endl;
return -1;
}
std::cout << "open fd " << fd << std::endl;
struct stat stat = {0};
int32_t status = fstat(fd, &stat);
std::cout << "fstat fd " << fd << " status " << status << std::endl;
char* buffer = new char[916688];
memset(buffer, 0, 916688);
ssize_t bytes = write(fd, buffer, 916688);
std::cout << "write fd " << fd << " bytes " << bytes << std::endl;
if (bytes != 916688) {
std::cerr << "failed to write: errno " << errno << " error " << strerror(errno) << std::endl;
return -1;
}
delete [] buffer;
buffer = new char[458276];
memset(buffer, 0, 458276);
bytes = write(fd, buffer, 458276);
std::cout << "write fd " << fd << " bytes " << bytes << std::endl;
if (bytes != 458276) {
std::cerr << "failed to write: errno " << errno << " error " << strerror(errno) << std::endl;
return -1;
}
delete [] buffer;
int32_t ret = close(fd);
std::cout << "close fd " << fd << " ret " << ret << std::endl;
return 0;
}
@yaozongyou
Copy link
Author

the output is :

[root@192 ~]# ./test /mnt/abc12345
open fd 3
fstat fd 3 status 0
write fd 3 bytes 916688
write fd 3 bytes -1
failed to write: errno 5 error Input/output error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment