Exemplo n.º 1
0
mode_t symlink_mode(const char *path) {
  if (path == NULL) {
    return 0;
  }

  return _symlink(path, (ino_t) 0, 0);
}
Exemplo n.º 2
0
mode_t file_mode(const char *path) {
  struct stat sbuf;
  mode_t res = 0;

  if (path == NULL) {
    return res;
  }

  pr_fs_clear_cache2(path);
  if (pr_fsio_lstat(path, &sbuf) != -1) {
    if (S_ISLNK(sbuf.st_mode)) {
      res = _symlink(path, (ino_t) 0, 0);

      if (res == 0) {
	/* a dangling symlink, but it exists to rename or delete. */
	res = sbuf.st_mode;
      }

    } else {
      res = sbuf.st_mode;
    }
  }

  return res;
}
Exemplo n.º 3
0
mode_t file_mode(const char *path) {
  struct stat st;
  mode_t mode = 0;

  if (path == NULL) {
    errno = EINVAL;
    return mode;
  }

  pr_fs_clear_cache2(path);
  if (pr_fsio_lstat(path, &st) >= 0) {
    if (S_ISLNK(st.st_mode)) {
      mode = _symlink(path, (ino_t) 0, 0);
      if (mode == 0) {
	/* a dangling symlink, but it exists to rename or delete. */
	mode = st.st_mode;
      }

    } else {
      mode = st.st_mode;
    }
  }

  return mode;
}
Exemplo n.º 4
0
/* Return the mode (including the file type) of the file pointed to by symlink
 * PATH, or 0 if it doesn't exist. Catch symlink loops using LAST_INODE and
 * RCOUNT.
 */
static mode_t _symlink(const char *path, ino_t last_inode, int rcount) {
  char buf[PR_TUNABLE_PATH_MAX + 1];
  struct stat sbuf;
  int i;

  if (++rcount >= 32) {
    errno = ELOOP;
    return 0;
  }

  memset(buf, '\0', sizeof(buf));

  i = pr_fsio_readlink(path, buf, sizeof(buf) - 1);
  if (i == -1)
    return (mode_t)0;
  buf[i] = '\0';

  pr_fs_clear_cache2(buf);
  if (pr_fsio_lstat(buf, &sbuf) != -1) {
    if (sbuf.st_ino && (ino_t) sbuf.st_ino == last_inode) {
      errno = ELOOP;
      return 0;
    }

    if (S_ISLNK(sbuf.st_mode)) {
      return _symlink(buf, (ino_t) sbuf.st_ino, rcount);
    }

    return sbuf.st_mode;
  }

  return 0;
}
Exemplo n.º 5
0
/* Return the mode (including the file type) of the file pointed to by symlink
 * PATH, or 0 if it doesn't exist. Catch symlink loops using LAST_INODE and
 * RCOUNT.
 */
static mode_t _symlink(const char *path, ino_t last_inode, int rcount) {
  char buf[PR_TUNABLE_PATH_MAX + 1];
  struct stat st;
  int i;

  if (++rcount >= PR_FSIO_MAX_LINK_COUNT) {
    errno = ELOOP;
    return 0;
  }

  memset(buf, '\0', sizeof(buf));

  i = pr_fsio_readlink(path, buf, sizeof(buf) - 1);
  if (i < 0) {
    return (mode_t) 0;
  }
  buf[i] = '\0';

  pr_fs_clear_cache2(buf);
  if (pr_fsio_lstat(buf, &st) >= 0) {
    if (st.st_ino > 0 &&
        (ino_t) st.st_ino == last_inode) {
      errno = ELOOP;
      return 0;
    }

    if (S_ISLNK(st.st_mode)) {
      return _symlink(buf, (ino_t) st.st_ino, rcount);
    }

    return st.st_mode;
  }

  return 0;
}
Exemplo n.º 6
0
mode_t symlink_mode2(pool *p, const char *path) {
  if (path == NULL) {
    errno = EINVAL;
    return 0;
  }

  return _symlink(p, path, (ino_t) 0, 0);
}
Exemplo n.º 7
0
    int
    symlink(const char *oldpath,
            const char *newpath)
    {
      const fuse_context        *fc     = fuse_get_context();
      const Config              &config = Config::get(fc);
      const ugid::SetResetGuard  ugid(fc->uid,fc->gid);
      const rwlock::ReadGuard    readlock(&config.srcmountslock);

      return _symlink(config.symlink,
                      config.srcmounts,
                      config.minfreespace,
                      oldpath,
                      newpath);
    }
Exemplo n.º 8
0
/**
 * Interrupt 80h. Handles the system calls.
 *
 *  @param regs Pointer to struct containing micro's registers.
 */
