コード例 #1
0
ファイル: navigation.c プロジェクト: hongxchen/RTPServer
NAV_TITLE_LIST* nav_get_title_list(const char *root, uint32_t flags, uint32_t min_title_length)
{
    BD_DIR_H *dir;
    BD_DIRENT ent;
    char *path = NULL;
    MPLS_PL **pl_list = NULL;
    MPLS_PL *pl = NULL;
    unsigned int ii, pl_list_size = 0;
    int res;
    NAV_TITLE_LIST *title_list;
    unsigned int title_info_alloc = 100;

    title_list = calloc(1, sizeof(NAV_TITLE_LIST));
    title_list->title_info = calloc(title_info_alloc, sizeof(NAV_TITLE_INFO));

    BD_DEBUG(DBG_NAV, "Root: %s:\n", root);
    path = str_printf("%s" DIR_SEP "BDMV" DIR_SEP "PLAYLIST", root);

    dir = dir_open(path);
    if (dir == NULL) {
        BD_DEBUG(DBG_NAV, "Failed to open dir: %s\n", path);
        X_FREE(path);
        X_FREE(title_list->title_info);
        X_FREE(title_list);
        return NULL;
    }
    X_FREE(path);

    ii = 0;
    for (res = dir_read(dir, &ent); !res; res = dir_read(dir, &ent)) {

        if (ent.d_name[0] == '.') {
            continue;
        }
        path = str_printf("%s" DIR_SEP "BDMV" DIR_SEP "PLAYLIST" DIR_SEP "%s",
                          root, ent.d_name);

        if (ii >= pl_list_size) {
            MPLS_PL **tmp = NULL;

            pl_list_size += 100;
            tmp = realloc(pl_list, pl_list_size * sizeof(MPLS_PL*));
            if (tmp == NULL) {
                X_FREE(path);
                break;
            }
            pl_list = tmp;
        }
        pl = mpls_parse(path);
        X_FREE(path);
        if (pl != NULL) {
            if ((flags & TITLES_FILTER_DUP_TITLE) &&
                !_filter_dup(pl_list, ii, pl)) {
                mpls_free(pl);
                continue;
            }
            if ((flags & TITLES_FILTER_DUP_CLIP) && !_filter_repeats(pl, 2)) {
                mpls_free(pl);
                continue;
            }
            if (min_title_length > 0 &&
                _pl_duration(pl) < min_title_length*45000) {
                mpls_free(pl);
                continue;
            }
            if (ii >= title_info_alloc) {
                NAV_TITLE_INFO *tmp = NULL;
                title_info_alloc += 100;

                tmp = realloc(title_list->title_info,
                              title_info_alloc * sizeof(NAV_TITLE_INFO));
                if (tmp == NULL) {
                    break;
                }
                title_list->title_info = tmp;
            }
            pl_list[ii] = pl;
            strncpy(title_list->title_info[ii].name, ent.d_name, 11);
            title_list->title_info[ii].name[10] = '\0';
            title_list->title_info[ii].ref = ii;
            title_list->title_info[ii].mpls_id  = atoi(ent.d_name);
            title_list->title_info[ii].duration = _pl_duration(pl_list[ii]);
            ii++;
        }
    }
    dir_close(dir);

    title_list->count = ii;
    for (ii = 0; ii < title_list->count; ii++) {
        mpls_free(pl_list[ii]);
    }
    X_FREE(pl_list);
    return title_list;
}
コード例 #2
0
ファイル: navigation.c プロジェクト: hongxchen/RTPServer
char* nav_find_main_title(const char *root)
{
    BD_DIR_H *dir;
    BD_DIRENT ent;
    char *path = NULL;
    MPLS_PL **pl_list = NULL;
    MPLS_PL **tmp = NULL;
    MPLS_PL *pl = NULL;
    unsigned count, ii, jj, pl_list_size = 0;
    int res;
    char longest[11];

    BD_DEBUG(DBG_NAV, "Root: %s:\n", root);
    path = str_printf("%s" DIR_SEP "BDMV" DIR_SEP "PLAYLIST", root);

    dir = dir_open(path);
    if (dir == NULL) {
        fprintf(stderr, "Failed to open dir: %s\n", path);
        X_FREE(path);
        return NULL;
    }
    X_FREE(path);

    ii = jj = 0;
    for (res = dir_read(dir, &ent); !res; res = dir_read(dir, &ent)) {

        if (ent.d_name[0] == '.') {
            continue;
        }
        path = str_printf("%s" DIR_SEP "BDMV" DIR_SEP "PLAYLIST" DIR_SEP "%s",
                          root, ent.d_name);

        if (ii >= pl_list_size) {
            pl_list_size += 100;
            tmp = realloc(pl_list, pl_list_size * sizeof(MPLS_PL*));
            if (tmp == NULL) {
                X_FREE(path);
                break;
            }
            pl_list = tmp;
        }
        pl = mpls_parse(path);
        X_FREE(path);
        if (pl != NULL) {
            if (_filter_dup(pl_list, ii, pl) &&
                _filter_repeats(pl, 2)) {
                pl_list[ii] = pl;
                if (_pl_duration(pl_list[ii]) >= _pl_duration(pl_list[jj])) {
                    strncpy(longest, ent.d_name, 11);
                    longest[10] = '\0';
                    jj = ii;
                }
                ii++;
            } else {
                mpls_free(pl);
            }
        }
    }
    dir_close(dir);

    count = ii;
    for (ii = 0; ii < count; ii++) {
        mpls_free(pl_list[ii]);
    }
    if (count > 0) {
        return str_dup(longest);
    } else {
        return NULL;
    }
}
コード例 #3
0
ファイル: scan.c プロジェクト: carriercomm/kalloc.github.com
int main () {
	dir=strdup("E:/www/default/foto_content");
	dir_read(dir);	
	return 0;
}
コード例 #4
0
static inline clash_action get_slots(Stream_t *Dir,
				     char *dosname, char *longname,
				     struct scan_state *ssp,
				     ClashHandling_t *ch)
{
	int error;
	clash_action ret;
	int match=0;
	direntry_t entry;
	int isprimary;
	int no_overwrite;
	int reason;
	int pessimisticShortRename;

	pessimisticShortRename = (ch->action[0] == NAMEMATCH_AUTORENAME);

	entry.Dir = Dir;
	no_overwrite = 1;
	if((is_reserved(longname,1)) ||
	   longname[strspn(longname,". ")] == '\0'){
		reason = RESERVED;
		isprimary = 1;
	} else if(contains_illegals(longname,long_illegals)) {
		reason = ILLEGALS;
		isprimary = 1;
	} else if(is_reserved(dosname,0)) {
		reason = RESERVED;
		ch->use_longname = 1;
		isprimary = 0;
	} else if(contains_illegals(dosname,short_illegals)) {
		reason = ILLEGALS;
		ch->use_longname = 1;
		isprimary = 0;
	} else {
		reason = EXISTS;
		clear_scan(longname, ch->use_longname, ssp);
		switch (lookupForInsert(Dir, dosname, longname, ssp,
								ch->ignore_entry, 
								ch->source_entry,
								pessimisticShortRename && 
								ch->use_longname)) {
			case -1:
				return NAMEMATCH_ERROR;
				
			case 0:
				return NAMEMATCH_SKIP; 
				/* Single-file error error or skip request */
				
			case 5:
				return NAMEMATCH_GREW;
				/* Grew directory, try again */
				
			case 6:
				return NAMEMATCH_SUCCESS; /* Success */
		}	    
		match = -2;
		if (ssp->longmatch > -1) {
			/* Primary Long Name Match */
#ifdef debug
			fprintf(stderr,
				"Got longmatch=%d for name %s.\n", 
				longmatch, longname);
#endif			
			match = ssp->longmatch;
			isprimary = 1;
		} else if ((ch->use_longname & 1) && (ssp->shortmatch != -1)) {
			/* Secondary Short Name Match */
#ifdef debug
			fprintf(stderr,
				"Got secondary short name match for name %s.\n", 
				longname);
#endif

			match = ssp->shortmatch;
			isprimary = 0;
		} else if (ssp->shortmatch >= 0) {
			/* Primary Short Name Match */
#ifdef debug
			fprintf(stderr,
				"Got primary short name match for name %s.\n", 
				longname);
#endif
			match = ssp->shortmatch;
			isprimary = 1;
		} else 
			return NAMEMATCH_RENAME;

		if(match > -1) {
			entry.entry = match;
			dir_read(&entry, &error);
			if (error)
			    return NAMEMATCH_ERROR;
			/* if we can't overwrite, don't propose it */
			no_overwrite = (match == ch->source || IS_DIR(&entry));
		}
	}
	ret = process_namematch(isprimary ? longname : dosname, longname,
				isprimary, ch, no_overwrite, reason);
	
	if (ret == NAMEMATCH_OVERWRITE && match > -1){
		if((entry.dir.attr & 0x5) &&
		   (ask_confirmation("file is read only, overwrite anyway (y/n) ? ",0,0)))
			return NAMEMATCH_RENAME;
		
		/* Free up the file to be overwritten */
		if(fatFreeWithDirentry(&entry))
			return NAMEMATCH_ERROR;
		
#if 0
		if(isprimary &&
		   match - ssp->match_free + 1 >= ssp->size_needed){
			/* reuse old entry and old short name for overwrite */
			ssp->free_start = match - ssp->size_needed + 1;
			ssp->free_size = ssp->size_needed;
			ssp->slot = match;
			ssp->got_slots = 1;
			strncpy(dosname, dir.name, 3);
			strncpy(dosname + 8, dir.ext, 3);
			return ret;
		} else
#endif
			{
			entry.dir.name[0] = DELMARK;
			dir_write(&entry);
			return NAMEMATCH_RENAME;
		}
	}

	return ret;
}
コード例 #5
0
ファイル: fatdir.c プロジェクト: TijmenW/FreeDOS
f_node_ptr dir_open(BYTE * dirname)
{
  f_node_ptr fnp;
  COUNT drive;
  BYTE *p;
  WORD i;
  struct cds FAR *cdsp;
  BYTE *pszPath = dirname + 2;

  /* Allocate an fnode if possible - error return (0) if not.     */
  if ((fnp = get_f_node()) == (f_node_ptr)0)
  {
    return (f_node_ptr)0;
  }

  /* Force the fnode into read-write mode                         */
  fnp->f_mode = RDWR;

  /* determine what drive we are using...                         */
  if (ParseDosName(dirname, &drive, (BYTE *) 0, (BYTE *) 0, (BYTE *) 0, FALSE)
      != SUCCESS)
  {
    release_f_node(fnp);
    return NULL;
  }

  /* If the drive was specified, drive is non-negative and        */
  /* corresponds to the one passed in, i.e., 0 = A, 1 = B, etc.   */
  /* We use that and skip the "D:" part of the string.            */
  /* Otherwise, just use the default drive                        */
  if (drive >= 0)
  {
    dirname += 2;               /* Assume FAT style drive       */
  }
  else
  {
    drive = default_drive;
  }
  if (drive >= lastdrive) {
    release_f_node(fnp);
    return NULL;
  }

  cdsp = &CDSp->cds_table[drive];

  /* Generate full path name                                      */
  /* not necessary anymore, since truename did that already
       i = cdsp->cdsJoinOffset;
     ParseDosPath(dirname, (COUNT *) 0, pszPath, (BYTE FAR *) & cdsp->cdsCurrentPath[i]); */

/* for testing only for now */
#if 0
  if ((cdsp->cdsFlags & CDSNETWDRV))
  {
    printf("FailSafe %x \n", Int21AX);
    return fnp;
  }
#endif

  if (cdsp->cdsDpb == 0)
  {
    release_f_node(fnp);
    return NULL;
  }

  fnp->f_dpb = cdsp->cdsDpb;

  /* Perform all directory common handling after all special      */
  /* handling has been performed.                                 */

  if (media_check(fnp->f_dpb) < 0)
  {
    release_f_node(fnp);
    return (f_node_ptr)0;
  }

  /* Walk the directory tree to find the starting cluster         */
  /*                                                              */
  /* Start from the root directory (dirstart = 0)                 */

  dir_init_fnode(fnp, 0);

  for (p = pszPath; *p != '\0';)
  {
    /* skip all path seperators                             */
    while (*p == '\\')
      ++p;
    /* don't continue if we're at the end                   */
    if (*p == '\0')
      break;

    /* Convert the name into an absolute name for           */
    /* comparison...                                        */
    /* first the file name with trailing spaces...          */

    memset(TempBuffer, ' ', FNAME_SIZE+FEXT_SIZE);
    
    for (i = 0; i < FNAME_SIZE; i++)
    {
      if (*p != '\0' && *p != '.' && *p != '/' && *p != '\\')
        TempBuffer[i] = *p++;
      else
        break;
    }

    /* and the extension (don't forget to   */
    /* add trailing spaces)...              */
    if (*p == '.')
      ++p;
    for (i = 0; i < FEXT_SIZE; i++)
    {
      if (*p != '\0' && *p != '.' && *p != '/' && *p != '\\')
        TempBuffer[i + FNAME_SIZE] = *p++;
      else
        break;
    }

    /* Now search through the directory to  */
    /* find the entry...                    */
    i = FALSE;

    DosUpFMem((BYTE FAR *) TempBuffer, FNAME_SIZE + FEXT_SIZE);

    while (dir_read(fnp) == 1)
    {
      if (fnp->f_dir.dir_name[0] != '\0' && fnp->f_dir.dir_name[0] != DELETED)
      {
        if (fcmp(TempBuffer, (BYTE *)fnp->f_dir.dir_name, FNAME_SIZE + FEXT_SIZE))
        {
          i = TRUE;
          break;
        }
      }
    }

    if (!i || !(fnp->f_dir.dir_attrib & D_DIR))
    {

      release_f_node(fnp);
      return (f_node_ptr)0;
    }
    else
    {
      /* make certain we've moved off */
      /* root                         */
      dir_init_fnode(fnp, getdstart(fnp->f_dir));
    }
  }
  return fnp;
}
コード例 #6
0
ファイル: scan.c プロジェクト: carriercomm/kalloc.github.com
void dir_read(char *path) {

        DIR *dirp;
        struct dirent *dp;
        struct stat *buf;
	char fullpath[1024];
	char tn_fullpath[1024];
	char dirname[1024];
	char cptn_fullpath[1024];
	char exec[1024];

	buf=malloc(sizeof(*buf));
	bzero(buf,sizeof(*buf));
	
	stat(path,buf);
	 if(S_ISDIR(buf->st_mode)) {

	dirp = opendir(path);
	while ((dp = readdir(dirp)))  {
		bzero(buf,sizeof(*buf));
		bzero(&fullpath,1024);
		if(strcmp(dp->d_name,"..") &&  strcmp(dp->d_name,".")) {
			snprintf(fullpath,BLOCK-1,"%s/%s",path,dp->d_name);
			stat(fullpath,buf);
			if(S_ISDIR(buf->st_mode)) {
				printf("dir: %s\n",fullpath);
				dir_read(fullpath);
			} else if(S_ISREG(buf->st_mode) && !strstr(dp->d_name,"tn_") &&  strstr(dp->d_name,".jpg")) {
				printf("file: %s\n",fullpath);
				bzero(&tn_fullpath,1024);
				bzero(&cptn_fullpath,1024);
				bzero(&dirname,1024);
				snprintf(tn_fullpath,BLOCK-1,"%s/tn_%s",path,dp->d_name);

				strncpy(dirname,strrchr(path,'/')+1,strlen(path)-(int)(strrchr(path,'/')-path)-1);

				bzero(buf,sizeof(*buf));
				stat(tn_fullpath,buf);

				if(!S_ISREG(buf->st_mode)) {
					bzero(&exec,BLOCK);
					snprintf(exec,BLOCK-1,"C:/DRV/im.exe -verbose -resize 120x120 %s %s",fullpath,tn_fullpath);
					system(exec);
					printf("create: %s\n",tn_fullpath);
				}
				snprintf(cptn_fullpath,BLOCK-1,"%s/tn_%s.jpg",path,dirname);
				bzero(buf,sizeof(*buf));
				stat(cptn_fullpath,buf);
				if(!S_ISREG(buf->st_mode)) {
					bzero(&exec,BLOCK);
					snprintf(exec,BLOCK-1,"cp %s %s",tn_fullpath,cptn_fullpath);
					system(exec);
				}
			}
		} 
	}
	closedir(dirp);

	}
	
	free(buf);

}       
コード例 #7
0
ファイル: fatdir.c プロジェクト: TijmenW/FreeDOS
COUNT dos_findfirst(UCOUNT attr, BYTE *name)
{
  REG f_node_ptr fnp;
  REG dmatch *dmp = (dmatch *) TempBuffer;
  REG COUNT i;
  COUNT nDrive;
  BYTE *p;

  BYTE local_name[FNAME_SIZE + 1],
    local_ext[FEXT_SIZE + 1];

/*  printf("ff %Fs\n", name);*/

  /* The findfirst/findnext calls are probably the worst of the   */
  /* DOS calls. They must work somewhat on the fly (i.e. - open   */
  /* but never close). Since we don't want to lose fnodes every   */
  /* time a directory is searched, we will initialize the DOS     */
  /* dirmatch structure and then for every find, we will open the */
  /* current directory, do a seek and read, then close the fnode. */

  /* Parse out the drive, file name and file extension.           */
  i = ParseDosName(name, &nDrive, &szDirName[2], local_name, local_ext, TRUE);
  if (i != SUCCESS)
    return i;
/*
  printf("\nff %s", Tname);
  printf("ff %s", local_name);
  printf("ff %s\n", local_ext);
*/

  /* Build the match pattern out of the passed string             */
  /* copy the part of the pattern which belongs to the filename and is fixed */
  for (p = local_name, i = 0; i < FNAME_SIZE && *p; ++p, ++i)
    SearchDir.dir_name[i] = *p;

  for (; i < FNAME_SIZE; ++i)
      SearchDir.dir_name[i] = ' ';

  /* and the extension (don't forget to add trailing spaces)...   */
  for (p = local_ext, i = 0; i < FEXT_SIZE && *p; ++p, ++i)
    SearchDir.dir_ext[i] = *p;

  for (; i < FEXT_SIZE; ++i)
      SearchDir.dir_ext[i] = ' ';

  /* Convert everything to uppercase. */
  DosUpFMem(SearchDir.dir_name, FNAME_SIZE + FEXT_SIZE);

  /* Now search through the directory to find the entry...        */

  /* Complete building the directory from the passed in   */
  /* name                                                 */
  szDirName[0] = 'A' + nDrive;
  szDirName[1] = ':';
    
  /* Special handling - the volume id is only in the root         */
  /* directory and only searched for once.  So we need to open    */
  /* the root and return only the first entry that contains the   */
  /* volume id bit set.                                           */
  if (attr == D_VOLID)
  {
    szDirName[2] = '\\';
    szDirName[3] = '\0';
  }
  /* Now open this directory so that we can read the      */
  /* fnode entry and do a match on it.                    */
  
/*  printf("dir_open %s\n", szDirName);*/
  if ((fnp = dir_open(szDirName)) == NULL)
    return DE_PATHNOTFND;

  /* Now initialize the dirmatch structure.            */
  
  nDrive=get_verify_drive(name);
  if (nDrive < 0)
      return nDrive;
  dmp->dm_drive = nDrive;
  dmp->dm_attr_srch = attr;

  /* Copy the raw pattern from our data segment to the DTA. */
  fmemcpy(dmp->dm_name_pat, SearchDir.dir_name, FNAME_SIZE + FEXT_SIZE);

  if (attr == D_VOLID)
  {
    /* Now do the search                                    */
    while (dir_read(fnp) == 1)
    {
      /* Test the attribute and return first found    */
      if ((fnp->f_dir.dir_attrib & ~(D_RDONLY | D_ARCHIVE)) == D_VOLID)
      {
        dmp->dm_dircluster = fnp->f_dirstart;        /* TE */
        memcpy(&SearchDir, &fnp->f_dir, sizeof(struct dirent));
        dir_close(fnp);
        return SUCCESS;
      }
    }

    /* Now that we've done our failed search, close it and  */
    /* return an error.                                     */
    dir_close(fnp);
    return DE_FILENOTFND;
  }
  /* Otherwise just do a normal find next                         */
  else
  {
    dmp->dm_entry = 0;
    if (!fnp->f_flags.f_droot)
      dmp->dm_dircluster = fnp->f_dirstart;
    else
      dmp->dm_dircluster = 0;
    dir_close(fnp);
    return dos_findnext();
  }
}
コード例 #8
0
ファイル: fatdir.c プロジェクト: TijmenW/FreeDOS
COUNT dos_findnext(void)
{
  REG dmatch *dmp = (dmatch *) TempBuffer;
  REG f_node_ptr fnp;
  BOOL found = FALSE;

  /* Allocate an fnode if possible - error return (0) if not.     */
  if ((fnp = get_f_node()) == (f_node_ptr)0)
  {
    return DE_NFILES;
  }
  
  memset(fnp, 0, sizeof(*fnp));

  /* Force the fnode into read-write mode                         */
  fnp->f_mode = RDWR;

  /* Select the default to help non-drive specified path          */
  /* searches...                                                  */
  fnp->f_dpb = CDSp->cds_table[dmp->dm_drive].cdsDpb;
  if (media_check(fnp->f_dpb) < 0)
  {
    release_f_node(fnp);
    return DE_NFILES;
  }

  dir_init_fnode(fnp, dmp->dm_dircluster);

  /* Search through the directory to find the entry, but do a     */
  /* seek first.                                                  */
  if (dmp->dm_entry > 0)
    {
    fnp->f_diroff = (ULONG)(dmp->dm_entry - 1) * DIRENT_SIZE;
    fnp->f_flags.f_dnew = FALSE;
    }
  else
    {
    fnp->f_diroff = 0;
    fnp->f_flags.f_dnew = TRUE;
    }          

  /* Loop through the directory                                   */
  while (dir_read(fnp) == 1)
  {
    ++dmp->dm_entry;
    if (fnp->f_dir.dir_name[0] != '\0' && fnp->f_dir.dir_name[0] != DELETED
          && (fnp->f_dir.dir_attrib & D_VOLID) != D_VOLID )
    {
      if (fcmp_wild((BYTE FAR *)dmp->dm_name_pat, (BYTE FAR *)fnp->f_dir.dir_name, FNAME_SIZE + FEXT_SIZE))
      {
        /*
            MSD Command.com uses FCB FN 11 & 12 with attrib set to 0x16.
            Bits 0x21 seem to get set some where in MSD so Rd and Arc
            files are returned. 
            RdOnly + Archive bits are ignored
         */
         
        /* Test the attribute as the final step */
        if (!(fnp->f_dir.dir_attrib & D_VOLID) &&
           ((~dmp->dm_attr_srch & fnp->f_dir.dir_attrib & (D_DIR | D_SYSTEM | D_HIDDEN)) == 0))
        {
          found = TRUE;
          break;
        }
        else
          continue;
      }
    }
  }

  /* If found, transfer it to the dmatch structure                */
  if (found)
    {
    dmp->dm_dircluster = fnp->f_dirstart;
    memcpy(&SearchDir, &fnp->f_dir, sizeof(struct dirent));
    }

  /* return the result                                            */
  release_f_node(fnp);

  return found ? SUCCESS : DE_NFILES;
}
コード例 #9
0
ファイル: fatdir.c プロジェクト: TijmenW/FreeDOS
COUNT dos_findfirst(UCOUNT attr, BYTE FAR * name)
{
  REG struct f_node FAR *fnp;
  REG dmatch FAR *dmp = (dmatch FAR *) dta;
  REG COUNT i;
  COUNT nDrive;
  BYTE *p;
  struct cds FAR *cdsp;

  static BYTE local_name[FNAME_SIZE + 1],
    local_ext[FEXT_SIZE + 1];

  /* The findfirst/findnext calls are probably the worst of the   */
  /* DOS calls. They must work somewhat on the fly (i.e. - open   */
  /* but never close). Since we don't want to lose fnodes every   */
  /* time a directory is searched, we will initialize the DOS     */
  /* dirmatch structure and then for every find, we will open the */
  /* current directory, do a seek and read, then close the fnode. */

  /* Start out by initializing the dirmatch structure.            */
  dmp->dm_drive = default_drive;
  dmp->dm_entry = 0;
  dmp->dm_cluster = 0;

  dmp->dm_attr_srch = attr | D_RDONLY | D_ARCHIVE;

  /* Parse out the drive, file name and file extension.           */
  i = ParseDosName(name, &nDrive, &LocalPath[2], local_name, local_ext, TRUE);
  if (i != SUCCESS)
    return i;

  if (nDrive >= 0)
  {
    dmp->dm_drive = nDrive;
  }
  else
    nDrive = default_drive;

  cdsp = &CDSp->cds_table[nDrive];

  if (cdsp->cdsFlags & 0x8000)
  {
    if (Remote_find(REM_FINDFIRST, attr, name, dmp) != 0)
      return DE_FILENOTFND;
    return SUCCESS;
  }

  /* Now build a directory.                                       */
  if (!LocalPath[2])
    strcpy(&LocalPath[2], ".");

  /* Build the match pattern out of the passed string             */
  /* copy the part of the pattern which belongs to the filename and is fixed */
  for (p = local_name, i = 0; i < FNAME_SIZE && *p && *p != '*'; ++p, ++i)
    SearchDir.dir_name[i] = *p;
  if (*p == '*')
  {
    for (; i < FNAME_SIZE; ++i)
      SearchDir.dir_name[i] = '?';
    while (*++p) ;
  }
  else
    for (; i < FNAME_SIZE; i++)
      SearchDir.dir_name[i] = ' ';

  /* and the extension (don't forget to add trailing spaces)...   */
  for (p = local_ext, i = 0; i < FEXT_SIZE && *p && *p != '*'; ++p, ++i)
    SearchDir.dir_ext[i] = *p;
  if (*p == '*')
  {
    for (; i < FEXT_SIZE; ++i)
      SearchDir.dir_ext[i] = '?';
    while (*++p) ;
  }
  else
    for (; i < FEXT_SIZE; i++)
      SearchDir.dir_ext[i] = ' ';

  /* Convert everything to uppercase. */
  upMem(SearchDir.dir_name, FNAME_SIZE + FEXT_SIZE);

  /* Copy the raw pattern from our data segment to the DTA. */
  fbcopy((BYTE FAR *) SearchDir.dir_name, dmp->dm_name_pat,
         FNAME_SIZE + FEXT_SIZE);

  /* Now search through the directory to find the entry...        */
  /* Special handling - the volume id is only in the root         */
  /* directory and only searched for once.  So we need to open    */
  /* the root and return only the first entry that contains the   */
  /* volume id bit set.                                           */
  if ((attr & ~(D_RDONLY | D_ARCHIVE)) == D_VOLID)
  {
    /* Now open this directory so that we can read the      */
    /* fnode entry and do a match on it.                    */
    if ((fnp = dir_open((BYTE FAR *) "\\")) == NULL)
      return DE_PATHNOTFND;

    /* Now do the search                                    */
    while (dir_read(fnp) == DIRENT_SIZE)
    {
      /* Test the attribute and return first found    */
      if ((fnp->f_dir.dir_attrib & ~(D_RDONLY | D_ARCHIVE)) == D_VOLID)
      {
        pop_dmp(dmp, fnp);
        dir_close(fnp);
        return SUCCESS;
      }
    }

    /* Now that we've done our failed search, close it and  */
    /* return an error.                                     */
    dir_close(fnp);
    return DE_FILENOTFND;
  }

  /* Otherwise just do a normal find next                         */
  else
  {
    /* Complete building the directory from the passed in   */
    /* name                                                 */
    if (nDrive >= 0)
      LocalPath[0] = 'A' + nDrive;
    else
      LocalPath[0] = 'A' + default_drive;
    LocalPath[1] = ':';

    /* Now open this directory so that we can read the      */
    /* fnode entry and do a match on it.                    */
    if ((fnp = dir_open((BYTE FAR *) LocalPath)) == NULL)
      return DE_PATHNOTFND;

    pop_dmp(dmp, fnp);
    dmp->dm_entry = 0;
    if (!fnp->f_flags.f_droot)
    {
      dmp->dm_cluster = fnp->f_dirstart;
      dmp->dm_dirstart = fnp->f_dirstart;
    }
    else
    {
      dmp->dm_cluster = 0;
      dmp->dm_dirstart = 0;
    }
    dir_close(fnp);
    return dos_findnext();
  }
}
コード例 #10
0
ファイル: fatdir.c プロジェクト: TijmenW/FreeDOS
COUNT dos_findnext(void)
{
  REG dmatch FAR *dmp = (dmatch FAR *) dta;
  REG struct f_node FAR *fnp;
  BOOL found = FALSE;
  BYTE FAR *p;
  BYTE FAR *q;
  COUNT nDrive;
  struct cds FAR *cdsp;

  /* assign our match parameters pointer.                         */
  dmp = (dmatch FAR *) dta;

  nDrive = dmp->dm_drive;

  cdsp = &CDSp->cds_table[nDrive];
  if (cdsp->cdsFlags & 0x8000)
  {
    if (Remote_find(REM_FINDNEXT, 0, 0, dmp) != 0)
      return DE_FILENOTFND;
    return SUCCESS;
  }

  /* Allocate an fnode if possible - error return (0) if not.     */
  if ((fnp = get_f_node()) == (struct f_node FAR *)0)
  {
    return DE_FILENOTFND;
  }

  /* Force the fnode into read-write mode                         */
  fnp->f_mode = RDWR;

  /* Select the default to help non-drive specified path          */
  /* searches...                                                  */
  fnp->f_dpb = (struct dpb *)CDSp->cds_table[dmp->dm_drive].cdsDpb;
  if (media_check(fnp->f_dpb) < 0)
  {
    release_f_node(fnp);
    return DE_FILENOTFND;
  }

  fnp->f_dsize = DIRENT_SIZE * (fnp->f_dpb)->dpb_dirents;

  /* Search through the directory to find the entry, but do a     */
  /* seek first.                                                  */
  if (dmp->dm_entry > 0)
    fnp->f_diroff = (dmp->dm_entry - 1) * DIRENT_SIZE;

  fnp->f_offset = fnp->f_highwater = fnp->f_diroff;
  fnp->f_cluster = dmp->dm_cluster;
  fnp->f_cluster_offset = 0l;   /*JPP */
  fnp->f_flags.f_dmod = dmp->dm_flags.f_dmod;
  fnp->f_flags.f_droot = dmp->dm_flags.f_droot;
  fnp->f_flags.f_dnew = dmp->dm_flags.f_dnew;
  fnp->f_flags.f_ddir = dmp->dm_flags.f_ddir;
  fnp->f_flags.f_dfull = dmp->dm_flags.f_dfull;

  fnp->f_dirstart = dmp->dm_dirstart;

  /* Loop through the directory                                   */
  while (dir_read(fnp) == DIRENT_SIZE)
  {
    ++dmp->dm_entry;
    if (fnp->f_dir.dir_name[0] != '\0' && fnp->f_dir.dir_name[0] != DELETED)
    {
      if (fcmp_wild((BYTE FAR *) (dmp->dm_name_pat), (BYTE FAR *) fnp->f_dir.dir_name, FNAME_SIZE + FEXT_SIZE))
      {
        /* Test the attribute as the final step */
        if (!(~dmp->dm_attr_srch & fnp->f_dir.dir_attrib))
        {
          found = TRUE;
          break;
        }
        else
          continue;
      }
    }
  }

  /* If found, transfer it to the dmatch structure                */
  if (found)
    pop_dmp(dmp, fnp);

  /* return the result                                            */
  release_f_node(fnp);

  return found ? SUCCESS : DE_FILENOTFND;
}
コード例 #11
0
ファイル: fatdir.c プロジェクト: TijmenW/FreeDOS
struct f_node FAR *dir_open(BYTE FAR * dirname)
{
  struct f_node FAR *fnp;
  COUNT drive;
  BYTE *p;
  WORD i,
    x;
  BYTE *s;
  struct cds FAR *cdsp;
  BYTE *pszPath = &TempCDS.cdsCurrentPath[2];

