Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

335
Vistas
¿Cómo obtener el número menor de un archivo en un controlador de Linux?

¿Hay una mejor solución para obtener el número menor?

¿Puedo evitar comprobar la versión del kernel?

 static long unlocked_ioctl(struct file *f, unsigned int o, unsigned long d) { #if KERNEL_VERSION(3, 18, 0) > LINUX_VERSION_CODE struct inode* inode = f->f_dentry->d_inode; #else struct inode* inode = f->f_path.dentry->d_inode; #endif int minor = iminor(inode); }
over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

Sí, hay una mejor manera: no se moleste en mirar el dentry cuando lo que quiere está allí como un campo de struct file .

 struct file { union { struct llist_node fu_llist; struct rcu_head fu_rcuhead; } f_u; struct path f_path; struct inode *f_inode; // <-- here's your inode // ... }

Puede acceder a f->f_inode directamente o usar la función file_inode() , de esta manera también puede evitar las comprobaciones de la versión del kernel.

 static long unlocked_ioctl(struct file *f, unsigned int o, unsigned long d) { int minor = iminor(file_inode(f)); // ... }
over 4 years ago · Santiago Trujillo Denunciar

0

Como complemento a la respuesta de Marco Bonelli, se agregó file_inode() en el kernel 3.9, por lo que si es necesario admitir versiones anteriores del kernel, se debe agregar algún código de compatibilidad del kernel. Yo uso algo como lo siguiente:

 /* * The file_dentry() inline function was added in kernel version 4.6.0. * Emulate it for earlier kernels. */ #if LINUX_VERSION_CODE < KERNEL_VERSION(4,6,0) static inline struct dentry *kcompat_file_dentry(const struct file *f) { #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20) return f->f_dentry; #else return f->f_path.dentry; #endif } #undef file_dentry #define file_dentry(f) kcompat_file_dentry(f) #endif /* * The file_inode() inline function was added in kernel 3.9.0. * Emulate it for earlier kernels. */ #if LINUX_VERSION_CODE < KERNEL_VERSION(3,9,0) static inline struct inode *kcompat_file_inode(struct file *f) { return file_dentry(f)->d_inode; } #undef file_inode #define file_inode(f) kcompat_file_inode(f) #endif
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda