示例#1
0
文件: fa_fs.c 项目: whyz/showtime
static int
fs_scandir(fa_protocol_t *fap, fa_dir_t *fd, const char *url,
           char *errbuf, size_t errlen)
{
    char buf[URL_MAX];
    struct stat st;
    struct dirent *d;
    int type;
    DIR *dir;
    int split_num;

    if((dir = opendir(url)) == NULL) {
        snprintf(errbuf, errlen, "%s", strerror(errno));
        return -1;
    }

    while((d = readdir(dir)) != NULL) {
        fs_urlsnprintf(buf, sizeof(buf), "", url, d->d_name);

        if(stat(buf, &st))
            continue;

        switch(st.st_mode & S_IFMT) {
        case S_IFDIR:
            type = CONTENT_DIR;
            break;

        case S_IFREG:
            type = CONTENT_FILE;

            if((split_num = is_splitted_file_name(d->d_name)) > 0) {
                if(split_num != 1)
                    continue;
                // Strip off last part (.00x) of filename
                buf[strlen(buf) - 4] = 0;
                d->d_name[strlen(d->d_name) - 4] = 0;
            }
            break;

        default:
            continue;
        }

        fs_urlsnprintf(buf, sizeof(buf), "file://", url, d->d_name);
        fa_dir_add(fd, buf, d->d_name, type);
    }
    closedir(dir);
    return 0;
}
示例#2
0
static int
ntfs_scandir(fa_protocol_t *fap, fa_dir_t *fd,
	     const char *url, char *errbuf, size_t errlen, int flags)
{
  DIR_ITER *di = ps3ntfs_diropen(url);
  char filename[1024];
  char buf[URL_MAX];
  struct stat st;
  int type;

  while(1) {
    if(ps3ntfs_dirnext(di, filename, &st))
      break;
    
  switch(st.st_mode & S_IFMT) {
    case S_IFDIR:
      type = CONTENT_DIR;
      break;

    case S_IFREG:
      type = CONTENT_FILE;
      break;

    default:
      continue;
    }

    fs_urlsnprintf(buf, sizeof(buf), "", url, filename);
    fa_dir_add(fd, buf, filename, type);
  }
  ps3ntfs_dirclose(di);
  return 0;
}