Пример #1
0
static int open_ts_file(stream_t * s)
{
    unsigned short  path_tmp[256] = {0};
    char * p_filename1;
    char file_new[256] = {0};
    int ret = 0;
	  mtos_sem_take(&ts_sem, 0);
    ret = ufs_close(s->fd);
	mtos_sem_give(&ts_sem);

    if (ret != FR_OK) {
        mtos_printk("UFS close FAIL %d\n", ret);
        return ret ;
    }

    memset(s->fd, 0, sizeof(ufs_file_t));
    memset(file_new, 0, 256);
    sprintf(file_new, "%s%04d%s", basename, rec_index, ".ts");
    memset(path_tmp, 0, 256);
    //mtos_printk("\n%s %d %s\n", __func__, __LINE__, file_new);
    p_filename1 = Convert_Utf8_To_Unicode((unsigned char *)file_new, path_tmp);
    memcpy(filename1, file_new, 256);

    do {
        //{
         mtos_sem_take(&ts_sem, 0);
        ret = ufs_open(s->fd, p_filename1, UFS_READ);
		 mtos_sem_give(&ts_sem);
        mtos_task_sleep(10);
    } while (ret == FR_NO_FILE && (is_file_seq_exit() == FALSE));
  if(ret == FR_OK)
  {
  	mtos_sem_take(&ts_sem, 0);
    ufs_ioctl(s->fd, FS_SEEK_LINKMAP, 0 , 0 , 0);
	mtos_sem_give(&ts_sem);
	}
    return ret;
}
Пример #2
0
/*
 * Open a file.
 */
