예제 #1
0
파일: vmdfs.c 프로젝트: DC-SWAT/DreamShell
/* Common code for both fat_read and fat_write */
static int vmdfs_fat_read(const char *vmdfile, vmd_root_t * root, uint16 * fat_buf) {
    uint16  fat_block, fat_size;

    /* Find the FAT starting block and length */
	fat_block = root->fat_loc;
    fat_size = root->fat_size;

    /* We can't reliably handle VMDs with a larger FAT... */
    if(fat_size > 1) {
        dbglog(DBG_ERROR, "vmdfs_fat_read: VMD has >1 (%d) FAT blocks\n",(int)fat_size);
        return -1;
    }
    
    file_t f = fs_open(vmdfile,O_RDONLY);
	fs_seek(f,fat_block*BLOCK_SIZE,SEEK_SET);
	fs_read(f,(uint8 *)fat_buf,BLOCK_SIZE);
	fs_close(f);
    
    if(!*fat_buf) {
        dbglog(DBG_ERROR, "vmdfs_fat_read: can't read block %d\n",(int)fat_block);
        return -2;
    }

    return 0;
}
예제 #2
0
/// read super block and write to image head
extern void initial_image_hdr(char* device, image_head* image_hdr)
{
    char sig;
    unsigned long long total_sector = 0;
    unsigned long long bused = 0;
    unsigned long long data_sec = 0;
    unsigned long long sec_per_fat = 0;
    unsigned long long cluster_count = 0;
    unsigned long long free_blocks = 0;

    log_mesg(2, 0, 0, fs_opt.debug, "%s: initial_image start\n", __FILE__);
    fs_open(device);

    get_fat_type();

    total_sector = get_total_sector();

    bused = get_used_block();//so I need calculate by myself.

    strncpy(image_hdr->magic, IMAGE_MAGIC, IMAGE_MAGIC_SIZE);
    strncpy(image_hdr->fs, fat_type, FS_MAGIC_SIZE);
    image_hdr->block_size  = (int)fat_sb.sector_size;
    image_hdr->totalblock  = (unsigned long long)total_sector;
    image_hdr->device_size = (unsigned long long)(total_sector * image_hdr->block_size);
    image_hdr->usedblocks  = (unsigned long long)bused;
    log_mesg(2, 0, 0, fs_opt.debug, "%s: Block Size:%i\n", __FILE__, image_hdr->block_size);
    log_mesg(2, 0, 0, fs_opt.debug, "%s: Total Blocks:%llu\n", __FILE__, image_hdr->totalblock);
    log_mesg(2, 0, 0, fs_opt.debug, "%s: Used Blocks:%llu\n", __FILE__, image_hdr->usedblocks);
    log_mesg(2, 0, 0, fs_opt.debug, "%s: Device Size:%llu\n", __FILE__, image_hdr->device_size);

    fs_close();
    log_mesg(2, 0, 0, fs_opt.debug, "%s: initial_image down\n", __FILE__);
}
예제 #3
0
static int io_open (lua_State *L) {
  const char *filename = luaL_checkstring(L, 1);
  const char *mode = luaL_optstring(L, 2, "r");
  int *pf = newfile(L);
  *pf = fs_open(filename, fs_mode2flag(mode));
  return (*pf == FS_OPEN_OK - 1) ? pushresult(L, 0, filename) : 1;
}
예제 #4
0
void read_super_blocks(char* device, file_system_info* fs_info) {
    fs_open(device);
    if (MAGIC == MINIX_SUPER_MAGIC) {
        fs_version = 1;
    } else if (MAGIC == MINIX_SUPER_MAGIC2) {
        fs_version = 1;
    } else if (MAGIC == MINIX2_SUPER_MAGIC) {
        fs_version = 2;
    } else if (MAGIC == MINIX2_SUPER_MAGIC2) {
        fs_version = 2;
    } else if (MAGIC3 == MINIX3_SUPER_MAGIC) {
        fs_version = 3;
    } else
        log_mesg(0, 1, 1, fs_opt.debug, "%s: bad magic number in super-block", __FILE__);

    log_mesg(0, 0, 0, fs_opt.debug, "%s: get_first_zone %lu\n", __FILE__, get_first_zone());
    log_mesg(0, 0, 0, fs_opt.debug, "%s: get_nzones %lu\n", __FILE__, get_nzones());
    log_mesg(0, 0, 0, fs_opt.debug, "%s: zones map size %lu\n", __FILE__, get_nzmaps());
    strncpy(fs_info->fs, minix_MAGIC, FS_MAGIC_SIZE);
    fs_info->block_size  = get_block_size();
    fs_info->totalblock  = get_nzones();
    fs_info->usedblocks  = count_used_block();
    fs_info->device_size = fs_info->totalblock * fs_info->block_size;
    fs_close();
}
예제 #5
0
/*
	sync command
*/
LOCAL	void	cmd_sync(INT ac, B *av[])
{
	ER	er;
	INT	fd;

	if (ac < 2) {
		er = fs_sync();
		if (er < E_OK) {
			P("fs_sync ERR [%#x]\n", er);
		}
	} else {
		fd = fs_open(av[1], O_RDWR);
		if (fd < 0) {
			P("fs_open(%s) ERR [%#x]\n", av[1], fd);
		} else {
			if (ac >= 3 && *av[2] == 'd') {
				er = fs_fdatasync(fd);
				if (er < E_OK) {
					P("fs_fdatasync ERR [%#x]\n", er);
				}
			} else {
				er = fs_fsync(fd);
				if (er < E_OK) {
					P("fs_sync ERR [%#x]\n", er);
				}
			}
		}
	}
}
예제 #6
0
파일: daq.c 프로젝트: cscscheng/telemetry
unsigned int daq_start(char* name, unsigned char ch, unsigned int interval, unsigned int samples) {

    // trwa ju¿ inne zadanie akwizycji - poczekaj na jego zakoñczenie
    if (daq_task.samples > 0) {
        return 0;
    }

    // dalsze sprawdzenie poprawnoœci parametrów
    if ( (ch >= ds_devices_count) || (interval < 1) || (interval > 3600) || (samples < 1) || (samples > 200) || !strlen(name) ) {
        return 0;
    }

    // utwórz plik na wyniki pomiarów
    if (!fs_open(&(daq_task.fp), (unsigned char*)name, 0) || daq_task.fp.size > 0) {
        return 0;
    }

    // kopiuj dane do struktury zadania DAQ
    memcpy((void*)daq_task.name, (void*)name, strlen(name));
    daq_task.ch = ch;
    daq_task.interval = interval;
    daq_task.samples = samples;

    //
    // funkcja daq_pooling() dokonuje od teraz okresowego (co <interval> sekund) pomiaru <samples> próbek
    //

    rs_text_P(PSTR("DAQ: rozpoczeto rejestracje do pliku ")); rs_text((char*)(daq_task.fp.name)); rs_send('\''); rs_newline();

    return 1;
}
예제 #7
0
void do_syscall(TrapFrame *tf) {
 	switch(tf->eax) {
		/* The ``add_irq_handle'' system call is artificial. We use it to 
		 * let user program register its interrupt handlers. But this is 
		 * very dangerous in a real operating system. Therefore such a 
		 * system call never exists in GNU/Linux.
 		 */
		case 0: 
			cli();
			add_irq_handle(tf->ebx, (void*)tf->ecx);
			sti();
			break;

		case SYS_brk: 
			sys_brk(tf); 
			break;

			/* TODO: Add more system calls. */

		case SYS_write: 
			sys_write(tf); 
			break;			  
		case SYS_open : 
			tf->eax = fs_open((char *)tf->ebx, tf->ecx); 
			break;
		case SYS_read : 
			tf->eax = fs_read(tf->ebx, (void *)tf->ecx, tf->edx);
		   	break;
		case SYS_lseek : tf->eax = fs_lseek(tf->ebx, tf->ecx, tf->edx); 
			break;
		case SYS_close : tf->eax = fs_close(tf->ebx);
			break;
		default: panic("Unhandled system call: id = %d", tf->eax);
	}
}
예제 #8
0
파일: hole.c 프로젝트: AMDmi3/neverball
static void hole_init_rc(const char *filename)
{
    fs_file fin;
    char buff[MAXSTR];

    hole   = 0;
    player = 0;
    count  = 0;
    done   = 0;

    /* Load the holes list. */

    if ((fin = fs_open(filename, "r")))
    {
        /* Skip shot and description. */

        if (fs_gets(buff, sizeof (buff), fin) &&
            fs_gets(buff, sizeof (buff), fin))
        {
            /* Read the list. */

            while (fs_gets(buff, sizeof (buff), fin) &&
                   sscanf(buff, "%s %s %d %s",
                          hole_v[count].file,
                          hole_v[count].back,
                          &hole_v[count].par,
                          hole_v[count].song) >= 1)
                count++;
        }

        fs_close(fin);
    }
}
예제 #9
0
파일: reg.c 프로젝트: comrid1987/jb3500
//-------------------------------------------------------------------------
//
//-------------------------------------------------------------------------
static void regloader_Save(p_reg_loader p, uint_t nType)
{
#if FS_ENABLE
	int fd;
	char filename[REGLOADER_FILEOFFSET + 8];
#endif

	switch (nType) {
#if SFS_ENABLE
	case 1:
		sfs_Write(&reg_SfsDev, (p->grp << 16) | p->da, p->data, p->size);
		p->ste = REGLOADER_S_IDLE;
		break;
#endif
#if FS_ENABLE
	case 2:
		regloader_Filename(p, filename);
		fd = fs_open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0);
		if (fd < 0)
			return;
		fs_write(fd, p->data, p->size);
		fs_close(fd);
		p->ste = REGLOADER_S_IDLE;
		regloader_trace("%s\n", filename);
		break;
#endif
	default:
		break;
	}
}
예제 #10
0
파일: set.c 프로젝트: senquack/neverball
static void set_load_hs(void)
{
    struct set *s = SET_GET(sets, curr);
    fs_file fp;

    if ((fp = fs_open(config_cheat() ? s->cheat_scores : s->user_scores, "r")))
    {
        char buf[MAXSTR];

        if (fs_gets(buf, sizeof (buf), fp))
        {
            strip_newline(buf);

            if (sscanf(buf, "version %d", &score_version) == 1)
            {
                switch (score_version)
                {
                case 2: set_load_hs_v2(fp, s, buf, sizeof (buf)); break;
                }
            }
            else
                set_load_hs_v1(fp, s, buf, sizeof (buf));
        }

        fs_close(fp);
    }
}
예제 #11
0
파일: reg.c 프로젝트: comrid1987/jb3500
//-------------------------------------------------------------------------
//
//-------------------------------------------------------------------------
static void regloader_Default(p_reg_loader p, uint_t nType)
{
#if FS_ENABLE
	int fd;
	char filename[REGLOADER_FILEOFFSET + 8];
#endif

	switch (nType) {
#if SFS_ENABLE
	case 1:
		break;
#endif
#if FS_ENABLE
	case 2:
		memcpy(filename, REGLOADER_FILEDIR, REGLOADER_FILEOFFSET);
		filename[REGLOADER_FILEOFFSET] = 'D';
		bcd2str16(p->da, &filename[REGLOADER_FILEOFFSET + 1]);
		bcd2str8(p->grp, &filename[REGLOADER_FILEOFFSET + 5]);
		filename[REGLOADER_FILEOFFSET + 7] = '\0';
		fd = fs_open(filename, O_RDONLY, 0);
		if (fd < 0) {
			bzero(p->data, p->size);
		} else {
			fs_read(fd, p->data, p->size);
			fs_close(fd);
		}
		p->ste = REGLOADER_S_NEED_SYNC;
		break;
#endif
	default:
		break;
	}
}
예제 #12
0
파일: open_close.c 프로젝트: WareX97/K2
int sys_open(char* filename, int flags, int mode) {
	fs_node_t* node = (fs_node_t*) search(filename);
	
	if(node)
		if(S_ISLNK(node->type))
			if(node->link)
				node = node->link;
	
	int ret = 0;
	if((ret = scan(node, flags)) < 0) 
		return ret;
		
	if(ret == 1)
		node = create(filename, mode);	
				
	if(!node)
		return 0;
		
	if(fs_open(node, flags) == -1)
		return -EACCES;
	
	int i;
	for(i = 0; i < PROC_MAX_FILES; i++) {
		if(current_task->fd[i] == 0)
			break;
	}

	if(i == PROC_MAX_FILES)
		return -EMFILE;
				
	current_task->fd[i] = (void*) node;
	return i;
}
예제 #13
0
	void load() {
		file_t		d;
		dirent_t	*de;
		node_t		*aux;

		total=0;
		d = fs_open(srcdir, O_RDONLY | O_DIR);
		if (!d) {
			printf("Can't open source directory (%s)\n", srcdir);
			ptr->next=NULL;
		} else {
			aux=ptr;
			strcpy(aux->name, "ALL FILES   ");
			aux->size=0;
			aux->next=(node_t *)malloc(sizeof(node_t));
			while ( (de = fs_readdir(d)) ) {
				if ((de->size >= 108) && (strstr(de->name, ".VMS") == NULL)) {
					total++;
					aux=aux->next;
					strcpy(aux->name, de->name);
					aux->size=de->size;
					aux->next=(node_t *)malloc(sizeof(node_t));
				}
			}
			free(aux->next);
			aux->next=NULL;
		}
		fs_close(d);
	}