  /* Allocate an fnode if possible - error return (0) if not.     */
  if ((fnp = get_f_node()) == (struct f_node FAR *)0)
  {
    return (struct f_node FAR *)NULL;
  }

  /* Force the fnode into read-write mode                         */
  fnp->f_mode = RDWR;

  /* and initialize temporary CDS                                 */
  TempCDS.cdsFlags = 0;
  /* determine what drive we are using...                         */
  dirname = adjust_far(dirname);
  if (ParseDosName(dirname, &drive, (BYTE *) 0, (BYTE *) 0, (BYTE *) 0, FALSE)
      != SUCCESS)
  {
    release_f_node(fnp);
    return NULL;
  }

  /* If the drive was specified, drive is non-negative and        */
  /* corresponds to the one passed in, i.e., 0 = A, 1 = B, etc.   */
  /* We use that and skip the "D:" part of the string.            */
  /* Otherwise, just use the default drive                        */
  if (drive >= 0)
  {
    dirname += 2;               /* Assume FAT style drive       */
    TempCDS.cdsDpb = CDSp->cds_table[drive].cdsDpb;
  }
  else
  {
    drive = default_drive;
    TempCDS.cdsDpb = CDSp->cds_table[drive].cdsDpb;

  }

  cdsp = &CDSp->cds_table[drive];

  TempCDS.cdsCurrentPath[0] = 'A' + drive;
  TempCDS.cdsCurrentPath[1] = ':';
  TempCDS.cdsJoinOffset = 2;

  x = cdsp->cdsJoinOffset;

  /* Generate full path name                                      */
  ParseDosPath(dirname, (COUNT *) 0, pszPath, (BYTE FAR *) & cdsp->cdsCurrentPath[x]);

  if ((cdsp->cdsFlags & 0x8000))
  {
    printf("FailSafe %x \n", Int21AX);
    return fnp;
  }

  if (TempCDS.cdsDpb == 0)
  {
    release_f_node(fnp);
    return NULL;
  }

/*  if (drive >= lastdrive)
   {
   release_f_node(fnp);
   return NULL;
   }
 */
  fnp->f_dpb = (struct dpb *)TempCDS.cdsDpb;

  /* Perform all directory common handling after all special      */
  /* handling has been performed.                                 */

  if (media_check((struct dpb *)TempCDS.cdsDpb) < 0)
  {
    release_f_node(fnp);
    return (struct f_node FAR *)0;
  }

  fnp->f_dsize = DIRENT_SIZE * TempCDS.cdsDpb->dpb_dirents;

  fnp->f_diroff = 0l;
  fnp->f_flags.f_dmod = FALSE;  /* a brand new fnode            */
  fnp->f_flags.f_dnew = TRUE;
  fnp->f_flags.f_dremote = FALSE;