__compactcall int
ufs_open(const char *path, struct open_file *f)
{
#ifndef LIBSA_FS_SINGLECOMPONENT
	const char *cp, *ncp;
	int c;
#endif
	ino32_t inumber;
	struct file *fp;
	struct fs *fs;
	int rc;
#ifndef LIBSA_NO_FS_SYMLINK
	ino32_t parent_inumber;
	int nlinks = 0;
	char namebuf[MAXPATHLEN+1];
	char *buf;
#endif

	/* allocate file system specific data structure */
	fp = alloc(sizeof(struct file));
	memset(fp, 0, sizeof(struct file));
	f->f_fsdata = (void *)fp;

	/* allocate space and read super block */
	fs = alloc(SBLOCKSIZE);
	fp->f_fs = fs;
	twiddle();

#ifdef LIBSA_FFSv2
	rc = ffs_find_superblock(f, fs);
	if (rc)
		goto out;
#else
	{
		size_t buf_size;
		rc = DEV_STRATEGY(f->f_dev)(f->f_devdata, F_READ,
			SBLOCKOFFSET / DEV_BSIZE, SBLOCKSIZE, fs, &buf_size);
		if (rc)
			goto out;
		if (buf_size != SBLOCKSIZE ||
#ifdef LIBSA_FFS
		    fs->lfs_version != REQUIRED_LFS_VERSION ||
#endif
		    fs->fs_magic != FS_MAGIC) {
			rc = EINVAL;
			goto out;
		}
	}
#if defined(LIBSA_LFS) && REQUIRED_LFS_VERSION == 2
	/*
	 * XXX	We should check the second superblock and use the eldest
	 *	of the two.  See comments near the top of lfs_mountfs()
	 *	in sys/ufs/lfs/lfs_vfsops.c.
	 *      This may need a LIBSA_LFS_SMALL check as well.
	 */
#endif
#endif

#ifdef LIBSA_FFSv1
	ffs_oldfscompat(fs);
#endif

	if (fs->fs_bsize > MAXBSIZE ||
	    (size_t)fs->fs_bsize < sizeof(struct fs)) {
		rc = EINVAL;
		goto out;
	}

	/*
	 * Calculate indirect block levels.
	 */
	{
		indp_t mult;
		int ln2;

		/*
		 * We note that the number of indirect blocks is always
		 * a power of 2.  This lets us use shifts and masks instead
		 * of divide and remainder and avoinds pulling in the
		 * 64bit division routine into the boot code.
		 */
		mult = UFS_NINDIR(fs);
#ifdef DEBUG
		if (mult & (mult - 1)) {
			/* Hummm was't a power of 2 */
			rc = EINVAL;
			goto out;
		}
#endif
		for (ln2 = 0; mult != 1; ln2++)
			mult >>= 1;

		fp->f_nishift = ln2;
	}

	/* alloc a block sized buffer used for all fs transfers */
	fp->f_buf = alloc(fs->fs_bsize);
	inumber = UFS_ROOTINO;
	if ((rc = read_inode(inumber, f)) != 0)
		goto out;

#ifndef LIBSA_FS_SINGLECOMPONENT
	cp = path;
	while (*cp) {

		/*
		 * Remove extra separators
		 */
		while (*cp == '/')
			cp++;
		if (*cp == '\0')
			break;

		/*
		 * Check that current node is a directory.
		 */
		if ((fp->f_di.di_mode & IFMT) != IFDIR) {
			rc = ENOTDIR;
			goto out;
		}

		/*
		 * Get next component of path name.
		 */
		ncp = cp;
		while ((c = *cp) != '\0' && c != '/')
			cp++;

		/*
		 * Look up component in current directory.
		 * Save directory inumber in case we find a
		 * symbolic link.
		 */
#ifndef LIBSA_NO_FS_SYMLINK
		parent_inumber = inumber;
#endif
		rc = search_directory(ncp, cp - ncp, f, &inumber);
		if (rc)
			goto out;

		/*
		 * Open next component.
		 */
		if ((rc = read_inode(inumber, f)) != 0)
			goto out;

#ifndef LIBSA_NO_FS_SYMLINK
		/*
		 * Check for symbolic link.
		 */
		if ((fp->f_di.di_mode & IFMT) == IFLNK) {
			int link_len = fp->f_di.di_size;
			int len;

			len = strlen(cp);

			if (link_len + len > MAXPATHLEN ||
			    ++nlinks > MAXSYMLINKS) {
				rc = ENOENT;
				goto out;
			}

			memmove(&namebuf[link_len], cp, len + 1);

			if (link_len < fs->fs_maxsymlinklen) {
				memcpy(namebuf, fp->f_di.di_db, link_len);
			} else {
				/*
				 * Read file for symbolic link
				 */
				size_t buf_size;
				indp_t	disk_block;

				buf = fp->f_buf;
				rc = block_map(f, (indp_t)0, &disk_block);
				if (rc)
					goto out;

				twiddle();
				rc = DEV_STRATEGY(f->f_dev)(f->f_devdata,
					F_READ, FSBTODB(fs, disk_block),
					fs->fs_bsize, buf, &buf_size);
				if (rc)
					goto out;

				memcpy(namebuf, buf, link_len);
			}

			/*
			 * If relative pathname, restart at parent directory.
			 * If absolute pathname, restart at root.
			 */
			cp = namebuf;
			if (*cp != '/')
				inumber = parent_inumber;
			else
				inumber = (ino32_t)UFS_ROOTINO;

			if ((rc = read_inode(inumber, f)) != 0)
				goto out;
		}
#endif	/* !LIBSA_NO_FS_SYMLINK */
	}

	/*
	 * Found terminal component.
	 */
	rc = 0;

#else /* !LIBSA_FS_SINGLECOMPONENT */

	/* look up component in the current (root) directory */
	rc = search_directory(path, strlen(path), f, &inumber);
	if (rc)
		goto out;

	/* open it */
	rc = read_inode(inumber, f);

#endif /* !LIBSA_FS_SINGLECOMPONENT */

	fp->f_seekp = 0;		/* reset seek pointer */

out:
	if (rc)
		ufs_close(f);
#ifdef FSMOD		/* Only defined for lfs */
	else
		fsmod = FSMOD;
#endif
	return rc;
}
Пример #3
0
BOOL
UfsFile::close()
{
	return ufs_close(_f);
}