Go to the documentation of this file.
30 xassert(
const char *msg,
const char *file,
int line)
32 fprintf(stderr,
"assertion failed: %s:%d: \"%s\"\n", file, line, msg);
38 #define DEBUG(LEVEL) if ((LEVEL) <= DebugLevel)
66 fprintf(stderr,
"%d %s: ", (
int)
mypid, buf);
79 fprintf(stderr,
"%d OPEN id %d, FD %d, fs %p\n",
98 fprintf(stderr,
"%d CLOSE id %d: ", (
int)
mypid, r->
id);
108 fprintf(stderr,
"%d CLOSE id %d, FD %d, fs %p\n",
121 int readlen = r->
size;
128 fprintf(stderr,
"%d READ id %d: ", (
int)
mypid, r->
id);
137 fprintf(stderr,
"seeking to %" PRId64 "\n", (int64_t)r->
offset);
140 if (lseek(fs->
fd, r->
offset, SEEK_SET) < 0) {
142 fprintf(stderr,
"%d FD %d, offset %" PRId64 ": ", (
int)
mypid, fs->
fd, (int64_t)r->
offset);
148 const auto x =
xread(fs->
fd, buf, readlen);
150 fprintf(stderr,
"%d READ %d,%d,%" PRId64 " ret %d\n", (
int)
mypid,
151 fs->
fd, readlen, (int64_t)r->
offset, x);
156 fprintf(stderr,
"%d FD %d: ", (
int)
mypid, fs->
fd);
170 int wrtlen = r->
size;
177 fprintf(stderr,
"%d WRITE id %d: ", (
int)
mypid, r->
id);
185 if (lseek(fs->
fd, r->
offset, SEEK_SET) < 0) {
187 fprintf(stderr,
"%d FD %d, offset %" PRId64 ": ", (
int)
mypid, fs->
fd, (int64_t)r->
offset);
194 fprintf(stderr,
"%d WRITE %d,%d,%" PRId64 "\n", (
int)
mypid,
195 fs->
fd, wrtlen, (int64_t)r->
offset);
197 const auto x =
xwrite(fs->
fd, buf, wrtlen);
201 fprintf(stderr,
"%d FD %d: ", (
int)
mypid, fs->
fd);
215 if (unlink(buf) < 0) {
217 fprintf(stderr,
"%d UNLNK id %d %s: ", (
int)
mypid, r->
id, buf);
225 fprintf(stderr,
"%d UNLNK %s\n", (
int)
mypid, buf);
247 fprintf(stderr,
"%d UNLNK id(%u) Error: no filename in shm buffer\n", (
int)
mypid, s->
id);
284 const int *
A = (
const int *)a;
285 const int *
B = (
const int *)b;
293 const int *k = (
const int *)key;
314 setbuf(stdout,
nullptr);
315 setbuf(stderr,
nullptr);
319 rmsgid = msgget(key, 0600);
327 smsgid = msgget(key, 0600);
335 shmid = shmget(key, 0, 0600);
342 shmbuf = (
char *)shmat(shmid,
nullptr, 0);
344 if (
shmbuf == (
void *) -1) {
355 memset(&sa,
'\0',
sizeof(sa));
358 sigaction(SIGALRM, &sa,
nullptr);
362 memset(&rmsg,
'\0',
sizeof(rmsg));
364 std::cerr <<
"msgrcv: " << rmsgid <<
", "
366 <<
", " << 0 <<
", " << 0 << std::endl;
371 if (EINTR == errno) {
372 if (
xread(0, rbuf, 512) <= 0) {
373 if (EWOULDBLOCK == errno)
375 else if (EAGAIN == errno)
382 if (EAGAIN == errno) {
400 fprintf(stderr,
"%d diskd exiting\n", (
int)
mypid);
403 if (msgctl(rmsgid, IPC_RMID,
nullptr) < 0)
404 perror(
"msgctl IPC_RMID");
406 if (msgctl(smsgid, IPC_RMID,
nullptr) < 0)
407 perror(
"msgctl IPC_RMID");
412 if (shmctl(shmid, IPC_RMID,
nullptr) < 0)
413 perror(
"shmctl IPC_RMID");
void xassert(const char *msg, const char *file, int line)
const char * xstrerr(int error)
void * xcalloc(size_t n, size_t sz)
static unsigned int fsHash(const void *key, unsigned int n)
void hash_remove_link(hash_table *, hash_link *)
int xwrite(int fd, const void *buf, size_t bufSize)
POSIX write(2) equivalent.
hash_link * hash_lookup(hash_table *, const void *)
static int do_close(diomsg *r, int)
static int do_read(diomsg *r, int, char *buf)
static void msg_handle(diomsg *r, int rl, diomsg *s)
static const int msg_snd_rcv_sz
int main(int argc, char *argv[])
static int do_write(diomsg *r, int, const char *buf)
static int fsCmp(const void *a, const void *b)
static void alarm_handler(int)
static int do_open(diomsg *r, int, const char *buf)
hash_table * hash_create(HASHCMP *, int, HASHHASH *)
int xread(int fd, void *buf, size_t bufSize)
POSIX read(2) equivalent.
int xopen(const char *filename, int oflag, int pmode=0)
POSIX open(2) equivalent.
int xclose(int fd)
POSIX close(2) equivalent.
static int do_unlink(diomsg *r, int, const char *buf)
void hash_join(hash_table *, hash_link *)