userland: Pass more sizes with ioctls where we can.
No "functional" change intended.
This commit is contained in:
parent
4c9e8f77e4
commit
9d06690ede
@ -284,7 +284,8 @@ KeyboardDevice::_ControlThread()
|
|||||||
memset(states, 0, sizeof(states));
|
memset(states, 0, sizeof(states));
|
||||||
|
|
||||||
if (fKeyboardID == 0) {
|
if (fKeyboardID == 0) {
|
||||||
if (ioctl(fFD, KB_GET_KEYBOARD_ID, &fKeyboardID) == 0) {
|
if (ioctl(fFD, KB_GET_KEYBOARD_ID, &fKeyboardID,
|
||||||
|
sizeof(fKeyboardID)) == 0) {
|
||||||
BMessage message(IS_SET_KEYBOARD_ID);
|
BMessage message(IS_SET_KEYBOARD_ID);
|
||||||
message.AddInt16("id", fKeyboardID);
|
message.AddInt16("id", fKeyboardID);
|
||||||
be_app->PostMessage(&message);
|
be_app->PostMessage(&message);
|
||||||
@ -529,7 +530,7 @@ KeyboardDevice::_UpdateSettings(uint32 opcode)
|
|||||||
if (get_key_repeat_rate(&fSettings.key_repeat_rate) != B_OK) {
|
if (get_key_repeat_rate(&fSettings.key_repeat_rate) != B_OK) {
|
||||||
LOG_ERR("error when get_key_repeat_rate\n");
|
LOG_ERR("error when get_key_repeat_rate\n");
|
||||||
} else if (ioctl(fFD, KB_SET_KEY_REPEAT_RATE,
|
} else if (ioctl(fFD, KB_SET_KEY_REPEAT_RATE,
|
||||||
&fSettings.key_repeat_rate) != B_OK) {
|
&fSettings.key_repeat_rate, sizeof(int32)) != B_OK) {
|
||||||
LOG_ERR("error when KB_SET_KEY_REPEAT_RATE, fd:%d\n", fFD);
|
LOG_ERR("error when KB_SET_KEY_REPEAT_RATE, fd:%d\n", fFD);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -538,7 +539,7 @@ KeyboardDevice::_UpdateSettings(uint32 opcode)
|
|||||||
if (get_key_repeat_delay(&fSettings.key_repeat_delay) != B_OK) {
|
if (get_key_repeat_delay(&fSettings.key_repeat_delay) != B_OK) {
|
||||||
LOG_ERR("error when get_key_repeat_delay\n");
|
LOG_ERR("error when get_key_repeat_delay\n");
|
||||||
} else if (ioctl(fFD, KB_SET_KEY_REPEAT_DELAY,
|
} else if (ioctl(fFD, KB_SET_KEY_REPEAT_DELAY,
|
||||||
&fSettings.key_repeat_delay) != B_OK) {
|
&fSettings.key_repeat_delay, sizeof(bigtime_t)) != B_OK) {
|
||||||
LOG_ERR("error when KB_SET_KEY_REPEAT_DELAY, fd:%d\n", fFD);
|
LOG_ERR("error when KB_SET_KEY_REPEAT_DELAY, fd:%d\n", fFD);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -570,7 +571,7 @@ KeyboardDevice::_UpdateLEDs()
|
|||||||
if ((fModifiers & B_SCROLL_LOCK) != 0)
|
if ((fModifiers & B_SCROLL_LOCK) != 0)
|
||||||
lockIO[2] = 1;
|
lockIO[2] = 1;
|
||||||
|
|
||||||
ioctl(fFD, KB_SET_LEDS, &lockIO);
|
ioctl(fFD, KB_SET_LEDS, &lockIO, sizeof(lockIO));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -413,7 +413,7 @@ TabletDevice::_UpdateSettings()
|
|||||||
if (get_click_speed(&fSettings.click_speed) != B_OK)
|
if (get_click_speed(&fSettings.click_speed) != B_OK)
|
||||||
LOG_ERR("error when get_click_speed\n");
|
LOG_ERR("error when get_click_speed\n");
|
||||||
else
|
else
|
||||||
ioctl(fDevice, MS_SET_CLICKSPEED, &fSettings.click_speed);
|
ioctl(fDevice, MS_SET_CLICKSPEED, &fSettings.click_speed, sizeof(bigtime_t));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -499,7 +499,8 @@ DataEditor::SetTo(BEntry &entry, const char *attribute)
|
|||||||
} else if (fIsDevice) {
|
} else if (fIsDevice) {
|
||||||
device_geometry geometry;
|
device_geometry geometry;
|
||||||
int device = fFile.Dup();
|
int device = fFile.Dup();
|
||||||
if (device < 0 || ioctl(device, B_GET_GEOMETRY, &geometry) < 0) {
|
if (device < 0 || ioctl(device, B_GET_GEOMETRY, &geometry,
|
||||||
|
sizeof(geometry)) < 0) {
|
||||||
if (device >= 0)
|
if (device >= 0)
|
||||||
close(device);
|
close(device);
|
||||||
fFile.Unset();
|
fFile.Unset();
|
||||||
|
@ -536,7 +536,7 @@ Shell::_Spawn(int row, int col, const ShellParameters& parameters)
|
|||||||
|
|
||||||
struct winsize ws = { handshake.row, handshake.col };
|
struct winsize ws = { handshake.row, handshake.col };
|
||||||
|
|
||||||
ioctl(0, TIOCSWINSZ, &ws);
|
ioctl(0, TIOCSWINSZ, &ws, sizeof(ws));
|
||||||
|
|
||||||
tcsetpgrp(0, getpgrp());
|
tcsetpgrp(0, getpgrp());
|
||||||
// set this process group ID as the controlling terminal
|
// set this process group ID as the controlling terminal
|
||||||
|
@ -56,7 +56,7 @@ error(const char* message, ...)
|
|||||||
|
|
||||||
va_list args;
|
va_list args;
|
||||||
va_start(args, message);
|
va_start(args, message);
|
||||||
|
|
||||||
vsnprintf(buffer, sizeof(buffer), message, args);
|
vsnprintf(buffer, sizeof(buffer), message, args);
|
||||||
|
|
||||||
va_end(args);
|
va_end(args);
|
||||||
@ -79,7 +79,7 @@ update_leds(int fd, uint32 modifiers)
|
|||||||
if ((modifiers & B_SCROLL_LOCK) != 0)
|
if ((modifiers & B_SCROLL_LOCK) != 0)
|
||||||
lockIO[2] = 1;
|
lockIO[2] = 1;
|
||||||
|
|
||||||
ioctl(fd, KB_SET_LEDS, &lockIO);
|
ioctl(fd, KB_SET_LEDS, &lockIO, sizeof(lockIO));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -106,7 +106,8 @@ keyboard_reader(void* arg)
|
|||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
raw_key_info rawKeyInfo;
|
raw_key_info rawKeyInfo;
|
||||||
if (ioctl(keyboard->device, KB_READ, &rawKeyInfo) != 0)
|
if (ioctl(keyboard->device, KB_READ, &rawKeyInfo,
|
||||||
|
sizeof(rawKeyInfo)) != 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
uint32 keycode = rawKeyInfo.keycode;
|
uint32 keycode = rawKeyInfo.keycode;
|
||||||
@ -313,7 +314,7 @@ start_console(struct console* con)
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
snprintf(name, sizeof(name), "/dev/pt/%s", entry->d_name);
|
snprintf(name, sizeof(name), "/dev/pt/%s", entry->d_name);
|
||||||
|
|
||||||
con->tty_master_fd = open(name, O_RDWR);
|
con->tty_master_fd = open(name, O_RDWR);
|
||||||
if (con->tty_master_fd >= 0) {
|
if (con->tty_master_fd >= 0) {
|
||||||
snprintf(name, sizeof(name), "/dev/tt/%s", entry->d_name);
|
snprintf(name, sizeof(name), "/dev/tt/%s", entry->d_name);
|
||||||
|
@ -412,7 +412,7 @@ command_list(int argc, const char* const* argv)
|
|||||||
|
|
||||||
// issue the request
|
// issue the request
|
||||||
ram_disk_ioctl_info request;
|
ram_disk_ioctl_info request;
|
||||||
if (ioctl(fd, RAM_DISK_IOCTL_INFO, &request) < 0)
|
if (ioctl(fd, RAM_DISK_IOCTL_INFO, &request, sizeof(request)) < 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
int32 rowIndex = table.CountRows();
|
int32 rowIndex = table.CountRows();
|
||||||
|
@ -20,8 +20,8 @@
|
|||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
|
|
||||||
|
|
||||||
/* The directory where the serial driver publishes its devices */
|
/* The directory where the serial driver publishes its devices */
|
||||||
#define SERIAL_DIR "/dev/ports"
|
#define SERIAL_DIR "/dev/ports"
|
||||||
|
|
||||||
// Scans a directory and adds the entries it founds as strings to the
|
// Scans a directory and adds the entries it founds as strings to the
|
||||||
// given list
|
// given list
|
||||||
@ -31,19 +31,19 @@ scan_directory(const char *directory, BList *list)
|
|||||||
BEntry entry;
|
BEntry entry;
|
||||||
BDirectory dir(SERIAL_DIR);
|
BDirectory dir(SERIAL_DIR);
|
||||||
char buf[B_OS_NAME_LENGTH];
|
char buf[B_OS_NAME_LENGTH];
|
||||||
|
|
||||||
ASSERT(list != NULL);
|
ASSERT(list != NULL);
|
||||||
while (dir.GetNextEntry(&entry) == B_OK) {
|
while (dir.GetNextEntry(&entry) == B_OK) {
|
||||||
entry.GetName(buf);
|
entry.GetName(buf);
|
||||||
list->AddItem(strdup(buf));
|
list->AddItem(strdup(buf));
|
||||||
};
|
};
|
||||||
|
|
||||||
return list->CountItems();
|
return list->CountItems();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*! \brief Creates and initializes a BSerialPort object.
|
/*! \brief Creates and initializes a BSerialPort object.
|
||||||
|
|
||||||
Query the driver, and builds a list of the available
|
Query the driver, and builds a list of the available
|
||||||
serial ports.
|
serial ports.
|
||||||
The BSerialPort object is initialized to these values:
|
The BSerialPort object is initialized to these values:
|
||||||
@ -73,17 +73,17 @@ BSerialPort::BSerialPort()
|
|||||||
|
|
||||||
/*! \brief Frees the resources associated with the object.
|
/*! \brief Frees the resources associated with the object.
|
||||||
Closes the port, if it's open, and deletes the devices list.
|
Closes the port, if it's open, and deletes the devices list.
|
||||||
*/
|
*/
|
||||||
BSerialPort::~BSerialPort()
|
BSerialPort::~BSerialPort()
|
||||||
{
|
{
|
||||||
if (ffd >= 0)
|
if (ffd >= 0)
|
||||||
close(ffd);
|
close(ffd);
|
||||||
|
|
||||||
if (fDevices != NULL) {
|
if (fDevices != NULL) {
|
||||||
for (int32 count = fDevices->CountItems() - 1; count >= 0; count--)
|
for (int32 count = fDevices->CountItems() - 1; count >= 0; count--)
|
||||||
free(fDevices->RemoveItem(count));
|
free(fDevices->RemoveItem(count));
|
||||||
delete fDevices;
|
delete fDevices;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -98,36 +98,36 @@ status_t
|
|||||||
BSerialPort::Open(const char *portName)
|
BSerialPort::Open(const char *portName)
|
||||||
{
|
{
|
||||||
char buf[64];
|
char buf[64];
|
||||||
|
|
||||||
if (portName == NULL)
|
if (portName == NULL)
|
||||||
return B_BAD_VALUE; // Heheee, we won't crash
|
return B_BAD_VALUE; // Heheee, we won't crash
|
||||||
|
|
||||||
if (portName[0] != '/')
|
if (portName[0] != '/')
|
||||||
snprintf(buf, 64, SERIAL_DIR"/%s", portName);
|
snprintf(buf, 64, SERIAL_DIR"/%s", portName);
|
||||||
else
|
else
|
||||||
// A name like "/dev/ports/serial2" was passed
|
// A name like "/dev/ports/serial2" was passed
|
||||||
snprintf(buf, 64, "%s", portName);
|
snprintf(buf, 64, "%s", portName);
|
||||||
|
|
||||||
if (ffd >= 0) //If this port is already open, close it
|
if (ffd >= 0) //If this port is already open, close it
|
||||||
close(ffd);
|
close(ffd);
|
||||||
|
|
||||||
// TODO: BeOS don't use O_EXCL, and this seems to lead
|
// TODO: BeOS don't use O_EXCL, and this seems to lead
|
||||||
// to some issues. I added this flag having read some comments
|
// to some issues. I added this flag having read some comments
|
||||||
// by Marco Nelissen on the annotated BeBook.
|
// by Marco Nelissen on the annotated BeBook.
|
||||||
// I think BeOS uses O_RDWR|O_NONBLOCK here.
|
// I think BeOS uses O_RDWR|O_NONBLOCK here.
|
||||||
ffd = open(buf, O_RDWR | O_NONBLOCK | O_EXCL);
|
ffd = open(buf, O_RDWR | O_NONBLOCK | O_EXCL);
|
||||||
|
|
||||||
if (ffd >= 0) {
|
if (ffd >= 0) {
|
||||||
// we used open() with O_NONBLOCK flag to let it return immediately,
|
// we used open() with O_NONBLOCK flag to let it return immediately,
|
||||||
// but we want read/write operations to block if needed,
|
// but we want read/write operations to block if needed,
|
||||||
// so we clear that bit here.
|
// so we clear that bit here.
|
||||||
int flags = fcntl(ffd, F_GETFL);
|
int flags = fcntl(ffd, F_GETFL);
|
||||||
fcntl(ffd, F_SETFL, flags & ~O_NONBLOCK);
|
fcntl(ffd, F_SETFL, flags & ~O_NONBLOCK);
|
||||||
|
|
||||||
_DriverControl();
|
_DriverControl();
|
||||||
}
|
}
|
||||||
// TODO: I wonder why the return type is a status_t,
|
// TODO: I wonder why the return type is a status_t,
|
||||||
// since we (as BeOS does) return the descriptor number for the device...
|
// since we (as BeOS does) return the descriptor number for the device...
|
||||||
return (ffd >= 0) ? ffd : errno;
|
return (ffd >= 0) ? ffd : errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -152,7 +152,7 @@ ssize_t
|
|||||||
BSerialPort::Read(void *buf, size_t count)
|
BSerialPort::Read(void *buf, size_t count)
|
||||||
{
|
{
|
||||||
ssize_t err = read(ffd, buf, count);
|
ssize_t err = read(ffd, buf, count);
|
||||||
|
|
||||||
return (err >= 0) ? err : errno;
|
return (err >= 0) ? err : errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -165,7 +165,7 @@ ssize_t
|
|||||||
BSerialPort::Write(const void *buf, size_t count)
|
BSerialPort::Write(const void *buf, size_t count)
|
||||||
{
|
{
|
||||||
ssize_t err = write(ffd, buf, count);
|
ssize_t err = write(ffd, buf, count);
|
||||||
|
|
||||||
return (err >= 0) ? err : errno;
|
return (err >= 0) ? err : errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -190,9 +190,9 @@ BSerialPort::SetBlocking(bool Blocking)
|
|||||||
*/
|
*/
|
||||||
status_t
|
status_t
|
||||||
BSerialPort::SetTimeout(bigtime_t microSeconds)
|
BSerialPort::SetTimeout(bigtime_t microSeconds)
|
||||||
{
|
{
|
||||||
status_t err = B_BAD_VALUE;
|
status_t err = B_BAD_VALUE;
|
||||||
|
|
||||||
if (microSeconds == B_INFINITE_TIMEOUT || microSeconds <= 25000000) {
|
if (microSeconds == B_INFINITE_TIMEOUT || microSeconds <= 25000000) {
|
||||||
fTimeout = microSeconds;
|
fTimeout = microSeconds;
|
||||||
_DriverControl();
|
_DriverControl();
|
||||||
@ -225,7 +225,7 @@ BSerialPort::SetTimeout(bigtime_t microSeconds)
|
|||||||
- \c B_115200_BPS
|
- \c B_115200_BPS
|
||||||
- \c B_230400_BPS
|
- \c B_230400_BPS
|
||||||
- \c B_31250_BPS
|
- \c B_31250_BPS
|
||||||
\return
|
\return
|
||||||
- \c B_OK if all goes fine,
|
- \c B_OK if all goes fine,
|
||||||
- an error code if something goes wrong.
|
- an error code if something goes wrong.
|
||||||
*/
|
*/
|
||||||
@ -233,7 +233,7 @@ status_t
|
|||||||
BSerialPort::SetDataRate(data_rate bitsPerSecond)
|
BSerialPort::SetDataRate(data_rate bitsPerSecond)
|
||||||
{
|
{
|
||||||
fBaudRate = bitsPerSecond;
|
fBaudRate = bitsPerSecond;
|
||||||
|
|
||||||
return _DriverControl();
|
return _DriverControl();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -352,7 +352,7 @@ BSerialPort::SetFlowControl(uint32 method)
|
|||||||
|
|
||||||
|
|
||||||
/*! \brief Returns the selected flow control.
|
/*! \brief Returns the selected flow control.
|
||||||
\return The flow control for the current open port.
|
\return The flow control for the current open port.
|
||||||
*/
|
*/
|
||||||
uint32
|
uint32
|
||||||
BSerialPort::FlowControl(void)
|
BSerialPort::FlowControl(void)
|
||||||
@ -365,8 +365,8 @@ BSerialPort::FlowControl(void)
|
|||||||
status_t
|
status_t
|
||||||
BSerialPort::SetDTR(bool asserted)
|
BSerialPort::SetDTR(bool asserted)
|
||||||
{
|
{
|
||||||
status_t status = ioctl(ffd, TCSETDTR, &asserted);
|
status_t status = ioctl(ffd, TCSETDTR, &asserted, sizeof(asserted));
|
||||||
|
|
||||||
return (status >= 0) ? status : errno;
|
return (status >= 0) ? status : errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -375,8 +375,8 @@ BSerialPort::SetDTR(bool asserted)
|
|||||||
status_t
|
status_t
|
||||||
BSerialPort::SetRTS(bool asserted)
|
BSerialPort::SetRTS(bool asserted)
|
||||||
{
|
{
|
||||||
status_t status = ioctl(ffd, TCSETRTS, &asserted);
|
status_t status = ioctl(ffd, TCSETRTS, &asserted, sizeof(asserted));
|
||||||
|
|
||||||
return (status >= 0) ? status : errno;
|
return (status >= 0) ? status : errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -392,8 +392,8 @@ BSerialPort::NumCharsAvailable(int32 *numChars)
|
|||||||
//No help from the BeBook...
|
//No help from the BeBook...
|
||||||
if (ffd < 0)
|
if (ffd < 0)
|
||||||
return B_NO_INIT;
|
return B_NO_INIT;
|
||||||
|
|
||||||
// TODO: Implement ?
|
// TODO: Implement ?
|
||||||
if (numChars)
|
if (numChars)
|
||||||
*numChars = 0;
|
*numChars = 0;
|
||||||
return B_OK;
|
return B_OK;
|
||||||
@ -406,11 +406,11 @@ BSerialPort::NumCharsAvailable(int32 *numChars)
|
|||||||
bool
|
bool
|
||||||
BSerialPort::IsCTS(void)
|
BSerialPort::IsCTS(void)
|
||||||
{
|
{
|
||||||
unsigned int bits = ioctl(ffd, TCGETBITS, 0);
|
unsigned int bits = ioctl(ffd, TCGETBITS, 0);
|
||||||
|
|
||||||
if (bits & TCGB_CTS)
|
if (bits & TCGB_CTS)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -421,11 +421,11 @@ BSerialPort::IsCTS(void)
|
|||||||
bool
|
bool
|
||||||
BSerialPort::IsDSR(void)
|
BSerialPort::IsDSR(void)
|
||||||
{
|
{
|
||||||
unsigned int bits = ioctl(ffd, TCGETBITS, 0);
|
unsigned int bits = ioctl(ffd, TCGETBITS, 0);
|
||||||
|
|
||||||
if (bits & TCGB_DSR)
|
if (bits & TCGB_DSR)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -436,11 +436,11 @@ BSerialPort::IsDSR(void)
|
|||||||
bool
|
bool
|
||||||
BSerialPort::IsRI(void)
|
BSerialPort::IsRI(void)
|
||||||
{
|
{
|
||||||
unsigned int bits = ioctl(ffd, TCGETBITS, 0);
|
unsigned int bits = ioctl(ffd, TCGETBITS, 0);
|
||||||
|
|
||||||
if (bits & TCGB_RI)
|
if (bits & TCGB_RI)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -451,11 +451,11 @@ BSerialPort::IsRI(void)
|
|||||||
bool
|
bool
|
||||||
BSerialPort::IsDCD(void)
|
BSerialPort::IsDCD(void)
|
||||||
{
|
{
|
||||||
unsigned int bits = ioctl(ffd, TCGETBITS, 0);
|
unsigned int bits = ioctl(ffd, TCGETBITS, 0);
|
||||||
|
|
||||||
if (bits & TCGB_DCD)
|
if (bits & TCGB_DCD)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -471,7 +471,7 @@ BSerialPort::WaitForInput(void)
|
|||||||
{
|
{
|
||||||
ssize_t size;
|
ssize_t size;
|
||||||
int err = ioctl(ffd, TCWAITEVENT, &size, sizeof size);
|
int err = ioctl(ffd, TCWAITEVENT, &size, sizeof size);
|
||||||
|
|
||||||
return (err < B_OK) ? errno : size;
|
return (err < B_OK) ? errno : size;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -484,14 +484,14 @@ int32
|
|||||||
BSerialPort::CountDevices()
|
BSerialPort::CountDevices()
|
||||||
{
|
{
|
||||||
int32 count = 0;
|
int32 count = 0;
|
||||||
|
|
||||||
// Refresh devices list
|
// Refresh devices list
|
||||||
_ScanDevices();
|
_ScanDevices();
|
||||||
|
|
||||||
if (fDevices != NULL)
|
if (fDevices != NULL)
|
||||||
count = fDevices->CountItems();
|
count = fDevices->CountItems();
|
||||||
|
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -508,7 +508,7 @@ BSerialPort::GetDeviceName(int32 n, char *name, size_t bufSize)
|
|||||||
{
|
{
|
||||||
status_t result = B_ERROR;
|
status_t result = B_ERROR;
|
||||||
const char *dev = NULL;
|
const char *dev = NULL;
|
||||||
|
|
||||||
if (fDevices != NULL)
|
if (fDevices != NULL)
|
||||||
dev = static_cast<char*>(fDevices->ItemAt(n));
|
dev = static_cast<char*>(fDevices->ItemAt(n));
|
||||||
|
|
||||||
@ -525,7 +525,7 @@ BSerialPort::GetDeviceName(int32 n, char *name, size_t bufSize)
|
|||||||
|
|
||||||
/*! \brief Build a list of available serial ports.
|
/*! \brief Build a list of available serial ports.
|
||||||
Query the serial driver about the available devices,
|
Query the serial driver about the available devices,
|
||||||
and build a list of them.
|
and build a list of them.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
BSerialPort::_ScanDevices()
|
BSerialPort::_ScanDevices()
|
||||||
@ -534,9 +534,9 @@ BSerialPort::_ScanDevices()
|
|||||||
if (fDevices != NULL) {
|
if (fDevices != NULL) {
|
||||||
for (int32 count = fDevices->CountItems() - 1; count >= 0; count--)
|
for (int32 count = fDevices->CountItems() - 1; count >= 0; count--)
|
||||||
free(fDevices->RemoveItem(count));
|
free(fDevices->RemoveItem(count));
|
||||||
|
|
||||||
// Add devices to the list
|
// Add devices to the list
|
||||||
scan_directory(SERIAL_DIR, fDevices);
|
scan_directory(SERIAL_DIR, fDevices);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -551,67 +551,67 @@ BSerialPort::_DriverControl()
|
|||||||
{
|
{
|
||||||
struct termios options;
|
struct termios options;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
if (ffd < 0)
|
if (ffd < 0)
|
||||||
return B_NO_INIT;
|
return B_NO_INIT;
|
||||||
|
|
||||||
//Load the current settings
|
//Load the current settings
|
||||||
err = tcgetattr(ffd, &options);
|
err = tcgetattr(ffd, &options);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
return errno;
|
return errno;
|
||||||
|
|
||||||
// Reset all flags
|
// Reset all flags
|
||||||
options.c_iflag &= ~(IXON | IXOFF | IXANY | INPCK);
|
options.c_iflag &= ~(IXON | IXOFF | IXANY | INPCK);
|
||||||
options.c_cflag &= ~(CRTSCTS | CSIZE | CSTOPB | PARODD | PARENB);
|
options.c_cflag &= ~(CRTSCTS | CSIZE | CSTOPB | PARODD | PARENB);
|
||||||
options.c_lflag &= ~(ECHO | ECHONL | ISIG | ICANON);
|
options.c_lflag &= ~(ECHO | ECHONL | ISIG | ICANON);
|
||||||
|
|
||||||
// Local line
|
// Local line
|
||||||
options.c_cflag |= CLOCAL;
|
options.c_cflag |= CLOCAL;
|
||||||
|
|
||||||
//Set the flags to the wanted values
|
//Set the flags to the wanted values
|
||||||
if (fFlow & B_HARDWARE_CONTROL)
|
if (fFlow & B_HARDWARE_CONTROL)
|
||||||
options.c_cflag |= CRTSCTS;
|
options.c_cflag |= CRTSCTS;
|
||||||
|
|
||||||
if (fFlow & B_SOFTWARE_CONTROL)
|
if (fFlow & B_SOFTWARE_CONTROL)
|
||||||
options.c_iflag |= (IXON | IXOFF);
|
options.c_iflag |= (IXON | IXOFF);
|
||||||
|
|
||||||
if (fStopBits & B_STOP_BITS_2)
|
if (fStopBits & B_STOP_BITS_2)
|
||||||
options.c_cflag |= CSTOPB; // Set 2 stop bits
|
options.c_cflag |= CSTOPB; // Set 2 stop bits
|
||||||
|
|
||||||
if (fDataBits & B_DATA_BITS_8)
|
if (fDataBits & B_DATA_BITS_8)
|
||||||
options.c_cflag |= CS8; // Set 8 data bits
|
options.c_cflag |= CS8; // Set 8 data bits
|
||||||
|
|
||||||
//Ok, set the parity now
|
//Ok, set the parity now
|
||||||
if (fParityMode != B_NO_PARITY) {
|
if (fParityMode != B_NO_PARITY) {
|
||||||
options.c_cflag |= PARENB; //Enable parity
|
options.c_cflag |= PARENB; //Enable parity
|
||||||
if (fParityMode == B_ODD_PARITY)
|
if (fParityMode == B_ODD_PARITY)
|
||||||
options.c_cflag |= PARODD; //Select odd parity
|
options.c_cflag |= PARODD; //Select odd parity
|
||||||
}
|
}
|
||||||
|
|
||||||
//Set the baud rate
|
//Set the baud rate
|
||||||
cfsetispeed(&options, fBaudRate);
|
cfsetispeed(&options, fBaudRate);
|
||||||
cfsetospeed(&options, fBaudRate);
|
cfsetospeed(&options, fBaudRate);
|
||||||
|
|
||||||
//Set the timeout
|
//Set the timeout
|
||||||
options.c_cc[VTIME] = 0;
|
options.c_cc[VTIME] = 0;
|
||||||
options.c_cc[VMIN] = 0;
|
options.c_cc[VMIN] = 0;
|
||||||
if (fBlocking) {
|
if (fBlocking) {
|
||||||
if (fTimeout == B_INFINITE_TIMEOUT) {
|
if (fTimeout == B_INFINITE_TIMEOUT) {
|
||||||
options.c_cc[VMIN] = 1;
|
options.c_cc[VMIN] = 1;
|
||||||
} else if (fTimeout != 0) {
|
} else if (fTimeout != 0) {
|
||||||
int timeout = fTimeout / 100000;
|
int timeout = fTimeout / 100000;
|
||||||
options.c_cc[VTIME] = (timeout == 0) ? 1 : timeout;
|
options.c_cc[VTIME] = (timeout == 0) ? 1 : timeout;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Ok, finished. Now tell the driver what we decided
|
//Ok, finished. Now tell the driver what we decided
|
||||||
err = tcsetattr(ffd, TCSANOW, &options);
|
err = tcsetattr(ffd, TCSANOW, &options);
|
||||||
|
|
||||||
return (err >= 0) ? err : errno;
|
return (err >= 0) ? err : errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* These functions are here to maintain Binary Compatibility */
|
/* These functions are here to maintain Binary Compatibility */
|
||||||
void BSerialPort::_ReservedSerialPort1() {}
|
void BSerialPort::_ReservedSerialPort1() {}
|
||||||
void BSerialPort::_ReservedSerialPort2() {}
|
void BSerialPort::_ReservedSerialPort2() {}
|
||||||
void BSerialPort::_ReservedSerialPort3() {}
|
void BSerialPort::_ReservedSerialPort3() {}
|
||||||
|
@ -118,7 +118,7 @@ get_device_icon(const char* device, void* icon, int32 size)
|
|||||||
// attributes. Should those attributes override the icon returned by
|
// attributes. Should those attributes override the icon returned by
|
||||||
// ioctl(,B_GET_ICON,)?
|
// ioctl(,B_GET_ICON,)?
|
||||||
device_icon iconData = {size, icon};
|
device_icon iconData = {size, icon};
|
||||||
if (ioctl(fd, B_GET_ICON, &iconData) != 0) {
|
if (ioctl(fd, B_GET_ICON, &iconData, sizeof(device_icon)) != 0) {
|
||||||
// legacy icon was not available, try vector icon
|
// legacy icon was not available, try vector icon
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
@ -230,7 +230,7 @@ get_device_icon(const char* device, uint8** _data, size_t* _size,
|
|||||||
// Try to get the icon by name first
|
// Try to get the icon by name first
|
||||||
|
|
||||||
char name[B_FILE_NAME_LENGTH];
|
char name[B_FILE_NAME_LENGTH];
|
||||||
if (ioctl(fd, B_GET_ICON_NAME, name) >= 0) {
|
if (ioctl(fd, B_GET_ICON_NAME, name, sizeof(name)) >= 0) {
|
||||||
status_t status = get_named_icon(name, _data, _size, _type);
|
status_t status = get_named_icon(name, _data, _size, _type);
|
||||||
if (status == B_OK) {
|
if (status == B_OK) {
|
||||||
close(fd);
|
close(fd);
|
||||||
|
@ -508,13 +508,13 @@ Services::_Listener()
|
|||||||
if (connection.Type() == SOCK_STREAM) {
|
if (connection.Type() == SOCK_STREAM) {
|
||||||
// accept incoming connection
|
// accept incoming connection
|
||||||
int value = 1;
|
int value = 1;
|
||||||
ioctl(i, FIONBIO, &value);
|
ioctl(i, FIONBIO, &value, sizeof(value));
|
||||||
// make sure we don't wait for the connection
|
// make sure we don't wait for the connection
|
||||||
|
|
||||||
socket = accept(connection.socket, NULL, NULL);
|
socket = accept(connection.socket, NULL, NULL);
|
||||||
|
|
||||||
value = 0;
|
value = 0;
|
||||||
ioctl(i, FIONBIO, &value);
|
ioctl(i, FIONBIO, &value, sizeof(value));
|
||||||
|
|
||||||
if (socket < 0)
|
if (socket < 0)
|
||||||
continue;
|
continue;
|
||||||
|
Loading…
Reference in New Issue
Block a user