예제 #14
0
static int course_load(struct course *course, const char *filename)
{
    fs_file fin;
    int rc = 0;

    memset(course, 0, sizeof (*course));

    strncpy(course->holes, filename, MAXSTR - 1);

    if ((fin = fs_open(filename, "r")))
    {
        if (fs_gets(course->shot, sizeof (course->shot), fin) &&
            fs_gets(course->desc, sizeof (course->desc), fin))
        {
            strip_newline(course->shot);
            strip_newline(course->desc);

            rc = 1;
        }

        fs_close(fin);
    }

    return rc;
}
/**
 * Writes the supplied boot status to the flash file system.  The boot status
 * contains the current state of an in-progress image copy operation.
 *
 * @param status                The boot status base to write.
 * @param entries               The array of boot status entries to write.
 * @param num_areas             The number of flash areas capable of storing
 *                                  image data.  This is equal to the length of
 *                                  the entries array.
 *
 * @return                      0 on success; nonzero on failure.
 */
int
boot_write_status(const struct boot_status *status,
                  const struct boot_status_entry *entries,
                  int num_areas)
{
    struct fs_file *file;
    int rc;

    rc = fs_open(BOOT_PATH_STATUS, FS_ACCESS_WRITE | FS_ACCESS_TRUNCATE, &file);
    if (rc != 0) {
        rc = BOOT_EFILE;
        goto done;
    }

    rc = fs_write(file, status, sizeof *status);
    if (rc != 0) {
        rc = BOOT_EFILE;
        goto done;
    }

    rc = fs_write(file, entries, num_areas * sizeof *entries);
    if (rc != 0) {
        rc = BOOT_EFILE;
        goto done;
    }

    rc = 0;

done:
    fs_close(file);
    return rc;
}
예제 #16
0
파일: set.c 프로젝트: senquack/neverball
void set_store_hs(void)
{
    const struct set *s = SET_GET(sets, curr);
    fs_file fp;

    if ((fp = fs_open(config_cheat() ? s->cheat_scores : s->user_scores, "w")))
    {
        int i;

        fs_printf(fp, "version %d\nset %s\n", SCORE_VERSION, s->id);

        put_score(fp, &s->time_score);
        put_score(fp, &s->coin_score);

        for (i = 0; i < s->count; i++)
        {
            const struct level *l = &level_v[i];

            int flags = 0;

            if (l->is_locked)    flags |= LEVEL_LOCKED;
            if (l->is_completed) flags |= LEVEL_COMPLETED;

            fs_printf(fp, "level %d %d %s\n", flags, l->version_num, l->file);

            put_score(fp, &l->scores[SCORE_TIME]);
            put_score(fp, &l->scores[SCORE_GOAL]);
            put_score(fp, &l->scores[SCORE_COIN]);
        }

        fs_close(fp);
    }
}
예제 #17
0
파일: plugin.c 프로젝트: pcercuei/dcplaya
static int r_plugin_path_load(char *path, unsigned int level)
{
  dirent_t *de;
  int count = 0;
  int fd = -1;
  char *path_end = 0;

  SDDEBUG(">> %s(%2d,[%s])\n", __FUNCTION__, level, path);
  SDINDENT;

  if (level == 0) {
    goto error;
  }

  fd = fs_open(path, O_RDONLY | O_DIR);
  if (fd<0) {
    count = -1;
    goto error;
  }

  path_end = path + strlen(path);
  path_end[0] = '/';
  path_end[1] = 0;

  while (de = fs_readdir(fd), de) {
    int type;

    type = filetype_get(de->name, de->size);
    /* 	SDDEBUG("[%s] : %04x\n", de->name, type); */

    if (type == filetype_dir) {
      int cnt;
      strcpy(path_end+1, de->name);
      cnt = r_plugin_path_load(path, level-1);
      count += (cnt > 0) ? cnt : 0;
      continue;
    }

    if (type != filetype_lef) {
      continue;
    }

    strcpy(path_end+1, de->name);
    count += plugin_load_and_register(path);
  }

 error:
  if (fd>=0) {
    fs_close(fd);
  }
  if (path_end) {
    *path_end = 0;
  }
  
  SDUNINDENT;
  SDDEBUG("<< %s(%2d,[%s]) = %d\n", __FUNCTION__, level, path, count);

  return count;
}
예제 #18
0
파일: elf.c 프로젝트: jdetter/Chronos
int elf_check_binary_path(const char* path)
{
	inode ino = fs_open(path, O_RDONLY, 0644, 0, 0);
	if(!ino) return -1;
	int result = elf_check_binary_inode(ino);
	fs_close(ino);
	return result;
}
예제 #19
0
파일: fs.c 프로젝트: 8cbx/ljudge
char *
fs_nread (const char *path, int len) {
  FILE *file = fs_open(path, FS_OPEN_READ);
  if (NULL == file) return NULL;
  char *buffer = fs_fnread(file, len);
  fs_close(file);
  return buffer;
}
예제 #20
0
파일: fs.c 프로젝트: 8cbx/ljudge
int
fs_nwrite (const char *path, const char *buffer, int len) {
  FILE *file = fs_open(path, FS_OPEN_WRITE);
  if (NULL == file) return -1;
  int result = fs_fnwrite(file, buffer, len);
  fclose(file);
  return result;
}
예제 #21
0
파일: fs.c 프로젝트: 8cbx/ljudge
char *
fs_read (const char *path) {
  FILE *file = fs_open(path, FS_OPEN_READ);
  if (NULL == file) return NULL;
  char *data = fs_fread(file);
  fclose(file);
  return data;
}
예제 #22
0
static void *image_load_jpg(const char *filename, int *width,
                                                  int *height,
                                                  int *bytes)
{
#if 0
    unsigned char *p = NULL;
    fs_file fp;

    if ((fp = fs_open(filename, "r")))
    {
        struct jpeg_decompress_struct cinfo;
        struct jpeg_error_mgr         jerr;

        int w, h, b, i = 0;

        /* Initialize the JPG decompressor. */

        cinfo.err = jpeg_std_error(&jerr);
        jpeg_create_decompress(&cinfo);

        /* Set up a VFS source manager. */

        fs_jpg_src(&cinfo, fp);

        /* Grab the JPG header info. */

        jpeg_read_header(&cinfo, TRUE);
        jpeg_start_decompress(&cinfo);

        w = cinfo.output_width;
        h = cinfo.output_height;
        b = cinfo.output_components;

        /* Allocate the final pixel buffer and copy pixels there. */

        if ((p = (unsigned char *) malloc (w * h * b)))
        {
            while (cinfo.output_scanline < cinfo.output_height)
            {
                unsigned char *buffer = p + w * b * (h - i - 1);
                i += jpeg_read_scanlines(&cinfo, &buffer, 1);
            }

            if (width)  *width  = w;
            if (height) *height = h;
            if (bytes)  *bytes  = b;
        }

        jpeg_finish_decompress(&cinfo);
        jpeg_destroy_decompress(&cinfo);

        fs_close(fp);
    }

    return p;
#endif
    return NULL;
}
예제 #23
0
파일: fs.c 프로젝트: 2trill2spill/freebsd
/* This implements the fs_library_vtable_t.open_for_recovery() API. */
static svn_error_t *
fs_open_for_recovery(svn_fs_t *fs,
                     const char *path,
                     svn_mutex__t *common_pool_lock,
                     apr_pool_t *pool,
                     apr_pool_t *common_pool)
{
  svn_error_t * err;
  svn_revnum_t youngest_rev;
  apr_pool_t * subpool = svn_pool_create(pool);

  /* Recovery for FSFS is currently limited to recreating the 'current'
     file from the latest revision. */

  /* The only thing we have to watch out for is that the 'current' file
     might not exist or contain garbage.  So we'll try to read it here
     and provide or replace the existing file if we couldn't read it.
     (We'll also need it to exist later anyway as a source for the new
     file's permissions). */

  /* Use a partly-filled fs pointer first to create 'current'. */
  fs->path = apr_pstrdup(fs->pool, path);

  SVN_ERR(initialize_fs_struct(fs));

  /* Figure out the repo format and check that we can even handle it. */
  SVN_ERR(svn_fs_fs__read_format_file(fs, subpool));

  /* Now, read 'current' and try to patch it if necessary. */
  err = svn_fs_fs__youngest_rev(&youngest_rev, fs, subpool);
  if (err)
    {
      const char *file_path;

      /* 'current' file is missing or contains garbage.  Since we are trying
       * to recover from whatever problem there is, being picky about the
       * error code here won't do us much good.  If there is a persistent
       * problem that we can't fix, it will show up when we try rewrite the
       * file a few lines further below and we will report the failure back
       * to the caller.
       *
       * Start recovery with HEAD = 0. */
      svn_error_clear(err);
      file_path = svn_fs_fs__path_current(fs, subpool);

      /* Best effort to ensure the file exists and is valid.
       * This may fail for r/o filesystems etc. */
      SVN_ERR(svn_io_remove_file2(file_path, TRUE, subpool));
      SVN_ERR(svn_io_file_create_empty(file_path, subpool));
      SVN_ERR(svn_fs_fs__write_current(fs, 0, 1, 1, subpool));
    }

  uninitialize_fs_struct(fs);
  svn_pool_destroy(subpool);

  /* Now open the filesystem properly by calling the vtable method directly. */
  return fs_open(fs, path, common_pool_lock, pool, common_pool);
}
예제 #24
0
파일: elf.c 프로젝트: jdetter/Chronos
uintptr_t elf_load_binary_path(const char* path, pgdir_t* pgdir, 
	uintptr_t* start, uintptr_t* end, int user)
{
        inode ino = fs_open(path, O_RDONLY, 0644, 0x0, 0x0);
        if(!ino) return 0;
        uintptr_t result = elf_load_binary_inode(ino, pgdir, start, end, user);
        fs_close(ino);
        return result;
}
/**
 * Reads the boot status from the flash file system.  The boot status contains
 * the current state of an interrupted image copy operation.  If the boot
 * status is not present in the file system, the implication is that there is
 * no copy operation in progress.
 *
 * @param out_status            On success, the boot status gets written here.
 * @param out_entries           On success, the array of boot entries gets
 *                                  written here.
 * @param num_areas             The number of flash areas capable of storing
 *                                  image data.  This is equal to the length of
 *                                  the out_entries array.
 *
 * @return                      0 on success; nonzero on failure.
 */
