본문 바로가기

프로그래밍./Error 메세지

unknown field ‘open’ specified in initializer


/nfsroot/RootFS-S5PC100/a_test/device/kstory_dd.c:17: error: variable ‘kstory_fops’ has initializer but incomplete type
/nfsroot/RootFS-S5PC100/a_test/device/kstory_dd.c:18: error: unknown field ‘open’ specified in initializer
/nfsroot/RootFS-S5PC100/a_test/device/kstory_dd.c:18: warning: excess elements in struct initializer
/nfsroot/RootFS-S5PC100/a_test/device/kstory_dd.c:18: warning: (near initialization for ‘kstory_fops’)
/nfsroot/RootFS-S5PC100/a_test/device/kstory_dd.c:19: error: unknown field ‘read’ specified in initializer
/nfsroot/RootFS-S5PC100/a_test/device/kstory_dd.c:19: warning: excess elements in struct initializer
/nfsroot/RootFS-S5PC100/a_test/device/kstory_dd.c:19: warning: (near initialization for ‘kstory_fops’)
/nfsroot/RootFS-S5PC100/a_test/device/kstory_dd.c:20: error: unknown field ‘write’ specified in initializer
/nfsroot/RootFS-S5PC100/a_test/device/kstory_dd.c:20: warning: excess elements in struct initializer
/nfsroot/RootFS-S5PC100/a_test/device/kstory_dd.c:20: warning: (near initialization for ‘kstory_fops’)
/nfsroot/RootFS-S5PC100/a_test/device/kstory_dd.c:21: error: unknown field ‘ioctl’ specified in initializer
/nfsroot/RootFS-S5PC100/a_test/device/kstory_dd.c:21: warning: excess elements in struct initializer
/nfsroot/RootFS-S5PC100/a_test/device/kstory_dd.c:21: warning: (near initialization for ‘kstory_fops’)
/nfsroot/RootFS-S5PC100/a_test/device/kstory_dd.c:22: error: unknown field ‘release’ specified in initializer
/nfsroot/RootFS-S5PC100/a_test/device/kstory_dd.c:22: warning: excess elements in struct initializer
/nfsroot/RootFS-S5PC100/a_test/device/kstory_dd.c:22: warning: (near initialization for ‘kstory_fops’)
/nfsroot/RootFS-S5PC100/a_test/device/kstory_dd.c: In function ‘module_start’:



이런식으로 나온다면 struct file_operations 을 사용하면서 문제가 생겼을거라 생각된다.
만약. 위 에러처럼 구조체 안에 모든 함수들에서 에러가 걸린다면
구조체를 선언하는 것 자체에서 문제가 생긴 것이다. 아래 소스에 문제가 있다.


사실 한참 허덕였는데, 처음 쓰는 구조체라서.. struct file_operations 인데 s가 빠졌다.


그리고 구조체 안에 여러가지 중에서 한 두가지만 문제가 생긴다면,
함수의 원형과 구조체에서 써준 이름. 함수 정의할 때 이름이 모두 같은지 잘 확인해야 한다.

추가로 구조체에서 함수와 연결하는 부분에서 initialization from incompatible pointer type 이런 경고가 발생한다면
내가 만든 함수의 매개변수들이 구조체의 open과 다른 것이다.

구조체에는 함수 포인터인데, 내가 만든 함수와 매개변수와 같은 형식이 동일해야 한다.
위 경고는 포인터에서 타입이 다르다는 의미이다.


fs.h 안에 아래와 같은 구조체가 정의되어 있다.



struct file_operations 의 원형


그냥 추가적으로, write에는 char에 const가 붙고, read에는 const가 없다는거.
아는 사람은 알겠지만, 코딩하다보면 오타나 그런게 아닐까 하는 의심이 생기기도 하니까.
혹은 복사 & 붙이기 신공을 사용하다가 똑같이 써버릴지도..

char __user
타입은 해더에 정의되어 있으므로 그냥 그대로 작성하면 된다.