/* If the following macro is defined, then the HMC device creates it's own *separateddeviceclass(anddynamicallyassignsamajornumber).Ifnot *definedthentheHMCdeviceisassignedtothe"misc"classdevices. * #defineHMCDRV_DEV_CLASS"hmcftp"
*/
#define HMCDRV_DEV_NAME "hmcdrv" #define HMCDRV_DEV_BUSY_DELAY 500/* delay between -EBUSY trials in ms */ #define HMCDRV_DEV_BUSY_RETRIES 3/* number of retries on -EBUSY */
/* check for non-blocking access, which is really unsupported
*/ if (fp->f_flags & O_NONBLOCK) return -EINVAL;
/* Because it makes no sense to open this device read-only (then a *FTPcommandcannotbeemitted),werespondwithanerror.
*/ if ((fp->f_flags & O_ACCMODE) == O_RDONLY) return -EINVAL;
/* prevent unloading this module as long as anyone holds the *devicefileopen-soincrementthereferencecounthere
*/ if (!try_module_get(THIS_MODULE)) return -ENODEV;
fp->private_data = NULL; /* no command yet */
rc = hmcdrv_ftp_startup(); if (rc)
module_put(THIS_MODULE);
/* *lseek()
*/ static loff_t hmcdrv_dev_seek(struct file *fp, loff_t pos, int whence)
{ switch (whence) { case SEEK_CUR: /* relative to current file position */
pos += fp->f_pos; /* new position stored in 'pos' */ break;
case SEEK_SET: /* absolute (relative to beginning of file) */ break; /* SEEK_SET */
/* We use SEEK_END as a special indicator for a SEEK_SET *(setabsoluteposition),combinedwithaFTPcommand *clear.
*/ case SEEK_END: if (fp->private_data) {
kfree(fp->private_data);
fp->private_data = NULL;
}
/* At this point the character device exists in the kernel (see */proc/devices),butnotunder/devnor/sys/devices/virtual.So *wehavetocreateanassociatedclass(see/sys/class).
*/
hmcdrv_dev_class = class_create(HMCDRV_DEV_CLASS);
if (IS_ERR(hmcdrv_dev_class)) {
rc = PTR_ERR(hmcdrv_dev_class); goto out_devdel;
}
/* Finally a device node in /dev has to be established (as 'mkdev' *doesfromthecommandline).Noticethatassignmentofadevice *nodename/modefunctionisoptional(onlyformode!=0600).
*/
hmcdrv_dev.mode = 0; /* "unset" */
hmcdrv_dev_class->devnode = hmcdrv_dev_name;
dev = device_create(hmcdrv_dev_class, NULL, hmcdrv_dev_no, NULL, "%s", HMCDRV_DEV_NAME); if (!IS_ERR(dev)) return0;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.