src/dird/catreq.c
bool despool_attributes_from_file(JCR *jcr, const char *file)
{
   bool ret=false;
   int32_t pktsiz;
   ssize_t nbytes;
   ssize_t size = 0;
   int32_t msglen;                    /* message length */
   POOLMEM *msg = get_pool_memory(PM_MESSAGE);
   FILE *spool_fd=NULL;
   int32_t recnum = 0;

   Dmsg1(100, "Begin despool_attributes_from_file\n", file);

   if (jcr->is_job_canceled() || !jcr->pool->catalog_files || !jcr->db) {
      goto bail_out;                  /* user disabled cataloging */
   }

   spool_fd = bfopen(file, "rb");
   //Dmsg1(000, "Open attr read file=%s\n", file);
   if (!spool_fd) {
      Dmsg0(100, "cancel despool_attributes_from_file\n");
      /* send an error message */
      goto bail_out;
   }
#if defined(HAVE_POSIX_FADVISE) && defined(POSIX_FADV_WILLNEED)
   posix_fadvise(fileno(spool_fd), 0, 0, POSIX_FADV_WILLNEED);
#endif

   /*
    * We read the attributes file or stream from the SD.  It should
    * be in the following format:
    *
    * 1. 4 bytes representing the record length
    * 2. An attribute  string starting with: UpdCat Job=nnn FileAttributes ...
    */
   for ( ;; ) {
      nbytes = fread((char *)&pktsiz, 1, sizeof(int32_t), spool_fd);
      if (nbytes == 0) {   /* EOF */
         break;
      }
      if (nbytes != sizeof(int32_t)) {
         Dmsg2(000, "Error: attr read status=%lld addr=%lld\n", nbytes, ftello(spool_fd));
         break;
      }
      size += sizeof(int32_t);
      msglen = ntohl(pktsiz);
      if (msglen > 10000000) {
         Qmsg1(jcr, M_FATAL, 0, _("fread attr spool error. Wanted %ld bytes, maximum permitted 10000000 bytes\n"), msglen);
         goto bail_out;
      }
      if (msglen > 0) {
         if (msglen > (int32_t)sizeof_pool_memory(msg)) {
            msg = realloc_pool_memory(msg, msglen + 1);
         }
         nbytes = fread(msg, 1, msglen, spool_fd);
         recnum++;
         if (nbytes > 0 && strncmp(msg, "UpdCat Job", 10) != 0) {
            Dmsg3(000, "Error: recnum=%ld nbytes=%lld msg=%s\n", recnum, nbytes, msg);
         }
         if (nbytes != (ssize_t)msglen) {
            berrno be;
            boffset_t size;
            size = ftello(spool_fd);
            Dmsg4(000, "Error at size=%lld record %ld: got nbytes=%lld, want msglen=%ld\n", size, recnum, (int32_t)nbytes, msglen);
            Qmsg3(jcr, M_FATAL, 0, _("fread attr spool error. Wanted %ld bytes but got %lld ERR=%s\n"),
                  msglen, nbytes, be.bstrerror());
            goto bail_out;
         }
         size += nbytes;
      }
      if (!jcr->is_job_canceled()) {
         update_attribute(jcr, msg, msglen);
         if (jcr->is_job_canceled() || (jcr->wjcr && jcr->wjcr->is_job_canceled())) {
            goto bail_out;
         }
      }
   }
   if (ferror(spool_fd)) {
      berrno be;
      Qmsg1(jcr, M_FATAL, 0, _("fread attr spool error. ERR=%s\n"),
            be.bstrerror());
      Dmsg1(050, "fread attr spool error. ERR=%s\n", be.bstrerror());
      goto bail_out;
   }
   ret = true;

bail_out:
   if (spool_fd) {
      //Dmsg1(000, "Close attr read file=%s\n", file);
      fclose(spool_fd);
   }

   if (jcr->is_job_canceled()) {
      jcr->cached_attribute = false;
      cancel_storage_daemon_job(jcr);
   }

   free_pool_memory(msg);
   Dmsg1(100, "End despool_attributes_from_file ret=%i\n", ret);
   return ret;
}
/*
 * Update File Attributes in the catalog with data read from
 * the storage daemon spool file. We receive the filename and
 * we try to read it.
 */