void int80(registers* regs) {

    switch (regs->eax) {

        case _SYS_READ:
            regs->eax = _read((unsigned int)regs->ebx, (char*)translate(regs->ecx), (size_t)regs->edx);
            break;
        case _SYS_WRITE:
            regs->eax = _write((unsigned int)regs->ebx, (const char*)translate(regs->ecx), (size_t)regs->edx);
            break;
        case _SYS_TIME:
            regs->eax = _time((time_t*)translate(regs->ebx));
            break;
        case _SYS_IOCTL:
            regs->eax = _ioctl(regs->ebx, regs->ecx, (void*)translate(regs->edx));
            break;
        case _SYS_TICKS:
            regs->eax = _getTicksSinceStart();
            break;
        case _SYS_YIELD:
            // This just makes sure we call the scheduler again, for now
            break;
        case _SYS_EXIT:
            _exit();
            break;
        case _SYS_GETPID:
            regs->eax = _getpid();
            break;
        case _SYS_GETPPID:
            regs->eax = _getppid();
            break;
        case _SYS_RUN:
            regs->eax = _run((EntryPoint) translate(regs->ebx), (char*) translate(regs->ecx), regs->edx);
            break;
        case _SYS_WAIT:
            regs->eax = _wait();
            break;
        case _SYS_KILL:
            _kill((pid_t) regs->ebx);
            break;
        case _SYS_PINFO:
            regs->eax = _pinfo((struct ProcessInfo*)translate(regs->ebx), (size_t)regs->ecx);
            break;
        case _SYS_SLEEP:
            _sleep(regs->ebx);
            break;
        case _SYS_NICE:
            regs->eax = _nice(regs->ebx);
            break;
        case _SYS_RENICE:
            regs->eax = _renice(regs->ebx, regs->ecx);
            break;
        case _SYS_CLOSE:
            regs->eax = _close(regs->ebx);
            break;
        case _SYS_OPEN:
            regs->eax = _open((char*)translate(regs->ebx), regs->ecx, regs->edx);
            break;
        case _SYS_CREAT:
            regs->eax = _creat((char*)translate(regs->ebx), regs->ecx);
            break;
        case _SYS_MKDIR:
            regs->eax = _mkdir((const char*)translate(regs->ebx), regs->ecx);
            break;
        case _SYS_RMDIR:
            regs->eax = _rmdir((const char*)translate(regs->ebx));
            break;
        case _SYS_UNLINK:
            regs->eax = _unlink((const char*)translate(regs->ebx));
            break;
        case _SYS_RENAME:
            regs->eax = _rename((const char*)translate(regs->ebx), (const char*)translate(regs->ecx));
            break;
        case _SYS_CHDIR:
            regs->eax = _chdir((const char*)translate(regs->ebx));
            break;
        case _SYS_GETCWD:
            regs->eax = _getcwd((char*)translate(regs->ebx), (size_t)regs->ecx);
            break;
        case _SYS_READDIR:
            regs->eax = _readdir(regs->ebx, (struct fs_DirectoryEntry*)translate(regs->ecx), regs->edx);
            break;
        case _SYS_SETPPERSONA:
            _setProcessPersona(regs->ebx, regs->ecx, regs->edx);
            break;
        case _SYS_GETPPERSONA:
            _getProcessPersona(regs->ebx, (int*)translate(regs->ecx), (int*) translate(regs->edx));
            break;
        case _SYS_SYMLINK:
            regs->eax = _symlink((const char *)translate(regs->ebx), (const char *)translate(regs->ecx));
            break;
        case _SYS_MKFIFO:
            regs->eax = _mkfifo((const char*)translate(regs->ebx));
            break;
        case _SYS_CHMOD:
            regs->eax = _chmod(regs->ebx, (const char*)translate(regs->ecx));
            break;
        case _SYS_STAT:
            regs->eax = _stat((const char*)translate(regs->ebx), (struct stat*)translate(regs->ecx));
            break;
        case _SYS_CHOWN:
            regs->eax = _chown((const char*)translate(regs->ebx));
            break;
        case _SYS_LOG:
            _loglevel(regs->ebx);
            break;
        case _SYS_STACKSIZE:
            regs->eax = _stacksize();
    }
}
Exemplo n.º 9
0
int main(int argc, char * argv[], char * env[])
{
	char line[128], command[128], pathname[128];
	int ID;
	
	// DEVICE SELECT
	get_device();

	// INITIALIZE 
	init();
	
	// MOUNT ROOT
	mount_root();

	// PROCESS LOOP
	while(1)
	{
		strcpy(line, "");
		strcpy(command, "");
		strcpy(pathname, "");
		strcpy(completePath, "");

		printf("\n\ninput a command (type help for more info): ");
		//read a line containting  command [pathname]; // [ ] means optional
		fgets(line, 256, stdin);
		line[strlen(line)-1] = '\0';

		//Find the command string and call the corresponding function;
		parseString(line, arg1, command, pathname);

		compPath(pathname);
		
		
		printf("PATHNAME: %s\n", pathname);
		ID = findCommand(command);
		switch(ID)
		{
			case -1 : printDir(running->cwd->ino);	break;
			case  0 : _menu  (arg1, pathname);	break;
			case  1 : _ls    (arg1, pathname);	break;
			case  2 : _cd    (arg1, pathname);	break;
			case  3 : _mkdir (arg1, pathname);	break;
			case  4 : _rmdir (arg1, pathname);	break;
			case  5 : _pwd   (arg1, pathname);	break;
			case  6 : _creat0(arg1, pathname);	break;
			case  7 : _rm    (arg1, pathname);	break;
			case  8 : _stat  (arg1, pathname);	break;
			case  9 : compPath(arg1); _link(arg1, pathname); break;
			case  10: _unlink(arg1, pathname); break;
			case  11: compPath(arg1); _symlink(arg1, pathname); break;
			case  12: _touch (arg1, pathname);	break;
			case  13: _chmod (arg1, pathname);	break;
			case  14: _chown (arg1, pathname);	break;
			case  15: _chgrp (arg1, pathname);	break;
			case  16: _open  (arg1, pathname);	break;
			case  17: _close (arg1, pathname);	break;
			case  18: _read  (arg1, pathname);	break;
			case  19: _write (arg1, pathname);	break;
			case  20: _pfd   (arg1, pathname);	break;
			case  21: _lseek (arg1, pathname);	break;
			case  22: _cat   (arg1, pathname);	break;
			case  23: _cp    (arg1, pathname);	break;
			case  24: _mv    (arg1, pathname);	break;
			case  25: __exit (arg1, pathname);	break;
		}
	}
	
	quit();
	return 0;
}