95 lines
1.8 KiB
C++
95 lines
1.8 KiB
C++
|
|
// 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();
|
|
}
|
|
|
|
|