Import backup from 2004-06-16

This commit is contained in:
josh committed 2017-07-25 22:23:47 -04:00
1 parent c76725eac3
commit f3fe4ef3b8
16 files changed
+463 -761

No files matched your search

-128
View File
@@ -1,128 +0,0 @@
// Device.cpp
// Device object for use in devfs
// Author: Josh Holtrop
// Date: 06/03/04
// Modified: 06/09/04
#include "Device.h"
#include "DeviceFolder.h"
#include "hos_defines.h"
#include "lang/string.h"
Device::Device()
{
uid = gid = major = minor = permissions = type = 0;
}
Device::Device(string aname)
{
uid = gid = major = minor = permissions = type = 0;
name = aname;
}
//Types:
// h = hard link (. and .. only)
// l = link, call setLink()
// d = directory, automatically initializes a new DeviceFolder object
// b = block device
// c = char device
Device::Device(string aname, dword auid, dword agid, dword amajor, dword aminor, char atype, word apermissions)
{
name = aname;
uid = auid;
gid = agid;
permissions = apermissions;
type = atype;
switch (type)
{
case 'd':
folder = new DeviceFolder();
break;
case 'b':
case 'c':
major = amajor;
minor = aminor;
break;
case 'l':
case 'h':
default:
}
}
Device::~Device()
{
switch (type)
{
case 'l':
case 'h':
delete link;
break;
case 'd':
delete (DeviceFolder *)folder;
break;
}
}
Device::Device(const Device & orig)
{
name = orig.name;
uid = orig.uid;
gid = orig.gid;
permissions = orig.permissions;
type = orig.type;
switch (type)
{
case 'b':
case 'c':
default:
major = orig.major;
minor = orig.minor;
break;
case 'l':
case 'h':
link = new string(*orig.link);
break;
case 'd':
folder = new DeviceFolder(*(DeviceFolder *)orig.folder);
break;
}
}
Device & Device::operator=(const Device & orig)
{
if (&orig != this)
{
this->~Device();
name = orig.name;
uid = orig.uid;
gid = orig.gid;
permissions = orig.permissions;
type = orig.type;
switch (type)
{
case 'b':
case 'c':
default:
major = orig.major;
minor = orig.minor;
break;
case 'l':
case 'h':
link = new string(*orig.link);
break;
case 'd':
folder = new DeviceFolder(*(DeviceFolder *)orig.folder);
break;
}
}
return *this;
}
void Device::setLink(string alink)
{
if (type == 'l' || type == 'h')
link = new string(alink);
}
-47
View File
@@ -1,47 +0,0 @@
// Device.h
// Device object for use in devfs
// Author: Josh Holtrop
// Date: 06/03/04
// Modified: 06/08/04
#ifndef __HOS_DEVICE__
#define __HOS_DEVICE__ __HOS_DEVICE__
#include "hos_defines.h"
#include "lang/string.h"
#include "lang/LinkedList.h"
#define DEVICE_FOLDER 0
#define DEVICE_BLOCK 1
#define DEVICE_CHAR 2
#define DEVICE_LINK 3
class Device
{
public:
string name;
union
{
dword major;
//can't be DeviceFolder * because not then Device & DeviceFolder are inter-dependent
void *folder;
string *link;
};
dword uid;
dword gid;
dword minor;
word permissions; //0644 or similar
char type; //'b', 'c', 'l', 'd'
Device();
Device(string aname);
Device(string aname, dword auid, dword agid, dword amajor, dword aminor, char atype, word apermissions);
Device(const Device & orig);
~Device();
Device & operator=(const Device & orig);
void setLink(string alink);
};
#endif
-94
View File
@@ -1,94 +0,0 @@
// DeviceFolder.cpp
// DeviceFolder object for use in devfs
// Author: Josh Holtrop
// Date: 06/03/04
// Modified: 06/09/04
#include "DeviceFolder.h"
#include "Device.h"
#include "lang/LinkedList.h"
#include "kio.h"
void DeviceFolder::ls()
{
LinkedList<Device>::iterator it = devices.begin();
while (it != devices.end())
{
printf("%c", (*it).type);
const char *bitmask = "rwxrwxrwx";
int i = 0;
for (dword mask = 0x100; mask; mask >>= 1)
{
if ((*it).permissions & mask)
printf("%c", bitmask[i]);
else
printf("-");
i++;
}
printf("\t%d\t%d\t", (*it).uid, (*it).gid);
switch ((*it).type)
{
case 'b':
case 'c':
default:
printf("%d, %d\t%s\n", (*it).major, (*it).minor, (*it).name.data());
break;
case 'd':
printf("\t%s/\n", (*it).name.data());
break;
case 'l':
printf("\t%s -> %s\n", (*it).name.data(), (*it).link->data());
break;
}
it++;
}
}
DeviceFolder::DeviceFolder(string location)
{
//initialize . and .. here
}
int DeviceFolder::addDevice(Device dev)
{
int i = 0;
LinkedList<Device>::iterator it = devices.begin();
while (it != devices.end() && (*it).name < dev.name)
{
it++;
i++;
}
if (it != devices.end())
if ((*it).name == dev.name)
return 1; //name conflict
devices.insert(i, dev);
return 0;
}
int DeviceFolder::mkdir(string name, dword uid, dword gid, word permissions)
{
Device dev(name, uid, gid, 0, 0, 'd', permissions);
return addDevice(dev);
}
int DeviceFolder::mklink(string name, dword uid, dword gid, string link)
{
Device dev(name, uid, gid, 0, 0, 'l', 0777);
dev.setLink(link);
return addDevice(dev);
}
int DeviceFolder::mknod(string name, dword uid, dword gid, dword major, dword minor, char type, word permissions)
{
Device dev(name, uid, gid, major, minor, type, permissions);
return addDevice(dev);
}
int DeviceFolder::size()
{
return devices.size();
}
-30
View File
@@ -1,30 +0,0 @@
// DeviceFolder.h
// DeviceFolder object for use in devfs
// Author: Josh Holtrop
// Date: 06/03/04
// Modified: 06/09/04
#ifndef __HOS_DEVICEFOLDER__
#define __HOS_DEVICEFOLDER__ __HOS_DEVICEFOLDER__
#include "lang/LinkedList.h"
#include "Device.h"
#include "kio.h"
class DeviceFolder
{
private:
LinkedList<Device> devices;
int addDevice(Device name);
public:
DeviceFolder(string location);
int size();
int mkdir(string name, dword uid, dword gid, word permissions);
int mklink(string name, dword uid, dword gid, string link);
int mknod(string name, dword uid, dword gid, dword major, dword minor, char type, word permissions);
void ls();
};
#endif
+28
View File
@@ -0,0 +1,28 @@
// Mount.cpp
// Author: Josh Holtrop
// Date: 06/16/04
// Modified: 06/16/04
#include "lang/string.h"
#include "Mount.h"
Mount::Mount()
{
}
Mount::Mount(string dev, string mount)
{
mountPoint = mount;
device = dev;
}
bool Mount::operator==(const Mount & second) const
{
/* Match *either* device or mountPoint to signal an invalid mount attempt */
return (device == second.device || mountPoint == second.mountPoint);
}
+28
View File
@@ -0,0 +1,28 @@
// Mount.h
// Author: Josh Holtrop
// Date: 06/16/04
// Modified: 06/16/04
#ifndef __HOS_MOUNT__
#define __HOS_MOUNT__ __HOS_MOUNT__
#include "hos_defines.h"
class Mount
{
public:
string mountPoint;
string device;
dword major;
dword minor;
Mount();
Mount(string dev, string mount);
bool operator==(const Mount & second) const;
};
#endif
+11 -18
View File
@@ -3,30 +3,23 @@
// device filesystem for HOS
// Author: Josh Holtrop
// Date: 06/03/04
// Modified: 06/10/04
// Modified: 06/16/04
#include "devfs.h"
#include "Device.h"
#include "DeviceFolder.h"
#include "kio.h"
DeviceFolder *dev;
#include "lang/string.h"
#include "vfs.h"
void devfs_init(string mountPoint)
{
printf("I'm going to make a new DeviceFolder\n");
dev = new DeviceFolder(mountPoint);
printf("I'm going to add hda1 to devfs\n");
dev->mknod("hda1", 0, 0, 3, 1, 'b', 0632);
dev->mkdir("test", 0, 501, 0644);
dev->mkdir("test1", 0, 0, 0755);
dev->mkdir("test1", 1, 1, 0644);
dev->mknod("psmouse", 2, 3, 4, 1, 'c', 0677);
dev->mklink("root", 5, 6, "hda1");
printf("I'm going to list the devices i know about:\n");
dev->ls();
// vfs_mount("devfs", mountPoint, 0755, 0, 0);
vfs_mount("devfs ", mountPoint);
vfs_mount("testdev ", "/mnt/win");
vfs_mount("/dev/hda6", "/scratch");
vfs_mount("/dev/rd0 ", "/");
vfs_mount("/dev/sda1", "/mnt/usb");
vfs_mount("sysfs ", "/sys");
vfs_mount("sysfs ", "/tmp");
vfs_mount("otherfs ", "/sys");
}
+1 -2
View File
@@ -8,8 +8,7 @@
#ifndef __HOS_DEVFS__
#define __HOS_DEVFS__ __HOS_DEVFS__
#include "Device.h"
#include "DeviceFolder.h"
#include "lang/string.h"
void devfs_init(string mountPoint);
+33 -7
View File
@@ -1,7 +1,8 @@
// vfs.c
// vfs.cpp
// Author: Josh Holtrop
// Date: 03/11/04
// Modified: 03/16/04
// Modified: 04/16/04
#include "hos_defines.h"
#include "vfs.h"
@@ -12,18 +13,43 @@
#include "lang/string.h"
#include "devfs.h"
#include "kio.h"
//#include "DeviceFolder.h"
#include "Mount.h"
//LinkedList<Mount> *mntList;
LinkedList<Mount> *mounts;
void vfs_init()
{
//mntList = new LinkedList<Mount>;
devfs_init("/dev");
mounts = new LinkedList<Mount>;
}
void list()
{
LinkedList<Mount>::iterator it = mounts->begin();
while (it != mounts->end())
{
printf("%s\t%s\n", (*it).device.data(), (*it).mountPoint.data());
++it;
}
}
int vfs_mount(string device, string mountPoint)
{
Mount mount(device, mountPoint);
LinkedList<Mount>::iterator it = mounts->begin();
int i = 0;
while (it != mounts->end() && (*it).mountPoint <= mount.mountPoint)
{
if (*it == mount)
return 1; //device already mounted or mount point already taken
i++;
++it;
}
mounts->insert(i, mount);
return 0;
}
+5 -1
View File
@@ -1,14 +1,18 @@
// vfs.h
// Author: Josh Holtrop
// Date: 03/11/04
// Modified: 05/21/04
// Modified: 06/16/04
#ifndef __HOS_VFS__
#define __HOS_VFS__ __HOS_VFS__
#include "hos_defines.h"
#include "lang/string.h"
void vfs_init();
int vfs_mount(string device, string mountPoint);
void list();
#endif