⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mfs_filesys_util.c

📁 实用的程序代码
💻 C
字号:
//////////////////////////////////////////////////////////////////////////////////// Copyright (c) 2002 Xilinx, Inc.  All rights reserved.//// Xilinx, Inc.// // File   : mfs_filesys_util.c// Date   : 2002, March 20.// Company: Xilinx// Group  : Emerging Software Technologies//// Description : //// $Header: /devl/xcs/repo/env/Jobs/MDT/sw/os/xilmfs/src/mfs_filesys_util.c,v 1.1 2002/04/08 20:40:54 sid Exp $//////////////////////////////////////////////////////////////////////////////////#include <stdio.h>#include "xilmfs.h"#ifndef MICROBLAZE//#define printnum(x) printf("%d ", (x)) //disabled for simulation#define printnum(x) #define print(x) puts((x))#define inbyte() fgetc(stdin)#endif/** * list contents of current directory  * return 1 on success and 0 on failure */int mfs_ls() {  int numentriesleft = mfs_file_system[mfs_current_dir].u.dir_data.num_entries;  int dir_block = mfs_current_dir;  int dir_index = 0;  printnum(mfs_file_system[mfs_current_dir].u.dir_data.num_entries - mfs_file_system[mfs_current_dir].u.dir_data.num_deleted);  while (numentriesleft > 0) {    if (dir_index == MFS_MAX_LOCAL_ENT) { /* move to the next dir block */      dir_index = 0;      dir_block = mfs_file_system[dir_block].next_block;    }    if (mfs_file_system[dir_block].u.dir_data.dir_ent[dir_index].deleted != 'y' ) {      print(mfs_file_system[dir_block].u.dir_data.dir_ent[dir_index].name);    }    dir_index += 1;    numentriesleft--;  }  print("\n");  return 1;}/** * print the file to stdout * return 1 on success, 0 on failure */int mfs_cat(char *filename) {  char buf2[513];  int tmp;  int fdr = mfs_file_open(filename, MFS_MODE_READ);  if (fdr < 0) { /* error opening file */    print("Cannot open file\n");    return 0;  }  while((tmp= mfs_file_read(fdr, buf2, 512))== 512){    buf2[512]='\0';    print(buf2);  }  if (tmp > 0) {    buf2[tmp] = '\0';    print(buf2);  }  tmp = mfs_file_close(fdr);  print("\n");  return 1;}/** * copy from stdin to named file */int mfs_copy_stdin_to_file(char *filename) {  char buf2[512];  int offset = 0;  int c;  int fdw = mfs_file_open(filename, MFS_MODE_CREATE);  if (fdw < 0) { /* cannot open file */    print ("Cannot open file\n");    return 0;  }  while ((c = inbyte()) != EOF) {    buf2[offset++] = c;    if (offset == 512) {      mfs_file_write(fdw, buf2, 512);      offset = 0;    }  }  if (offset != 512) { /* write the last buffer */    mfs_file_write(fdw, buf2, offset);  }  mfs_file_close(fdw);  return 1;}/** * copy from_file to to_file * to_file is created new * copy fails if to_file exists already * copy fails is from_file or to_file cannot be opened * return 1 on success, 0 on failure */int mfs_file_copy(char *from_file, char *to_file) {  char buf2[512];  int tmp;  int fdr = mfs_file_open(from_file, MFS_MODE_READ);  int fdw = mfs_file_open(to_file, MFS_MODE_CREATE);  if (fdr < 0 || fdw < 0) { /* error opening file */    print("Cannot open file to read/write\n");    mfs_file_close(fdr);    mfs_file_close(fdw);    return 0;  }  while((tmp= mfs_file_read(fdr, buf2, 512))== 512){    mfs_file_write(fdw, buf2, 512);  }  if (tmp > 0) {    mfs_file_write(fdw, buf2, tmp);  }  tmp = mfs_file_close(fdr);  tmp = mfs_file_close(fdw);  return 1;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -