Skip to content

Commit

Permalink
Remove unused FileSystem methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian committed Mar 1, 2009
1 parent 3037c82 commit 7f3b83f
Show file tree
Hide file tree
Showing 5 changed files with 0 additions and 274 deletions.
6 changes: 0 additions & 6 deletions rvm/src/org/jikesrvm/runtime/BootRecord.java
Original file line number Diff line number Diff line change
Expand Up @@ -234,16 +234,10 @@ public void setHeapRange(int id, Address start, Address end) {
public Address sysSyncCacheIP;

// files
public Address sysStatIP;
public Address sysReadByteIP;
public Address sysWriteByteIP;
public Address sysReadBytesIP;
public Address sysWriteBytesIP;
public Address sysBytesAvailableIP;
public Address sysSyncFileIP;
public Address sysSetFdCloseOnExecIP;

public Address sysAccessIP;

// mmap - memory mapping
public Address sysMMapIP;
Expand Down
90 changes: 0 additions & 90 deletions rvm/src/org/jikesrvm/runtime/FileSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.jikesrvm.Callbacks;
import org.jikesrvm.scheduler.RVMThread;
import static org.jikesrvm.runtime.SysCall.sysCall;
import org.jikesrvm.util.StringUtilities;
import org.vmmagic.pragma.NoInline;
import org.vmmagic.pragma.NoOptCompile;
import org.vmmagic.pragma.BaselineSaveLSRegisters;
Expand All @@ -36,69 +35,6 @@
*/
public class FileSystem {

// options for open()
public static final int OPEN_READ = 0; // open for read/only access
public static final int OPEN_WRITE = 1; // open for read/write access, create if doesn't already exist,
// truncate if already exists
public static final int OPEN_MODIFY = 2; // open for read/write access, create if doesn't already exist
public static final int OPEN_APPEND = 3; // open for read/write access, create if doesn't already exist, append writes

// options for seek()
public static final int SEEK_SET = 0; // set i/o position to start of file plus "offset"
public static final int SEEK_CUR = 1; // set i/o position to current position plus "offset"
public static final int SEEK_END = 2; // set i/o position to end of file plus "offset"

// options for stat()
public static final int STAT_EXISTS = 0;
public static final int STAT_IS_FILE = 1;
public static final int STAT_IS_DIRECTORY = 2;
public static final int STAT_IS_READABLE = 3;
public static final int STAT_IS_WRITABLE = 4;
public static final int STAT_LAST_MODIFIED = 5;
public static final int STAT_LENGTH = 6;

// options for access()
public static final int ACCESS_F_OK = 00;
public static final int ACCESS_R_OK = 04;
public static final int ACCESS_W_OK = 02;
public static final int ACCESS_X_OK = 01;

/**
* Get file status.
* @param fileName file name
* @param kind kind of info desired (one of STAT_XXX, above)
* @return desired info (-1 -> error)
* The boolean ones return 0 in case of non-true, 1 in case of
* true status.
*/
public static int stat(String fileName, int kind) {
// convert file name from unicode to filesystem character set
// (assume file name is ascii, for now)
byte[] asciiName = StringUtilities.stringToBytesNullTerminated(fileName);
int rc = sysCall.sysStat(asciiName, kind);
if (VM.TraceFileSystem) VM.sysWrite("FileSystem.stat: name=" + fileName + " kind=" + kind + " rc=" + rc + "\n");
return rc;
}

/**
* Get user's perms for a file.
* @param fileName file name
* @param kind kind of access perm(s) to check for (ACCESS_W_OK,...)
* @return 0 if access ok (-1 -> error)
*/
public static int access(String fileName, int kind) {
// convert file name from unicode to filesystem character set
// (assume file name is ascii, for now)
byte[] asciiName = StringUtilities.stringToBytesNullTerminated(fileName);

int rc = sysCall.sysAccess(asciiName, kind);

if (VM.TraceFileSystem) {
VM.sysWrite("FileSystem.access: name=" + fileName + " kind=" + kind + " rc=" + rc + "\n");
}
return rc;
}

/**
* Read single byte from file.
*
Expand Down Expand Up @@ -172,30 +108,6 @@ public static int writeBytes(int fd, byte[] buf, int off, int cnt) {
return result;
}

@NoInline
@NoOptCompile
@BaselineSaveLSRegisters
@Unpreemptible
public static boolean sync(int fd) {
RVMThread.saveThreadState();
RVMThread.enterNative();
boolean result=sysCall.sysSyncFile(fd) == 0;
RVMThread.leaveNative();
return result;
}

@NoInline
@NoOptCompile
@BaselineSaveLSRegisters
@Unpreemptible
public static int bytesAvailable(int fd) {
RVMThread.saveThreadState();
RVMThread.enterNative();
int result=sysCall.sysBytesAvailable(fd);
RVMThread.leaveNative();
return result;
}

// not sure if this is the right place to have this.
/**
* Called from VM.boot to set up java.lang.System.in, java.lang.System.out,
Expand All @@ -220,5 +132,3 @@ public void notifyExit(int value) {
});
}
}


16 changes: 0 additions & 16 deletions rvm/src/org/jikesrvm/runtime/SysCall.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import org.jikesrvm.scheduler.RVMThread;
import org.vmmagic.pragma.Uninterruptible;
import org.vmmagic.unboxed.Address;
import org.vmmagic.unboxed.Word;
import org.vmmagic.unboxed.Extent;
import org.vmmagic.unboxed.Offset;

Expand Down Expand Up @@ -113,9 +112,6 @@ public abstract class SysCall {
public abstract long sysPerfCtrReadCycles();

// files
@SysCallTemplate
public abstract int sysStat(byte[] name, int kind);

@SysCallTemplate
public abstract int sysReadByte(int fd);

Expand All @@ -128,18 +124,6 @@ public abstract class SysCall {
@SysCallTemplate
public abstract int sysWriteBytes(int fd, Address buf, int cnt);

@SysCallTemplate
public abstract int sysBytesAvailable(int fd);

@SysCallTemplate
public abstract int sysSyncFile(int fd);

@SysCallTemplate
public abstract int sysSetFdCloseOnExec(int fd);

@SysCallTemplate
public abstract int sysAccess(byte[] name, int kind);

// mmap - memory mapping
@SysCallTemplate
public abstract Address sysMMap(Address start, Extent length, int protection, int flags, int fd, Offset offset);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.jikesrvm.runtime.Entrypoints;
import org.jikesrvm.runtime.RuntimeEntrypoints;
import org.jikesrvm.scheduler.RVMThread;
import org.jikesrvm.runtime.FileSystem;
import org.vmmagic.unboxed.Address;
import org.vmmagic.unboxed.Offset;

Expand Down Expand Up @@ -445,26 +444,6 @@ static void emitVirtualMachineDeclarations(int bootImageDataAddress, int bootIma
p("static const int Runtime_TRAP_STORE_CHECK = " + RuntimeEntrypoints.TRAP_STORE_CHECK + ";\n");
pln();

// values in FileSystem
//
p("static const int FileSystem_OPEN_READ = " + FileSystem.OPEN_READ + ";\n");
p("static const int FileSystem_OPEN_WRITE = " + FileSystem.OPEN_WRITE + ";\n");
p("static const int FileSystem_OPEN_MODIFY = " + FileSystem.OPEN_MODIFY + ";\n");
p("static const int FileSystem_OPEN_APPEND = " + FileSystem.OPEN_APPEND + ";\n");
p("static const int FileSystem_SEEK_SET = " + FileSystem.SEEK_SET + ";\n");
p("static const int FileSystem_SEEK_CUR = " + FileSystem.SEEK_CUR + ";\n");
p("static const int FileSystem_SEEK_END = " + FileSystem.SEEK_END + ";\n");
p("static const int FileSystem_STAT_EXISTS = " + FileSystem.STAT_EXISTS + ";\n");
p("static const int FileSystem_STAT_IS_FILE = " + FileSystem.STAT_IS_FILE + ";\n");
p("static const int FileSystem_STAT_IS_DIRECTORY = " + FileSystem.STAT_IS_DIRECTORY + ";\n");
p("static const int FileSystem_STAT_IS_READABLE = " + FileSystem.STAT_IS_READABLE + ";\n");
p("static const int FileSystem_STAT_IS_WRITABLE = " + FileSystem.STAT_IS_WRITABLE + ";\n");
p("static const int FileSystem_STAT_LAST_MODIFIED = " +
FileSystem
.STAT_LAST_MODIFIED +
";\n");
p("static const int FileSystem_STAT_LENGTH = " + FileSystem.STAT_LENGTH + ";\n");

// Value in org.mmtk.vm.Constants:
p("static const int MMTk_Constants_BYTES_IN_PAGE = " + org.mmtk.utility.Constants.BYTES_IN_PAGE + ";\n");

Expand Down
141 changes: 0 additions & 141 deletions tools/bootImageRunner/sysIO.C
Original file line number Diff line number Diff line change
Expand Up @@ -18,70 +18,6 @@
#include <sys/ioctl.h>
#include "sys.h"

/**
* Check user's perms.
* @param name null terminated filename
* @param king kind of access perm to check for (see FileSystem.ACCESS_W_OK)
* @return 0 on success (-1=error)
*/
EXTERNAL int sysAccess(char *name, int kind)
{
SYS_START();
TRACE_PRINTF("%s: access %s\n", Me, name);
#ifdef RVM_FOR_HARMONY
CONSOLE_PRINTF("Unsupported call to sysAccess\n");
return -1; // TODO: Harmony
#else
return access(name, kind);
#endif
}

/**
* How many bytes can be read from file/socket without blocking?
* @param fd file/socket descriptor
* @return >=0: count, -1: error
*/
EXTERNAL int sysBytesAvailable(int fd)
{
SYS_START();
TRACE_PRINTF("%s: bytesAvailable %d\n", Me, fd);
#ifdef RVM_FOR_HARMONY
CONSOLE_PRINTF("Unsupported call to sysSetFdCloseOnExec\n");
return -1; // TODO: Harmony
#else
int count = 0;
if (ioctl(fd, FIONREAD, &count) == -1)
{
bool badFD = (errno == EBADF);
ERROR_PRINTF("%s: FIONREAD ioctl on %d failed: %s (errno=%d)\n", Me, fd, strerror( errno ), errno);
return -1;
}
TRACE_PRINTF("%s: available fd=%d count=%d\n", Me, fd, count);
return count;
#endif // RVM_FOR_HARMONY
}

/**
* Sync
* @param fd file descriptor
* @return 0, -1 => error
*/
EXTERNAL int sysSyncFile(int fd)
{
SYS_START();
TRACE_PRINTF("%s: sync %d\n", Me, fd);
#ifdef RVM_FOR_HARMONY
return hyfile_sync(fd);
#else
if (fsync(fd) != 0) {
// some kinds of files cannot be sync'ed, so don't print error message
// however, do return error code in case some application cares
return -1;
}
return 0;
#endif // RVM_FOR_HARMONY
}

/**
* Read one byte from file.
* @param fd file descriptor
Expand Down Expand Up @@ -218,80 +154,3 @@ EXTERNAL int sysWriteBytes(int fd, char *buf, int cnt)
return -2;
#endif // RVM_FOR_HARMONY
}

/**
* Close file or socket.
* @param file/socket descriptor
* @return 0: success, -1: file/socket not currently open, -2: i/o error
*/
static int sysClose(int fd)
{
SYS_START();
TRACE_PRINTF("%s: close %d\n", Me, fd);
#ifdef RVM_FOR_HARMONY
return hyfile_close(fd);
#else
if ( -1 == fd ) return -1;
int rc = close(fd);
if (rc == 0) return 0; // success
if (errno == EBADF) return -1; // not currently open
return -2; // some other error
#endif // RVM_FOR_HARMONY
}

/**
* Set the close-on-exec flag for given file descriptor.
*
* Taken: the file descriptor
* Returned: 0 if sucessful, nonzero otherwise
*/
EXTERNAL int sysSetFdCloseOnExec(int fd)
{
SYS_START();
TRACE_PRINTF("%s: setFdCloseOnExec %d\n", Me, fd);
#ifdef RVM_FOR_HARMONY
CONSOLE_PRINTF("Unsupported call to sysSetFdCloseOnExec\n");
return -1; // TODO: Harmony
#else
return fcntl(fd, F_SETFD, FD_CLOEXEC);
#endif // RVM_FOR_HARMONY
}

/**
* Get file status.
* @param name null terminated filename
* @param kind of info desired (see FileSystem.STAT_XXX)
* @return Returned: status (-1=error)
*/
EXTERNAL int sysStat(char *name, int kind)
{
SYS_START();
TRACE_PRINTF("%s: sysStat %s %d\n", Me, name, kind);
#ifdef RVM_FOR_HARMONY
CONSOLE_PRINTF("Unsupported call to sysStat\n");
return -1; // TODO: Harmony
#else
struct stat info;

if (stat(name, &info))
return -1; // does not exist, or other trouble

switch (kind) {
case FileSystem_STAT_EXISTS:
return 1; // exists
case FileSystem_STAT_IS_FILE:
return S_ISREG(info.st_mode) != 0; // is file
case FileSystem_STAT_IS_DIRECTORY:
return S_ISDIR(info.st_mode) != 0; // is directory
case FileSystem_STAT_IS_READABLE:
return (info.st_mode & S_IREAD) != 0; // is readable by owner
case FileSystem_STAT_IS_WRITABLE:
return (info.st_mode & S_IWRITE) != 0; // is writable by owner
case FileSystem_STAT_LAST_MODIFIED:
return info.st_mtime; // time of last modification
case FileSystem_STAT_LENGTH:
return info.st_size; // length
}
return -1; // unrecognized request
#endif // RVM_FOR_HARMONY
}

0 comments on commit 7f3b83f

Please sign in to comment.