  fnp->f_dirstart = 0;

  /* Walk the directory tree to find the starting cluster         */
  /*                                                              */
  /* Set the root flags since we always start from the root       */

  fnp->f_flags.f_droot = TRUE;
  for (p = pszPath; *p != '\0';)
  {
    /* skip all path seperators                             */
    while (*p == '\\')
      ++p;
    /* don't continue if we're at the end                   */
    if (*p == '\0')
      break;

    /* Convert the name into an absolute name for           */
    /* comparison...                                        */
    /* first the file name with trailing spaces...          */
    for (i = 0; i < FNAME_SIZE; i++)
    {
      if (*p != '\0' && *p != '.' && *p != '/' && *p != '\\')
        TempBuffer[i] = *p++;
      else
        break;
    }

    for (; i < FNAME_SIZE; i++)
      TempBuffer[i] = ' ';

    /* and the extension (don't forget to   */
    /* add trailing spaces)...              */
    if (*p == '.')
      ++p;
    for (i = 0; i < FEXT_SIZE; i++)
    {
      if (*p != '\0' && *p != '.' && *p != '/' && *p != '\\')
        TempBuffer[i + FNAME_SIZE] = *p++;
      else
        break;
    }
    for (; i < FEXT_SIZE; i++)
      TempBuffer[i + FNAME_SIZE] = ' ';

    /* Now search through the directory to  */
    /* find the entry...                    */
    i = FALSE;

    upMem((BYTE FAR *) TempBuffer, FNAME_SIZE + FEXT_SIZE);

    while (dir_read(fnp) == DIRENT_SIZE)
    {
      if (fnp->f_dir.dir_name[0] != '\0' && fnp->f_dir.dir_name[0] != DELETED)
      {
        if (fcmp((BYTE FAR *) TempBuffer, (BYTE FAR *) fnp->f_dir.dir_name, FNAME_SIZE + FEXT_SIZE))
        {
          i = TRUE;
          break;
        }
      }
    }

    if (!i || !(fnp->f_dir.dir_attrib & D_DIR))
    {

      release_f_node(fnp);
      return (struct f_node FAR *)0;
    }
    else
    {
      /* make certain we've moved off */
      /* root                         */
      fnp->f_flags.f_droot = FALSE;
      fnp->f_flags.f_ddir = TRUE;
      /* set up for file read/write   */
      fnp->f_offset = 0l;
      fnp->f_cluster_offset = 0l;	/*JPP */
      fnp->f_highwater = 0l;
      fnp->f_cluster = fnp->f_dir.dir_start;
      fnp->f_dirstart = fnp->f_dir.dir_start;
      /* reset the directory flags    */
      fnp->f_diroff = 0l;
      fnp->f_flags.f_dmod = FALSE;
      fnp->f_flags.f_dnew = TRUE;
      fnp->f_dsize = DIRENT_SIZE * TempCDS.cdsDpb->dpb_dirents;

    }
  }
  return fnp;
}
コード例 #12
0
ファイル: driver.c プロジェクト: girish979/searchengine
void dir_read(const char dir[]) 
{
	struct direct **files;
	long nfiles, x;
	int dir_filter(const struct direct *entry);
	char path[500];
	char fnames[500];

//
	//FILE *doc_dic;
//
 
	nfiles = scandir(dir, &files, dir_filter, alphasort);
  
  
	for(x=0;x<nfiles;x++)
	{
		if( files[x]->d_type == DT_DIR )
	  	{
	  	  	strcpy(path,"\0");
	  	  	strcpy(path,dir);
			strcat(path,"/");
		        strcat(path,files[x]->d_name);
		        dir_read(path);
	  	  	
	 	 }
	}
 
  	if(nfiles <= 0);
    //return 0;
 
	for(x=0;x<nfiles;x++)
		if(files[x]->d_type != DT_DIR)
		{
			strcpy(fnames,"\0");
	    		sprintf(fnames,"%s/%s", dir, files[x]->d_name);
			strcat(fnames,"\0");
	    		//printf("\nIndexing File : %s",fnames);
//////////////Doc Dic start
/*
			doc_dic = fopen("../bin/docdic","ab+");
		
			doc_dictionay *dd_node = (doc_dictionay *)malloc(sizeof(doc_dictionay));

			dd_node->docID = ++doc_count;
			strcpy(dd_node->path,fnames);
			dd_node->path[strlen(dd_node->path)]='\0';
			fwrite(dd_node,sizeof(doc_dictionay),1,doc_dic);
			
			fclose(doc_dic); 
			free(dd_node);
*/

//Doc Dic


			++doc_count;


			
			
			
			



			g_idocid = doc_count;

			//v2.1
			strcpy(g_ifile,"\0");//Remove previous contents
			strcpy(g_ifile,fnames); //copying current indexing file to global variable g_ifile
			g_ifile[strlen(g_ifile)]='\0';
			//printf("Indexing File gfile name %s\n",g_ifile);
			//End of v2.1

			/* */
		
			fflush(stdin);
			do_stem(fnames);// stemmed o/p will be in ../bin/stemop
			genHash("../bin/stemop");  //For every File read Start building Tree

			//Write Doc_Dic
			doc_dictionay *dd_node = (doc_dictionay *)malloc(sizeof(doc_dictionay));
			dd_node->docID = doc_count;
			dd_node->doc_len = doc_len;
			strcpy(dd_node->path,fnames);
			dd_node->path[strlen(dd_node->path)]='\0';
			dd_node->next = NULL;
			if(doc_dic_root)
			{
				doc_dic_last->next = dd_node;
				doc_dic_last = dd_node;

			}
			else
			{
				doc_dic_root = dd_node;
				doc_dic_last = doc_dic_root;
			}

			//
			
			avg_doc_len = (double) ( ((  avg_doc_len*(doc_count-1) ) + doc_len )/doc_count);
	



			
		}
}
コード例 #13
0
JNIEXPORT jobjectArray JNICALL Java_org_videolan_Libbluray_listBdFilesN(JNIEnv * env,
                                                                        jclass cls, jlong np, jstring jpath,
                                                                        jboolean onlyBdRom) {

    BLURAY *bd = (BLURAY*)(intptr_t)np;
    BD_DISC *disc = bd_get_disc(bd);

    const char *path = (*env)->GetStringUTFChars(env, jpath, NULL);
    if (!path) {
        BD_DEBUG(DBG_JNI | DBG_CRIT, "listBdFilesN() failed: no path\n");
        return NULL;
    }
    BD_DEBUG(DBG_JNI, "listBdFilesN(%s)\n", path);

    /* open directory stream */
    BD_DIR_H *dp;
    if (onlyBdRom) {
        dp = disc_open_bdrom_dir(disc, path);
    } else {
        dp = disc_open_dir(disc, path);
    }
    if (!dp) {
        BD_DEBUG(DBG_JNI, "failed opening directory %s\n", path);
        (*env)->ReleaseStringUTFChars(env, jpath, path);
        return NULL;
    }
    (*env)->ReleaseStringUTFChars(env, jpath, path);

    /* count files and create java strings (java array size must be known when it is created) */
    jstring  *files = NULL;
    unsigned  count = 0;
    unsigned  allocated = 0;
    BD_DIRENT ent;
    while (!dir_read(dp, &ent)) {
        if (strcmp(ent.d_name, ".") && strcmp(ent.d_name, "..")) {
            if (allocated <= count) {
                allocated += 512;
                jstring *tmp = realloc(files, sizeof(*files) * allocated);
                if (!tmp) {
                    BD_DEBUG(DBG_JNI | DBG_CRIT, "failed allocating memory for %u directory entries\n", allocated);
                    break;
                }
                files = tmp;
            }
            files[count] = (*env)->NewStringUTF(env, ent.d_name);
            count++;
        }
    }
    dir_close(dp);

    /* allocate java array */
    jobjectArray arr = bdj_make_array(env, "java/lang/String", count);
    if (!arr) {
        BD_DEBUG(DBG_JNI | DBG_CRIT, "failed creating array [%d]\n", count);
    } else {
        /* populate files to array */
        unsigned ii;
        for (ii = 0; ii < count; ii++) {
            (*env)->SetObjectArrayElement(env, arr, ii, files[ii]);
        }
    }

    X_FREE(files);

    return arr;
}
コード例 #14
0
ファイル: shell.c プロジェクト: mrinalstonybrook/sbu-unix
void shell()
{
	
	char shell_buffer[100];
	char *tmp1,*tmp2;
	tmp1=shell_buffer;	
	char *mountpt="/hiphop/";
	int flag=0;
	int cmd_loc=5;
	struct file fd;
	struct file *fd_p;
	 //uint64_t *fd1=(uint64_t *)kmalloc(sizeof(struct file));
          //fd=(struct file*)fd1;
	int i=0;
	char commands[3][10]={"echo","ls","cd"};
	commands[1][2]='\0';
	commands[0][5]='\0';
	commands[2][2]='\0';
	//char *tmp;
	char* tmp3;
	//blacken();
	clear_screen();
	char pwd[40]="";
      pwd[0]='\0';
	int k=3;
	while(1)
	{	
		for(i=0;i<k;i++)
			shell_buffer[i]='\0';
		flag=0;
		cmd_loc=5;
		printk("\n Shell ~%s>",pwd);
		scank("%s",shell_buffer);
		tmp1=shell_buffer;
		for(i=0;i<3;i++)
		{
			tmp2=commands[i];
			if(*tmp1!=*tmp2)
			continue;
			while(*tmp1==*tmp2)
			{
				tmp1++;
				tmp2++;
				//printk("[%c] [%c]",*tmp1,*tmp2);
			}
			if((*tmp2=='\0')&&(*tmp1==' '))
			{
				flag=1;
				tmp1++;
				cmd_loc=i;
			}
			//printk("[i=%d]",i);
		}
		
		if(flag==0)
		{
			printk("command not found");
			continue;
		}
		tmp2=tmp1;
		//printk("%s",tmp2);
             tmp3=mountpt;
	  	while(*tmp1==*tmp3)
		{
			tmp1++;
			tmp3++;
		}
         	flag=0;
		
		if((*tmp1!='\0')&&(*tmp3=='\0') && *(tmp1-1)=='/')
		{
			flag=1;
		}
		switch(cmd_loc)
		{
			case 0:
				//printk("echo encountered");
				break;
			case 1:
				//printk("ls encountered");
				
				strcpy(fd.filename,tmp2);
                            fd.location=flag;//while(1);
				//printk("%s,%d",fd.filename,fd.location);
				for(i=0;i<k;i++)
					shell_buffer[i]='\0';
			//	while(1);
				//readdir_ls(&fd,shell_buffer,10);
				if(flag==1)
				dir_read(&fd,shell_buffer,100);
   				else
				read_dir_ls(&fd,shell_buffer,100);
    				tmp2=shell_buffer;
        			while(*tmp2!='\0')
				{
					if(*tmp2==',')
					*tmp2='\t';
					tmp2++;
				}
				printk("\n%s",shell_buffer);
				//while(1);

				break;
			case 2:
				/*if(strcmp("..",tmp2)==0)
				{	
					if(flag==1)
					tmp=pwd+strlen(pwd)-1;
					else
					tmp=pwd+strlen(pwd)-2;
					tmp1=pwd;

					while(*tmp!='/' || tmp1!=tmp)
                                     tmp--;
    					if(tmp1==tmp)
                                      *tmp='\0';
                                   else {
					tmp++;
                                   tmp='\0';}
				}*/
				//else
				//{
					
					strcpy(fd.filename,tmp2);
					fd.location=flag;
					if(flag==1)
					{ 
					printk("\n [[%d]]",make_dir(fd.filename));
					fd_p=(struct file*)0x1;
					//fd_p=file_open(fd.filename,5);
					if(fd_p==NULL)
					{
						printk("NO directory exists");
						continue;
					}
                                    }
					else
					{
						fd_p=open_file_tarfs(fd.filename);//fd_p=open_dir_tarfs(fd.filename);
						if(fd_p==NULL)
						{
						printk("NO directory exists");
						continue;
						}

					}				
					strcpy(pwd,tmp2);
			
				//}
				
				//fd.location;
				break;

			default:
				printk("BAD command");
		}
		
	}
		
}
コード例 #15
0
int
diff_dirs (struct comparison const *cmp,
	   int (*handle_file) (struct comparison const *,
			       char const *, char const *))
{
  struct dirdata dirdata[2];
  int volatile val = EXIT_SUCCESS;
  int i;

  if ((cmp->file[0].desc == -1 || dir_loop (cmp, 0))
      && (cmp->file[1].desc == -1 || dir_loop (cmp, 1)))
    {
      error (0, 0, "%s: recursive directory loop",
	     cmp->file[cmp->file[0].desc == -1].name);
      return EXIT_TROUBLE;
    }

  /* Get contents of both dirs.  */
  for (i = 0; i < 2; i++)
    if (! dir_read (&cmp->file[i], &dirdata[i]))
      {
	perror_with_name (cmp->file[i].name);
	val = EXIT_TROUBLE;
      }

  if (val == EXIT_SUCCESS)
    {
      char const **volatile names[2];
      names[0] = dirdata[0].names;
      names[1] = dirdata[1].names;

      /* Use locale-specific sorting if possible, else native byte order.  */
      locale_specific_sorting = true;
      if (setjmp (failed_locale_specific_sorting))
	locale_specific_sorting = false;

      /* Sort the directories.  */
      for (i = 0; i < 2; i++)
	qsort (names[i], dirdata[i].nnames, sizeof *dirdata[i].names,
	       compare_names_for_qsort);

      /* If `-S name' was given, and this is the topmost level of comparison,
	 ignore all file names less than the specified starting name.  */

      if (starting_file && ! cmp->parent)
	{
	  while (*names[0] && compare_names (*names[0], starting_file) < 0)
	    names[0]++;
	  while (*names[1] && compare_names (*names[1], starting_file) < 0)
	    names[1]++;
	}

      /* Loop while files remain in one or both dirs.  */
      while (*names[0] || *names[1])
	{
	  /* Compare next name in dir 0 with next name in dir 1.
	     At the end of a dir,
	     pretend the "next name" in that dir is very large.  */
	  int nameorder = (!*names[0] ? 1 : !*names[1] ? -1
			   : compare_names (*names[0], *names[1]));
	  int v1 = (*handle_file) (cmp,
				   0 < nameorder ? 0 : *names[0]++,
				   nameorder < 0 ? 0 : *names[1]++);
	  if (val < v1)
	    val = v1;
	}
    }

  for (i = 0; i < 2; i++)
    {
      if (dirdata[i].names)
	free (dirdata[i].names);
      if (dirdata[i].data)
	free (dirdata[i].data);
    }

  return val;
}