]> mj.ucw.cz Git - libucw.git/blobdiff - ucw/fb-direct.c
Resources: Allow res_free(NULL) and res_detach(NULL)
[libucw.git] / ucw / fb-direct.c
index 1c4409ac3f914899db4abf866f30e365ecfe0553..ccdb851b1f492211edd069ee7400cd571e9ebea3 100644 (file)
 #include <unistd.h>
 #include <stdio.h>
 
 #include <unistd.h>
 #include <stdio.h>
 
-uns fbdir_cheat;
-
-static struct cf_section fbdir_cf = {
-  CF_ITEMS {
-    CF_UNS("Cheat", &fbdir_cheat),
-    CF_END
-  }
-};
-
 #define FBDIR_ALIGN 512
 
 enum fbdir_mode {                              // Current operating mode
 #define FBDIR_ALIGN 512
 
 enum fbdir_mode {                              // Current operating mode
@@ -68,11 +59,22 @@ struct fb_direct {
 };
 #define FB_DIRECT(f) ((struct fb_direct *)(f)->is_fastbuf)
 
 };
 #define FB_DIRECT(f) ((struct fb_direct *)(f)->is_fastbuf)
 
+#ifndef TEST
+uns fbdir_cheat;
+
+static struct cf_section fbdir_cf = {
+  CF_ITEMS {
+    CF_UNS("Cheat", &fbdir_cheat),
+    CF_END
+  }
+};
+
 static void CONSTRUCTOR
 fbdir_global_init(void)
 {
   cf_declare_section("FBDirect", &fbdir_cf, 0);
 }
 static void CONSTRUCTOR
 fbdir_global_init(void)
 {
   cf_declare_section("FBDirect", &fbdir_cf, 0);
 }
+#endif
 
 static void
 fbdir_read_sync(struct fb_direct *F)
 
 static void
 fbdir_read_sync(struct fb_direct *F)
@@ -157,7 +159,7 @@ fbdir_refill(struct fastbuf *f)
   if (!r->status)
     return 0;
   if (r->status < 0)
   if (!r->status)
     return 0;
   if (r->status < 0)
-    die("Error reading %s: %s", f->name, strerror(r->returned_errno));
+    bthrow(f, "fb.read", "Error reading %s: %s", f->name, strerror(r->returned_errno));
   f->bptr = f->buffer = r->buffer;
   f->bstop = f->bufend = f->buffer + r->status;
   f->pos += r->status;
   f->bptr = f->buffer = r->buffer;
   f->bstop = f->bufend = f->buffer + r->status;
   f->pos += r->status;
@@ -190,8 +192,8 @@ fbdir_spout(struct fastbuf *f)
          asio_submit(r);
          asio_sync(F->io_queue);
          DBG("FB-DIRECT: Truncating at %llu", (long long)f->pos);
          asio_submit(r);
          asio_sync(F->io_queue);
          DBG("FB-DIRECT: Truncating at %llu", (long long)f->pos);
-         if (sh_ftruncate(F->fd, f->pos) < 0)
-           die("Error truncating %s: %m", f->name);
+         if (ucw_ftruncate(F->fd, f->pos) < 0)
+           bthrow(f, "fb.write", "Error truncating %s: %m", f->name);
        }
       else
        asio_submit(r);
        }
       else
        asio_submit(r);
@@ -205,7 +207,7 @@ fbdir_spout(struct fastbuf *f)
 }
 
 static int
 }
 
 static int
-fbdir_seek(struct fastbuf *f, sh_off_t pos, int whence)
+fbdir_seek(struct fastbuf *f, ucw_off_t pos, int whence)
 {
   DBG("FB-DIRECT: Seek %llu %d", (long long)pos, whence);
 
 {
   DBG("FB-DIRECT: Seek %llu %d", (long long)pos, whence);
 
@@ -213,7 +215,7 @@ fbdir_seek(struct fastbuf *f, sh_off_t pos, int whence)
     return 1;
 
   fbdir_change_mode(FB_DIRECT(f), M_NULL);                     // Wait for all async requests to finish
     return 1;
 
   fbdir_change_mode(FB_DIRECT(f), M_NULL);                     // Wait for all async requests to finish
-  sh_off_t l = sh_seek(FB_DIRECT(f)->fd, pos, whence);
+  ucw_off_t l = ucw_seek(FB_DIRECT(f)->fd, pos, whence);
   if (l < 0)
     return 0;
   f->pos = l;
   if (l < 0)
     return 0;
   f->pos = l;
@@ -306,7 +308,7 @@ fbdir_open_fd_internal(int fd, const char *name, struct asio_queue *q, uns buffe
   f->close = fbdir_close;
   f->config = fbdir_config;
   f->can_overwrite_buffer = 2;
   f->close = fbdir_close;
   f->config = fbdir_config;
   f->can_overwrite_buffer = 2;
-  return f;
+  return fb_tie(f);
 }
 
 #ifdef TEST
 }
 
 #ifdef TEST