Esempio n. 1
0
/*
 * Open a directory.
 * Params:
 *   state->ebx - address of user string containing path of directory to open
 *   state->ecx - length of path
 *
 * Returns: a file descriptor (>= 0) if successful,
 *   or an error code (< 0) if unsuccessful
 */
static int Sys_OpenDirectory(struct Interrupt_State *state) {
  char *path;
  struct File *file;
  int rc = 0;

  rc = get_path_from_registers(state->ebx, state->ecx, &path);
  if(rc != 0) {
    return rc;
  }

  rc = next_descriptor();
  if(rc < 0) {
    return rc;
  }

  Enable_Interrupts(); // duped from schulman
  rc = Open_Directory(path, &file);
  Disable_Interrupts();
  Free(path);

  if(rc >= 0) {
    return add_file_to_descriptor_table(file);
  } else {
    return rc;
  }
}
Esempio n. 2
0
/*
 * Open a directory.
 * Params:
 *   state->ebx - address of user string containing path of directory to open
 *   state->ecx - length of path
 *
 * Returns: a file descriptor (>= 0) if successful,
 *   or an error code (< 0) if unsuccessful
 */
static int Sys_OpenDirectory(struct Interrupt_State *state)
{
	char path[VFS_MAX_PATH_LEN] = {'\0' };
	struct File **pDir; /* important */
	int fd;
	int rc;
	struct File** fileList = g_currentThread->userContext->fileList;

	for(fd = 0; fd < USER_MAX_FILES; fd++){
		if(fileList[fd] == NULL){
			pDir = &fileList[fd];
			break;
		}
	}
	
	if(fd == USER_MAX_FILES)
	{
		return -1;
	}

	Copy_From_User(path, state->ebx, state->ecx);
    Enable_Interrupts();			
    //Print("Sys_OpenDirectory : %s\n", path);
	if((rc = Open_Directory(path, pDir)) < 0){ /* important */
		fd = rc;
	}
	//Print("%d, fileList[fd] : %x\n", fd, fileList[fd]);
	Disable_Interrupts();

	return fd;
    //TODO("Open directory system call");
}
Esempio n. 3
0
int tClean() {
    struct VFS_Dir_Entry dirEntry;
    int fd, retR, i;
    fd = Open_Directory("/d");
    for (i = 0;
         (retR = Read_Entry(fd, &dirEntry)) == 0 && dirEntry.name[0] == '.';
         i++);
    if (dirEntry.name[0] != '.') {
        return -1;              /* not empty */
    }
    if (i > 2) {
        return -1;              /* many dotfiles */
    }
    if (retR != VFS_NO_MORE_DIR_ENTRIES) {
        return -1;              /* failed out */
    }
    return 1;
}
Esempio n. 4
0
int tStatDirectory()
{
  int fd, retS, retC;
  struct VFS_File_Stat s;

  retC = Create_Directory("/d/basic10d");
  if (retC < 0)
    return -1;

  fd = Open_Directory("/d/basic10d");
  if (fd < 0)
    return -1;

  retS = FStat(fd, &s);

  Close(fd);
  Delete("/d/basic10d");

  return ( (retS >= 0) && (s.isDirectory)  ) ? 1 : -1;
}
Esempio n. 5
0
int tStatDirectory() {
    int fd, retS, retC;
    struct VFS_File_Stat s;

    retC = Create_Directory("/d/basic10d");
    if (retC < 0) {
        Print("couldn't create basic10d: %d %s\n", retC,
              Get_Error_String(retC));
        return -1;
    }

    fd = Open_Directory("/d/basic10d");
    if (fd < 0) {
        Print("couldn't reopen basic10d: %d %s\n", fd, Get_Error_String(fd));
        return -1;
    }

    retS = FStat(fd, &s);

    if (Close(fd) < 0) {
        Print("failed to close");
        return -1;
    }
    (void)Delete("/d/basic10d", false);

    if (retS < 0) {
        Print("couldn't fstat opened basic10d: %d %s\n", retS,
              Get_Error_String(retS));
    }
    if (!s.isDirectory) {
        Print("fstat didn't think basic10d was a directory\n");
    }


    return ((retS >= 0) && (s.isDirectory)) ? 1 : -1;
}
Esempio n. 6
0
int tReadEntry() {
    int fd, retR, retC;
    struct VFS_Dir_Entry dirEntry;

    retC = Create_Directory("/d/basic11d");
    if (retC < 0) {
        Print("couldn't create basic11d: %d %s\n", retC,
              Get_Error_String(retC));
        return -1;
    }

    retC = Create_Directory("/d/basic11d/d1");
    if (retC < 0) {
        Print("couldn't create basic11d/d1: %d %s\n", retC,
              Get_Error_String(retC));
        return -1;
    }

    retC = Create_Directory("/d/basic11d/d2");
    if (retC < 0) {
        Print("couldn't create basic11d/d2: %d %s\n", retC,
              Get_Error_String(retC));
        return -1;
    }

    fd = Open("/d/basic11d/f1", O_CREATE);
    if (fd < 0) {
        Print("couldn't open basic11d/f1: %d %s\n", fd, Get_Error_String(fd));
        return -1;
    }

    if (Close(fd) < 0) {
        Print("failed to close");
        return -1;
    }

    fd = Open_Directory("/d/basic11d");
    if (fd < 0) {
        Print("couldn't opendir basic11d: %d %s\n", fd, Get_Error_String(fd));
        return -1;
    }

    retR = Read_Entry(fd, &dirEntry);

    if ((retR < 0) ||
        (strncmp(dirEntry.name, "d1", 2) != 0) ||
        (!dirEntry.stats.isDirectory))
        return -1;

    retR = Read_Entry(fd, &dirEntry);

    if ((retR < 0) ||
        (strncmp(dirEntry.name, "d2", 2) != 0) ||
        (!dirEntry.stats.isDirectory))
        return -1;

    retR = Read_Entry(fd, &dirEntry);

    if ((retR < 0) ||
        (strncmp(dirEntry.name, "f1", 2) != 0) ||
        (dirEntry.stats.isDirectory))
        return -1;

    if (Close(fd) < 0) {
        Print("failed to close");
        return -1;
    }

    fd = Open_Directory("/d/basic11d");
    if (fd < 0)
        return -1;

    // no  retR = Seek(fd, 2);
    // no if (retR < 0)
    // no   return -1;

    // no retR = Read_Entry(fd, &dirEntry);

    // no if ((retR < 0) ||
    // no     (strncmp(dirEntry.name, "f1", 2) != 0) ||
    // no      (dirEntry.stats.isDirectory))
    // no   return -1;

    if (Close(fd) < 0) {
        Print("failed to close");
        return -1;
    }

    (void)Delete("/d/basic11d/d1", false);
    (void)Delete("/d/basic11d/d2", false);
    (void)Delete("/d/basic11d/f1", false);

    (void)Delete("/d/basic11d", false);

    return 1;
}
Esempio n. 7
0
int tReadEntry()
{
  int fd, retR, retC;
  struct VFS_Dir_Entry dirEntry;

  retC = Create_Directory("/d/basic11d");
  if (retC < 0) {
    Print("couldn't create basic11d: %d\n", retC);
    return -1;
  }

  retC = Create_Directory("/d/basic11d/d1");
  if (retC < 0) {
    Print("couldn't create basic11d/d1: %d\n", retC);
    return -1;
  }

  retC = Create_Directory("/d/basic11d/d2");
  if (retC < 0) {
    Print("couldn't create basic11d/d2: %d\n", retC);
    return -1;
  }

  fd = Open("/d/basic11d/f1", O_CREATE);
  if (fd < 0) {
    Print("couldn't create basic11d/f1: %d\n", fd);
    return -1;
  }

  Close(fd);

  fd = Open_Directory("/d/basic11d");
  if (fd < 0) {
    Print("couldn't opendir basic11d: %d\n", fd);
    return -1;
  }

  do {
    retR = Read_Entry(fd, &dirEntry);
  } while(retR == 0 && dirEntry.name[0] == '.');

  if ((retR < 0) ||
      (strncmp(dirEntry.name, "d1", 2) != 0) ||
       (! dirEntry.stats.isDirectory))
    return -1;

  retR = Read_Entry(fd, &dirEntry);

  if ((retR < 0) ||
      (strncmp(dirEntry.name, "d2", 2) != 0) ||
       (! dirEntry.stats.isDirectory))
    return -1;

  retR = Read_Entry(fd, &dirEntry);

  if ((retR < 0) ||
      (strncmp(dirEntry.name, "f1", 2) != 0) ||
       (dirEntry.stats.isDirectory))
    return -1;
  
  Close(fd);

  fd = Open_Directory("/d/basic11d");
  if (fd < 0)
    return -1;

  retR = Seek(fd, 2);
  if (retR < 0)
    return -1;

  retR = Read_Entry(fd, &dirEntry);

  if ((retR < 0) ||
      (strncmp(dirEntry.name, "f1", 2) != 0) ||
       (dirEntry.stats.isDirectory))
    return -1;
  
  Close(fd);
  Delete("/d/basic11d/d1");
  Delete("/d/basic11d/d2");
  Delete("/d/basic11d/f1");

  Delete("/d/basic11d");
  return 1;
}
Esempio n. 8
0
int tReadEntry()
{
  int fd, retR, retC;
  struct VFS_Dir_Entry dirEntry;

  retC = Create_Directory("/d/basic11d");
  if (retC < 0)
    return -1;

  retC = Create_Directory("/d/basic11d/d1");
  if (retC < 0)
    return -1;

  retC = Create_Directory("/d/basic11d/d2");
  if (retC < 0)
    return -1;

  fd = Open("/d/basic11d/f1", O_CREATE);
  if (fd < 0)
    return -1;

  Close(fd);

Print("all file/dir created.\n");

  fd = Open_Directory("/d/basic11d");
  if (fd < 0)
    return -1;

  retR = Read_Entry(fd, &dirEntry);
Print("read 1 entry.\n");

  if ((retR < 0) ||
      (strncmp(dirEntry.name, "d1", 2) != 0) ||
       (! dirEntry.stats.isDirectory))
    return -1;

  retR = Read_Entry(fd, &dirEntry);
Print("read 2 entry.\n");

  if ((retR < 0) ||
      (strncmp(dirEntry.name, "d2", 2) != 0) ||
       (! dirEntry.stats.isDirectory))
    return -1;

  retR = Read_Entry(fd, &dirEntry);
Print("read 3 entry.\n");

  if ((retR < 0) ||
      (strncmp(dirEntry.name, "f1", 2) != 0) ||
       (dirEntry.stats.isDirectory))
    return -1;
  
  Close(fd);

  fd = Open_Directory("/d/basic11d");
  if (fd < 0)
    return -1;
Print("opened basic11d.\n");

  retR = Seek(fd, 2);
  if (retR < 0)
  {
   	Print("failed seek.\n");
	 return -1;
  }

  retR = Read_Entry(fd, &dirEntry);
Print("read no2 entry.\n");

  if ((retR < 0) ||
      (strncmp(dirEntry.name, "f1", 2) != 0) ||
       (dirEntry.stats.isDirectory))
    return -1;
  
  Close(fd);

  Delete("/d/basic11d/d1");
  Delete("/d/basic11d/d2");
  Delete("/d/basic11d/f1");

  Delete("/d/basic11d");

	Print("all files deleted.\n");
  return 1;
}