Update File Attributes in the catalog with data read from
the storage daemon spool file. We receive the filename and
we try to read it.
Update File Attributes in the catalog with data read from the storage daemon spool file . We receive the filename and we try to read it .
bool despool_attributes_from_file(JCR *jcr, const char *file)
{
   bool ret=false;
   int32_t pktsiz;
   ssize_t nbytes;
   ssize_t size = 0;
   int32_t msglen;                    
   POOLMEM *msg = get_pool_memory(PM_MESSAGE);
   FILE *spool_fd=NULL;
   int32_t recnum = 0;
   Dmsg1(100, "Begin despool_attributes_from_file\n", file);
   if (jcr->is_job_canceled() || !jcr->pool->catalog_files || !jcr->db) {
      goto bail_out;                  
   }
   spool_fd = bfopen(file, "rb");
   if (!spool_fd) {
      Dmsg0(100, "cancel despool_attributes_from_file\n");
      goto bail_out;
   }
#if defined(HAVE_POSIX_FADVISE) && defined(POSIX_FADV_WILLNEED)
   posix_fadvise(fileno(spool_fd), 0, 0, POSIX_FADV_WILLNEED);
#endif
   for ( ;; ) {
      nbytes = fread((char *)&pktsiz, 1, sizeof(int32_t), spool_fd);
      if (nbytes == 0) {   
         break;
      }
      if (nbytes != sizeof(int32_t)) {
         Dmsg2(000, "Error: attr read status=%lld addr=%lld\n", nbytes, ftello(spool_fd));
         break;
      }
      size += sizeof(int32_t);
      msglen = ntohl(pktsiz);
      if (msglen > 10000000) {
         Qmsg1(jcr, M_FATAL, 0, _("fread attr spool error. Wanted %ld bytes, maximum permitted 10000000 bytes\n"), msglen);
         goto bail_out;
      }
      if (msglen > 0) {
         if (msglen > (int32_t)sizeof_pool_memory(msg)) {
            msg = realloc_pool_memory(msg, msglen + 1);
         }
         nbytes = fread(msg, 1, msglen, spool_fd);
         recnum++;
         if (nbytes > 0 && strncmp(msg, "UpdCat Job", 10) != 0) {
            Dmsg3(000, "Error: recnum=%ld nbytes=%lld msg=%s\n", recnum, nbytes, msg);
         }
         if (nbytes != (ssize_t)msglen) {
            berrno be;
            boffset_t size;
            size = ftello(spool_fd);
            Dmsg4(000, "Error at size=%lld record %ld: got nbytes=%lld, want msglen=%ld\n", size, recnum, (int32_t)nbytes, msglen);
            Qmsg3(jcr, M_FATAL, 0, _("fread attr spool error. Wanted %ld bytes but got %lld ERR=%s\n"),
                  msglen, nbytes, be.bstrerror());
            goto bail_out;
         }
         size += nbytes;
      }
      if (!jcr->is_job_canceled()) {
         update_attribute(jcr, msg, msglen);
         if (jcr->is_job_canceled() || (jcr->wjcr && jcr->wjcr->is_job_canceled())) {
            goto bail_out;
         }
      }
   }
   if (ferror(spool_fd)) {
      berrno be;
      Qmsg1(jcr, M_FATAL, 0, _("fread attr spool error. ERR=%s\n"),
            be.bstrerror());
      Dmsg1(050, "fread attr spool error. ERR=%s\n", be.bstrerror());
      goto bail_out;
   }
   ret = true;
bail_out:
   if (spool_fd) {
      fclose(spool_fd);
   }
   if (jcr->is_job_canceled()) {
      jcr->cached_attribute = false;
      cancel_storage_daemon_job(jcr);
   }
   free_pool_memory(msg);
   Dmsg1(100, "End despool_attributes_from_file ret=%i\n", ret);
   return ret;
}
bool despool_attributes_from_file ( JCR * jcr , const char * file ) { bool ret = false ; int32_t pktsiz ; ssize_t nbytes ; ssize_t size = 0 ; int32_t msglen ; POOLMEM * msg = get_pool_memory ( PM_MESSAGE ) ; FILE * spool_fd = NULL ; int32_t recnum = 0 ; Dmsg1 ( 100 , " \n " , file ) ; if ( jcr -> is_job_canceled ( ) || ! jcr -> pool -> catalog_files || ! jcr -> db ) { goto bail_out ; } spool_fd = bfopen ( file , " " ) ; if ( ! spool_fd ) { Dmsg0 ( 100 , " \n " ) ; goto bail_out ; } #if defined ( HAVE_POSIX_FADVISE ) && defined ( POSIX_FADV_WILLNEED ) posix_fadvise ( fileno ( spool_fd ) , 0 , 0 , POSIX_FADV_WILLNEED ) ; #endif for ( ; ; ) { nbytes = fread ( ( char * ) & pktsiz , 1 , sizeof ( int32_t ) , spool_fd ) ; if ( nbytes == 0 ) { break ; } if ( nbytes != sizeof ( int32_t ) ) { Dmsg2 ( 000 , " \n " , nbytes , ftello ( spool_fd ) ) ; break ; } size += sizeof ( int32_t ) ; msglen = ntohl ( pktsiz ) ; if ( msglen > 10000000 ) { Qmsg1 ( jcr , M_FATAL , 0 , _ ( " \n " ) , msglen ) ; goto bail_out ; } if ( msglen > 0 ) { if ( msglen > ( int32_t ) sizeof_pool_memory ( msg ) ) { msg = realloc_pool_memory ( msg , msglen + 1 ) ; } nbytes = fread ( msg , 1 , msglen , spool_fd ) ; recnum ++ ; if ( nbytes > 0 && strncmp ( msg , " " , 10 ) != 0 ) { Dmsg3 ( 000 , " \n " , recnum , nbytes , msg ) ; } if ( nbytes != ( ssize_t ) msglen ) { berrno be ; boffset_t size ; size = ftello ( spool_fd ) ; Dmsg4 ( 000 , " \n " , size , recnum , ( int32_t ) nbytes , msglen ) ; Qmsg3 ( jcr , M_FATAL , 0 , _ ( " \n " ) , msglen , nbytes , be . bstrerror ( ) ) ; goto bail_out ; } size += nbytes ; } if ( ! jcr -> is_job_canceled ( ) ) { update_attribute ( jcr , msg , msglen ) ; if ( jcr -> is_job_canceled ( ) || ( jcr -> wjcr && jcr -> wjcr -> is_job_canceled ( ) ) ) { goto bail_out ; } } } if ( ferror ( spool_fd ) ) { berrno be ; Qmsg1 ( jcr , M_FATAL , 0 , _ ( " \n " ) , be . bstrerror ( ) ) ; Dmsg1 ( 050 , " \n " , be . bstrerror ( ) ) ; goto bail_out ; } ret = true ; bail_out : if ( spool_fd ) { fclose ( spool_fd ) ; } if ( jcr -> is_job_canceled ( ) ) { jcr -> cached_attribute = false ; cancel_storage_daemon_job ( jcr ) ; } free_pool_memory ( msg ) ; Dmsg1 ( 100 , " \n " , ret ) ; return ret ; }
Update File Attributes in the catalog with data read from
 the storage daemon spool file.
Update File Attributes in the catalog with data read from the storage daemon spool file .
/* message length */ /* user disabled cataloging */ //Dmsg1(000, "Open attr read file=%s\n", file); /* send an error message */ /*
    * We read the attributes file or stream from the SD.  It should
    * be in the following format:
    *
    * 1. 4 bytes representing the record length
    * 2. An attribute  string starting with: UpdCat Job=nnn FileAttributes ...
    */ /* EOF */ //Dmsg1(000, "Close attr read file=%s\n", file);