int
boot_read_status(struct boot_status *out_status,
                 struct boot_status_entry *out_entries,
                 int num_areas)
{
    struct fs_file *file;
    uint32_t bytes_read;
    int rc;
    int i;

    rc = fs_open(BOOT_PATH_STATUS, FS_ACCESS_READ, &file);
    if (rc != 0) {
        rc = BOOT_EBADSTATUS;
        goto done;
    }

    rc = fs_read(file, sizeof *out_status, out_status, &bytes_read);
    if (rc != 0 || bytes_read != sizeof *out_status) {
        rc = BOOT_EBADSTATUS;
        goto done;
    }

    rc = fs_read(file, num_areas * sizeof *out_entries, out_entries,
                   &bytes_read);
    if (rc != 0 || bytes_read != num_areas * sizeof *out_entries) {
        rc = BOOT_EBADSTATUS;
        goto done;
    }

    if (out_status->bs_img1_length == 0xffffffff) {
        out_status->bs_img1_length = 0;
    }
    if (out_status->bs_img2_length == 0xffffffff) {
        out_status->bs_img2_length = 0;
    }

    for (i = 0; i < num_areas; i++) {
        if (out_entries[i].bse_image_num == 0 &&
            out_status->bs_img1_length == 0) {

            rc = BOOT_EBADSTATUS;
            goto done;
        }
        if (out_entries[i].bse_image_num == 1 &&
            out_status->bs_img2_length == 0) {

            rc = BOOT_EBADSTATUS;
            goto done;
        }
    }

    rc = 0;

done:
    fs_close(file);
    return rc;
}
예제 #26
0
static void
boot_test_util_verify_status_clear(void)
{
    struct fs_file *file;
    int rc;

    rc = fs_open(BOOT_PATH_STATUS, FS_ACCESS_READ, &file);
    TEST_ASSERT(rc == FS_ENOENT);
}
예제 #27
0
// Lua: compile(filename) -- compile lua file into lua bytecode, and save to .lc
static int node_compile( lua_State* L )
{
  Proto* f;
  int file_fd = FS_OPEN_OK - 1;
  size_t len;
  const char *fname = luaL_checklstring( L, 1, &len );
  if ( len > FS_NAME_MAX_LENGTH )
    return luaL_error(L, "filename too long");

  char output[FS_NAME_MAX_LENGTH];
  c_strcpy(output, fname);
  // check here that filename end with ".lua".
  if (len < 4 || (c_strcmp( output + len - 4, ".lua") != 0) )
    return luaL_error(L, "not a .lua file");

  output[c_strlen(output) - 2] = 'c';
  output[c_strlen(output) - 1] = '\0';
  NODE_DBG(output);
  NODE_DBG("\n");
  if (luaL_loadfsfile(L, fname) != 0) {
    return luaL_error(L, lua_tostring(L, -1));
  }

  f = toproto(L, -1);

  int stripping = 1;      /* strip debug information? */

  file_fd = fs_open(output, fs_mode2flag("w+"));
  if (file_fd < FS_OPEN_OK)
  {
    return luaL_error(L, "cannot open/write to file");
  }

  lua_lock(L);
  int result = luaU_dump(L, f, writer, &file_fd, stripping);
  lua_unlock(L);

  if (fs_flush(file_fd) < 0) {   // result codes aren't propagated by flash_fs.h
    // overwrite Lua error, like writer() does in case of a file io error
    result = 1;
  }
  fs_close(file_fd);
  file_fd = FS_OPEN_OK - 1;

  if (result == LUA_ERR_CC_INTOVERFLOW) {
    return luaL_error(L, "value too big or small for target integer type");
  }
  if (result == LUA_ERR_CC_NOTINTEGER) {
    return luaL_error(L, "target lua_Number is integral but fractional value found");
  }
  if (result == 1) {    // result status generated by writer() or fs_flush() fail
    return luaL_error(L, "writing to file failed");
  }

  return 0;
}
/*..........................................................................*/
static struct fs_file *get_404_file(char const **ppURI) {
    struct fs_file *file;

