Exemplo n.º 1
0
static int
open_rdonly(const char * const path,
            tpath_entry *pe,
            int flags)
{
        return open_existing(path, pe, flags);
}
Exemplo n.º 2
0
Arquivo: file.c Projeto: HarryR/sanos
int dfs_open(struct file *filp, char *name) {
  struct filsys *fs;
  struct inode *inode;
  int rc;

  fs = (struct filsys *) filp->fs->data;

  switch (filp->flags & (O_CREAT | O_EXCL | O_TRUNC | O_SPECIAL)) {
    case 0:
    case O_EXCL:
      // Open existing file
      rc = open_existing(fs, name, &inode);
      break;

    case O_CREAT:
      // Open file, create new file if it does not exists
      rc = open_always(fs, name, filp->mode, &inode);
      break;

    case O_CREAT | O_EXCL:
    case O_CREAT | O_TRUNC | O_EXCL:
      // Create new file, fail if it exists
      rc = create_new(fs, name, NOINODE, filp->mode, &inode);
      filp->flags |= F_MODIFIED;
      break;

    case O_TRUNC:
    case O_TRUNC | O_EXCL:
      // Open and truncate existing file
      rc = truncate_existing(fs, name, &inode);
      filp->flags |= F_MODIFIED;
      break;

    case O_CREAT | O_TRUNC:
      // Create new file, unlink existing file if it exists
      rc = create_always(fs, name, filp->mode, &inode);
      filp->flags |= F_MODIFIED;
      break;

    case O_SPECIAL:
      // Create new file with special inode number
      rc = create_new(fs, name, filp->flags >> 24, filp->mode, &inode);
      filp->flags |= F_MODIFIED;
      break;

    default:
      return -EINVAL;
  }

  if (rc < 0) return rc;

  if (filp->flags & O_APPEND) filp->pos = inode->desc->size;

  filp->data = inode;
  filp->mode = inode->desc->mode;
  filp->owner = inode->desc->uid;
  filp->group = inode->desc->gid;

  return 0;
}
Exemplo n.º 3
0
Arquivo: file.c Projeto: HarryR/sanos
int dfs_open(struct file *filp, char *name, int mode)
{
  struct filsys *fs;
  struct inode *inode;
  int len;

  fs = (struct filsys *) filp->fs->data;
  len = strlen(name);

  switch (filp->flags & (VFS_O_CREAT | VFS_O_EXCL | VFS_O_TRUNC | VFS_O_SPECIAL))
  {
    case 0:
    case VFS_O_EXCL:
      // Open existing file
      inode = open_existing(fs, name, len);
      break;

    case VFS_O_CREAT:
      // Open file, create new file if it does not exists
      inode = open_always(fs, name, len, mode);
      break;

    case VFS_O_CREAT | VFS_O_EXCL:
    case VFS_O_CREAT | VFS_O_TRUNC | VFS_O_EXCL:
      // Create new file, unlink existing file if it exists
      inode = create_new(fs, name, len, mode);
      break;

    case VFS_O_TRUNC:
    case VFS_O_TRUNC | VFS_O_EXCL:
      // Open and truncate existing file
      inode = truncate_existing(fs, name, len);
      filp->flags |= F_MODIFIED;
      break;

    case VFS_O_CREAT | VFS_O_TRUNC:
      // Create new file, fail if it exists
      inode = create_always(fs, name, len, -1, mode);
      break;

    case VFS_O_SPECIAL:
      // Create new file with special inode number
      inode = create_always(fs, name, len, filp->flags >> 24, mode);
      break;

    default:
      return -1;
  }

  if (!inode) return -1;

  if (filp->flags & VFS_O_APPEND) filp->pos = (int) inode->desc->size;
  filp->data = inode;

  return 0;
}
Exemplo n.º 4
0
static int
open_wronly(const char * const path,
            tpath_entry *pe,
            int flags)
{
        int ret;

        ret = open_existing(path, pe, flags);
        if (0 == ret)
                pe->flag = FLAG_DIRTY;

        return ret;
}
Exemplo n.º 5
0
static int
open_wronly(const char * const path,
            pentry_t *pe,
            int flags)
{
        int ret;

        ret = open_existing(path, pe, flags);
        if (0 == ret)
                pentry_set_flag(pe, FLAG_DIRTY);

        return ret;
}
Exemplo n.º 6
0
static void m2i_open_write(path_t *path, cbmdirent_t *dent, uint8_t type, buffer_t *buf, uint8_t append) {
  uint16_t offset;
  uint8_t *str;
  uint8_t *nameptr;
  uint8_t i;
  FRESULT res;

  /* Check for read-only image file */
  if (!(partition[path->part].imagehandle.flag & FA_WRITE)) {
    set_error(ERROR_WRITE_PROTECT);
    return;
  }

  if (append) {
    open_existing(path, dent, type, buf, 1);
  } else {
    if (check_invalid_name(dent->name)) {
      set_error(ERROR_SYNTAX_JOKER);
      return;
    }

    /* Find an empty entry */
    offset = find_empty_entry(path->part);
    if (offset < M2I_ENTRY_OFFSET)
      return;

    memset(ops_scratch, ' ', sizeof(ops_scratch));
    str = ops_scratch;

    switch (type & TYPE_MASK) {
    case TYPE_DEL:
      *str++ = 'D';
      break;

    case TYPE_SEQ:
      *str++ = 'S';
      break;

    case TYPE_PRG:
      *str++ = 'P';
      break;

    case TYPE_USR:
      *str++ = 'U';
      break;

    default:
      /* Unknown type - play it safe, don't create a file */
      return;
    }

    *str++ = ':';

    /* Generate a FAT name */
    for (i=0;i<8;i++) {
      *str++ = '0';
    }
    *str = 0;

    do {
      FILINFO finfo;

      finfo.lfn = NULL;
      /* See if it's already there */
      res = f_stat(&partition[path->part].fatfs, ops_scratch + M2I_FATNAME_OFFSET, &finfo);
      if (res == FR_OK) {
        str = ops_scratch + M2I_FATNAME_OFFSET+7;
        /* Increment name */
        while (1) {
          if (++(*str) > '9') {
            *str-- = '0';
            continue;
          }
          break;
        }
      }
    } while (res == FR_OK);

    if (res != FR_NO_FILE)
      return;

    /* Copy the CBM file name */
    nameptr = dent->name;
    str = ops_scratch + M2I_CBMNAME_OFFSET;
    while (*nameptr)
      *str++ = *nameptr++;

    /* Update dent with the new FAT name */
    ustrcpy(dent->pvt.fat.realname, ops_scratch + M2I_FATNAME_OFFSET);

    /* Finish creating the M2I entry */
    ops_scratch[M2I_FATNAME_OFFSET + 8]  = ' ';
    ops_scratch[M2I_FATNAME_OFFSET + 12] = ':';
    ops_scratch[M2I_CBMNAME_OFFSET + CBM_NAME_LENGTH] = 13;
    ops_scratch[M2I_CBMNAME_OFFSET + CBM_NAME_LENGTH + 1] = 10;

    /* Write it */
    if (image_write(path->part, offset, ops_scratch, M2I_ENTRY_LEN, 1))
      return;

    /* Write the actual file - always without P00 header */
    fat_open_write(path, dent, TYPE_RAW, buf, append);

    /* Abort on error */
    if (current_error) {
      /* No error checking here. Either it works or everything has failed. */
      ops_scratch[0] = '-';
      image_write(path->part, offset, ops_scratch, 1, 1);
    }
  }
}
Exemplo n.º 7
0
static void m2i_open_read(path_t *path, cbmdirent_t *dent, buffer_t *buf) {
  open_existing(path, dent, TYPE_RAW, buf, 0);
}