Пример #1
0
  // @mfunc Open this <c OMFile>.
  //   @precondition <f !isOpen()>
  //   @precondition <f !isClosed()>
  //   @postcondition <f isOpen()>
void OMFile::open(void)
{
  TRACE("OMFile::open");
  PRECONDITION("Not already open", !isOpen());
  PRECONDITION("Never been opened", !isClosed());
  PRECONDITION("Valid mode", (_mode == readOnlyMode) ||
                             (_mode == writeOnlyMode) ||
                             (_mode == modifyMode));

  if (_isNew) { // new file - create
    ASSERT("Correct mode for new file", _mode != readOnlyMode);
    if (_mode == modifyMode) {
      createModify();
    } else { // _mode == writeOnly
      createWrite();
    }
  } else {      // existing file - open
    ASSERT("Correct mode for existing file", (_mode == readOnlyMode) ||
                                             (_mode == modifyMode));
    if (_mode == readOnlyMode) {
      openRead();
    } else { // _mode == modifyMode
      openModify();
    }
    ASSERT("No root object", _root == 0);
    _root = restoreRoot();
  }

  _isOpen = true;
  POSTCONDITION("Open", isOpen());
}
Пример #2
0
static int
updateMtab(struct MountInfo const *mnt, struct Options const *opt)
{
  int		res = -1;
  int		fd;
  assert(opt->mtab!=0);

  if (opt->do_chroot && fchroot(opt->cur_dir_fd)==-1) {
      perror("secure-mount: fchroot(\".\")");
      return -1;
  }

  fd=open(opt->mtab, O_CREAT|O_APPEND|O_WRONLY, 0644);
  
  if (fd==-1) {
    perror("secure-mount: open(<mtab>)");
    goto err0;
  }

  if (lockf(fd, F_LOCK, 0)==-1) {
    perror("secure-mount: lockf()");
    goto err1;
  }

  if (writeStrX(fd, mnt->src)==-1 ||
      writeStrX(fd, " ")==-1 ||
      writeStrX(fd, mnt->dst)==-1 ||
      writeStrX(fd, mnt->xflag & XFLAG_FILE ? "/" : "")==-1 ||
      writeStrX(fd, mnt->xflag & XFLAG_FILE ? mnt->name : "")==-1 ||
      writeStrX(fd, " ")==-1 ||
      writeStrX(fd, getType(mnt))==-1 ||
      writeStrX(fd, " ")==-1 ||
      writeStrX(fd, mnt->data ? mnt->data : "defaults")==-1 ||
      writeStrX(fd, " 0 0\n")==-1) {
    perror("secure-mount: write()");
    goto err1;
  }

  res = 0;

  err1:	close(fd);
  err0:
  restoreRoot(opt);
  return res;
}
Пример #3
0
  // @mfunc Constructor. Create an <c OMFile> object representing
  //        an existing named external file.
  //   @parm The name of this <c OMFile>.
  //   @parm The access mode of this <c OMFile>.
  //   @parm The <c OMStoredObject> containing the root
  //         <c OMStorable> object.
  //   @parm The <c OMClassFactory> to use to restore objects from
  //         this <c OMFile>.
  //   @parm The <e OMFile::OMLoadMode> for this <c OMFile>.
OMFile::OMFile(const wchar_t* fileName,
               void* clientOnRestoreContext,
               OMStoredObjectEncoding encoding,
               const OMAccessMode mode,
               OMStoredObject* store,
               const OMClassFactory* factory,
               OMDictionary* dictionary,
               const OMLoadMode loadMode)
: _root(0),
  _rootStore(store),
  _dictionary(dictionary),
  _classFactory(factory),
  _referencedProperties(0),
  _mode(mode),
  _loadMode(loadMode),
  _fileName(0),
  _encoding(encoding),
  _clientOnSaveContext(0),
  _clientOnRestoreContext(clientOnRestoreContext),
  _rawStorage(0),
  _isOpen(false),
  _isClosed(false),
  _isNew(false),
  _isValid(true),
  _byteOrder(unspecified)
{
  TRACE("OMFile::OMFile");

  PRECONDITION("Valid file name", validWideString(fileName));
  PRECONDITION("Valid dictionary", _dictionary != 0);
  _fileName = saveWideString(fileName);
  ASSERT("No root object", _root == 0);
  _root = restoreRoot();
  _isOpen = true;
  POSTCONDITION("File is open", _isOpen);
}