Esempio n. 1
0
File: runq.c Progetto: 99years/plan9
/*
 *  free files matching name in the current directory
 */
void
remmatch(char *name)
{
	long i;

	syslog(0, runqlog, "removing %s/%s", curdir, name);

	for(i=0; i<nfiles; i++){
		if(strcmp(&dirbuf[i].name[1], &name[1]) == 0)
			sysremove(dirbuf[i].name);
	}

	/* error file (may have) appeared after we read the directory */
	/* stomp on data file in case of phase error */
	sysremove(file(name, 'D'));
	sysremove(file(name, 'E'));
}
Esempio n. 2
0
extern void
m_free(message *mp)
{
	if(mp->fd >= 0){
		close(mp->fd);
		sysremove(s_to_c(mp->tmp));
		s_free(mp->tmp);
	}
	s_free(mp->sender);
	s_free(mp->date);
	s_free(mp->body);
	s_free(mp->havefrom);
	s_free(mp->havesender);
	s_free(mp->havereplyto);
	s_free(mp->havesubject);
	free((char *)mp);
}
Esempio n. 3
0
File: runq.c Progetto: 99years/plan9
int
emptydir(char *name)
{
	int fd;
	long n;
	char buf[2048];

	fd = open(name, OREAD);
	if(fd < 0)
		return 1;
	n = read(fd, buf, sizeof(buf));
	close(fd);
	if(n <= 0) {
		if(debug)
			fprint(2, "removing directory %s\n", name);
		syslog(0, runqlog, "rmdir %s", name);
		sysremove(name);
		return 1;
	}
	return 0;
}
Esempio n. 4
0
static void
_writembox(Mailbox *mb, Mlock *lk)
{
	Dir *d;
	Message *m;
	String *tmp;
	int mode, errs;
	Biobuf *b;

	tmp = s_copy(mb->path);
	s_append(tmp, ".tmp");

	/*
	 * preserve old files permissions, if possible
	 */
	d = dirstat(mb->path);
	if(d != nil){
		mode = d->mode&0777;
		free(d);
	} else
		mode = MBOXMODE;

	sysremove(s_to_c(tmp));
	b = sysopen(s_to_c(tmp), "alc", mode);
	if(b == 0){
		fprint(2, "can't write temporary mailbox %s: %r\n", s_to_c(tmp));
		return;
	}

	logmsg("writing new mbox", nil);
	errs = 0;
	for(m = mb->root->part; m != nil; m = m->next){
		if(lk != nil)
			syslockrefresh(lk);
		if(m->deleted)
			continue;
		logmsg("writing", m);
		if(Bwrite(b, m->start, m->end - m->start) < 0)
			errs = 1;
		if(Bwrite(b, "\n", 1) < 0)
			errs = 1;
	}
	logmsg("wrote new mbox", nil);

	if(sysclose(b) < 0)
		errs = 1;

	if(errs){
		fprint(2, "error writing temporary mail file\n");
		s_free(tmp);
		return;
	}

	sysremove(mb->path);
	if(sysrename(s_to_c(tmp), mb->path) < 0)
		fprint(2, "%s: can't rename %s to %s: %r\n", argv0,
			s_to_c(tmp), mb->path);
	s_free(tmp);
	if(mb->d != nil)
		free(mb->d);
	mb->d = dirstat(mb->path);
}
Esempio n. 5
0
static void
syscall_handler (struct intr_frame* frame) 
{
	// -------- System Call Handler Overview -------- 
	// Get system call number
	// switch statement using system call number
	// collect arguments for system call function if necessary
	// call system call function
	// set frame->eax to return value if necessary
	// ----------------------------------------------
	uintptr_t* kpaddr_sp = (uintptr_t*) frame->esp;
	int syscall_num = -1;
	if(check_uptr(kpaddr_sp))
		syscall_num = next_value(&kpaddr_sp);
	else
		sysexit(-1);

	switch(syscall_num)
	{
		case SYS_HALT:                   
			{
				// Terminates Pintos
				shutdown_power_off();
			}
			break;
		case SYS_EXIT:                 
			{
				uintptr_t status = -1;
				if(check_uptr(kpaddr_sp))
					status = next_value(&kpaddr_sp);
				sysexit(status);
			}
			break;
		case SYS_EXEC:  //pid_t exec (const char *file);
			{
				const char* file =  next_charptr(&kpaddr_sp);
				if(file == NULL)
					sysexit(-1);

				unsigned len = strlen(file);
				if(!check_buffer(file, len))
					sysexit(-1);
				else
					sysexec(frame, file);
			}
			break;
		case SYS_WAIT:  //int wait (pid_t);
			{
				uintptr_t childid = -1;
				if(check_uptr(kpaddr_sp))
					childid = next_value(&kpaddr_sp);
				else
					sysexit(childid);
			
				int retval = process_wait((tid_t) childid);
				frame->eax = retval;
			}
			break;
		case SYS_CREATE:	//bool create (const char *file, unsigned initial_size);
			{
				const char* file =  next_charptr(&kpaddr_sp);
				if(file == NULL)
					sysexit(-1);

				unsigned len = strlen(file);
				if(!check_buffer(file, len))
					sysexit(-1);

				uintptr_t size = 0;
				if(check_uptr(kpaddr_sp))
					size = next_value(&kpaddr_sp);
				else
					sysexit(-1);

				syscreate(frame, file, size);
			}
			break;
		case SYS_REMOVE:	//bool remove (const char *file);
			{
				const char* file =  next_charptr(&kpaddr_sp);
				if(file == NULL)
					sysexit(-1);

				unsigned len = strlen(file);
				if(!check_buffer(file, len))
					sysexit(-1);

				sysremove(frame, file);
			}
			break;
		case SYS_OPEN:          
			{
				//int open (const char *file);
				const char* file =  next_charptr(&kpaddr_sp);
				if(file == NULL)
					sysexit(-1);

				unsigned len = strlen(file);
				if(!check_buffer(file, len))
					sysexit(-1);

	      		sysopen(frame, file);
			}
			break;
		case SYS_FILESIZE:     
			{
				//int filesize (int fd);
	      		int fd = 0;
	      		if (check_uptr(kpaddr_sp))
					fd = (int) next_value(&kpaddr_sp);
	      		else
					sysexit(-1);

	      		sysfilesize(frame, fd);
			}
			break;
		case SYS_READ:        
			{
				//int read (int fd, void *buffer, unsigned length);
				int fd = 0;
				if (check_uptr(kpaddr_sp))
					fd = (int) next_value(&kpaddr_sp);
				else
					sysexit(-1);

				const char* file =  next_charptr(&kpaddr_sp);
				if(file == NULL)
					sysexit(-1);

				unsigned len = strlen(file);
				if(!check_buffer(file, len))
					sysexit(-1);

				unsigned length = 0;
				if (check_uptr(kpaddr_sp))
					length = (unsigned) next_value(&kpaddr_sp);
				else
					sysexit(-1);

				sysread(frame, fd, (void*) file, length);
			}
			break;
		case SYS_WRITE:      
			{
				//int write (int fd, const void *buffer, unsigned length);
				uintptr_t fd = 0;
				if(check_uptr(kpaddr_sp))
					fd = next_value(&kpaddr_sp);
				else
					sysexit(-1);

				const char* file =  next_charptr(&kpaddr_sp);
				if(file == NULL)
					sysexit(-1);

				unsigned len = strlen(file);
				if(!check_buffer(file, len))
					sysexit(-1);

				uintptr_t length = 0;
				if(check_uptr(kpaddr_sp))
					length = next_value(&kpaddr_sp);
				else
					sysexit(-1);

				if(fd == CONSOLEWRITE) // Write to Console
				{
					while(length > 0)
					{
						if(length > MAX_SIZE)
						{
							putbuf (file, MAX_SIZE);
							file += MAX_SIZE;
							length -= MAX_SIZE;
						}
						else
						{
							putbuf (file, length);
							length = 0;
						}
					}
				}
				else
				{
					syswrite(frame, fd, file, length);
				}
			}
			break;
		case SYS_SEEK:
			{
				//void seek (int fd, unsigned position);
				int fd = 0;
				if (check_uptr(kpaddr_sp))
					fd = (int) next_value(&kpaddr_sp);
				else
					sysexit(-1);

				unsigned position = 0;
				if (check_uptr(kpaddr_sp))
					position = (unsigned) next_value(&kpaddr_sp);
				else
					sysexit(-1);

				sysseek(fd, position);
			}
			break;
		case SYS_TELL:
			{
				//unsigned tell (int fd);
				int fd = 0;
				if (check_uptr(kpaddr_sp))
					fd = (int) next_value(&kpaddr_sp);
				else
					sysexit(-1);

				systell(frame, fd);
			}
			break;
		case SYS_CLOSE:    
			{
				//void close (int fd);
				int fd = 0;
				if (check_uptr(kpaddr_sp))
					fd = (int) next_value(&kpaddr_sp);
				else
					sysexit(-1);

				sysclose(fd);
			}
			break;
		default:
			{
				printf("Unrecognized System Call\n");
				sysexit(-1);
			}
			break;
	}
}