Skip to content

Commit

Permalink
Add error injection with wrong storage capacity
Browse files Browse the repository at this point in the history
Closes #62
  • Loading branch information
ligurio committed Aug 11, 2021
1 parent 6d538d0 commit 9930bdc
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 0 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ Supported fault injections are:
but applicable to any file operation).
- `errinj_slowdown` - slowdown invoked file operation.
- `errinj_1byte_read` - amount of data `read()` is returned is limited by 1 byte.
- `errinj_wrong_capacity` - report a wrong storage capacity. There are many
fraudulent USB sticks in circulation that report to have a high capacity (ex:
8GB) but are really only capable of storing a much smaller amount (ex: 1GB).
Attempts to write on these devices will often result in unrelated files being
overwritten. Any use of a fraudulent flash memory device can easily lead to
database corruption, therefore.
https://www.sqlite.org/howtocorrupt.html

### Building

Expand Down
2 changes: 2 additions & 0 deletions unreliablefs.conf.5
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ limited by supported errno's.
File operation slowdown for nanoseconds specified by duration parameter.
.It Cm errinj_1byte_read
Return exactly 1 byte on every read() operation.
.It Cm errinj_wrong_capacity
Report a wrong storage capacity.
.El
.Pp
The options are:
Expand Down
2 changes: 2 additions & 0 deletions unreliablefs_errinj.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const char *errinj_name[] =
"errinj_noop",
"errinj_slowdown",
"errinj_1byte_read",
"errinj_wrong_capacity",
};

typedef enum {
Expand All @@ -30,6 +31,7 @@ typedef enum {
ERRINJ_NOOP,
ERRINJ_SLOWDOWN,
ERRINJ_1BYTE_READ,
ERRINJ_WRONG_CAPACITY,
} errinj_type;

typedef struct errinj_conf errinj_conf;
Expand Down
1 change: 1 addition & 0 deletions unreliablefs_errinj.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

#define ERRNO_NOOP -999
#define ERRNO_1BYTE_READ -998
#define ERRNO_WRONG_CAPACITY -997

int error_inject(const char* path, fuse_op operation);
struct err_inj_q *config_init(const char* conf_path);
Expand Down
2 changes: 2 additions & 0 deletions unreliablefs_ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,8 @@ int unreliable_statfs(const char *path, struct statvfs *buf)
int ret = error_inject(path, OP_STATFS);
if (ret == -ERRNO_NOOP) {
return 0;
if (ret == -ERRNO_WRONG_CAPACITY) {
/* wrong capacity */
} else if (ret) {
return ret;
}
Expand Down

0 comments on commit 9930bdc

Please sign in to comment.