-static uint16_t ad_openforks_v2(struct adouble *ad, uint16_t attrbits)
-{
- uint16_t ret = 0;
- struct ad_fd *adf;
- off_t off;
-
- if (!(attrbits & (ATTRBIT_DOPEN | ATTRBIT_ROPEN))) {
- off_t len;
- /* XXX know the locks layout:
- AD_FILELOCK_OPEN_WR is first
- and use it for merging requests
- */
- if (ad_meta_fileno(ad) != -1) {
- /* there's a resource fork test the four bytes for
- * data RW/RD and fork RW/RD locks in one request
- */
- adf = ad->ad_mdp;
- off = LOCK_DATA_WR;
- len = 4;
- }
- else {
- /* no resource fork, only data RD/RW may exist */
- adf = &ad->ad_data_fork;
- off = AD_FILELOCK_OPEN_WR;
- len = 2;
- }
- if (!testlock(adf, off, len))
- return ret;
- }
- /* either there's a lock or we already know one
- fork is open
- */
- if (!(attrbits & ATTRBIT_DOPEN)) {
- if (ad_meta_fileno(ad) != -1) {
- adf = ad->ad_mdp;
- off = LOCK_DATA_WR;
- }
- else {
- adf = &ad->ad_data_fork;
- off = AD_FILELOCK_OPEN_WR;
- }
- ret = testlock(adf, off, 2) > 0? ATTRBIT_DOPEN : 0;
- }
-
- if (!(attrbits & ATTRBIT_ROPEN)) {
- if (ad_meta_fileno(ad) != -1) {
- adf = ad->ad_mdp;
- off = LOCK_RSRC_WR;
- ret |= testlock(adf, off, 2) > 0? ATTRBIT_ROPEN : 0;
- }
- }
-
- return ret;
-}
-
-/* test for sharemode locks, adouble:ea stores them on the datafork */
-static uint16_t ad_openforks_ea(struct adouble *ad, uint16_t attrbits)
-{
- uint16_t ret = 0;
- struct ad_fd *adf;
- off_t off;
- off_t len;
-
- if (ad_data_fileno(ad) == -1)
- return 0;
-
- if (!(attrbits & (ATTRBIT_DOPEN | ATTRBIT_ROPEN))) {
- /* Test all 4 locks at once */
- off = AD_FILELOCK_OPEN_WR;
- len = 4;
- if (testlock(&ad->ad_data_fork, off, len) == 0)
- return 0;
- }
-
- /* either there's a lock or we already know one fork is open */
-
- if (!(attrbits & ATTRBIT_DOPEN)) {
- off = AD_FILELOCK_OPEN_WR;
- ret = testlock(&ad->ad_data_fork, off, 2) > 0 ? ATTRBIT_DOPEN : 0;
- }
-
- if (!(attrbits & ATTRBIT_ROPEN)) {
- off = AD_FILELOCK_RSRC_OPEN_WR;
- ret |= testlock(&ad->ad_data_fork, off, 2) > 0? ATTRBIT_ROPEN : 0;
- }
-
- return ret;
-}
-
-static int ad_testlock_v2(struct adouble *ad, int eid, const off_t off)
-{
- struct ad_fd *adf;
- off_t lock_offset;
-
- lock_offset = off;
- if (eid == ADEID_DFORK) {
- adf = &ad->ad_data_fork;
- if (ad_meta_fileno(ad) != -1) {
- adf = ad->ad_mdp;
- lock_offset = df2off(off);
- }
- } else { /* rfork */
- if (ad_meta_fileno(ad) == -1) {
- /* there's no resource fork. return no lock */
- return 0;
- }
- adf = ad->ad_mdp;
- lock_offset = hf2off(off);
- }
- return testlock(adf, lock_offset, 1);
-}
-
-static int ad_testlock_ea(struct adouble *ad, int eid, const off_t off)
-{
- off_t lock_offset;
-
- if (eid == ADEID_DFORK) {
- lock_offset = off;
- } else { /* rfork */
- lock_offset = rf2off(off);
- }
- return testlock(&ad->ad_data_fork, lock_offset, 1);
-}
-