Ejemplo n.º 1
0
FRESULT pf_readdir (
	DIR *dj,			/* Pointer to the open directory object */
	FILINFO *fno		/* Pointer to file information to return */
)
{
	FRESULT res;
	BYTE sp[12], dir[32];
	FATFS *fs = FatFs;


	if (!fs) {				/* Check file system */
		res = FR_NOT_ENABLED;
	} else {
		dj->fn = sp;
		if (!fno) {
			res = dir_rewind(dj);
		} else {
			res = dir_read(dj, dir);	/* Get current directory item */
			if (res == FR_NO_FILE) res = FR_OK;
			if (res == FR_OK) {				/* A valid entry is found */
				get_fileinfo(dj, dir, fno);	/* Get the object information */
				res = dir_next(dj);			/* Increment read index for next */
				if (res == FR_NO_FILE) res = FR_OK;
			}
		}
	}

	return res;
}
Ejemplo n.º 2
0
static void
handle_pragma_interface (cpp_reader* /*dfile*/)
{
  tree fname = parse_strconst_pragma ("interface", 1);
  struct c_fileinfo *finfo;
  const char *filename;

  if (fname == error_mark_node)
    return;
  else if (fname == 0)
    filename = lbasename (LOCATION_FILE (input_location));
  else
    filename = TREE_STRING_POINTER (fname);

  finfo = get_fileinfo (LOCATION_FILE (input_location));

  if (impl_file_chain == 0)
    {
      /* If this is zero at this point, then we are
	 auto-implementing.  */
      if (main_input_filename == 0)
	main_input_filename = LOCATION_FILE (input_location);
    }

  finfo->interface_only = interface_strcmp (filename);
  /* If MULTIPLE_SYMBOL_SPACES is set, we cannot assume that we can see
     a definition in another file.  */
  if (!MULTIPLE_SYMBOL_SPACES || !finfo->interface_only)
    finfo->interface_unknown = 0;
}
Ejemplo n.º 3
0
FRESULT pf_readdir (
	DIR *dj,			/* Pointer to the open directory object */
	FILINFO *fno		/* Pointer to file information to return */
)
{
	FRESULT res;
	BYTE sp[12], dir[32];
	FATFS *fs = FatFs;


	if (!fs) {				/* Check file system */
		res = FR_NOT_ENABLED;
	} else {
		dj->fn = sp;
		if (!fno) {
			res = dir_rewind(dj);
		} else {
			res = dir_read(dj, dir, &fno->lfname[0]);
			if (res == FR_NO_FILE) res = FR_OK;
			if (res == FR_OK) {				/* A valid entry is found */
				get_fileinfo(dj, dir, fno);	/* Get the object information */
				res = dir_next2(dj);			/* Increment index for next */
				if (res == FR_NO_FILE) res = FR_OK;
			}
		}
	}

	if (fno->lfname[0] == '\0') strcpy(&fno->lfname[0],&fno->fname[0]);
	//printf("%s %s(%d)\n",&fno->fname[0], &fno->lfname[0],strlen(&fno->lfname[0]));
	return res;
}
Ejemplo n.º 4
0
static void
do_file_response
(
    struct HTTPRequest *req,    /* HTTP request */
    FILE *out,                  /* output fd    */
    char *docroot               /* docroot path */
)
{
    struct FileInfo *info = NULL;

    dbg( "req=%p, out=%p, docroot=%p\n", req, out, docroot );

    info = get_fileinfo( docroot, req->path );
    if( 0 == info->ok )
    {
        free_fileinfo( info );
        not_found( req, out );
        return ;
    }

    output_common_header_fields( req, out, "200 OK" );

    fprintf( out, "Content-Length: %ld\r\n", info->size              );
    fprintf( out, "Content-Type: %s\r\n", guess_content_type( info ) );
    fprintf( out, "\r\n"                                             );

    outputBodyFields( info, req, out );

    fflush( out );
    free_fileinfo( info );
}
Ejemplo n.º 5
0
int build_download_list(list_t *download, list_t *src)
{
    int count = 0;
    char *cache_path;
    package_t   *pkg, *tmp;
    fileinfo_t  info;
    list_for_each_entry(tmp, src, list)
    {
        cache_path = make_cache_path(tmp->filename);

        if( get_fileinfo(cache_path, &info) != 0)
        {
            pkg = (package_t*)malloc(sizeof(package_t));

            INIT_LIST_HEAD(&pkg->file_list);
            pkg->id       = tmp->id;
            pkg->name     = strdup(tmp->name);
            pkg->version  = strdup(tmp->version);
            pkg->group    = strdup(tmp->group);
            pkg->filename = strdup(tmp->filename);
            pkg->description = strdup(tmp->description);
            list_add_tail(&pkg->list, download);
            count++;
        };
    }
Ejemplo n.º 6
0
void
init_c_lex (void)
{
  struct cpp_callbacks *cb;
  struct c_fileinfo *toplevel;

  /* The get_fileinfo data structure must be initialized before
     cpp_read_main_file is called.  */
  toplevel = get_fileinfo ("<top level>");
  if (flag_detailed_statistics)
    {
      header_time = 0;
      body_time = get_run_time ();
      toplevel->time = body_time;
    }

  cb = cpp_get_callbacks (parse_in);

  cb->line_change = cb_line_change;
  cb->ident = cb_ident;
  cb->def_pragma = cb_def_pragma;
  cb->valid_pch = c_common_valid_pch;
  cb->read_pch = c_common_read_pch;

  /* Set the debug callbacks if we can use them.  */
  if (debug_info_level == DINFO_LEVEL_VERBOSE
      && (write_symbols == DWARF2_DEBUG
          || write_symbols == VMS_AND_DWARF2_DEBUG))
    {
      cb->define = cb_define;
      cb->undef = cb_undef;
    }
}
Ejemplo n.º 7
0
int url_config_proc (const char * path)
{
    struct flock lk;
    int fd;

    {
        int rst;
        NET_FILE_INFO info = {0};
        char path[] = "/usr/local/web";

        rst = get_fileinfo(path, &info);
        http_out("get_fileinfo [%s][%d %d %d] %d<br>\n",
                path, info.file_size, info.file_mtime, info.file_type,
                rst);
    }
    return HTTPD_OK;

    if(LOGIN_OK != login_http_authorization())
    {
        return HTTPD_UNAUTH;
    }
    else
    {
        http_out("AUTH_TYPE: %s <br>\n", http_get_env(ENV_AUTH_TYPE));
        http_out("REMOTE_USER: %s <br>\n", http_get_env(ENV_REMOTE_USER));
        return OK;
    }

    fd = open(CONPLAT_CONF "/lock", O_WRONLY);
    if(fd < 0)
    {
        http_out("cannot open file");
        return HTTPD_OK;
    }

    lk.l_type = F_WRLCK;
    lk.l_whence = SEEK_SET;
    lk.l_len = 0;

    if(0 != fcntl(fd, F_SETLKW, &lk))
    {
        http_out("cannot lock file");
        close(fd);
        return HTTPD_OK;
    }

    http_out("sleep<br>");
    sleep(60);

    fcntl(fd, F_UNLCK);
    close(fd);
    http_out("exit");

	return HTTPD_OK;
}
Ejemplo n.º 8
0
_WCRTLINK long filelength( int handle )
{
    __file_handle *fh;
    FILEINFO info;

    __handle_check( handle, -1 );
    fh = (__file_handle*) __getOSHandle( handle);
    get_fileinfo(fh->name,&info);

    return( info.size );
}
Ejemplo n.º 9
0
static void
update_header_times (const char *name)
{
  /* Changing files again.  This means currently collected time
     is charged against header time, and body time starts back at 0.  */
  if (flag_detailed_statistics)
    {
      int this_time = get_run_time ();
      struct c_fileinfo *file = get_fileinfo (name);
      header_time += this_time - body_time;
      file->time += this_time - body_time;
      body_time = this_time;
    }
}
Ejemplo n.º 10
0
//
// Create an object from a file. Attach some info-headers to it
//
obex_object_t *build_object_from_file(obex_t *handle, const char *localname, const char *remotename)
{
    obex_object_t *object = NULL;
    obex_headerdata_t hdd;
    uint8_t *ucname;
    int ucname_len, size;
    int i;
    char lastmod[21*2] = {"1970-01-01T00:00:00Z"};

    /* Get filesize and modification-time */
    size = get_fileinfo(localname, lastmod);

    object = OBEX_ObjectNew(handle, OBEX_CMD_PUT);
    if(object == NULL)
        return NULL;

    ucname_len = strlen(remotename)*2 + 2;
    ucname = malloc(ucname_len);
    if(ucname == NULL)
        goto err;

    ucname_len = strcpy_utf8_to_unicode(ucname, remotename, ucname_len);

    //ucname_len = OBEX_CharToUnicode(ucname, remotename, ucname_len);
    //printf("ucname len %d\n", ucname_len);
    //for(i=0; i< ucname_len; i++)
    //	printf("%d ", ucname[i]);

    //printf("\n");

    hdd.bs = ucname;
    OBEX_ObjectAddHeader(handle, object, OBEX_HDR_NAME, hdd, ucname_len, 0);
    free(ucname);

    hdd.bq4 = size;
    OBEX_ObjectAddHeader(handle, object, OBEX_HDR_LENGTH, hdd, sizeof(uint32_t), 0);

    hdd.bs = NULL;
    OBEX_ObjectAddHeader(handle, object, OBEX_HDR_BODY,
                         hdd, 0, OBEX_FL_STREAM_START);

    DEBUG(4, "Lastmod = %s\n", lastmod);
    return object;

err:
    if(object != NULL)
        OBEX_ObjectDelete(handle, object);
    return NULL;
}
Ejemplo n.º 11
0
//
// Create an object from a file. Attach some info-headers to it
//
obex_object_t *build_object_from_file(obex_t *handle, const char *localname, const char *remotename)
{
	obex_object_t *object = NULL;
	obex_headerdata_t hdd;
	uint8_t *ucname;
	int ucname_len, size;
	char lastmod[21*2] = {"1970-01-01T00:00:00Z"};
		
	/* Get filesize and modification-time */
	size = get_fileinfo(localname, lastmod);

	object = OBEX_ObjectNew(handle, OBEX_CMD_PUT);
	if(object == NULL)
		return NULL;

	ucname_len = strlen(remotename)*2 + 2;
	ucname = malloc(ucname_len);
	if(ucname == NULL)
		goto err;

	ucname_len = OBEX_CharToUnicode(ucname, remotename, ucname_len);

	hdd.bs = ucname;
	OBEX_ObjectAddHeader(handle, object, OBEX_HDR_NAME, hdd, ucname_len, 0);
	free(ucname);

	hdd.bq4 = size;
	OBEX_ObjectAddHeader(handle, object, OBEX_HDR_LENGTH, hdd, sizeof(uint32_t), 0);

#if 0
	/* Win2k excpects this header to be in unicode. I suspect this in
	   incorrect so this will have to wait until that's investigated */
	hdd.bs = lastmod;
	OBEX_ObjectAddHeader(handle, object, OBEX_HDR_TIME, hdd, strlen(lastmod)+1, 0);
#endif
		
	hdd.bs = NULL;
	OBEX_ObjectAddHeader(handle, object, OBEX_HDR_BODY,
				hdd, 0, OBEX_FL_STREAM_START);

	DEBUG(4, "Lastmod = %s\n", lastmod);
	return object;

err:
	if(object != NULL)
		OBEX_ObjectDelete(handle, object);
	return NULL;
}
Ejemplo n.º 12
0
void
dump_time_statistics (void)
{
  struct c_fileinfo *file = get_fileinfo (input_filename);
  int this_time = get_run_time ();
  file->time += this_time - body_time;

  fprintf (stderr, "\n******\n");
  print_time ("header files (total)", header_time);
  print_time ("main file (total)", this_time - body_time);
  fprintf (stderr, "ratio = %g : 1\n",
	   (double) header_time / (double) (this_time - body_time));
  fprintf (stderr, "\n******\n");

  splay_tree_foreach (file_info_tree, dump_one_header, 0);
}
Ejemplo n.º 13
0
Archivo: whd.c Proyecto: Zirconi/whd
void process(int fd, int efd, char *rstline, char *method, char *uri, char *protocol, char *filename, char *filetype, char *response)
{
    rio_t rio;
    int err;
    struct stat sbuf;
    char *file;
    rio_readinitb(&rio, fd);

    if((err = rio_readlineb(&rio, rstline, MAXLEN)) <= 0)
    {
        if((err = epoll_ctl(efd, EPOLL_CTL_DEL, fd, NULL)) < 0)
            FATAL("PROCESS.EPOLL_CTL");
        close(fd);
    }
    else
    {
        sscanf(rstline, "%s %s %s", method, uri, protocol);
        if(strcasecmp(method, "GET"))
            //TEST
            ERR(fd, efd);
        if(uri[0] != '/')
            ERR(fd, efd);
        process_rstheader(&rio);
        parse_uri(uri, filename, filetype);
        if(get_fileinfo(filename) < 0)
            call_403(fd);
        else
        {
            lstat(filename, &sbuf);
            err = open(filename, O_RDONLY, 0);
            file = mmap(0 ,sbuf.st_size, PROT_READ, MAP_PRIVATE, err, 0);
            close(err);
            sprintf(response, "HTTP/1.1 200 OK\r\n");
            sprintf(response, "%sContent-length: %lu\r\n", response, sbuf.st_size);
            sprintf(response, "%sContent-type: %s\r\n\r\n", response, filetype);
            rio_writen(fd, response, strlen(response));
            rio_writen(fd, file, sbuf.st_size);
            munmap(file, sbuf.st_size);
        }
    }
}
Ejemplo n.º 14
0
int __qwrite( int handle, const void *buffer, unsigned len )
{
    int             atomic;
    __file_handle   *fh;
    unsigned        len_written;

    __handle_check( handle, -1 );

    fh = (__file_handle*) __getOSHandle( handle );

    atomic = 0;
    if( __GetIOMode( handle ) & _APPEND )
    {
      FILEINFO info;
        
      _AccessFileH( handle );
      atomic = 1;
      get_fileinfo(fh->name,&info);
      fh->offset = info.size;
    };

    if(write_file(fh->name,buffer,fh->offset,len,&len_written))
    {
      if ( len_written == 0)
      {
        if( atomic == 1 )
          _ReleaseFileH( handle );

        return (-1);
      };   
    };
    
    fh->offset+=len_written;
        

    if( atomic == 1 )
    {
        _ReleaseFileH( handle );
    }
    return( len_written );
}
Ejemplo n.º 15
0
static int default_init( mpg123_handle_t *fr )
{
	fr->rdat.fdread = plain_read;
	fr->rdat.read = fr->rdat.r_read  != NULL ? fr->rdat.r_read  : read;
	fr->rdat.lseek = fr->rdat.r_lseek != NULL ? fr->rdat.r_lseek : lseek;
	fr->rdat.filelen = get_fileinfo( fr );
	fr->rdat.filepos = 0;

	// don't enable seeking on ICY streams, just plain normal files.
	// this check is necessary since the client can enforce ICY parsing on files that would otherwise be seekable.
	// it is a task for the future to make the ICY parsing safe with seeks ... or not.
	if( fr->rdat.filelen >= 0 )
	{
		fr->rdat.flags |= READER_SEEKABLE;
		if( !strncmp((char *)fr->id3buf,"TAG", 3 ))
		{
			fr->rdat.flags |= READER_ID3TAG;
			fr->metaflags  |= MPG123_NEW_ID3;
		}
	}
	else if( fr->p.flags & MPG123_SEEKBUFFER )
	{
		// switch reader to a buffered one, if allowed.
		if( fr->rd == &readers[READER_STREAM] )
		{
			fr->rd = &readers[READER_BUF_STREAM];
			fr->rdat.fullread = plain_fullread;
		}
		else
		{
			return -1;
		}

		bc_init( &fr->rdat.buffer );
		fr->rdat.filelen = 0; // we carry the offset, but never know how big the stream is.
		fr->rdat.flags |= READER_BUFFERED;
	}

	return 0;
}
Ejemplo n.º 16
0
static void do_file_response(struct HTTPRequest *req, FILE *out, char *docroot) {
  struct FileInfo *info;

  info = get_fileinfo(docroot, req->path);
  if (!info->ok) {
    free_fileinfo(info);
    not_found(req, out);
    return;
  }
  output_common_header_fields(req, out, "200 OK");
  fprintf(out, "Content-Length: %ld\r\n", info->size);
  fprintf(out, "Content-Type: %s\r\n", guess_content_type(info));
  fprintf(out, "\r\n");
  if (strcmp(req->method, "HEAD") != 0) {
    int fd;
    char buf[BLOCK_BUF_SIZE];
    ssize_t n;

    fd = open(info->path, O_RDONLY);
    if (fd < 0) {
      log_exit("failed to open %s: %s", info->path, strerror(errno));
    }
    while (1) {
      n = read(fd, buf, BLOCK_BUF_SIZE);
      if (n < 0) {
          log_exit("failed to read %s: %s", info->path, strerror(errno));
      }
      if (n == 0) {
        break;
      }
      if (fwrite(buf, n, 1, out) < 1) {
        log_exit("failed to write to socket: %s", strerror(errno));
      }
    }
    close(fd);
  }
  fflush(out);
  free_fileinfo(info);
}
Ejemplo n.º 17
0
/*
 * NAME:	readdir
 *
 * FUNCTION:	read directory according to specifications
 *		in directory search structure
 *
 * PARAMETER:
 *
 * RETURN:	EINVAL	- if not a directory
 *		errors from subroutines
 *
 * note:
 * N.B. directory file offset encodes (directory page number,
 * entry index number), and shold NOT be interpreted/modified
 * by caller (lseek()) except that intial offset set to 0.
 *
 * no guarantees can be made that the exact offset
 * requested can be found if directory has been updated
 * by other threads between consecutive readdir()s.
 * transfer length of zero signals start offset beyond eof.
 *
 * unused space in the directory are not returned to the user,
 * i.e., more than requested size may have to be read
 * from directory to fill the user's buffer.
 */
readdir(
    struct vnode	*dvp,		/* inode of directory being read */
    struct fsfd	*fsfp,		/* directory search information */
    char 		*ubuf,		/* user's data area */
    uint32		ubytes,		/* size of user's data area */
    uint32		*matchcnt,	/* count of entries returned */
    uint32		level,		/* level of output struct */
    uint32		flags,		/* offsets needed in output? */
    EAOP		*eaopp,		/* pointer to EAOP */
    struct ucred	*crp)
{
    int32 	rc = 0;
    int32 	ReturnCode = NO_ERROR;
    inode_t	*dip;			/* directory inode */
    inode_t	*ip;			/* object inode */
    uint32	matches;		/* output matches found */
    uint32	dtmatches;		/* matches found per dtFind call */
    uint32	position;		/* offsets in output */
    uint32	count;			/* output buffer count */
    int32 	tbytes;			/* byte count in dirent buffer */
    struct dirent *dbuf;		/* dirent buffer */
    struct dirent *dbufp;		/* dirent buffer */
    uint32 ffhdsize;		/* size of ffbuf header */
    component_t lastmatch;		/* pointer to last matching entry */
    char *ffbuf;			/* output buffer pointer */
    char *nxbuf;			/* output buffer pointer */
    char *bufp;			/* output buffer pointer */

    MMPHPrereaddir();      /* MMPH Performance Hook */

    /* set state from search structure
     */
    dip = VP2IP(dvp);
    position = flags & FF_GETPOS;

    /* validate request */
    if (ubytes == 0)
    {
        rc = EINVAL;
        goto readdir_Exit;
    }

    /* continuous read of empty directory ? */
    if (fsfp->fsd_offset == -1)
    {
        rc = ERROR_NO_MORE_FILES;
        goto readdir_Exit;
    }

    dbuf = (struct dirent *)allocpool(dirent_pool, 0);	// D228565
    if (dbuf == 0)						// D228565
    {
        rc = ENOMEM;
        goto readdir_Exit;
    }

    /* set up variable to manipulate output buffer pointers
     * based on level.
     */
    if (level == 1)
        ffhdsize = FFBUFHD;
    else if (level == 11)
        ffhdsize = FFBUFHD3L;
    else if (level < 11)
        ffhdsize = FFBUFHD2;
    else
        ffhdsize = FFBUFHD4L;
    if (position)
        ffhdsize += sizeof(uint32);

    ffbuf = ubuf;
    count = 0;
    matches = *matchcnt;
    *matchcnt = 0;

    while ((*matchcnt < matches) && (rc == 0))
    {
        IREAD_LOCK(dip);

        /* directory became void when last link was removed */
        if ((dip->i_nlink == 0) || ((dip->i_mode & IFMT) != IFDIR))
        {
            IREAD_UNLOCK(dip);
            freepool(dirent_pool, (caddr_t *)dbuf);
            rc = ENOTDIR;
            goto readdir_Exit;
        }

        /* fill a directory buffer.
        * read on-disk structure (struct ldtentry_t) and
        * translate into readdir() structure (struct dirent).
        */
        tbytes = 0;
        dtmatches = matches - *matchcnt;
        dbufp = dbuf;					// D228565
        rc = dtFind(dip, &fsfp->fsd_pattern, fsfp->fsd_lastmatch,
                    &fsfp->fsd_offset, &dtmatches, PSIZE, &tbytes, dbufp);
        IREAD_UNLOCK(dip);
        if (rc)
        {
            freepool(dirent_pool, (caddr_t *)dbuf);
            goto readdir_Exit;
        }

        /* copy translate buffer to user FileFindBuf buffer */

        while ((*matchcnt < matches) && (ReturnCode == NO_ERROR))
        {
            uint32 namlen;

            /* translation buffer empty? */
            if (tbytes == 0)
                break;

            /* get size of next name */
            namlen = dbufp->d_namlen;

            /* user buffer full?
            * the +1 here is to allow for the null character
            * terminating the name string.
            */
            if ((count + ffhdsize + namlen + 1) > ubytes)
            {
                rc = ERROR_BUFFER_OVERFLOW;
                break;
            }

            /* get the inode for the file
            */
            ICACHE_LOCK();
            rc = iget(dvp->v_vfsp, dbufp->d_ino, &ip, 0);
            ICACHE_UNLOCK();

            if (rc)
                goto try_next;

            nxbuf = ffbuf;


            /* fill in file search info for files that have
             * the proper attributes; ignore others.
             */
            rc = get_fileinfo(ip, &nxbuf, ubytes, dbufp->d_name,
                              namlen, fsfp->fsd_havattr, level,
                              eaopp, flags);

            if ((rc == ERROR_BUFFER_OVERFLOW) && (*matchcnt == 0) &&
                    ((level == FIL_QUERYEASFROMLIST) ||
                     (level == FIL_QUERYEASFROMLISTL)))
            {
                /* Can't fit EA in buffer, try without
                 * getting EA
                 */

                if (level == FIL_QUERYEASFROMLIST)
                    level = FIL_QUERYEASIZE;
                else
                    level = FIL_QUERYEASIZEL;

                ReturnCode = ERROR_EAS_DIDNT_FIT;
                rc = get_fileinfo(ip, &nxbuf, ubytes,
                                  dbufp->d_name, namlen,
                                  fsfp->fsd_havattr, level,
                                  eaopp, flags);
            }
            /* release the inode */
            jfs_rele(IP2VP(ip));

            if (rc == 0)
            {
                /* set offset if requested */
                if (position)
                {
                    rc = KernCopyOut(ffbuf,
                                     &dbufp->d_offset,
                                     sizeof(int32));
                    if (rc)
                    {
                        /* This is very unlikely to
                         * happen! */
                        ASSERT(0);
                        break;
                    }
                }

                /* update output buffer count */
                count += nxbuf - ffbuf;

                /* move to next entry in output buffer */
                ffbuf = nxbuf;

                /* update match count */
                *matchcnt += 1;
            }
            else if (rc != -1)
                break;

try_next:
            /* rc == -1 indicates no attribute match,
             * just keep going.
             */
            rc = 0;

            /* save name for next call setup */
            lastmatch.name = dbufp->d_name;
            lastmatch.namlen = namlen;

            /* update dirent buffer count */
            tbytes -= dbufp->d_reclen;

            /* move to next entry in dirent buffer */
            dbufp = (struct dirent *)
                    ((caddr_t)dbufp + dbufp->d_reclen);
        }
        /* We don't want to continue if ReturnCode = ERROR_EAS_DIDNT_FIT
         */
        if (rc == 0)
            rc = ReturnCode;

        /* set return code for end of directory with no matches */
        if (fsfp->fsd_offset == -1)
            rc = ERROR_NO_MORE_FILES;
        else if ((rc == 0) || (rc == ERROR_EAS_DIDNT_FIT))
        {
            /* save last matching name for next call */
            UniStrncpy(fsfp->fsd_lastmatch,lastmatch.name,
                       lastmatch.namlen);
            fsfp->fsd_lastmatch[lastmatch.namlen] = '\0';
        }
    }

    /* claim success if we return any entries */
    if (*matchcnt != 0)
        rc = ReturnCode;

    freepool(dirent_pool, (caddr_t *)dbuf);

readdir_Exit:

    MMPHPostreaddir();     /* MMPH Performance Hook */
    return rc;
}
Ejemplo n.º 18
0
//响应文件信息查询包
void MasterServer::on_file_info_req(SocketHandle socket_handle, Protocol *protocol)
{
	SFSProtocolFamily* protocol_family = (SFSProtocolFamily*)get_protocol_family();
	ProtocolFileInfo *protocol_fileinfo = (ProtocolFileInfo *)protocol_family->create_protocol(PROTOCOL_FILE_INFO);
	assert(protocol_fileinfo != NULL);

	ProtocolFileInfoReq *protocol_file_info_req = (ProtocolFileInfoReq *)protocol;
	const string& fid = protocol_file_info_req->get_fid();
	bool query_chunkpath = protocol_file_info_req->get_query_chunkpath();
	SLOG_INFO("receive file_info_req protocol.fd=%d, fid=%s, query=%d", socket_handle, fid.c_str(), query_chunkpath?1:0);

	FileInfo& file_info = protocol_fileinfo->get_fileinfo();
	if(get_fileinfo(fid, file_info))  //已经存在
	{
		SLOG_DEBUG("find file_info succ: fid=%s, size=%d.", fid.c_str(), file_info.size);
		int i;
		for(i=0; i<file_info.get_chunkpath_count(); ++i)
		{
			ChunkPath &chunk_path = file_info.get_chunkpath(i);
			SLOG_DEBUG("chunk[%d]:id=%s, ip=%s, port=%d, index=%d, offset=%d."
					,i, chunk_path.id.c_str(), chunk_path.ip.c_str(), chunk_path.port, chunk_path.index, chunk_path.offset);
		}
		file_info.result = FileInfo::RESULT_SUCC;
	}
	else if(find_saving_task(fid))  //正在保存
	{
		SLOG_DEBUG("fid=%s is saving.", fid.c_str());
		file_info.result = FileInfo::RESULT_SAVING;
	}
	else if(query_chunkpath)  //分配chunk
	{
		file_info.fid = fid;
		file_info.name = ""; //无效
		file_info.size = 0;  //无效

		ChunkPath chunk_path;
		ChunkInfo chunk_info;
		if(get_chunk(chunk_info))  //分配chunk
		{
			file_info.result = FileInfo::RESULT_CHUNK;
			chunk_path.id = chunk_info.id;
			chunk_path.ip = chunk_info.ip;
			chunk_path.port = chunk_info.port;
			chunk_path.index = 0;  //无效
			chunk_path.offset = 0; //无效
			file_info.add_chunkpath(chunk_path);

			add_saving_task(fid);
			SLOG_DEBUG("dispatch chunk[id=%s,ip=%s,port=%d] for fid=%s.", chunk_info.id.c_str(), chunk_info.ip.c_str(), chunk_info.port, fid.c_str());
		}
		else
		{
			SLOG_WARN("get chunk failed for fid=%s.", fid.c_str());
			file_info.result = FileInfo::RESULT_FAILED;
		}
	}
	else  //失败
	{
		SLOG_WARN("get file_info failed for fid=%s.", fid.c_str());
		file_info.result = FileInfo::RESULT_FAILED;
	}

	if(!send_protocol(socket_handle, protocol_fileinfo))
	{
		SLOG_ERROR("send file_info protocol failed. fd=%d, fid=%s.", socket_handle, fid.c_str());
		protocol_family->destroy_protocol(protocol_fileinfo);
	}
}
Ejemplo n.º 19
0
static int default_init(mpg123_handle *fr)
{
#if (!defined (WIN32) || defined (__CYGWIN__))
    if(fr->p.timeout > 0)
    {
        int flags;
        if(fr->rdat.r_read != NULL)
        {
            error("Timeout reading does not work with user-provided read function. Implement it yourself!");
            return -1;
        }
        flags = fcntl(fr->rdat.filept, F_GETFL);
        flags |= O_NONBLOCK;
        fcntl(fr->rdat.filept, F_SETFL, flags);
        fr->rdat.fdread = timeout_read;
        fr->rdat.timeout_sec = fr->p.timeout;
        fr->rdat.flags |= READER_NONBLOCK;
    }
    else
#endif
        fr->rdat.fdread = plain_read;

    fr->rdat.read  = fr->rdat.r_read  != NULL ? fr->rdat.r_read  : posix_read;
    fr->rdat.lseek = fr->rdat.r_lseek != NULL ? fr->rdat.r_lseek : posix_lseek;
    fr->rdat.filelen = get_fileinfo(fr);
    fr->rdat.filepos = 0;
    if(fr->rdat.filelen >= 0)
    {
        fr->rdat.flags |= READER_SEEKABLE;
        if(!strncmp((char*)fr->id3buf,"TAG",3))
        {
            fr->rdat.flags |= READER_ID3TAG;
            fr->metaflags  |= MPG123_NEW_ID3;
        }
    }
    /* Switch reader to a buffered one, if allowed. */
    else if(fr->p.flags & MPG123_SEEKBUFFER)
    {
#ifdef NO_FEEDER
        error("Buffered readers not supported in this build.");
        fr->err = MPG123_MISSING_FEATURE;
        return -1;
#else
        if     (fr->rd == &readers[READER_STREAM])
        {
            fr->rd = &readers[READER_BUF_STREAM];
            fr->rdat.fullread = plain_fullread;
        }
#ifndef NO_ICY
        else if(fr->rd == &readers[READER_ICY_STREAM])
        {
            fr->rd = &readers[READER_BUF_ICY_STREAM];
            fr->rdat.fullread = icy_fullread;
        }
#endif
        else
        {
            if(NOQUIET) error("mpg123 Programmer's fault: invalid reader");
            return -1;
        }
        bc_init(&fr->rdat.buffer);
        fr->rdat.filelen = 0; /* We carry the offset, but never know how big the stream is. */
        fr->rdat.flags |= READER_BUFFERED;
#endif /* NO_FEEDER */
    }
    return 0;
}
Ejemplo n.º 20
0
static int default_init(mpg123_handle *fr)
{
#ifdef TIMEOUT_READ
	if(fr->p.timeout > 0)
	{
		int flags;
		if(fr->rdat.r_read != NULL)
		{
			error("Timeout reading does not work with user-provided read function. Implement it yourself!");
			return -1;
		}
		flags = fcntl(fr->rdat.filept, F_GETFL);
		flags |= O_NONBLOCK;
		fcntl(fr->rdat.filept, F_SETFL, flags);
		fr->rdat.fdread = timeout_read;
		fr->rdat.timeout_sec = fr->p.timeout;
		fr->rdat.flags |= READER_NONBLOCK;
	}
	else
#endif
	fr->rdat.fdread = plain_read;

	fr->rdat.read  = fr->rdat.r_read  != NULL ? fr->rdat.r_read  : posix_read;
	fr->rdat.lseek = fr->rdat.r_lseek != NULL ? fr->rdat.r_lseek : posix_lseek;
#ifndef NO_ICY
	/* ICY streams of any sort shall not be seekable. */
	if(fr->p.icy_interval > 0) fr->rdat.lseek = nix_lseek;
#endif

	fr->rdat.filelen = fr->p.flags & MPG123_NO_PEEK_END ? -1 : get_fileinfo(fr);
	fr->rdat.filepos = 0;
	if(fr->p.flags & MPG123_FORCE_SEEKABLE)
		fr->rdat.flags |= READER_SEEKABLE;
	/*
		Don't enable seeking on ICY streams, just plain normal files.
		This check is necessary since the client can enforce ICY parsing on files that would otherwise be seekable.
		It is a task for the future to make the ICY parsing safe with seeks ... or not.
	*/
	if(fr->rdat.filelen >= 0)
	{
		fr->rdat.flags |= READER_SEEKABLE;
		if(!strncmp((char*)fr->id3buf,"TAG",3))
		{
			fr->rdat.flags |= READER_ID3TAG;
			fr->metaflags  |= MPG123_NEW_ID3;
		}
	}
	/* Switch reader to a buffered one, if allowed. */
	else if(fr->p.flags & MPG123_SEEKBUFFER)
	{
#ifdef NO_FEEDER
		error("Buffered readers not supported in this build.");
		fr->err = MPG123_MISSING_FEATURE;
		return -1;
#else
		if     (fr->rd == &readers[READER_STREAM])
		{
			fr->rd = &readers[READER_BUF_STREAM];
			fr->rdat.fullread = plain_fullread;
		}
#ifndef NO_ICY
		else if(fr->rd == &readers[READER_ICY_STREAM])
		{
			fr->rd = &readers[READER_BUF_ICY_STREAM];
			fr->rdat.fullread = icy_fullread;
		}
#endif
		else
		{
			if(NOQUIET) error("mpg123 Programmer's fault: invalid reader");
			return -1;
		}
		bc_init(&fr->rdat.buffer);
		fr->rdat.filelen = 0; /* We carry the offset, but never know how big the stream is. */
		fr->rdat.flags |= READER_BUFFERED;
#endif /* NO_FEEDER */
	}
	return 0;
}
Ejemplo n.º 21
0
int main(int argc, char *argv[])
{
	struct timeval start_time, end_time;
	struct sigaction handler;
	double seconds,total_time; // for timers
	bool lrzcat = false;
	int c, i;
	int hours,minutes;
	extern int optind;
	char *eptr; /* for environment */

        control = &base_control;

	initialise_control(control);

	if (strstr(argv[0], "lrunzip"))
		control->flags |= FLAG_DECOMPRESS;
	else if (strstr(argv[0], "lrzcat")) {
		control->flags |= FLAG_DECOMPRESS | FLAG_STDOUT;
		lrzcat = true;
	}

	/* generate crc table */
	CrcGenerateTable();

	/* Get Preloaded Defaults from lrzip.conf
	 * Look in ., $HOME/.lrzip/, /etc/lrzip.
	 * If LRZIP=NOCONFIG is set, then ignore config
	 */
	eptr = getenv("LRZIP");
	if (eptr == NULL)
		read_config(control);
	else if (!strstr(eptr,"NOCONFIG"))
		read_config(control);

	while ((c = getopt_long(argc, argv, "bcdDefghHiklL:nN:o:O:p:qS:tTUm:vVw:z?", long_options, &i)) != -1) {
		switch (c) {
		case 'b':
			if (control->flags & FLAG_NOT_LZMA)
				failure("Can only use one of -l, -b, -g, -z or -n\n");
			control->flags |= FLAG_BZIP2_COMPRESS;
			break;
		case 'c':
			control->flags |= FLAG_CHECK;
			control->flags |= FLAG_HASH;
			break;
		case 'd':
			control->flags |= FLAG_DECOMPRESS;
			break;
		case 'D':
			control->flags &= ~FLAG_KEEP_FILES;
			break;
		case 'e':
			control->flags |= FLAG_ENCRYPT;
			break;
		case 'f':
			control->flags |= FLAG_FORCE_REPLACE;
			break;
		case 'g':
			if (control->flags & FLAG_NOT_LZMA)
				failure("Can only use one of -l, -b, -g, -z or -n\n");
			control->flags |= FLAG_ZLIB_COMPRESS;
			break;
		case 'h':
		case '?':
			usage();
			return -1;
		case 'H':
			control->flags |= FLAG_HASH;
			break;
		case 'i':
			control->flags |= FLAG_INFO;
			break;
		case 'k':
			control->flags |= FLAG_KEEP_BROKEN;
			break;
		case 'l':
			if (control->flags & FLAG_NOT_LZMA)
				failure("Can only use one of -l, -b, -g, -z or -n\n");
			control->flags |= FLAG_LZO_COMPRESS;
			break;
		case 'L':
			control->compression_level = atoi(optarg);
			if (control->compression_level < 1 || control->compression_level > 9)
				failure("Invalid compression level (must be 1-9)\n");
			break;
		case 'm':
			control->ramsize = atol(optarg) * 1024 * 1024 * 100;
			break;
		case 'n':
			if (control->flags & FLAG_NOT_LZMA)
				failure("Can only use one of -l, -b, -g, -z or -n\n");
			control->flags |= FLAG_NO_COMPRESS;
			break;
		case 'N':
			control->nice_val = atoi(optarg);
			if (control->nice_val < -20 || control->nice_val > 19)
				failure("Invalid nice value (must be -20..19)\n");
			break;
		case 'o':
			if (control->outdir)
				failure("Cannot have -o and -O together\n");
			if (unlikely(STDOUT))
				failure("Cannot specify an output filename when outputting to stdout\n");
			control->outname = optarg;
			control->suffix = "";
			break;
		case 'O':
			if (control->outname)	/* can't mix -o and -O */
				failure("Cannot have options -o and -O together\n");
			if (unlikely(STDOUT))
				failure("Cannot specify an output directory when outputting to stdout\n");
			control->outdir = malloc(strlen(optarg) + 2);
			if (control->outdir == NULL)
				fatal("Failed to allocate for outdir\n");
			strcpy(control->outdir,optarg);
			if (strcmp(optarg+strlen(optarg) - 1, "/")) 	/* need a trailing slash */
				strcat(control->outdir, "/");
			break;
		case 'p':
			control->threads = atoi(optarg);
			if (control->threads < 1)
				failure("Must have at least one thread\n");
			break;
		case 'q':
			control->flags &= ~FLAG_SHOW_PROGRESS;
			break;
		case 'S':
			if (control->outname)
				failure("Specified output filename already, can't specify an extension.\n");
			if (unlikely(STDOUT))
				failure("Cannot specify a filename suffix when outputting to stdout\n");
			control->suffix = optarg;
			break;
		case 't':
			if (control->outname)
				failure("Cannot specify an output file name when just testing.\n");
			if (!KEEP_FILES)
				failure("Doubt that you want to delete a file when just testing.\n");
			control->flags |= FLAG_TEST_ONLY;
			break;
		case 'T':
			control->flags &= ~FLAG_THRESHOLD;
			break;
		case 'U':
			control->flags |= FLAG_UNLIMITED;
			break;
		case 'v':
			/* set verbosity flag */
			if (!(control->flags & FLAG_VERBOSITY) && !(control->flags & FLAG_VERBOSITY_MAX))
				control->flags |= FLAG_VERBOSITY;
			else if ((control->flags & FLAG_VERBOSITY)) {
				control->flags &= ~FLAG_VERBOSITY;
				control->flags |= FLAG_VERBOSITY_MAX;
			}
			break;
		case 'V':
			print_output("lrzip version %s\n", PACKAGE_VERSION);
			exit(0);
			break;
		case 'w':
			control->window = atol(optarg);
			break;
		case 'z':
			if (control->flags & FLAG_NOT_LZMA)
				failure("Can only use one of -l, -b, -g, -z or -n\n");
			control->flags |= FLAG_ZPAQ_COMPRESS;
			break;
		}
	}

	argc -= optind;
	argv += optind;

	if (control->outname && argc > 1)
		failure("Cannot specify output filename with more than 1 file\n");

	if (VERBOSE && !SHOW_PROGRESS) {
		print_err("Cannot have -v and -q options. -v wins.\n");
		control->flags |= FLAG_SHOW_PROGRESS;
	}

	if (UNLIMITED && control->window) {
		print_err("If -U used, cannot specify a window size with -w.\n");
		control->window = 0;
	}

	if (argc < 1)
		control->flags |= FLAG_STDIN;

	if (UNLIMITED && STDIN) {
		print_err("Cannot have -U and stdin, unlimited mode disabled.\n");
		control->flags &= ~FLAG_UNLIMITED;
	}

	setup_overhead(control);

	/* Set the main nice value to half that of the backend threads since
	 * the rzip stage is usually the rate limiting step */
	if (control->nice_val > 0 && !NO_COMPRESS) {
		if (unlikely(setpriority(PRIO_PROCESS, 0, control->nice_val / 2) == -1))
			print_err("Warning, unable to set nice value\n");
	} else {
		if (unlikely(setpriority(PRIO_PROCESS, 0, control->nice_val) == -1))
			print_err("Warning, unable to set nice value\n");
	}

	/* One extra iteration for the case of no parameters means we will default to stdin/out */
	for (i = 0; i <= argc; i++) {
		if (i < argc)
			control->infile = argv[i];
		else if (!(i == 0 && STDIN))
			break;
		if (control->infile) {
			if ((strcmp(control->infile, "-") == 0))
				control->flags |= FLAG_STDIN;
			else {
				struct stat infile_stat;

				stat(control->infile, &infile_stat);
				if (unlikely(S_ISDIR(infile_stat.st_mode)))
					failure("lrzip only works directly on FILES.\n"
					"Use lrztar or pipe through tar for compressing directories.\n");
			}
		}

		if (INFO && STDIN)
			failure("Will not get file info from STDIN\n");

		if ((control->outname && (strcmp(control->outname, "-") == 0)) ||
			/* If no output filename is specified, and we're using
			 * stdin, use stdout */
			(!control->outname && STDIN) || lrzcat ) {
				control->flags |= FLAG_STDOUT;
				control->outFILE = stdout;
				control->msgout = stderr;
				register_outputfile(control, control->msgout);
		}

		if (lrzcat) {
			control->msgout = stderr;
			control->outFILE = stdout;
			register_outputfile(control, control->msgout);
		}

		if (!STDOUT) {
			control->msgout = stdout;
			register_outputfile(control, control->msgout);
		}

		if (STDIN)
			control->inFILE = stdin;
		/* Implement signal handler only once flags are set */
		sigemptyset(&handler.sa_mask);
		handler.sa_flags = 0;
		handler.sa_handler = &sighandler;
		sigaction(SIGTERM, &handler, 0);
		sigaction(SIGINT, &handler, 0);

		if (!FORCE_REPLACE) {
			if (STDIN && isatty(fileno((FILE *)stdin))) {
				print_err("Will not read stdin from a terminal. Use -f to override.\n");
				usage();
				exit (1);
			}
			if (!TEST_ONLY && STDOUT && isatty(fileno((FILE *)stdout))) {
				print_err("Will not write stdout to a terminal. Use -f to override.\n");
				usage();
				exit (1);
			}
		}

		if (CHECK_FILE) {
			if (!DECOMPRESS) {
				print_err("Can only check file written on decompression.\n");
				control->flags &= ~FLAG_CHECK;
			} else if (STDOUT) {
				print_err("Can't check file written when writing to stdout. Checking disabled.\n");
				control->flags &= ~FLAG_CHECK;
			}
		}

		setup_ram(control);
		show_summary();

		gettimeofday(&start_time, NULL);

		if (unlikely(STDIN && ENCRYPT))
			failure("Unable to work from STDIN while reading password\n");

		memcpy(&local_control, &base_control, sizeof(rzip_control));
		if (DECOMPRESS || TEST_ONLY)
			decompress_file(&local_control);
		else if (INFO)
			get_fileinfo(&local_control);
		else
			compress_file(&local_control);

		/* compute total time */
		gettimeofday(&end_time, NULL);
		total_time = (end_time.tv_sec + (double)end_time.tv_usec / 1000000) -
			      (start_time.tv_sec + (double)start_time.tv_usec / 1000000);
		hours = (int)total_time / 3600;
		minutes = (int)(total_time / 60) % 60;
		seconds = total_time - hours * 3600 - minutes * 60;
		if (!INFO)
			print_progress("Total time: %02d:%02d:%05.2f\n", hours, minutes, seconds);
	}

	return 0;
}