    *ppURI = "/404.html";
    file = fs_open(*ppURI);
    if (file == NULL) {
        /* 404.html doesn't exist. Try 404.htm instead. */
        *ppURI = "/404.htm";
        file = fs_open(*ppURI);
        if (file == NULL) {
            /* 404.htm doesn't exist either. Indicate to the caller that
            * it should send back a default 404 page.
            */
            *ppURI = NULL;
        }
    }

    return (file);
}
예제 #29
0
void read_super_blocks(char* device, file_system_info* fs_info)
{
    fs_open(device);
    strncpy(fs_info->fs, reiserfs_MAGIC, FS_MAGIC_SIZE);
    fs_info->block_size  = fs->super->s_v1.sb_block_size;
    fs_info->totalblock  = fs->super->s_v1.sb_block_count;
    fs_info->usedblocks  = fs->super->s_v1.sb_block_count - fs->super->s_v1.sb_free_blocks;
    fs_info->device_size = fs_info->block_size * fs_info->totalblock;
    fs_close();
}
예제 #30
0
파일: fs.c 프로젝트: 8cbx/ljudge
size_t
fs_size (const char *path) {
  size_t size;
  FILE *file = fs_open(path, FS_OPEN_READ);
  if (NULL == file) return -1;
  fseek(file, 0, SEEK_END);
  size = ftell(file);
  fs_close(file);
  return size;
}